熱度 6||
今天 與大家分享來自晨旭晚霞博客中TQ2440裸奔程序。
//=========================================
// NAME: main.c
// DESC: TQ2440流水燈測試程序
// 板載LED為PB
//=========================================
/* 頭文件包含 */
#define U32 unsigned int
/* 中斷向量表 */
#define _ISR_STARTADDRESS 0x33ffff00
#define pISR_EINT0 (*(unsigned *)(_ISR_STARTADDRESS+0x20))
#define pISR_EINT1 (*(unsigned *)(_ISR_STARTADDRESS+0x24))
#define pISR_EINT2 (*(unsigned *)(_ISR_STARTADDRESS+0x28))
#define pISR_EINT4_7 (*(unsigned *)(_ISR_STARTADDRESS+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 Key1_ISR(void) //EINT1
{
rSRCPND = rSRCPND | (0x1<<1);
rINTPND = rINTPND | (0x1<<1);
led_display(0x1);
}
static void __irq Key2_ISR(void) //EINT4
{
rSRCPND = rSRCPND | (0x1<<4);
rINTPND = rINTPND | (0x1<<4);
if(rEINTPEND & (1<<4))
{
rEINTPEND = rEINTPEND | (0x1<<4);
led_display(0x2);
}
}
static void __irq Key3_ISR(void) //EINT2
{
rSRCPND = rSRCPND | (0x1<<2);
rINTPND = rINTPND | (0x1<<2);
led_display(0x4);
}
static void __irq Key4_ISR(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/