找回密码
 立即注册
查看: 1031|回复: 2

求助!使用Keil中断号扩展,但STC32G128的IO中断依旧进不去

[复制链接]
  • 打卡等级:初来乍到
  • 打卡总天数:3
  • 最近打卡:2024-12-26 09:36:03
已绑定手机

3

主题

9

回帖

87

积分

注册会员

积分
87
发表于 2023-10-21 20:35:43 | 显示全部楼层 |阅读模式
如题,已经使用了KEIL的中断号扩展工具,但是今天在学习的过程当中尝试使用P4口的IO中断,无论如何无法进入。

代码描述:使用IO口中断,当按下P40口的接地按钮后,P20处的LED亮起;按下P41口按钮接地,P21口LED亮起。
请求大佬们的帮助!!!!!
  1. #include <STC32G.H>
  2. #include <GPIO.h>
  3. //#include <DELAY.H>
  4. #include "intrins.h"              //汇编相关头文件
  5. #include "stc32_stc8_usb.h"
  6. #define MAIN_FOSC 24000000UL                //定义IRC系统时钟
  7. void sys_init()
  8. {
  9.     WTST = 0;  //设置程序指令延时参数,赋值为0可将CPU执行指令的速度设置为最快
  10.     EAXFR = 1; //扩展寄存器(XFR)访问使能
  11.     CKCON = 0; //提高访问XRAM速度
  12. }
  13. void P4EXIT_Init(void)
  14. {
  15. //        P26IM0=;        //PXXIM*,其中XX是IO口,*是0和1;00下降沿中断、01上升沿中断、10低电平中断、11高电平中断;和M1对应
  16. //        P26IM1=;
  17. //       
  18. //        P26INTE=;        //PXXINTE,其中XX是IO口,具体哪个能用看手册.0为关断,1为使能
  19. //        P26INTF=;        //PXXINTF,其中XX是IO口,具体哪个能用看手册.0为没有中断请求,1为请求中断,需要软件清0!!!
  20.         P4IM0=0x00;
  21.         P4IM1=0x00;                        //
  22.         P4INTE=0xFF;                //P4端口使能中断——0010 0000
  23.         P4INTF=0xFF;
  24.        
  25. }
  26. void P4EXIT_isr(void) interrupt 41
  27. {
  28.         //在中断里干什么?
  29.         static unsigned int intf;
  30.         intf=P4INTF;
  31.         if(intf==1)                //进入中断了要除标志位,必须软件清空
  32.         {
  33.                 P4INTF=0x00;
  34.                 if(intf & 0x01)                //如果P40按下
  35.                 {
  36.                         P20=~P20;
  37.                 }
  38.                 if(intf & 0x02)        //如果P41按下
  39.                 {
  40.                         P21=~P21;
  41.                 }
  42.                 if(intf & 0x04)//如果P42按下
  43.                 {
  44.                        
  45.                 }
  46.                 if(intf & 0x08)//如果P43按下
  47.                 {
  48.                 }
  49.                 if(intf & 0x10)//如果P44按下
  50.                 {
  51.                 }
  52.                 if(intf & 0x20)//如果P45按下
  53.                 {
  54.                 }
  55.                 if(intf & 0x40)//如果P46按下
  56.                 {
  57.                 }
  58.                 if(intf & 0x80)//如果P47按下
  59.                 {
  60.                 }
  61.         }
  62.        
  63.        
  64. }
  65. void main(void)
  66. {
  67.         sys_init();
  68.         GPIO_init_pin(20,0);   //初始化单个IO引脚函数
  69.         GPIO_init_pin(21,0);   //初始化单个IO引脚函数
  70.         GPIO_init_pin(40,0);   //初始化单个IO引脚函数
  71.         GPIO_init_pin(41,0);   //初始化单个IO引脚函数
  72.         GPIO_init_pin(42,0);   //初始化单个IO引脚函数
  73.         GPIO_init_pin(43,0);   //初始化单个IO引脚函数
  74.         GPIO_init_pin(44,0);   //初始化单个IO引脚函数
  75.         GPIO_init_pin(45,0);   //初始化单个IO引脚函数
  76.         GPIO_init_pin(46,0);   //初始化单个IO引脚函数
  77.         GPIO_init_pin(47,0);   //初始化单个IO引脚函数
  78.         P4EXIT_Init();
  79.        
  80.         EA=1;
  81.         P20=1;
  82.         P21=1;
  83.         while(1)
  84.         {
  85.                
  86.         }
  87. }
复制代码
下面是我GPIO.C里面的代码
  1. #include "GPIO.h"
  2. #include <STC32G.H>
  3. #include "intrins.h"              //汇编相关头文件
  4. #define uchar unsigned char
  5. #define uint unsigned int
  6. #define uint32 unsigned long
  7. #define u8 unsigned char
  8. #define u16 unsigned int
  9. #define u32 unsigned long
  10. void GPIO_init_pin(int pin,int mode)   //初始化单个IO引脚函数  
  11. {
  12.         int a,b;
  13.         u8 c[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
  14.         a=pin/10; //取得端口号
  15.         b=pin%10; //取得引脚号
  16.         switch(a)
  17.         {
  18.                 case 0:
  19.                                 switch(mode)
  20.                                 {
  21.                                         case 0:P0M0&=c[b];        P0M1&=c[b]; break;
  22.                                         case 1:P0M0|=~c[b];        P0M1&=c[b]; break;
  23.                                         case 2:P0M0&=c[b];        P0M1|=~c[b]; break;
  24.                                         case 3:P0M0|=~c[b];        P0M1|=~c[b]; break;                               
  25.                                 }
  26.                                 break;
  27.                 case 1:
  28.                                 switch(mode)
  29.                                 {
  30.                                         case 0:P1M0&=c[b];        P1M1&=c[b]; break;
  31.                                         case 1:P1M0|=~c[b];        P1M1&=c[b]; break;
  32.                                         case 2:P1M0&=c[b];        P1M1|=~c[b]; break;
  33.                                         case 3:P1M0|=~c[b];        P1M1|=~c[b]; break;                               
  34.                                 }
  35.                                 break;
  36.                 case 2:
  37.                                 switch(mode)
  38.                                 {
  39.                                         case 0:P2M0&=c[b];        P2M1&=c[b]; break;
  40.                                         case 1:P2M0|=~c[b];        P2M1&=c[b]; break;
  41.                                         case 2:P2M0&=c[b];        P2M1|=~c[b]; break;
  42.                                         case 3:P2M0|=~c[b];        P2M1|=~c[b]; break;                               
  43.                                 }
  44.                                 break;
  45.                 case 3:
  46.                                 switch(mode)
  47.                                 {
  48.                                         case 0:P3M0&=c[b];        P3M1&=c[b]; break;
  49.                                         case 1:P3M0|=~c[b];        P3M1&=c[b]; break;
  50.                                         case 2:P3M0&=c[b];        P3M1|=~c[b]; break;
  51.                                         case 3:P3M0|=~c[b];        P3M1|=~c[b]; break;                               
  52.                                 }
  53.                                 break;
  54.                 case 4:
  55.                                 switch(mode)
  56.                                 {
  57.                                         case 0:P4M0&=c[b];        P4M1&=c[b]; break;
  58.                                         case 1:P4M0|=~c[b];        P4M1&=c[b]; break;
  59.                                         case 2:P4M0&=c[b];        P4M1|=~c[b]; break;
  60.                                         case 3:P4M0|=~c[b];        P4M1|=~c[b]; break;                               
  61.                                 }
  62.                                 break;
  63.                 case 5:
  64.                                 switch(mode)
  65.                                 {
  66.                                         case 0:P5M0&=c[b];        P5M1&=c[b]; break;
  67.                                         case 1:P5M0|=~c[b];        P5M1&=c[b]; break;
  68.                                         case 2:P5M0&=c[b];        P5M1|=~c[b]; break;
  69.                                         case 3:P5M0|=~c[b];        P5M1|=~c[b]; break;                               
  70.                                 }
  71.                                 break;
  72.                 case 6:
  73.                                 switch(mode)
  74.                                 {
  75.                                         case 0:P6M0&=c[b];        P6M1&=c[b]; break;
  76.                                         case 1:P6M0|=~c[b];        P6M1&=c[b]; break;
  77.                                         case 2:P6M0&=c[b];        P6M1|=~c[b]; break;
  78.                                         case 3:P6M0|=~c[b];        P6M1|=~c[b]; break;                               
  79.                                 }
  80.                                 break;
  81.                 case 7:
  82.                                 switch(mode)
  83.                                 {
  84.                                         case 0:P7M0&=c[b];        P7M1&=c[b]; break;
  85.                                         case 1:P7M0|=~c[b];        P7M1&=c[b]; break;
  86.                                         case 2:P7M0&=c[b];        P7M1|=~c[b]; break;
  87.                                         case 3:P7M0|=~c[b];        P7M1|=~c[b]; break;                               
  88.                                 }
  89.                                 break;
  90.                                
  91.         }
  92. }
  93. bit Get_IO(int IO)
  94. {
  95.         bit status;
  96.         switch(IO)
  97.         {
  98.                 case 00: status=P00;break;
  99.                 case 01: status=P01;break;
  100.                 case 02: status=P02;break;
  101.                 case 03: status=P03;break;
  102.                 case 04: status=P04;break;
  103.                 case 05: status=P05;break;
  104.                 case 06: status=P06;break;
  105.                 case 07: status=P07;break;
  106.                
  107.                 case 10: status=P10;break;
  108.                 case 11: status=P11;break;
  109.                 case 12: status=P12;break;
  110.                 case 13: status=P13;break;
  111.                 case 14: status=P14;break;
  112.                 case 15: status=P15;break;
  113.                 case 16: status=P16;break;
  114.                 case 17: status=P17;break;
  115.                
  116.                 case 20: status=P20;break;
  117.                 case 21: status=P21;break;
  118.                 case 22: status=P22;break;
  119.                 case 23: status=P23;break;
  120.                 case 24: status=P24;break;
  121.                 case 25: status=P25;break;
  122.                 case 26: status=P26;break;
  123.                 case 27: status=P27;break;
  124.                
  125.                 case 30: status=P30;break;
  126.                 case 31: status=P31;break;
  127.                 case 32: status=P32;break;
  128.                 case 33: status=P33;break;
  129.                 case 34: status=P34;break;
  130.                 case 35: status=P35;break;
  131.                 case 36: status=P36;break;
  132.                 case 37: status=P37;break;
  133.                
  134.                 case 40: status=P40;break;
  135.                 case 41: status=P41;break;
  136.                 case 42: status=P42;break;
  137.                 case 43: status=P43;break;
  138.                 case 44: status=P44;break;
  139.                
  140.                 case 50: status=P50;break;
  141.                 case 51: status=P51;break;
  142.                 case 52: status=P52;break;
  143.                 case 53: status=P53;break;
  144.                 case 54: status=P54;break;
  145.                 case 55: status=P55;break;
  146.                
  147.                 case 60: status=P60;break;
  148.                 case 61: status=P61;break;
  149.                 case 62: status=P62;break;
  150.                 case 63: status=P63;break;
  151.                 case 64: status=P64;break;
  152.                 case 65: status=P65;break;
  153.                 case 66: status=P66;break;
  154.                 case 67: status=P67;break;
  155.                
  156.                 case 70: status=P70;break;
  157.                 case 71: status=P71;break;
  158.                 case 72: status=P72;break;
  159.                 case 73: status=P73;break;
  160.                 case 74: status=P74;break;
  161.                 case 75: status=P75;break;
  162.                 case 76: status=P76;break;
  163.                 case 77: status=P77;break;
  164.                 default: status=1;  break; //其他情况
  165.         }
  166.         return status;
  167. }
  168. void Out_IO(unsigned char IO,bit status)
  169. {
  170.         switch(IO)
  171.         {
  172.                 case 00: P00=status;break;
  173.                 case 01: P01=status;break;
  174.                 case 02: P02=status;break;
  175.                 case 03: P03=status;break;
  176.                 case 04: P04=status;break;
  177.                 case 05: P05=status;break;
  178.                 case 06: P06=status;break;
  179.                 case 07: P07=status;break;
  180.                
  181.                 case 10: P10=status;break;
  182.                 case 11: P11=status;break;
  183.                 case 12: P12=status;break;
  184.                 case 13: P13=status;break;
  185.                 case 14: P14=status;break;
  186.                 case 15: P15=status;break;
  187.                 case 16: P16=status;break;
  188.                 case 17: P17=status;break;
  189.                
  190.                 case 20: P20=status;break;
  191.                 case 21: P21=status;break;
  192.                 case 22: P22=status;break;
  193.                 case 23: P23=status;break;
  194.                 case 24: P24=status;break;
  195.                 case 25: P25=status;break;
  196.                 case 26: P26=status;break;
  197.                 case 27: P27=status;break;
  198.                
  199.                 case 30: P30=status;break;
  200.                 case 31: P31=status;break;
  201.                 case 32: P32=status;break;
  202.                 case 33: P33=status;break;
  203.                 case 34: P34=status;break;
  204.                 case 35: P35=status;break;
  205.                 case 36: P36=status;break;
  206.                 case 37: P37=status;break;
  207.                
  208.                 case 40: P40=status;break;
  209.                 case 41: P41=status;break;
  210.                 case 42: P42=status;break;
  211.                 case 43: P43=status;break;
  212.                 case 44: P44=status;break;
  213.                
  214.                 case 50: P50=status;break;
  215.                 case 51: P51=status;break;
  216.                 case 52: P52=status;break;
  217.                 case 53: P53=status;break;
  218.                 case 54: P54=status;break;
  219.                 case 55: P55=status;break;
  220.                
  221.                 case 60: P60=status;break;
  222.                 case 61: P61=status;break;
  223.                 case 62: P62=status;break;
  224.                 case 63: P63=status;break;
  225.                 case 64: P64=status;break;
  226.                 case 65: P65=status;break;
  227.                 case 66: P66=status;break;
  228.                 case 67: P67=status;break;
  229.                
  230.                 case 70: P70=status;break;
  231.                 case 71: P71=status;break;
  232.                 case 72: P72=status;break;
  233.                 case 73: P73=status;break;
  234.                 case 74: P74=status;break;
  235.                 case 75: P75=status;break;
  236.                 case 76: P76=status;break;
  237.                 case 77: P77=status;break;
  238.                 default:  break; //其他情况
  239.         }
  240. }
复制代码


回复

使用道具 举报 送花

  • 打卡等级:以坛为家I
  • 打卡总天数:391
  • 最近打卡:2025-05-02 09:44:56

45

主题

381

回帖

1575

积分

金牌会员

静坐常思己过,闲谈莫论人非

积分
1575
发表于 2023-11-25 16:53:40 | 显示全部楼层
不一定是没进去,也有可能是连续多次的进入,导致前后两次中断时间太短,LED没来得及亮就又灭了。
处事要代人所想,读书需切己用功
回复 支持 1 反对 0

使用道具 举报 送花

  • 打卡等级:偶尔看看III
  • 打卡总天数:55
  • 最近打卡:2025-05-02 08:32:59

718

主题

1万

回帖

1万

积分

管理员

积分
15630
发表于 2023-11-25 19:33:57 | 显示全部楼层
用仿真功能来调试
回复 支持 反对

使用道具 举报 送花

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

本版积分规则

QQ|手机版|小黑屋|深圳国芯人工智能有限公司 ( 粤ICP备2022108929号-2 )

GMT+8, 2025-5-2 20:28 , Processed in 0.131651 second(s), 63 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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