[C语言] 谁帮我写个这种情形下函数指针数组的示范,先谢谢了.

[复制链接]
1600|3
 楼主| datouyuan 发表于 2016-9-8 16:16 | 显示全部楼层 |阅读模式
本帖最后由 datouyuan 于 2016-9-8 16:19 编辑

之前的一些项目只用了一个引脚变化中断,这些模块单独使用是完全正常的.
这些模块都以状态机方式做的,耗时极短.
  1. //U2270b 曼彻斯特码 P17
  2. void manchester_int(void) interrupt 8
  3. {
  4. }

  5. //模拟温度湿度模块 P16
  6. void wdsd_int(void) interrupt 8
  7. {
  8. }


现在要2个模块要同时使用,程序修改如下,也能完全从正常使用.
  1. //U2270b 曼彻斯特码 P17
  2. void manchester_int(void)
  3. {
  4. }

  5. //mcu模拟温度湿度模块 P16
  6. void wdsd_int(void)
  7. {
  8. }

  9. //u8P1是全局变量,存的是上次中断P1的值
  10. //P1WKUP 使能对应引脚中断
  11. void p1_change_int(void) interrupt 8
  12. {
  13.         uint8 temp=u8P1;//读P1端口值
  14.         u8P1=P1;                //存P1端口值,以供其他模块使用
  15.         temp=temp^u8P1;        //对应位为1表示P1端口对应位发生了引脚变化

  16.         if(P1WKUP & temp & 0x80) manchester_int();
  17.         if(P1WKUP & temp & 0x40) wdsd_int();
  18. }


假如有8个功能完全不同的模块要使用8个引脚中断,能否用一种统一的方法做?
  1. void p1_change_int(void) interrupt 8
  2. {
  3.         uint8 i=0x01;
  4.         uint8 j=0;
  5.         uint8 temp=u8P1;
  6.         u8P1=P1;
  7.         temp=temp^u8P1;//
  8.         do{
  9.                 if(i & P1WKUP & temp)
  10.                 {
  11.                         //可否根据i或j的值直接调用不同的函数?
  12.                         //函数指针数组可否做到?
  13.                 }
  14.                 i<<=1;j++;
  15.         }while(i);
  16. }


函数指针数组可否做到?谁帮我写个这种情形下函数指针数组的示范,先谢谢了.


airwill 发表于 2016-9-8 19:43 | 显示全部楼层
引脚 IO 口没有办法用统一的指针来操作, 因为 IO 口指令不支持间接寻址
 楼主| datouyuan 发表于 2016-9-9 09:34 | 显示全部楼层
airwill 发表于 2016-9-8 19:43
引脚 IO 口没有办法用统一的指针来操作, 因为 IO 口指令不支持间接寻址

可以使用变量i或j操作,不一定非用IO口.
i<<=1;j++;
416356084 发表于 2016-9-9 11:27 | 显示全部楼层
datouyuan 发表于 2016-9-9 09:34
可以使用变量i或j操作,不一定非用IO口.
i

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

本版积分规则

个人签名:maowenyuan@126.com

31

主题

1088

帖子

9

粉丝
快速回复 在线客服 返回列表 返回顶部