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

双核单片机红外遥控码代码,第1张

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

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

 

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/dianzi/2514825.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-08-05
下一篇 2022-08-05

发表评论

登录后才能评论

评论列表(0条)

保存