|
AN #20 - How to decode SONY IR remote control signals |
|
|
How to decode SONY IR remote control signals
The sample source code of this application note shows that you don't have to use ASM.
Kantor Zoltan who wrote this program shows
you how to do the job with just BASCOM-BASIC.
Just connect a SFH506-36 to the INT0 of the 8051 compatible chip.
Download source code in .BAS file
Here is the code:
' (c)1999, By Kantor Zoltan
'foprogi
'*******************************************************************************************
'compiler opciok
'*******************************************************************************************
$baud = 19200 'baudrate
$crystal = 11059200 'frequency
$romstart = &H8200 'rom starting address
$ramsize = &H0200 'size of RAM
$ramstart = &H3000
$large
$iramstart = &H30
$map
'Hardware
'int0 IR sensor
'if there is an infra signal then the pin is 1
'number of received bit: 12+1 start
'device code:5 bit
'button code:7 bit
'if you have question please let me know:
'mailto:kantor@mail.matav.hu
'mailto:kantor@freemail.c3.hu
'mailto:kantor@tar.hu
'*******************************************************************************************
'konfig
'*******************************************************************************************
Config Timer0 = Timer , Gate = Internal , Mode = 2
'Timer0 = timer : timer0 operates as a timer
'Gate = Internal :
no external gate control
'Mode = 2 :
8-bit reload
Th0 = 0
Set Tcon.0 'edge trig
Set Tcon.2
On Timer0 Timer_0_int
On Int0 Int0_int
Enable Interrupts 'enable the use of interrupts
Enable Timer0
Enable Int0
Start Timer0 'start the timer
'*******************************************************************************************
'valtozo definiciok
'*******************************************************************************************
Triac Alias P1.0
Led Alias P3.3
Dim New_ir_command As Bit
Dim Infra_count As Byte
Dim Infra_count_old As Byte
Dim Infra_command As Word
Dim Segb1 As Byte
Dim Segbit1 As Bit
Dim N As Byte
Dim Segw1 As Word
Dim Segb2 As Byte
New_ir_command = 0
Ide:
If New_ir_command = 0 Then Goto Ide
Infra_count_old = 0
Segw1 = Infra_command
Print N ; " Number of received bit "
Print "Received command ";
Printhex Segw1
Shift Segw1 , Right , 2
Segb2 = High(segw1)
Print "Device " ; Segb2
Segb2 = Low(segw1) / 2
Print "Button " ; Segb2
Print
Goto Ide
'*******************************************************************************************
'* int rutinok
'*******************************************************************************************
'****************************************
'* timer0 rutin
'****************************************
Rem The Interrupt Handler For The Timer0 Interrupt
Rem .27.. ms each irq
Timer_0_int:
If Infra_count < 150 Then
Incr Infra_count
New_ir_command = 0
Else
New_ir_command = 0
If Infra_count_old <> 0 Then
New_ir_command = 1
End If
End If
Timer_0_int_end:
Return
'****************************************
'* int0 rutin
'****************************************
Rem The Interrupt Handler For The INT0 Interrupt
Rem infra falling edge trigger the irq
Int0_int:
If Infra_count = 150 Then
Infra_count = 0 'start receive (Infra_count=0)
New_ir_command = 0
Infra_count_old = 0
Infra_command = 0
N = 0
End If
Segb1 = Infra_count - Infra_count_old
If Segb1 > 5 Then Set Infra_command.15 Else Reset Infra_command.15
Infra_count_old = Infra_count
Shift Infra_command , Right
Incr N
Int0_int_end:
Return
|