找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 6933|回复: 1
收起左侧

S3C2440微控制器外部中断实验

[复制链接]
ID:757182 发表于 2020-5-21 10:46 | 显示全部楼层 |阅读模式
实验目的:掌握S3C2440微控制器I/O和外部中断的使用方法
实验内容:
用外部中断的方式,实现:
(1)按下K11,LED1闪烁2次;
(2)按下K12,LED2闪烁2次;
(3)按下K13,LED3闪烁2次;
(4)按下K14,LED4闪烁2次;
(5)按下K15,LED1与LED3一起闪烁2次;
(6)按下K16,LED2与LED4一起闪烁2次;
要求使用下降沿触发外部中断。

  1. #include "2440addr.h"
  2. #include "2440lib.h"
  3. #define rGPBCON    (*(volatile unsigned *)0x56000010) //Port B control
  4. #define rGPBDAT    (*(volatile unsigned *)0x56000014) //Port B data
  5. #define rGPBUP     (*(volatile unsigned *)0x56000018) //Pull-up control B

  6. U16 i,a;
  7. int delay(int times);

  8. void INIT_interrupt(void);
  9. static void __irq Eint1_ISR(void)
  10. {
  11.         U8 j = 0;
  12.         for( j=0;i<2;i++){
  13.             rGPBDAT=(rGPBDAT&~(0xf<<5))|0x1c0;    //LED1亮  1110
  14.             delay(50000000);
  15.             rGPBDAT=(rGPBDAT&~(0xf<<5))|0x1E0;    //全灭 1111       
  16.             delay(50000000);
  17.             rSRCPND=(rSRCPND&~(0x1<<1))|(0x1<<1);
  18.             rINTPND=(rINTPND&~(0x1<<1))|(0x1<<1);
  19.         }
  20. }
  21. static void __irq Eint2_ISR(void)
  22. {       
  23.         U8 j = 0;
  24.         for(j=0;i<2;i++){
  25.                 rGPBDAT=(rGPBDAT&~(0xf<<5))|0x1a0;       //LED2亮  1101
  26.             delay(50000000);
  27.             rGPBDAT=(rGPBDAT&~(0xf<<5))|0x1E0;       //全灭 1111
  28.             delay(50000000);
  29.                 rSRCPND=(rSRCPND&~(0x1<<2))|(0x1<<2);
  30.             rINTPND=(rINTPND&~(0x1<<2))|(0x1<<2 );
  31.     }
  32. }
  33. static void __irq Eint3_ISR(void)
  34. {       
  35.         U8 j = 0;
  36.         for(j=0;i<2;i++){
  37.                 rGPBDAT= (rGPBDAT&~(0xf<<5))|0x160;      //LED3亮 1011
  38.             delay(50000000);
  39.             rGPBDAT=(rGPBDAT&~(0xf<<5))|0x1E0;       //全灭 1111
  40.             delay(50000000);
  41.                 rSRCPND=(rSRCPND&~(0x1<<3))|(0x1<<3);
  42.             rINTPND=(rINTPND&~(0x1<<3))|(0x1<<3 );
  43.     }
  44. }
  45. static void __irq Eint4_7_ISR(void)
  46. {
  47.         U8 j = 0;
  48.         if(rEINTPEND == (rEINTPEND&~(0x1<<4))|(0x1<<4)){
  49.         for(j=0;i<2;i++){
  50.                  rGPBDAT= (rGPBDAT&~(0xf<<5))|0x0e0;      //LED4亮 0111
  51.          delay(50000000);
  52.          rGPBDAT=(rGPBDAT&~(0xf<<5))|0x1E0;       //全灭 1111
  53.          delay(50000000);
  54.          }
  55.      rEINTPEND=(1<<4);
  56.      ClearPending(BIT_EINT4_7);
  57.         }else if(rEINTPEND == (rEINTPEND&~(0x1<<5))|(0x1<<5)){
  58.         for(j=0;i<2;i++){
  59.          rGPBDAT= (rGPBDAT&~(0xf<<5))|0x140;      //LED1,3亮 1010
  60.          delay(50000000);
  61.          rGPBDAT=(rGPBDAT&~(0xf<<5))|0x1E0;       //全灭 1111
  62.          delay(50000000);
  63.          }
  64.      rEINTPEND=(1<<5);
  65.      ClearPending(BIT_EINT4_7);
  66.         }else if(rEINTPEND == (rEINTPEND&~(0x1<<6))|(0x1<<6)){
  67.         for(j=0;i<2;i++){
  68.                  rGPBDAT= (rGPBDAT&~(0xf<<5))|0xA0;      //LED2,4亮 0101
  69.          delay(50000000);
  70.          rGPBDAT=(rGPBDAT&~(0xf<<5))|0x1E0;       //全灭 1111
  71.          delay(50000000);
  72.          }
  73.      rEINTPEND=(1<<6);
  74.      ClearPending(BIT_EINT4_7);     
  75.         }
  76.         rSRCPND=(rSRCPND&~(0x1<<1))|(0x1<<1);
  77.     rINTPND=(rINTPND&~(0x1<<1))|(0x1<<1 );
  78.     rEINTPEND=(rEINTPEND&~(0x7<<4))|(0x7<<4);
  79. }

  80. void INIT_interrupt()
  81. {

  82.      rINTMSK=(rINTMSK&~(0x1<<1));  //中断屏蔽(INTMSK)寄存器
  83.     //56000050 11                     10
  84.         rGPFCON = (rGPFCON&~(0x3<<2))|(0x2<<2);//GPF1设置为 外部中断1
  85.         rGPFCON = (rGPFCON&~(0x3<<4))|(0x2<<4);//GPF2设置为 外部中断2
  86.         rGPFCON = (rGPFCON&~(0x3<<6))|(0x2<<6);//GPF3设置为 外部中断3
  87.         rGPFCON = (rGPFCON&~(0x3<<8))|(0x2<<8);//GPF4设置为 外部中断4
  88.         rGPFCON = (rGPFCON&~(0x3<<10))|(0x2<<10);//GPF5设置为 外部中断5
  89.         rGPFCON = (rGPFCON&~(0x3<<12))|(0x2<<12);//GPF6设置为 外部中断6
  90.        
  91.         rEXTINT1 =(rEXTINT1&~(0x7<<4))|(0x2<<4)  //外部中断1,使用下降沿触发
  92.     rEXTINT1 =(rEXTINT1&~(0x7<<8))|(0x2<<8)  //外部中断2,使用下降沿触发
  93.         rEXTINT1 =(rEXTINT1&~(0x7<<12))|(0x2<<12)  //外部中断3,使用下降沿触发
  94.     rEXTINT1 =(rEXTINT1&~(0x7<<16))|(0x2<<16)  //外部中断4,使用下降沿触发
  95.     rEXTINT1 =(rEXTINT1&~(0x7<<20))|(0x2<<20)  //外部中断5,使用下降沿触发
  96.     rEXTINT1 =(rEXTINT1&~(0x7<<24))|(0x2<<24)  //外部中断6,使用下降沿触发

  97.     pISR_EINT1=(U32)Eint1_ISR;//把EINT1的中断入口地址放进去
  98.     pISR_EINT2=(U32)Eint2_ISR;//把EINT2的中断入口地址放进去
  99.     pISR_EINT3=(U32)Eint3_ISR;//把EINT3的中断入口地址放进去
  100.     pISR_EINT4_7=(U32)Eint4_7_ISR;//把EINT4_7的中断入口地址放进去



  101.     rSRCPND=(rSRCPND&~(0xF<<1))|(0xF<<1);     //初始化时也清除一下挂起寄存器
  102.     rINTPND=(rINTPND&~(0xF<<1))|(0xF<<1);
  103.     rEINTPEND=(rEINTPEND&~(0x7<<4))|(0x7<<4);
  104.    
  105.             
  106.     //如果有外部中断4-23,则中断挂起寄存器也要清零一下,中断屏蔽寄存器也要改为可服务
  107.     rINTMSK=(rINTMSK&~(0xF<<1))|(0x0<<1);  //中断屏蔽(INTMSK)寄存器 EINT1\ENIT2\ENIT3\ENIT4_7使能
  108.     rEINTMASK = (rEINTMASK&~(0x7<<4))|(0x0<<4);//子中断屏蔽寄存器 EINT4\ENIT5\ENIT6使能

  109. }


  110. /*  自定义简单延迟程序  */
  111. int delay(int times)
  112. {
  113.     int i;
  114.     for(i=0;i<times;i++);
  115.     return 0;
  116. }




  117. void xmain(void)
  118. {
  119.         ChangeClockDivider(3,1);
  120.         ChangeMPllValue(127,2,1);                //405MHZ
  121.         //Rtc_Init();                                //实时时钟初始化
  122.         Isr_Init();
  123.         Uart_Init(0, 115200);
  124.         Uart_Select(0);
  125.        
  126.         rGPBCON=(rGPBCON & ~(0xFF<<10)) | (0x55<<10);//GPB5-8  set output
  127.     rGPBUP |= (0xFF<<5);   //disable GPB pull up

  128.         INIT_interrupt();
  129.        
  130.         while(1);   
  131. }
复制代码

全部资料51hei下载地址:
外部中断实验.zip (127.18 KB, 下载次数: 11)

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

ID:277550 发表于 2024-1-6 20:13 | 显示全部楼层
还有TX玩 2440 么
回复

使用道具 举报

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

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

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