雙核單片機(jī)紅外遙控碼代碼
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
評(píng)論