pic16f876a红外接收及ERROR程序
扫描二维码
随时随地手机看文章
pIC16f876a红外ERROR程序
include
statusequ03h
rp0equ05h
zequ02h
cequ00h
pclequ02h
portaequ05h
trISAequ85h
portcequ07h
triscequ87h
portbequ06h
trisbequ86h
;--------tmr0--------------
tmr0equ01h;4Mt=256(256-tmr0b)=50ms
option_regequ81h
iNTConequ0bh
t0ifequ02h
wtempequ19h
;-----------------------
ADDREQU20H;写入地址寄存器
NUMEQU21H;写入值
RECEQU22H;读计数
WRCEQU24H;写计数
rec1EQU25H
countEQU26H
;-------------------------
count1EQU27H
count2EQU28H
flagequ30h
flag1equ31h
flag2equ32h
flag3equ33h
;
flag4equ34h
;===============================
org00h
nop
gotostart
org04h
;
;=========中断服务子服务=======
serv
MOVwfwtemp
bcfintcon,t0if
btfscflag4,0
gotodelay3ms7
;
btfssflag4,3
gotowww
decfszcount1
gotowww;250uS未到继续计脉冲数gotowww
MOVlw0x03
MOVwfcount1
bsfflag4,2
gotowww
;
delay3ms7
btfssflag4,4
gotowww
decfszcount2
gotowww;3.7mS未到继续计脉冲数gotowww
bsfflag4,1
MOVlw0x0f
MOVwfcount2
;
wwwMOVlw0x0e;250us
MOVwftmr0
MOVfwtemp,0
retfie
;==================================
start
nop
bsfstatus,rp0
clrftrisc
MOVlwb’00000000’
MOVwftrisa
MOVlwb’00000101’
MOVwftrisb
MOVlwb’00000000’;1:1
MOVwfoption_reg
bcfstatus,rp0
clrfflag4
;-----------
MOVlw00h;写入EEPROM初始地址从0开始
MOVwfADDR
MOVwfrec1
MOVlw0;//初始写入值
MOVwfNUM
MOVlw30h;间接寻址,读出值初始存放地址
MOVwfFSR
MOVlw0100h;//写入次数
MOVwfWRC
;
;============复位时将EEPROM全清除掉==============
clrfcount
CCbsfSTATUS,RP1
bsfSTATUS,RP0
btfscEECON1,WR
goto$-1
bcfSTATUS,RP0
bcfSTATUS,RP1
MOVfcount,0
bsfSTATUS,RP1
MOVwfEEADR
bcfSTATUS,RP1
MOVlw0x00
bsfSTATUS,RP1
MOVwfEEDATA
bsfSTATUS,RP0
bcfEECON1,EEPGD
bsfEECON1,WREN
bcfINTCON,GIE
MOVlw55h
MOVwfEECON2
MOVlw0aah
MOVwfEECON2
bsfEECON1,WR
btfscEECON1,WR
goto$-1
bsfINTCON,GIE
bcfEECON1,WREN
bcfSTATUS,RP0
bcfSTATUS,RP1
incfcount,1
decfszWRC
gotocc
;
MOVlw8Fh;//重新写入次数值
MOVwfWRC
MOVwfREC
;\\\\\\\\\\\\\
;
MOVlw0x03
MOVwfcount1;3*250us=750us
MOVlw0x0f
MOVwfcount2;15*250us=3.7ms
;
MOVlw0xa0
MOVwfintcon
bcfintcon,t0if;TMR0设置
MOVlw0x0e
MOVwftmr0
;
MOVlw0x0f
MOVwfPORTC;初始亮PORTC,判断程序运行是否正常
clrfflag
clrfflag1
clrfflag2
clrfflag3
;
clrfflag4;标志寄存器
;==============NUM===============
main
MOVlw0x0f
MOVwfportc
MOVlw0x0f
MOVwfcount2
clrfflag4
btfscportb,2
gotomain
bsfflag4,0
bcfflag4,4
;
btfssportb,2;3.7ms内有高电平?
goto$-1;有
;
outMOVlw0x0f
MOVwfcount2
;------------------------------
;d7
bcfflag4,0;d0=1在3。7定时
bcfflag4,2;d2=1脉冲低电平在750US内,代表0
bcfflag4,3;750US不进行计时
btfssportb,2
goto$-1
dd7bsfflag4,3;开始计时
btfssportb,2;测脉冲高电平宽度
gotoss7;脉冲高电平《750US
btfssflag4,2
gotodd7
bsfflag,7;》750US;FLAG,D7=1
gotoout7
ss7bcfflag,7
out7MOVlw0x03
MOVwfcount1
;d6
bcfflag4,0
bcfflag4,2
bcfflag4,3
btfssportb,2
goto$-1
dd6bsfflag4,3
btfssportb,2
gotoss6
btfssflag4,2
gotodd6
bsfflag,6
gotoout6
ss6bcfflag,6
out6MOVlw0x03
MOVwfcount1
;d5
bcfflag4,0
bcfflag4,2;d2=1脉冲低电平在750US内,代表0
bcfflag4,3;750US不进行计时
btfssportb,2
goto$-1
dd5bsfflag4,3;开始计时
btfssportb,2;测脉冲高电平宽度
gotoss5;脉冲高电平《750US
btfssflag4,2
gotodd5
bsfflag,5;》750US;FLAG,D7=1
gotoout5
ss5bcfflag,5
out5MOVlw0x03
MOVwfcount1
;d4
bcfflag4,0
bcfflag4,2
bcfflag4,3
btfssportb,2
goto$-1
dd4bsfflag4,3
btfssportb,2
gotoss4
btfssflag4,2
gotodd4
bsfflag,4
gotoout4
ss4bcfflag,4
out4MOVlw0x03
MOVwfcount1
;d3
bcfflag4,0
bcfflag4,2
bcfflag4,3
btfssportb,2
goto$-1
dd3bsfflag4,3
btfssportb,2
gotoss3
btfssflag4,2
gotodd3
bsfflag,3
gotoout3
ss3bcfflag,3
out3MOVlw0x03
MOVwfcount1
;d2
bcfflag4,0
bcfflag4,2
bcfflag4,3
btfssportb,2
goto$-1
dd2bsfflag4,3
btfssportb,2
gotoss2
btfssflag4,2
gotodd2
bsfflag,2
gotoout2
ss2bcfflag,2
out2MOVlw0x03
MOVwfcount1
;d1
bcfflag4,0
bcfflag4,2
bcfflag4,3
btfssportb,2
goto$-1
dd1bsfflag4,3
btfssportb,2
gotoss1
btfssflag4,2
gotodd1
bsfflag,1
gotoout1
ss1bcfflag,1
out1MOVlw0x03
MOVwfcount1
;d0
bcfflag4,0
bcfflag4,2
bcfflag4,3
btfssportb,2
goto$-1
dd0bsfflag4,3
btfssportb,2
gotoss0
btfssflag4,2
gotodd0
bsfflag,0
gotoout6
ss0bcfflag,0
out0MOVlw0x03
MOVwfcount1
;------------------------
btfssportb,2
goto$-1
btfscportb,2
goto$-1
btfssportb,2
goto$-1
btfscportb,2
goto$-1
btfssportb,2
goto$-1
btfscportb,2
goto$-1
btfssportb,2
goto$-1
btfscportb,2
goto$-1
btfssportb,2
goto$-1
btfscportb,2
goto$-1
btfssportb,2
goto$-1
btfscportb,2
goto$-1
btfssportb,2
goto$-1
btfscportb,2
goto$-1
btfssportb,2
goto$-1
btfscportb,2
goto$-1
;==========================
;d7a
bcfflag4,0;d0=1在3。7定时
bcfflag4,2;d2=1脉冲低电平在750US内,代表0
bcfflag4,3;750US不进行计时
btfssportb,2
goto$-1
dd7absfflag4,3;开始计时
btfssportb,2;测脉冲高电平宽度
gotoss7a;脉冲高电平《750US
btfssflag4,2
gotodd7a
bsfflag1,7;》750US;FLAG,D7=1
gotoout7a
ss7abcfflag1,7
out7aMOVlw0x03
MOVwfcount1
;d6a
bcfflag4,0
bcfflag4,2
bcfflag4,3
btfssportb,2
goto$-1
dd6absfflag4,3
btfssportb,2
gotoss6a
btfssflag4,2
gotodd6a
bsfflag1,6
gotoout6a
ss6abcfflag1,6
out6aMOVlw0x03
MOVwfcount1
;d5a
bcfflag4,0
bcfflag4,2;d2=1脉冲低电平在750US内,代表0
bcfflag4,3;750US不进行计时
btfssportb,2
goto$-1
dd5absfflag4,3;开始计时
btfssportb,2;测脉冲高电平宽度
gotoss5a;脉冲高电平《750US
btfssflag4,2
gotodd5a
bsfflag1,5;》750US;FLAG,D7=1
gotoout5a
ss5abcfflag1,5
out5aMOVlw0x03
MOVwfcount1
;d4a
bcfflag4,0
bcfflag4,2
bcfflag4,3
btfssportb,2
goto$-1
dd4absfflag4,3
btfssportb,2
gotoss4a
btfssflag4,2
gotodd4a
bsfflag1,4
gotoout4a
ss4abcfflag1,4
out4aMOVlw0x03
MOVwfcount1
;d3a
bcfflag4,0
bcfflag4,2
bcfflag4,3
btfssportb,2
goto$-1
dd3absfflag4,3
btfssportb,2
gotoss3a
btfssflag4,2
gotodd3a
bsfflag1,3
gotoout3a
ss3abcfflag1,3
out3aMOVlw0x03
MOVwfcount1
;d2a
bcfflag4,0
bcfflag4,2
bcfflag4,3
btfssportb,2
goto$-1
dd2absfflag4,3
btfssportb,2
gotoss2a
btfssflag4,2
gotodd2a
bsfflag1,2
gotoout2a
ss2abcfflag1,2
out2aMOVlw0x03
MOVwfcount1
;d1a
bcfflag4,0
bcfflag4,2
bcfflag4,3
btfssportb,2
goto$-1
dd1absfflag4,3
btfssportb,2
gotoss1a
btfssflag4,2
gotodd1a
bsfflag1,1
gotoout1a
ss1abcfflag1,1
out1aMOVlw0x03
MOVwfcount1
;d0a
bcfflag4,0
bcfflag4,2
bcfflag4,3
btfssportb,2
goto$-1
dd0absfflag4,3
btfssportb,2
gotoss0a
btfssflag4,2
gotodd0a
bsfflag1,0
gotoout6a
ss0abcfflag1,0
out0aMOVlw0x03
MOVwfcount1
;---------------------------
MOVfflag,0
MOVwfNUM
callwrite
MOVfflag1,0
MOVwfNUM
callwrite
jjjbtfssPORTB,0
gotoback1
clrfflag4
MOVlwb’01010101’
MOVwfportc
gotojjj
;
back1gotomain
;===========写子程序============
write
clrfPORTC;//////表示进入写状态
;
bsfSTATUS,RP1
bsfSTATUS,RP0;/bank4
btfscEECON1,WR;WR=0上一次写完成
goto$-1
bcfSTATUS,RP0
bcfSTATUS,RP1;/bank0
MOVfADDR,W
bsfSTATUS,RP1;/bank2
MOVwfEEADR;ADDR-->EEADR
bcfSTATUS,RP1;/bank0
MOVfNUM,W
bsfSTATUS,RP1;/bank2
MOVwfEEDATA;VALU-->EEDATA
bsfSTATUS,RP0;/bank3
bcfEECON1,EEPGD;选定EEPROM为访问对象
bsfEECON1,WREN;开放写操作使能控制位
bcfINTCON,GIE;
;
MOVlw55h;“5指令序列”
MOVwfEECON2
MOVlw0aah
MOVwfEECON2
bsfEECON1,WR;启动写操作
;
btfscEECON1,WR
goto$-1;等待写操作成
bsfINTCON,GIE
bcfEECON1,WREN
bcfSTATUS,RP0
bcfSTATUS,RP1;bank0
incfADDR,1
;
MOVlw0x0f;////
MOVwfPORTC
return
;================================
end