双核单片机红外遥控码代码

控制/MCU

1879人已加入

描述

一个用应广双核单片机做的红外遮挡开光(反射式)全部代码。

IR_SW equ pb.1

IR_INPUT equ pa.0
IR_OUTPUT equ pa.6


byte ir_new
byte ir_old
byte ir_enable
byte i
byte ir_new1
byte ir_new2
byte ir_new3

  goto main0
goto main1

//----------------FPPA0-------------------
main0:
.ADJUST_OTP_IHRCR 8MIPS  // IHRC/2 = 8MIPS, WatchDog Disable, RAM 0,1 temporary be used

sp = 0x30

disgint
inten = 0

mov a,0b000_11_111 //disable timer
mov t16m,a

set1 pbc.1
set0 IR_SW

set0 pac.0
set1 pac.6
set0 IR_OUTPUT

delay 200

ir_new = 0
ir_old = 0
ir_enable = 0

mov a,0
mov intrq,a


set1 fppen.1 //eanble FPPA1

ir_enable = 1
i = 20
while(i)
{
  delay 200
  i--
}

if(IR_INPUT)
{
  ir_old = 1
}
else
{
  ir_old = 0
}

ir_enable = 0
i = 5
while(i)
{
  delay 200
  i--
}

clkmd.1 = 1 //enable watch dog


main0_loop:
wdreset
call check_ir

if(ir_new != ir_old)
{
  if(ir_new != 1)
  {
   tog IR_SW
  }
  ir_old = ir_new
}

i = 100
while(i)
{
  delay 200
  i--
}
goto main0_loop

check_ir:
ir_enable = 1
i = 20
while(i)
{
  delay 200
  i--
}

if(IR_INPUT)
{
  ir_new1 = 1
}
else
{
  ir_new1 = 0
}

i = 5
while(i)
{
  delay 200
  i--
}

if(IR_INPUT)
{
  ir_new2 = 1
}
else
{
  ir_new2 = 0
}

i = 5
while(i)
{
  delay 200
  i--
}

if(IR_INPUT)
{
  ir_new3 = 1
}
else
{
  ir_new3 = 0
}

if((ir_new1 == ir_new2) && (ir_new2 == ir_new3))
{
  ir_new = ir_new1
}
else
{
  ir_new = ir_old
}

ir_enable = 0
i = 20
while(i)
{
  delay 200
  i--
}
ret

//----------------FPPA1-------------------
main1:
sp = 0x38
delay 200
main1_loop: //output 38k IR signal
if(ir_enable)
{
  set1 IR_OUTPUT
  delay 33
  set0 IR_OUTPUT
  delay 67
}
else
{
  set0 IR_OUTPUT
  delay 10
}
goto main1_loop

 

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分