#include "2440addr.h"<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
#define KEY1 (1 << 0) //GPF0 GPB6
#define KEY2 (1 << 0) //GPF0 GPB7
#define KEY3 (1 << 5) //GPG5 GPB6
#define KEY4 (1 << 5) //GPG5 GPB7
#define LED1 (1 << 4) //GPF4
#define LED2 (1 << 5) //GPF5
#define LED3 (1 << 6) //GPF6
#define LED4 (1 << 7) //GPF7
void Init()
{
rGPFCON = (rGPFCON & 0x00ff) | 0x5500; //set GPF[7:4] output
rGPFCON = rGPFCON & (~(3<<0)); //set GPF[0] input
rGPGCON = rGPGCON & (~(3<<10)); //set GPG[5] input
rGPBCON = (rGPBCON & (~( (3<<12)|(3<<14) )) ) \
| ( (1<<12)|(1<<14) ); //set GPB[7:6] output
}
void key_on_light()
{
rGPBDAT = (rGPBDAT | (1<<7)); //set GPB7 high
rGPBDAT = rGPBDAT & (~(1<<6)); //set GPB6 low
if (rGPFDAT & KEY1) {
rGPFDAT |= LED1; //熄灭LED1
}
else {
rGPFDAT &= ~LED1; //点亮LED1
}
if (rGPGDAT & KEY3) {
rGPFDAT |= LED3; //熄灭LED3
}
else {
rGPFDAT &= ~LED3; //点亮LED3
}
rGPBDAT = (rGPBDAT | (1<<6)); //set GPB6 high
rGPBDAT = rGPBDAT & (~(1<<7)); //set GPB7 low
if (rGPFDAT & KEY1) {
rGPFDAT |= LED2; //熄灭LED2
}
else {
rGPFDAT &= ~LED2; //点亮LED2
}
if (rGPGDAT & KEY4) {
rGPFDAT |= LED4; //熄灭LED4
}
else {
rGPFDAT &= ~LED4; //点亮LED4
}
}
void Main()
{
Init();
while(1) {
key_on_light();
}
}
文章评论(0条评论)
登录后参与讨论