以下是TQ2440裸奔按键LED功能的程序
init.s
AREA init, CODE, READONLY
start LDR SP,=4096
import main
bl main
end
def.h
#ifndef __DEF_H__
#define GPBCON (*(volatile unsigned int*) 0x56000010)
#define GPBDAT (*(volatile unsigned int*) 0x56000014)
#define GPFCON (*(volatile unsigned int*) 0x56000050)
#define WTCON (*(volatile unsigned int*) 0x53000000)
#define GPFDAT (*(volatile unsigned int*) 0x56000054)
#define KEY1 0x02
#define KEY2 0x10
#define KEY3 0x04
#define KEY4 0x01
#define LED1 0x1cf
#define LED2 0x1bf
#define LED3 0x17f
#define LED4 0x0ff
#define LED_OFF 0x1ff
#endif
main.c
#include "def.h"
void delay(unsigned int a)
{
while (a--);
}
void init()
{
WTCON = 0;//使看门狗无效
GPBCON &= ~((3<<2*5)|(3<<2*6)|(3<<2*7)|(3<<2*8));
GPBCON |= ((1<<2*5)|(1<<2*6)|(1<<2*7)|(1<<2*8));//5,6,7,8口输出(01输出)
GPFCON &= ~((3<<2*0)|(3<<2*1)|(3<<2*2)|(3<<2*4));//0,1,2,4口输入(00输入)
}
main()
{
init();
while (1)
{
if (!(GPFDAT & KEY4))
{
delay(5000);
while (!(GPFDAT & KEY4))
{
GPBDAT = LED4;
}
}
else
GPBDAT = LED_OFF;
/***********按键4点亮LED4,松手LED4灭*****************/
if (!(GPFDAT & KEY1))
{
delay(5000);
while (!(GPFDAT & KEY1))
{
GPBDAT = LED1;
}
}
else
GPBDAT = LED_OFF;
/***********按键1点亮LED1,松手LED1灭*****************/
if (!(GPFDAT & KEY2))
{
delay(5000);
while (!(GPFDAT & KEY2))
{
GPBDAT = LED2;
}
}
else
GPBDAT = LED_OFF;
/***********按键2点亮LED2,松手LED2灭*****************/
if (!(GPFDAT & KEY3))
{
delay(5000);
while (!(GPFDAT & KEY3))
{
GPBDAT = LED3;
}
}
else
GPBDAT = LED_OFF;
/***********按键3点亮LED3,松手LED3灭*****************/