实验目的:按键控制led灯
实验环境: mini2440(arm920t)
工具: ads1.2 h-jtag1.0
步骤:
1.在ads中新建key工程,添加文件init.s main.c如下
init.s
- area init,code,readonly
- start
- ldr sp,=4096
- import main
- bl main
- end
main.c
- #define rGPBCON (*((volatile unsigned *)0x56000010))
-
#define rGPBDATA (*((volatile unsigned *)0x56000014))
-
-
#define rGPGCON (*((volatile unsigned *)0x56000060))
-
#define rGPGDATA (*((volatile unsigned *)0x56000064))
-
-
#define LED1_ON rGPBDATA &=(~(1<<5))
-
#define LED2_ON rGPBDATA &=(~(1<<6))
-
#define LED3_ON rGPBDATA &=(~(1<<7))
-
#define LED4_ON rGPBDATA &=(~(1<<8))
-
-
#define LED1_OFF rGPBDATA |=(1<<5)
-
#define LED2_OFF rGPBDATA |=(1<<6)
-
#define LED3_OFF rGPBDATA |=(1<<7)
-
#define LED4_OFF rGPBDATA |=(1<<8)
-
-
-
void delay(int i)
-
{
-
while(i--);
-
}
-
-
int main()
-
{
-
rGPBCON = 0x15400;
-
rGPGCON = 0x2882;
-
LED1_OFF;
-
LED2_OFF;
-
LED3_OFF;
-
LED4_OFF;
-
-
while(1)
-
{
-
if((rGPGDATA&=(1<<0)) == 0)
-
{
-
delay(100);
-
if((rGPGDATA&=(1<<0)) == 0)
-
{
-
LED1_ON;
-
delay(100000);
-
}
-
}
-
if((rGPGDATA&=(1<<3)) == 0)
-
{
-
delay(100);
-
if((rGPGDATA&=(1<<3)) == 0)
-
{
-
LED2_ON;
-
delay(100000);
-
}
-
}
-
if((rGPGDATA&=(1<<5)) == 0)
-
{
-
delay(100);
-
if((rGPGDATA&=(1<<5)) == 0)
-
{
-
LED3_ON;
-
delay(100000);
-
}
-
}
-
if((rGPGDATA&=(1<<6)) == 0)
-
{
-
delay(100);
-
if((rGPGDATA&=(1<<6)) == 0)
-
{
-
LED4_ON;
-
delay(100000);
-
}
-
}
-
-
-
LED1_OFF;
-
LED2_OFF;
-
LED3_OFF;
-
LED4_OFF;
-
}
-
return 0;
-
}
2.ADS AXD H-JTAG的配置同led程序。
备注 :
判断按键是否按下时,通过延时一段时间做第二次判断,实现按键去抖。
阅读(305) | 评论(0) | 转发(0) |