BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / embedded-system / #11108同步于 2011/9/13
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Embedded_System机器人发帖

【求助】PIC单片机,RB中断

hudiefei
2011/9/13镜像同步17 回复
这个我能发在这里吗?可以贴代码么? 可以的话中午来贴
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
hobby机器人#1 · 2011/9/13
为啥不能贴呢? 不过最好把问题描述清楚一点儿,这样别人才能帮助你 【 在 hudiefei 的大作中提到: 】 : 这个我能发在这里吗?可以贴代码么? : 可以的话中午来贴
diou203机器人#2 · 2011/9/13
RB。。数据业务么
hudiefei机器人#3 · 2011/9/13
代码在下面。这个程序要完成的是教室人数统计,通过两个红外先后通断判断当前人的进出,计数,写进eeprom,然后送液晶显示。rb4,rb7分别接两个红外。rc4,rc7接led灯,显示此次中断的具体红外。本来正常的应该是每次计数之后c口都要清零,但是下载后发现有时候能清零,有时候不能,最多计数到003. 另外我还有个问题就是因为rb外部中断发生的时间很随机,我一开始的时候需要对sum,portc等清零,但是后面的连续操作里不需要清零,如果中断返回在这些清零指令前面肯定会影响。因为软件仿真的时候中断设置在清零指令前面,返回来之后就做了清零操作,我本以为,返回来应该是在sleep那个loop那的的,是因为软件仿真中sleep不起作用还是程序本身就存在问题呢?我的问题是不是还是在中断操作上?还是在计数程序count上呢? 非常感谢 偶是小菜菜 pcl equ 0x02 status equ 0x03 c equ 0 z equ 2 rp0 equ 5 rp1 equ 6 pclath equ 0x0a intcon equ 0x0b portb equ 0x06 trisb equ 0x86 portc equ 0x07 trisc equ 0x87 portd equ 0x08 trisd equ 0x88 porte equ 0x09 rw equ 0 rs equ 1 trise equ 0x89 adcon1 equ 0x9f;bank1 gie equ 7 rbif equ 0 intf equ 1 eecon1 equ 0x18c eepgd equ 7 wren equ 2 wr equ 1 rd equ 0 eecon2 equ 0x18d;bank2 eedata equ 0x10c eeadr equ 0x10d addr equ 0x70 sum equ 0x71 number equ 0x72 deyh equ 0x20 deyl equ 0x21 hund equ 0x23 ten equ 0x24 ment equ 0x25 temp equ 0x26 hunds equ 0x27 tens equ 0x28 ments equ 0x29 w_temp equ 0x7f status_temp equ 0x7e pclath_temp equ 0x7d portb_b equ 0x7c intcon_temp equ 0x7b potion_reg equ 0x81 intedg equ 6 org 0x0000 nop goto main org 0x0004 goto serv main nop nop bcf status,rp1 bsf status,rp0;bank1 clrf trisc clrf trisd clrf trise movlw 0xff movwf trisb bcf potion_reg,intedg bcf status,rp1 bcf status,rp0;bank0 clrf portc clrf portb_b clrf sum clrf number call eep call play bcf status,rp1 bcf status,rp0 movlw 0x98 loop movwf intcon movf portb,1;通过读此时的B口的电平作为基准电平 bcf intcon,rbif;rbif=0 sleep nop goto loop serv;中断服务程序 movwf w_temp swapf status,0 clrf status movwf status_temp movf pclath,0 movwf pclath_temp clrf pclath ;调查中断源 bcf status,rp1 bcf status,rp0 btfsc intcon,intf;intf=1 goto intserv btfsc intcon,rbif goto rbserv ;int中断,对EEPROM和屏幕显示清零 intserv bcf status,rp1 bcf status,rp0 clrf sum call eep call play bcf intcon,intf goto retfie0 ;rb中断,计数,EEPROM存储,屏幕显示 rbserv call delay10 bcf status,rp1 bcf status,rp0 comf portb,0 movwf portb_b movlw 0x90 andwf portb_b,0 btfsc status,z;z=0跳过下一步 goto rbloop call delay10 comf portb,0 movwf portb_b movlw 0x90 andwf portb_b,0 btfsc status,z;z=0跳过下一步 goto rbloop call count call eep call play rbloop bcf status,rp1 bcf status,rp0 comf portb,0 bcf intcon,rbif andlw 0xf0 btfsc status,z goto retfie0 goto rbloop retfie0 movf pclath_temp,0 movwf pclath swapf status_temp,0 movwf status swapf w_temp,1 swapf w_temp,0 retfie ;count count bcf status,rp1 bcf status,rp0 movlw 0x10;portb4=high andwf portb_b,0 btfsc status,z; goto inc;b4=0,b7=1 movlw 0x80 andwf portb_b,0 btfss status,z return;portb4and7=1 goto dec;portb4=1,portb7=0 dec btfss portc,7 goto d2 d1 movf sum,1 btfss status,z;z=1,step over next commend decf sum,1 clrf portc call delay10 return d2 btfss portc,4 goto r1 goto r0 r1 bsf portc,4 call delay10 return r0 clrf portc call delay10 return inc btfss portc,4 goto in2 in1 movlw 0xff xorwf sum,0 btfss status,z;z=0,step over next commend,set the uper limit0xff incf sum,1 clrf portc call delay10 return in2 btfss portc,7 goto re1 goto re0 re1 bsf portc,7 call delay10 return re0 clrf portc call delay10 return eep movlw 0x03 movwf addr bsf status,rp1 bsf status,rp0;bank3 btfsc eecon1,wr goto $-1 bcf status,rp0;bank2 movf addr,0 movwf eeadr movf sum,0 movwf eedata bsf status,rp0;bank3 bcf eecon1,eepgd bsf eecon1,wren bcf status,rp1 bcf status,rp0 bcf intcon,gie bsf status,rp1 bsf status,rp0 movlw 0x55 movwf eecon2 movlw 0xaa movwf eecon2 bsf eecon1,wr bcf status,rp1 bcf status,rp0 bsf intcon,gie bsf status,rp1 bsf status,rp0 bcf eecon1,wren btfsc eecon1,wr goto $-1 bsf status,rp1 bcf status,rp0;bank2 movf addr,0 movwf eeadr bsf status,rp0 bcf eecon1,eepgd bsf eecon1,rd bcf status,rp0 clrf number movf eedata,0 movwf number return hun nop bcf status,rp1 bcf status,rp0 clrf hund clrf hunds clrf ten clrf tens clrf ment clrf ments ;查找百位 hund1 movf number,0 movwf temp movlw 0x64 subwf temp,1 btfss status,c;C goto hund01;有借位 incf hund,1;无借位 movlw 0x64 subwf temp,1 btfss status,c;C goto hund01;有借位 incf hund,1;无借位 goto ten1 ;查找十位 hund01 movlw 0x64 addwf temp,1 ten1 movlw 0x0a subwf temp,1 btfss status,c;C goto ten01;有借位 incf ten,1;无借位 movlw 0x0a subwf temp,1 btfss status,c;C goto ten01;有借位 incf ten,1;无借位 movlw 0x0a subwf temp,1 btfss status,c;C goto ten01;有借位 incf ten,1;无借位 movlw 0x0a subwf temp,1 btfss status,c;C goto ten01;有借位 incf ten,1;无借位 movlw 0x0a subwf temp,1 btfss status,c;C goto ten01;有借位 incf ten,1;无借位 movlw 0x0a subwf temp,1 btfss status,c;C goto ten01;有借位 incf ten1,1;无借位 movlw 0x0a subwf temp,1 btfss status,c;C goto ten01;有借位 incf ten,1;无借位 movlw 0x0a subwf temp,1 btfss status,c;C goto ten01;有借位 incf ten,1;无借位 movlw 0x0a subwf temp,1 btfss status,c;C goto ten01;有借位 incf ten,1;无借位 goto men1 ten01 movlw 0x0a addwf temp,1 men1 movf temp,0 movwf ment return convert addwf pcl,1 table retlw 0x30 retlw 0x31 retlw 0x32 retlw 0x33 retlw 0x34 retlw 0x35 retlw 0x36 retlw 0x37 retlw 0x38 retlw 0x39 return play nop bcf status,rp1 bsf status,rp0;进入体1 movlw 06h movwf adcon1;设置为全数字信号 clrf trisd clrf trise;将d与e设置为输出 bcf status,rp0 clrf portd clrf porte call delay10 call hun movf intcon,0 movwf intcon_temp clrf intcon movf hund,0 call convert movwf hunds movf ten,0 call convert movwf tens movf ment,0 call convert movwf ments movf intcon_temp,0 movwf intcon ini movlw 0x01 movwf portd bsf porte,rs bcf porte,rs call delay10;先送指令再触发 清屏 movlw 0x34 movwf portd bsf porte,rs bcf porte,rs;先送指令再触发 功能设置 call delay10 movlw 0x08 movwf portd bsf porte,rs bcf porte,rs;先送指令再触发 显示开 call delay10 movlw 0x06 movwf portd bsf porte,rs bcf porte,rs;先送指令再触发 设置输入方式 call delay10 movlw 0x14 movwf portd bsf porte,rs bcf porte,rs;先送指令再触发 moving call delay10 movlw 0x0c movwf portd bsf porte,rs bcf porte,rs;先送指令再触发 显示开 call delay10 show movlw 0x80 movwf portd bcf porte,rw bsf porte,rs bcf porte,rs;先送指令再触发 写入数据 call delay2 movlw 0x4e movwf portd bsf porte,rw bsf porte,rs bcf porte,rs;先送指令再触发 写入数据 call delay2 movlw 0x81 movwf portd bcf porte,rw bsf porte,rs bcf porte,rs;先送指令再触发 写入数据 call delay2 movlw 0x4f movwf portd bsf porte,rw bsf porte,rs bcf porte,rs;先送指令再触发 写入数据 call delay2 movlw 0x82 movwf portd bcf porte,rw bsf porte,rs bcf porte,rs;先送指令再触发 写入数据 call delay2 movlw 0x57 movwf portd bsf porte,rw bsf porte,rs bcf porte,rs;先送指令再触发 写入数据 call delay2 movlw 0x83 movwf portd bcf porte,rw bsf porte,rs bcf porte,rs;先送指令再触发 写入数据 call delay2 movlw 0x3a movwf portd bsf porte,rw bsf porte,rs bcf porte,rs;先送指令再触发 写入数据 call delay2 movlw 0x84 movwf portd bcf porte,rw bsf porte,rs bcf porte,rs;先送指令再触发 写入数据 call delay2 movlw 0x20 movwf portd bsf porte,rw bsf porte,rs bcf porte,rs;先送指令再触发 写入数据 call delay2 movlw 0x85 movwf portd bcf porte,rw bsf porte,rs bcf porte,rs;先送指令再触发 写入数据 call delay2 movlw 0x20 movwf portd bsf porte,rw bsf porte,rs bcf porte,rs;先送指令再触发 写入数据 call delay2 movlw 0x86 movwf portd bcf porte,rw bsf porte,rs bcf porte,rs;先送指令再触发 写入数据 call delay2 movlw 0x20 movwf portd bsf porte,rw bsf porte,rs bcf porte,rs;先送指令再触发 写入数据 call delay2 movlw 0x84 movwf portd bcf porte,rw bsf porte,rs bcf porte,rs;先送指令再触发 写入数据 call delay2 movf hunds,0 movwf portd bsf porte,rw bsf porte,rs bcf porte,rs;先送指令再触发 写入数据 call delay2 movlw 0x85 movwf portd bcf porte,rw bsf porte,rs bcf porte,rs;先送指令再触发 写入数据 call delay2 movf tens,0 movwf portd bsf porte,rw bsf porte,rs bcf porte,rs;先送指令再触发 写入数据 call delay2 movlw 0x86 movwf portd bcf porte,rw bsf porte,rs bcf porte,rs;先送指令再触发 写入数据 call delay2 movf ments,0 movwf portd bsf porte,rw bsf porte,rs bcf porte,rs;先送指令再触发 写入数据 call delay2 movlw 0x87 movwf portd bcf porte,rw bsf porte,rs bcf porte,rs;先送指令再触发 写入数据 call delay2 movlw 0x2f movwf portd bsf porte,rw bsf porte,rs bcf porte,rs;先送指令再触发 写入数据 call delay2 movlw 0x88 movwf portd bcf porte,rw bsf porte,rs bcf porte,rs;先送指令再触发 写入数据 call delay2 movlw 0x55 movwf portd bsf porte,rw bsf porte,rs bcf porte,rs;先送指令再触发 写入数据 call delay2 movlw 0x89 movwf portd bcf porte,rw bsf porte,rs bcf porte,rs;先送指令再触发 写入数据 call delay2 movlw 0x50 movwf portd bsf porte,rw bsf porte,rs bcf porte,rs;先送指令再触发 写入数据 call delay2 movlw 0x8a movwf portd bcf porte,rw bsf porte,rs bcf porte,rs;先送指令再触发 写入数据 call delay2 movlw 0x45 movwf portd bsf porte,rw bsf porte,rs bcf porte,rs;先送指令再触发 写入数据 call delay2 movlw 0x8b movwf portd bcf porte,rw bsf porte,rs bcf porte,rs;先送指令再触发 写入数据 call delay2 movlw 0x52 movwf portd bsf porte,rw bsf porte,rs bcf porte,rs;先送指令再触发 写入数据 call delay2 movlw 0x8c movwf portd bcf porte,rw bsf porte,rs bcf porte,rs;先送指令再触发 写入数据 call delay2 movlw 0x3a movwf portd bsf porte,rw bsf porte,rs bcf porte,rs;先送指令再触发 写入数据 call delay2 movlw 0x8d movwf portd bcf porte,rw bsf porte,rs bcf porte,rs;先送指令再触发 写入数据 call delay2 movlw 0x32 movwf portd bsf porte,rw bsf porte,rs bcf porte,rs;先送指令再触发 写入数据 call delay2 movlw 0x8e movwf portd bcf porte,rw bsf porte,rs bcf porte,rs;先送指令再触发 写入数据 call delay2 movlw 0x35 movwf portd bsf porte,rw bsf porte,rs bcf porte,rs;先送指令再触发 写入数据 call delay2 movlw 0x8f movwf portd bcf porte,rw bsf porte,rs bcf porte,rs;先送指令再触发 写入数据 call delay2 movlw 0x35 movwf portd bsf porte,rw bsf porte,rs bcf porte,rs;先送指令再触发 写入数据 call delay2 return delay2;2ms delay movlw 0x03 movwf deyh again2 movlw 0xdc movwf deyl again1 decfsz deyl,1 goto again1 decfsz deyh,1 goto again2 return delay10;10ms delay movlw 0x0d movwf deyh again4 movlw 0xff movwf deyl again3 decfsz deyl,1 goto again3 decfsz deyh,1 goto again4 return end
hudiefei机器人#4 · 2011/9/13
还有就是int中断没有作用,我不能人工清零,int脚接的是人工复位键 这个是16f877的
hobby机器人#5 · 2011/9/14
看到你写的功能描述,我的第一想法是:图书馆就有这个东东啊,能统计每天多少人到图书馆的,可以要求参考一下源代码。。。
hobby机器人#6 · 2011/9/14
此外,单片机不能用C语言编程吗? 汇编的可读性很差呀
hudiefei机器人#7 · 2011/9/14
老师要汇编 今天更加不好,早上还能计数,虽然不是很准,但是现在什么也木有 好惆怅 【 在 hobby 的大作中提到: 】 : 此外,单片机不能用C语言编程吗? : 汇编的可读性很差呀 : -- : ...................
Taivas机器人#8 · 2011/9/14
中断返回后应该是返回到进入中断前的位置的,这个位置是随机的,因为你不知道程序运行到哪里会发生中断。还有建议c口清零写在终断里,在中断里判断是否需要清零,然后给予相应处理,然后再跳出中断不就行了么?
hudiefei机器人#9 · 2011/9/14
恩,中断返回是随机的。 【 在 Taivas 的大作中提到: 】 : 中断返回后应该是返回到进入中断前的位置的,这个位置是随机的,因为你不知道程序运行到哪里会发生中断。还有建议c口清零写在终断里,在中断里判断是否需要清零,然后给予相应处理,然后再跳出中断不就行了么? : --