按键同时控制LED灯和蜂鸣器的相关程序
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
//按键同时控制LED灯和蜂鸣器的相关程序
//头文件 寄存器的相关地址
#define GPH2CON *(volatile unsigned long*)0xE0200C40//butten1~4
#define GPH2DAT *(volatile unsigned long*)0xE0200C44//butten
#define GPJ2CON *(volatile unsigned long*)0xE0200280//led
#define GPJ2DAT *(volatile unsigned long*)0xE0200284//led
#define GPD0CON *(volatile unsigned long*)0xE02000A0//buzzer
#define GPD0DAT *(volatile unsigned long*)0xE02000A4//buzzer
int main(void)
{
int i;
GPJ2CON = 0x1111;
GPJ2DAT = 0xF;
GPD0CON = 0x1;
while(1)
{
if(GPH2DAT == 0xE )//K1
{
GPD0DAT = 0x1;
for(i = 0; i < 100000; i++);
GPJ2DAT = 0xE;
for(i = 0; i < 100000; i++);
GPD0DAT = 0x0;
GPJ2DAT = 0xF;
}
if(GPH2DAT == 0xD)//K2
{
GPD0DAT = 0x1;
for(i = 0; i < 100000; i++);
GPJ2DAT = 0xD;
for(i = 0; i < 100000; i++);
GPD0DAT = 0x0;
GPJ2DAT = 0xF;
}
if(GPH2DAT == 0xB)//K3
{
GPD0DAT = 0x1;
for(i = 0; i < 100000; i++);
GPJ2DAT = 0xB;
for(i = 0; i < 100000; i++);
GPD0DAT = 0x0;
GPJ2DAT = 0xF;
}
if(GPH2DAT == 0x7)//K4
{
GPD0DAT = 0x1;
for(i = 0; i < 100000; i++);
GPJ2DAT = 0x7;
for(i = 0; i < 100000; i++);
GPJ2DAT = 0xF;
GPD0DAT = 0x0;
}
else
{
GPJ2DAT = 0xF;
GPD0DAT = 0x0;
}
}
return 0;
}