- #include "Mini51.h"
- #include "DrvGPIO.h"
- #include "DrvSYS.h"
- void EINT0Callback(void);
- void delay_ms(uint32_t count);
- void clock_init(void);
- void port_init(void);
- void eint0_init(void);
- void sys_init(void);
- uint8_t count;
- void delay_ms(uint32_t count)
- {
- uint32_t i,j;
- for(i=count;i>0;i--)
- for(j=2395;j>0;j--);
- }
- void clock_init(void)
- {
- UNLOCKREG();
- DrvSYS_Open(XTL_CLK);// external 12M as clock
- while (DrvSYS_GetChipClockSourceStatus(XTL_CLK) != 1); //use delay is ok too
- LOCKREG();
- }
- void port_init(void)
- {
- DrvGPIO_Open(E_PORT3, E_PIN1, E_IO_OUTPUT);//LED0
- DrvGPIO_Open(E_PORT3, E_PIN6, E_IO_OUTPUT);//LED1
- DrvGPIO_Open(E_PORT5, E_PIN2, E_IO_OUTPUT);//LED2
- DrvGPIO_Open(E_PORT2, E_PIN6, E_IO_OUTPUT);//LED3
- }
- void eint0_init(void)
- {
- DrvGPIO_InitFunction(FUNC_EXTINT0);
- DrvGPIO_EnableEINT(E_EINT0_PIN, E_IO_FALLING, E_MODE_EDGE, EINT0Callback);
- }
- void EINT0Callback(void)
- {
- DrvGPIO_DisableEINT (E_EINT0_PIN);//disable intp0
- delay_ms(20); //chattering ignore
- if (DrvGPIO_GetBit (E_PORT3, E_PIN2)== 0)////chattering ignore
- {
- count=!count;
- }
- DrvGPIO_EnableEINT(E_EINT0_PIN, E_IO_FALLING, E_MODE_EDGE, EINT0Callback); //enable intp0 again
- }
- void sys_init(void)
- {
- clock_init();
- port_init();
- eint0_init();
- }
- int main (void)
- {
- sys_init();
- while(1)
- {
- if(count)
- DrvGPIO_ClrBit(E_PORT3, 1);
- else
- DrvGPIO_SetBit(E_PORT3, 1);
- }
- }
|