天嵌 ARM开发社区

 找回密码
 注册
查看: 2302|回复: 0

TQ2440裸奔程序:EINT中断按键测试程序

[复制链接]
freewing 发表于 2016-7-7 14:20:59 | 显示全部楼层 |阅读模式
  今天 与大家分享来自晨旭晚霞博客中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/
  


您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

i.MX8系列ARM cortex A53 M4 工控板上一条 /1 下一条

Archiver|手机版|小黑屋|天嵌 嵌入式开发社区 ( 粤ICP备11094220号-2 )

GMT+8, 2024-11-1 06:49 , Processed in 1.046875 second(s), 22 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表