今天 与大家分享来自晨旭晚霞博客中TQ2440裸奔程序。
//=========================================
// NAME: main.c
// DESC: TQ2440流水灯测试程序
// 板载LED为PB
//=========================================
/* 头文件包含 */
#define U32 unsigned int
/* 中断向量表 */
#define ISRSTARTADDRESS 0x33ffff00
#define pISR_EINT0 (*(unsigned *)(ISRSTARTADDRESS+0x20))
#define pISR_EINT1 (*(unsigned *)(ISRSTARTADDRESS+0x24))
#define pISR_EINT2 (*(unsigned *)(ISRSTARTADDRESS+0x28))
#define pISR_EINT4_7 (*(unsigned *)(ISRSTARTADDRESS+0x30))
/* 中断控制 寄存器地址 */
#define rSRCPND (*(volatile unsigned *)0x4a000000) //Interrupt request status 源挂起寄存器
#define rINTMSK (*(volatile unsigned *)0x4a000008) //Interrupt mask control 中断屏蔽寄存器
#define rINTPND (*(volatile unsigned *)0x4a000010) //Interrupt request status 中断挂起寄存器
/* 外部中断 寄存器地址 */
#define rEXTINT0 (*(volatile unsigned *)0x56000088) //External interrupt control register 0 外部中断控制寄存器
#define rEINTMASK (*(volatile unsigned *)0x560000a4) //External interrupt mask 外部中断屏蔽寄存器
#define rEINTPEND (*(volatile unsigned *)0x560000a8) //External interrupt pending 外部中断挂起寄存器
/* LED灯寄存器地址 */
#define rGPBCON (*(volatile unsigned *)0x56000010) //Port B control
#define rGPBDAT (*(volatile unsigned *)0x56000014) //Port B data
#define rGPBUP (*(volatile unsigned *)0x56000018) //Pull-up control B
/* EINT F 寄存器地址 */
#define rGPFCON (*(volatile unsigned *)0x56000050) //Port F control
void led_init(void)
{
//板载LED为GPB[5:8]
rGPBCON = (rGPBCON & ~(0xff<<10)) | (0x55<<10); //rGPBCON为01 配置为输出
rGPBUP = rGPBUP | (0xf<<5); //rGPBUP为1 禁止上拉
rGPBDAT = rGPBDAT | (0xf<<5); //LED灯全关
}
void led_display(unsigned char data)
{
//0x0全灭 0xf全亮 0x01 0x02 0x04 0x80 各自灯亮
rGPBDAT = (rGPBDAT & ~(0xf<<5)) | ((~data) <<5);
}
void eint_init(void)
{
rGPFCON = 0xaaaa; //GPF[0:15]配置成外部中断
rSRCPND = rSRCPND | 0x1f; //清除EINT[0:7]源中断请求
rINTMSK = rINTMSK & ~(0x1f); //清除EINT[0:7]中断屏蔽请求
rINTPND = rINTPND | 0x1f; //清除EINT[0:7]中断挂起请求
rEINTPEND = rEINTPEND | (1<<4);
rEINTMASK = rEINTMASK & ~(1<<4);
rEXTINT0 = rEXTINT0 & ~((0x7<<0) | (0x7<<4) | (0x7<<8) | (0x7<<16));
rEXTINT0 = rEXTINT0 | ((0x2<<0) | (0x2<<4) | (0x2<<8) | (0x2<<16));//EINT下降沿触发方式 01x 0x2
}
static void _irq Key1ISR(void) //EINT1
{
rSRCPND = rSRCPND | (0x1<<1);
rINTPND = rINTPND | (0x1<<1);
led_display(0x1);
}
static void _irq Key2ISR(void) //EINT4
{
rSRCPND = rSRCPND | (0x1<<4);
rINTPND = rINTPND | (0x1<<4);
if(rEINTPEND & (1<<4))
{
rEINTPEND = rEINTPEND | (0x1<<4);
led_display(0x2);
}
}
static void _irq Key3ISR(void) //EINT2
{
rSRCPND = rSRCPND | (0x1<<2);
rINTPND = rINTPND | (0x1<<2);
led_display(0x4);
}
static void _irq Key4ISR(void) //EINT0
{
rSRCPND = rSRCPND | 0x1;
rINTPND = rINTPND | 0x1;
led_display(0x8);
}
void Main(void)
{
led_init();
eint_init();
/* 中断函数入口地址 */
pISR_EINT0 = (U32)Key4_ISR;
pISR_EINT1 = (U32)Key1_ISR;
pISR_EINT2 = (U32)Key3_ISR;
pISR_EINT4_7 = (U32)Key2_ISR;
while(1);
}
供货情况:
天嵌科技提供专业嵌入式板卡和行业解决方案。如有需要,可以联系天嵌科技的销售人员。
销售电话:020-38219416 38373101
技术支持:020-38219416转807 820
网址:http://www.embedsky.com
官方淘宝:https://embedsky.taobao.com/