有工程代码附件可以下载
这是个汇编文件
- init.s
- IMPORT Main
- AREA |C$$code|, CODE, READONLY
- global start
- start
- bl Main
- END
这个是C文件
- #define rGPFCON (*(volatile unsigned *)(0x7F0080A0))
- #define rGPFDAT (*(volatile unsigned *)(0x7F0080A4))
- #define rGPFPUD (*(volatile unsigned *)(0x7F0080A8))
- #define rGPNCON (*(volatile unsigned *)(0x7F008830))
- #define rGPNDAT (*(volatile unsigned *)(0x7F008834))
- #define rGPNPUD (*(volatile unsigned *)(0x7F008838))
- void msDelay(int time)
- {
- volatile unsigned int i,j;
- for(i = 0; i < 200000; i++)
- for(j=0; j<time; j++);
- }
- void GPIO_Init(void)
- {
- rGPFCON = rGPFCON & (~(0x1 << (31)));
- rGPFCON = rGPFCON | (0x1 << (2*15));
- rGPFPUD = rGPFPUD & (~(0x3 << (2*15)));
- rGPFDAT = rGPFDAT & 0x7ffff;
- rGPNCON = rGPNCON & (0xffffffff << (2*6));
- }
- void BeepOff(void)
- {
- rGPFDAT = rGPFDAT & 0x7fff;
- }
- void BeepOn(void)
- {
- rGPFDAT = rGPFDAT | 0x8000;
- }
- unsigned int KeyScan(void)
- {
- if((rGPNDAT & 0X3f) != 0x3f)
- return 1;
- else
- return 0;
- }
- void KeyTest(void)
- {
- unsigned int KeyStatus;
- while(1)
- {
- KeyStatus = KeyScan();
- if(KeyStatus == 1)
- {
- BeepOn();
- msDelay(10);
- BeepOff();
- }
- else
- BeepOff();
- }
- }
- void Main(void)
- {
- GPIO_Init();
- BeepOff();
- KeyTest();
- }