在这个程序中,当按下板子上的一个按键时,蜂鸣器发出鸣叫声。当按下另一个按键时,停止发出鸣叫声。
- #include <stdio.h>
- #include "DrvGPIO.h"
- #include "DrvSYS.h"
- #include "NUC1xx.h"
- void delay(uint32_t i)
- {
- uint32_t j;
- while(i--)
- {
- for(j=0;j<1000;j++);
- }
- }
- int main ()
- {
- UNLOCKREG();
- SYSCLK->PWRCON.XTL12M_EN=1;
- LOCKREG();
-
- DrvGPIO_Open(E_GPA,2, E_IO_OUTPUT);
- DrvGPIO_Open(E_GPA,3, E_IO_OUTPUT);
- DrvGPIO_Open(E_GPA,4, E_IO_OUTPUT);
- DrvGPIO_Open(E_GPA,5, E_IO_OUTPUT);
- DrvGPIO_Open(E_GPB,14,E_IO_INPUT );
- DrvGPIO_Open(E_GPB,15,E_IO_INPUT );
- DrvGPIO_Open(E_GPB,10,E_IO_OUTPUT);
- while(1)
- {
- if (DrvGPIO_GetBit(E_GPB,14) == 0)
- {
- DrvGPIO_ClrBit(E_GPB,10);
- }
- if (DrvGPIO_GetBit(E_GPB,15) == 0)
- {
- DrvGPIO_SetBit(E_GPB,10);
- }
- }
- }
|