123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- #include <stdarg.h>
- #include "yc11xx.h"
- #include "ycdef.h"
- #include "yc11xx_gpio.h"
- #define KEY_ON 0
- #define KEY_OFF 1
- #define KEY_SCAN_GPIO 23
- #define LED_GPIO 28
- #define Led_Run(x) GPIO_CONFIG(x) = (GPIO_CONFIG(x)==GPCFG_OUTPUT_HIGH)? GPCFG_OUTPUT_LOW: GPCFG_OUTPUT_HIGH;
- /**
- *@brief Configure led gpio output.
- *@param Gpio: gpio number.
- *@param St false low, true high.
- *@return None.
- */
- void Led_Gpio_Config(uint8_t Gpio,bool St)
- {
- GPIO_SetOutput(Gpio,St);
- }
- /**
- *@brief check key scan gpio status KEY_ON:input low; KEY_OFF: high.
- *@param Gpio: gpio number.
- *@return KEY_ON
- *@return KEY_ OFF
- */
- uint8_t Key_Scan(uint8_t Gpio)
- {
- if(GPIO_GetInputStatus(Gpio) == KEY_ON)
- {
- while(GPIO_GetInputStatus(Gpio) == KEY_ON)
- return KEY_ON;
- }
- else
- return KEY_OFF;
-
- }
- void delay_ems(uint32_t time)
- {
- unsigned int cnt,j;
- for(cnt=0;cnt<time;cnt++)
- {
- for(j=0;j<4000;j++);
- }
- }
- void delay_eus(uint32_t time)
- {
- while(time--)
- {
- for(int i=0;i<250000;i++);
- }
- }
- /**
- *@brief Configure key scan gpio input.
- *@param Gpio: gpio number.
- *@param St false pullup, true pulldown.
- *@return None.
- */
- void Key_Gpio_Config(uint8_t Gpio,bool St)
- {
- GPIO_SetInput(Gpio,St);
- }
- int main(void)
- {
- Key_Gpio_Config(KEY_SCAN_GPIO,false);
- Led_Gpio_Config(LED_GPIO,true);
- delay_eus(10000);
- Led_Gpio_Config(LED_GPIO,false);
- delay_eus(10);
- Led_Gpio_Config(LED_GPIO,true);
- while(1)
- {
- if(Key_Scan(KEY_SCAN_GPIO) == KEY_ON)
- {
- Led_Gpio_Config(LED_GPIO,false);
- Led_Gpio_Config(LED_GPIO,true);
- }
- }
- }
|