View previous topic :: View next topic |
Author |
Message |
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Sun Jan 27, 2013 11:57 am Post subject: Universal Infra-red Remote control receiver |
|
|
This is being derived from the 32 x 8 Matrix Clock project since I have written a universal Infra-red remote decoder as part of its functions and I have now the small 21 button Infra-red push button remote with a VS 1838B receiver module (DX.COM part SKU: 136284)
I thought it would be nice to make a remote control receiver that will let you sit in your chair and control things around your house that do not have already this ability. Some TV remotes have DVD controls on them that many people do not have the DVD that goes with them so these unused buttons could be used to turn the lights off & on as an example!
Regards Paul |
|
Back to top |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Mon Jan 28, 2013 10:55 am Post subject: |
|
|
Now here is the basic circuit needed to decode the data sent from an Infra-red remote transmitter. You can use any receiver module the most common is for 38Khz carrier which is what I am using. The MAX3232 is needed only if you are plugging into an proper RS232 port, without it you must make certain that your serial device does not exceed the voltage for the AVR!
Regards Paul |
|
Back to top |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Mon Jan 28, 2013 12:05 pm Post subject: |
|
|
Now here is the code to find the timing of the transmitted data. Below you will also see a sample in the terminal of the information sent. The code starts with a pulse of 452 then we get 8 of around 52 followed by 9 of around 165 then a 58 a 165 and so on until we get to 4047 then 221 which in this remote indicates the end of the transmission. I use the values around 52 as an "0" those around 165 as a "1" . Now in many devices you will see a block in the transmission that does not change this is the ID of the transmitter which if you find that the rest of the data is different with all the buttons on the various transmitters you want to use you could ignore this part in this case its the first 16 8 "0s" then 8 "1s" the next 16 are the button data "1010001001011101". Once you have the timing you can move to decoding the data.
Regards Paul
Code: |
'
'--------------------------------------------------------------------------
' This program stores the pulse times in an array and then prints them out
' showing what was sent buy the remote
'
'
'------------------------------------------------------------------------
'
'
'
$regfile = "m8adef.dat"
$crystal = 8000000
$hwstack = 64
$swstack = 64
$framesize = 64
$baud = 19200
Dim Tmr(80) As Word
Dim Length As Word
Dim Bx As Byte
Dim Px As Byte
Dim Jx As Byte
Config Pind.3 = Input
On Int1 Int_1isr
Enable Int1
Enable Interrupts
Print "READY"
Do
If Bx = 1 Then
For Jx = 1 To Px
Print Tmr(jx)
Next Jx
Px = 0
Bx = 0
' this divides the prints on a terminal screen I reccomend Realterm for this
Print ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
'
End If
Loop
Int_1isr:
Incr Px
'Bx = 1
Pulsein Length , Pind , 3 , 1
Tmr(px) = Length
If Length = 0 Then Bx = 1
Return
|
|
|
Back to top |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Mon Jan 28, 2013 12:57 pm Post subject: |
|
|
Now we look at the data we are getting from the remote as you can see in the raw data I found the last 18 bits were always the same so I used shift right 18 times to discard them in the second terminal print, this can make the variables smaller that need to be used with it. The program is below.
Note the data corresponds to buttons 0, 1, 2, and 3.
Regards Paul
Code: |
'-------------------------------------------
'
' Data decoding for Infra-red remotes
' 10 blocks are decoded so that repeat
' while button pressed can be seen
' This gives the binary code for each
' button you press and decimal value
' I reccomend Realterm for this
$regfile = "m8adef.dat"
$crystal = 8000000
$hwstack = 128
$swstack = 256
$framesize = 256
$baud = 19200
Dim Tmr(80) As Word
Dim X As Byte
Dim Length As Word
Dim Recvdata As Word
Dim Datagot(10) As Long
Dim Bx As Byte
Dim Px As Byte
Dim Jx As Byte
Dim Bitt As Bit
Dim Flag As Byte
Config Pind.3 = Input
On Int1 Int_1isr
Enable Int1
Enable Interrupts
Print "READY"
Flag = 1
Do
If Bx = 3 Then
'With the IR remote I am using the last 18 bits remain the same so
'I use shift right to discard them
'For X = 1 To 10
'Shift Datagot(x) , Right , 18
'Next X
'We get 10 lots of data as some remotes transmit a lot of data
'so we need to look at it all to see what we want and do not need
Print Bin(datagot(1)) ; ">got-1>" ; Datagot(1)
Print Bin(datagot(2)) ; ">got-2>" ; Datagot(2)
Print Bin(datagot(3)) ; ">got-3>" ; Datagot(3)
Print Bin(datagot(4)) ; ">got-4>" ; Datagot(4)
Print Bin(datagot(5)) ; ">got-5>" ; Datagot(5)
Print Bin(datagot(6)) ; ">got-6>" ; Datagot(6)
Print Bin(datagot(7)) ; ">got-7>" ; Datagot(7)
Print Bin(datagot(8)) ; ">got-8>" ; Datagot(8)
Print Bin(datagot(9)) ; ">got-9>" ; Datagot(9)
Print Bin(datagot(10)) ; ">got-10>" ; Datagot(10)
Datagot(1) = 0
Datagot(2) = 0
Datagot(3) = 0
Datagot(4) = 0
Datagot(5) = 0
Datagot(6) = 0
Datagot(7) = 0
Datagot(8) = 0
Datagot(9) = 0
Datagot(10) = 0
Px = 0
Bx = 0
Flag = 1
'
End If
Loop
End
Int_1isr:
Pulsein Length , Pind , 3 , 1 'here we measure the length of the pulse
'Note many start with a 450 pulse which
'you can use to indicate start BUT NOT ALL DO!
Select Case Length
Case 0 'end of data, was so for all that I had
Bx = 3
Case Is < 80 'adjust for timing as seen in
'PROTOCOL_TEST_TIMING
Datagot(flag).px = 0
Case Is < 190
Datagot(flag).px = 1
'Most of the time this is only there to get the receiver to start up
'and is not needed for decode of data
'Case Is < 500 'start of transmission
Case Is > 3500 'end block
Incr Flag
Px = 0
End Select
Incr Px
Return
|
|
|
Back to top |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Wed Jan 30, 2013 10:39 am Post subject: |
|
|
Now taking a slight step backwards here we have all the codes for the 21 buttons displayed on the terminal starting at the top left working to the right and down. You can clearly see where the two bytes never change they are all "1s" then "0s" 8 of each Note the last "0" comes from the start code so ignore it that is shift it all one place to the right to get rid of it! Now for a comparison the second screen shows the buttons of another remote "an LG TV" you can see there the non changing ID for it at the end it also follows the same format with 16 bit ID. Take care not all have the same format as this and some have more than 32 bits of data but the 32bits appears to be the most common. Also picture of the remote from dx.com I am using it measures 8.5cm high by 4cm wide.
Regards Paul |
|
Back to top |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Wed Jan 30, 2013 12:19 pm Post subject: |
|
|
Now a working example that prints to the terminal as it receives the button data just the first four buttons print their name but this confirms it is working and by placing say set a pin in one then reset the pin in another we could turn a LED on/off. Note the use of the Overlay function to divide the button data and ID from the Long variable.
regards Paul
Code: |
'Universal Infra-red remote control receiver
'
'
'
'
'
'
$regfile = "m8adef.dat"
$crystal = 8000000
$hwstack = 64
$swstack = 64
$framesize = 64
$baud = 19200
Declare Sub Handel_ir
'------------------------------
'----These are the constants for the buttons on the remote
'----these are the values sent
Const Onoff = 14917
Const Modee = 14662
Const Spekr = 14407
Const Arrowright = 15172
Const Dblarrowleft=16192
Const Dblarrowright = 15427
Const Eq = 30727
Const Minus = 27157
Const Plus = 30217
Const Zero = 26902
Const Yinyang = 26137
Const Usd = 29197
Const One = 29452
Const Two = 26392
Const Three = 8542
Const Four = 30472
Const Five = 25372
Const Six = 9562
Const Seven = 15682
Const Eight = 11602
Const Nine = 13642
'--------------------------------------------------
Dim X As Byte
Dim Length As Word
Dim Datagot As Long
Dim Recdat(2)as Word At Datagot Overlay
Dim Bx As Byte
Dim Px As Byte
Config Pind.3 = Input
On Int1 Int_1isr
Enable Int1
Enable Interrupts
'Lets us know the micro is up & running and can talc to the PC
Print "READY"
Do
If Bx = 3 Then 'we have all the data
'Now we shift the data one bit to the right this lines up the
'ID as Recdat(1) and the button data as Recdat(2)
'we have broken the Datagot into two words and used no ram
Shift Datagot , Right , 1
Call Handel_ir
'Print the data to the terminal
Print Bin(datagot) ; "<<got>>" ; Datagot
Print Bin(recdat(2)) ; "<<Button Data>>" ; Recdat(2)
Datagot = 0
Px = 0
Bx = 0
'
End If
Loop
End
'Here we decide what button was pressed and what to do about it
'we could have used just the value here but by using a constant
'we can see better what button it is and we only need change
'it in one place for a diffrent remote
Sub Handel_ir
Select Case Recdat(2) 'find the button from its constant
Case Onoff
Print "On Off"
Case Modee
Print "Mode"
Case Spekr
Print "Speaker"
Case Arrowright
Print "Arrow Right"
Case Dblarrowleft
Case Dblarrowright
Case Eq
Case Minus
Case Plus
Case Zero
Case Yinyang
Case Usd
Case One
Case Two
Case Three
Case Four
Case Five
Case Six
Case Seven
Case Eight
Case Nine
End Select
End Sub
'this gets called when we receive IR pulses
Int_1isr:
Pulsein Length , Pind , 3 , 1 'here we measure the length of the pulse
'Note many start with a 450 pulse which
'you can use to indicate start BUT NOT ALL DO!
Select Case Length
Case 0 'end of data,
Bx = 3
Case Is < 80 'adjust for timing as seen in
'PROTOCOL_TEST_TIMING
Datagot.px = 0
Case Is < 190
Datagot.px = 1
'Most of the time this is only there to get the receiver to start up
'and is not needed for decode of data
Case Is < 500 'start of transmission
Case Is > 3500 'end block some remotes transmit
'more than one block of data
'but we will not need this second
'block most of the time
'Incr Flag
Px = 0
End Select
Incr Px
Return
|
|
|
Back to top |
|
|
bzijlstra
Joined: 30 Dec 2004 Posts: 1179 Location: Tilburg - Netherlands
|
Posted: Wed Jan 30, 2013 1:52 pm Post subject: Great work!! |
|
|
Paul
That is great work!! Thanks for sharing.
And it all started with a 32 x 8 display
Have fun
Ben Zijlstra |
|
Back to top |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Thu Jan 31, 2013 4:33 am Post subject: |
|
|
Thank you Ben!
I am still using one for this data just soldered the receiver onto the board and away I go. Note they are listed as temporary sold out maybe I was to greedy buying 8 of them. I also sent them a message that they should think of putting a kit of the remote transmitter, receiver, RTC chip and battery on sale . I also suggested a M328 instead of the M8 giving it much wider appeal.
Now for something else with Infra-red remote. My compact florescent lights are talking to it
What I have noticed is that while they warm up I get some "0s" sent to the receiver this is triggering of the interrupt by them I have posted a terminal output of it you can see the buttons at the top from the remote then all the "0s" as the lights warm up, the button data of 3510 at the bottom is the Air conditioner being turned on via its IR remote just shows how universal this is.
Now as I am using PULSEIN to receive the IR data it has a reflection in the mirror that is PULSEOUT so having the timing of the IR codes there is no reason why we can not generate them with the AVR and Bascom I happen to have some IR LEDs so I am going to have a go!
Regards Paul. |
|
Back to top |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Fri Feb 01, 2013 9:15 am Post subject: |
|
|
Today I thought why not re-invent the wheel make a IR-Remote receiver that you can just tell it the codes which it then stores in eeprom a sort of learning remote so no need to change the Bascom code at all.
So one way is via RS232 and since I already have the code written for a command prompt type interface I have added it so with this code you can talk to the AVR. I have not removed the fixed constants yet so that the steps can be seen in the way I change it from fixed constants to EEPROM stored user variable ones.
Regards Paul
Code: |
'Universal Infra-red remote control receiver
'with command line communication to RS232
'
'
'
'
'
$regfile = "m8adef.dat"
$crystal = 8000000
$hwstack = 64
$swstack = 80
$framesize = 64
$baud = 19200
Declare Sub Handel_ir
Declare Sub Rs232help
'------------------------------
'----These are the constants for the buttons on the remote
'----these are the values sent
Const Onoff = 14917
Const Modee = 14662
Const Spekr = 14407
Const Arrowright = 15172
Const Dblarrowleft = 16192
Const Dblarrowright = 15427
Const Eq = 30727
Const Minus = 27157
Const Plus = 30217
Const Zero = 26902
Const Yinyang = 26137
Const Usd = 29197
Const One = 29452
Const Two = 26392
Const Three = 8542
Const Four = 30472
Const Five = 25372
Const Six = 9562
Const Seven = 15682
Const Eight = 11602
Const Nine = 13642
'--------------------------------------------------
Const Prompt = "Ready>>"
Const Changecode = "Changecode"
Const Notincommands = " Unknown Command"
Const Help = "Help"
'----------------------------------------------
Dim Code(40) As Eram Long 'storage for 40 button codes
Dim Getcommands(8) As String * 20 'Here we have an array to chop up the commands from RS232
Dim A As Byte
Dim Charwaiting As Word
Dim Uart_char As Byte
Dim Uart_command As String * 30 'Needs to be long enough for commands
Dim X As Byte
Dim Length As Word
Dim Datagot As Long
Dim Recdat(2)as Word At Datagot Overlay
Dim Bx As Byte
Dim Px As Byte
Declare Sub Uartrx
Config Pind.3 = Input
On Int1 Int_1isr
Enable Int1
Enable Interrupts
'Lets us know the micro is up & running and can talk to the PC
Print Prompt;
Do
'-------------------------------------
'--This will create a command line prompt so that
'--we can use rs232 to communicate with the AVR
Charwaiting = Ischarwaiting()
If Charwaiting = 1 Then
Uart_char = Inkey()
If Uart_char = 13 Or Len(uart_command) > 30 Then
Call Uartrx
Print Prompt; 'Using a constant will let us change the prompt
Uart_command = ""
Else
Uart_command = Uart_command + Chr(uart_char) 'this adds each character to the string
Print Chr(uart_char); 'this echos the commad back to the screen
'so the user can see what they have typed
End If
End If
If Bx = 3 Then 'we have all the data
'Now we shift the data one bit to the right this lines up the
'ID as Recdat(1) and the button data as Recdat(2)
'we have broken the Datagot into two words and used no ram
Shift Datagot , Right , 1
Call Handel_ir
'Print the data to the terminal
Print Bin(datagot) ; "<<got>>" ; Datagot
Print Bin(recdat(2)) ; "<<Button Data>>" ; Recdat(2)
Datagot = 0
Px = 0
Bx = 0
'
End If
Loop
End
'Here we decide what button was pressed and what to do about it
'we could have used just the value here but by using a constant
'we can see better what button it is and we only need change
'it in one place for a diffrent remote
Sub Handel_ir
Select Case Recdat(2) 'find the button from its constant
Case Onoff
Print "On Off"
Case Modee
Print "Mode"
Case Spekr
Print "Speaker"
Case Arrowright
Print "Arrow Right"
Case Dblarrowleft
Case Dblarrowright
Case Eq
Case Minus
Case Plus
Case Zero
Case Yinyang
Case Usd
Case One
Case Two
Case Three
Case Four
Case Five
Case Six
Case Seven
Case Eight
Case Nine
End Select
End Sub
'---------------------------------------------------
' This decides what to do with commands via rs232
Sub Uartrx
Local L As Byte
Local Ip As String * 30
Local Lcount As Byte
'--Break up RS232 command with the split command using the space " "
Print
Lcount = Split(uart_command , Getcommands(1) , " ") 'This will chop up the command so we can work with it
'Here we change the IP/MACs address and store it in EEPROM
Select Case Getcommands(1)
Case Changecode
'We are going to change something in eeprom
Select Case Getcommands(2) 'This will be what to change and
'232commands(3) will be the value
Case "1" 'Change button one
Print "change button 1"
Print Prompt
End Select
' This sends the list of commands to the serial port when the server is sent a Help
'--Note the use of the constants so the words can be changed
Case Help 'notice we use a constant for language changes!
Call Rs232help 'Prints the list of commands
Case ""
Exit Sub
Case Else
Print Prompt ; Uart_command ; Notincommands 'notice we use constants for language changes!
End Select
End Sub
Sub Rs232help
Print "List of commands"
End Sub
'this gets called when we receive IR pulses
Int_1isr:
Pulsein Length , Pind , 3 , 1 'here we measure the length of the pulse
'Note many start with a 450 pulse which
'you can use to indicate start BUT NOT ALL DO!
Select Case Length
Case 0 'end of data,
Bx = 3
Case Is < 80 'adjust for timing as seen in
'PROTOCOL_TEST_TIMING
Datagot.px = 0
Case Is < 190
Datagot.px = 1
'Most of the time this is only there to get the receiver to start up
'and is not needed for decode of data
Case Is < 500 'start of transmission
Case Is > 3500 'end block some remotes transmit
'more than one block of data
'but we will not need this second
'block most of the time
'Incr Flag
Px = 0
End Select
Incr Px
Return
|
|
|
Back to top |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Sat Feb 02, 2013 11:03 am Post subject: |
|
|
Have now added command line interface that enables commands to be sent to the AVR it only has a few commands at present > Help (prints the help to terminal), Show On (causes the printing of the received codes to terminal) Show Off (turns it off), the backspace key deletes the characters one by one from the end of the line, escape key aborts the command. So we now have a way of communicating to the AVR. Next I will replace the constants for the codes with the EEPROM locations (variables) this will enable the codes to be changed without the need to change the program in the AVR.
Regards Paul
Code: |
'Universal Infra-red remote control receiver
'with command line communication to RS232
'
' The command line enables commands to be sent to the AVR
' so that the value of the codes san be changed It enables you to
' turn on the show code mode which prints the value to the terminal
'
'
'
'
$regfile = "m8adef.dat"
$crystal = 8000000
$hwstack = 64
$swstack = 80
$framesize = 64
$baud = 19200
Declare Sub Handel_ir
Declare Sub Rs232help
'------------------------------
'----These are the constants for the buttons on the remote
'----these are the values sent
Const Onoff = 14917
Const Modee = 14662
Const Spekr = 14407
Const Arrowright = 15172
Const Dblarrowleft = 16192
Const Dblarrowright = 15427
Const Eq = 30727
Const Minus = 27157
Const Plus = 30217
Const Zero = 26902
Const Yinyang = 26137
Const Usd = 29197
Const One = 29452
Const Two = 26392
Const Three = 8542
Const Four = 30472
Const Five = 25372
Const Six = 9562
Const Seven = 15682
Const Eight = 11602
Const Nine = 13642
'--------------------------------------------------
'---These are prompts for the command line
'---they only need to be changer here if you want
'---some other word or language
Const Prompt = "Ready>>"
Const Changecode = "Changecode"
Const Notincommands = " Unknown Command"
Const Help = "Help"
Const Invalid = "Invalid "
Const Kode = "Code "
Const Position = "Position"
Const Accepted = "Accepted "
Const Aborted = "Aborted"
Const Prints = "Prints "
Const This = "This "
Const Value = "Value "
Const Of = "Of "
Const Changes = "Changes "
Const Aborts = "Aborts "
Const Entire = "Entire "
Const Funktion = "Function "
Const Escape = "Escape "
Const Backspace = "Backspace "
Const Deletes = "Deletes "
Const The = "The "
Const Last = "Last "
Const Karacter = "Character "
Const Showw = "Show"
Const Onn = "On"
Const Offf = "Off"
'----------------------------------------------
Dim Code(40) As Eram Long 'storage for 40 button codes
Dim Getcommands(8) As String * 20 'Here we have an array to chop up the commands from RS232
'--Flag bits 1 or 0
Dim Show As Bit
'----
Dim A As Byte
Dim Charwaiting As Word
Dim Uart_char As Byte
Dim Uart_command As String * 30 'Needs to be long enough for commands
Dim X As Byte
Dim Length As Word
Dim Karpos As Byte
Dim Datagot As Long
Dim Recdat(2)as Word At Datagot Overlay
Dim Bx As Byte
Dim Px As Byte
Declare Sub Uartrx
Config Pind.3 = Input
On Int1 Int_1isr
Enable Int1
Enable Interrupts
'Lets us know the micro is up & running and can talk to the PC
Print Prompt;
Show = 0
Do
'-------------------------------------
'--This will create a command line prompt so that
'--we can use rs232 to communicate with the AVR
Charwaiting = Ischarwaiting()
If Charwaiting = 1 Then
Uart_char = Inkey()
'Print Uart_char;
If Len(uart_command) > 30 Then
Uart_char = 13
End If
Select Case Uart_char
Case 27 'the escape character to abort entry
Print Prompt; 'Using a constant will let us change the prompt
Uart_command = ""
Case 8
Print Chr(8); 'the backspace
Karpos = Len(uart_command) 'find the length of Uart_command
If Karpos > 0 Then 'if it has characters
Delchar Uart_command , Karpos 'delete last character
End If
Case 13
Call Uartrx
Print Prompt; 'Using a constant will let us change the prompt
Uart_command = ""
Case Else
Uart_command = Uart_command + Chr(uart_char) 'this adds each character to the string
Print Chr(uart_char); 'this echos the commad back to the screen
'so the user can see what they have typed
End Select
End If
If Bx = 3 Then 'we have all the data
'Now we shift the data one bit to the right this lines up the
'ID as Recdat(1) and the button data as Recdat(2)
'we have broken the Datagot into two words and used no ram
Shift Datagot , Right , 1
Call Handel_ir
'Print the data to the terminal
If Show = 1 Then
Print Bin(datagot) ; "<<got>>" ; Datagot
Print Bin(recdat(2)) ; "<<Button Data>>" ; Recdat(2)
Print Prompt;
End If
Datagot = 0
Px = 0
Bx = 0
'
End If
Loop
End
'Here we decide what button was pressed and what to do about it
'we could have used just the value here but by using a constant
'we can see better what button it is and we only need change
'it in one place for a diffrent remote
Sub Handel_ir
Select Case Recdat(2) 'find the button from its constant
Case Onoff
Print "On Off"
Case Modee
Print "Mode"
Case Spekr
Print "Speaker"
Case Arrowright
Print "Arrow Right"
Case Dblarrowleft
Case Dblarrowright
Case Eq
Case Minus
Case Plus
Case Zero
Case Yinyang
Case Usd
Case One
Case Two
Case Three
Case Four
Case Five
Case Six
Case Seven
Case Eight
Case Nine
End Select
End Sub
'---------------------------------------------------
' This decides what to do with commands via rs232
Sub Uartrx
Local L As Byte
Local M As Byte
Local N As Long
Local Lcount As Byte
'--Break up RS232 command with the split command using the space " "
Print
Lcount = Split(uart_command , Getcommands(1) , " ") 'This will chop up the command so we can work with it
M = Val(getcommands(2)) 'assign the number value of Getcommands(2) to M
N = Val(getcommands(3)) 'assign the number value of Getcommands(3) to N
Select Case Getcommands(1)
Case Changecode 'We are going to change something in eeprom
' will be what one to change and
'232commands(3) will be the value
'---Test if M is a valid value
If M > 0 And M < 41 Then
'---Test if N is a valid value
'---Note I show the use of a binary value for M so you can see the 32 bits of the long
If N > 0 And N < &B11111111111111111111111111111111 Then
Code(m) = N 'M is the codes location and N is its value
Print Kode ; Accepted
End If
Else
Print Prompt ; Invalid ; Kode ; Position
End If
' This sends the list of commands to the serial port when the server is sent a Help
'--Note the use of the constants so the words can be changed
Case Help 'notice we use a constant for language changes!
Call Rs232help 'Prints the list of commands
Case Showw
Select Case Getcommands(2)
Case Onn
Show = 1 'turn on data print to terminal
Print Kode ; Showw ; " " ; Onn
Case Offf
Show = 0 'turn off data print to terminal
Print Kode ; showw ; " " ; Offf
End Select
Case ""
Case Else
Print Prompt ; Uart_command ; Notincommands 'notice we use constants for language changes!
End Select
End Sub
'------------------------------
'---This print the Help list of commands
Sub Rs232help
Print Help ; " " ; Prints ; This
Print Changecode ; " " ; Changes ; Value ; Of ; Kode
Print Escape ; Aborts ; Entire ; Funktion
Print Backspace ; Deletes ; The ; Last ; Karacter
End Sub
'this gets called when we receive IR pulses
Int_1isr:
Pulsein Length , Pind , 3 , 1 'here we measure the length of the pulse
'Note many start with a 450 pulse which
'you can use to indicate start BUT NOT ALL DO!
Select Case Length
Case 0 'end of data,
Bx = 3
Case Is < 80 'adjust for timing as seen in
'PROTOCOL_TEST_TIMING
Datagot.px = 0
Case Is < 190
Datagot.px = 1
'Most of the time this is only there to get the receiver to start up
'and is not needed for decode of data
Case Is < 500 'start of transmission
Case Is > 3500 'end block some remotes transmit
'more than one block of data
'but we will not need this second
'block most of the time
'Incr Flag
Px = 0
End Select
Incr Px
Return
|
|
|
Back to top |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Sat Feb 02, 2013 12:51 pm Post subject: |
|
|
Now I have moved to using the eeprom we first turn on Show On this sends the received code to the terminal then we press a button on the remote the code will be printed to the terminal it is also stored in a variable then we load that to an eeprom location we do this by typing Record 1 this stores it in button one now we can record more by pressing another button and recording it to another location say two, Record 2 when finished we Show Off next we set the eeprom as valid by typing EEpromvalid now when we press a button the code is tested against the eeprom and if valid we do something, at present I have set up three that print button one to three. This is now a receiver that can record buttons from your remote using commands from your PC. All this has not reached 4K so you can still use the demo version of bascom.
Regards Paul
Code: |
'Universal Infra-red remote control receiver
'with command line communication to RS232
'
' The command line enables commands to be sent to the AVR
' so that the value of the codes san be changed It enables you to
' turn on the show code mode which prints the value to the terminal
'
'
'
'
$regfile = "m8adef.dat"
$crystal = 8000000
$hwstack = 64
$swstack = 80
$framesize = 64
$baud = 19200
Declare Sub Handel_ir
Declare Sub Rs232help
'------------------------------
'----These are the constants for the buttons on the remote
'----these are the values sent
'Const Onoff = 14917
'Const Modee = 14662
'Const Spekr = 14407
'Const Arrowright = 15172
'Const Dblarrowleft = 16192
'Const Dblarrowright = 15427
'Const Eq = 30727
'Const Minus = 27157
'Const Plus = 30217
'Const Zero = 26902
'Const Yinyang = 26137
'Const Usd = 29197
'Const One = 29452
'Const Two = 26392
'Const Three = 8542
'Const Four = 30472
'Const Five = 25372
'Const Six = 9562
'Const Seven = 15682
'Const Eight = 11602
'Const Nine = 13642
'--------------------------------------------------
'---These are prompts for the command line
'---they only need to be changer here if you want
'---some other word or language
Const Prompt = "Ready>>"
Const Changecode = "Changecode"
Const Notincommands = " Unknown Command"
Const Help = "Help"
Const Invalid = "Invalid "
Const Kode = "Code "
Const Position = "Position"
Const Accepted = "Accepted "
Const Aborted = "Aborted"
Const Prints = "Prints "
Const This = "This "
Const Value = "Value "
Const Of = "Of "
Const Changes = "Changes "
Const Aborts = "Aborts "
Const Entire = "Entire "
Const Funktion = "Function "
Const Escape = "Escape "
Const Backspace = "Backspace "
Const Deletes = "Deletes "
Const The = "The "
Const Last = "Last "
Const Karacter = "Character "
Const Showw = "Show"
Const Onn = "On"
Const Offf = "Off"
Const Eevalid = "EEpromvalid"
Const Eeinvalid = "EEprominvalid"
Const Turns = "Turns "
Const Reacting = "Reacting "
Const Sent = "Sent "
Const Dataa = "Data "
Const Too = "To "
Const Record = "Record"
Const Stor = "Stor"
Const Writes = "Writes "
Const Location = "Location "
Const Terminal = "Terminal " "
'----------------------------------------------
Dim Code(40) As Eram Long 'storage for 40 button codes
Dim Getcommands(4) As String * 15 'Here we have an array to chop up the commands from RS232
Dim Evalid As Eram Byte
'--Flag bits 1 or 0
Dim Show As Bit
Dim Isvalid As Byte
'----
Dim A As Byte
Dim Charwaiting As Word
Dim Uart_char As Byte
Dim Uart_command As String * 30 'Needs to be long enough for commands
Dim X As Byte
Dim Length As Word
Dim Karpos As Byte
Dim Datagot As Long
Dim Datastor As Long
Dim Recdat(2)as Word At Datagot Overlay
Dim Bx As Byte
Dim Px As Byte
Declare Sub Uartrx
Config Pind.3 = Input
On Int1 Int_1isr
Enable Int1
Enable Interrupts
'Lets us know the micro is up & running and can talk to the PC
Print Prompt;
Show = 0
Isvalid = Evalid
Do
'-------------------------------------
'--This will create a command line prompt so that
'--we can use rs232 to communicate with the AVR
Charwaiting = Ischarwaiting()
If Charwaiting = 1 Then
Uart_char = Inkey()
'Print Uart_char;
If Len(uart_command) > 30 Then
Uart_char = 13
End If
Select Case Uart_char
Case 27 'the escape character to abort entry
Print Prompt; 'Using a constant will let us change the prompt
Uart_command = ""
Case 8
Print Chr(; 'the backspace
Karpos = Len(uart_command) 'find the length of Uart_command
If Karpos > 0 Then 'if it has characters
Delchar Uart_command , Karpos 'delete last character
End If
Case 13
Call Uartrx
Print Prompt; 'Using a constant will let us change the prompt
Uart_command = ""
Case Else
Uart_command = Uart_command + Chr(uart_char) 'this adds each character to the string
Print Chr(uart_char); 'this echos the commad back to the screen
'so the user can see what they have typed
End Select
End If
If Bx = 3 Then 'we have all the data
'Now we shift the data one bit to the right this lines up the
'ID as Recdat(1) and the button data as Recdat(2)
'we have broken the Datagot into two words and used no ram
Shift Datagot , Right , 1
'--if the eeprom is loaded with valid data
If Isvalid = 5 Then
Call Handel_ir
End If
'Print the data to the terminal
If Show = 1 Then
Datastor = Datagot
Print Bin(datagot) ; "<<got >>" ; Datagot
Print Bin(recdat(2)) ; "<<Button Data >>" ; Recdat(2)
Print Prompt;
End If
Datagot = 0
Px = 0
Bx = 0
'
End If
Loop
End
'---------------------------
'--This replaces the original sub it now uses the EEPROM
'--contents
'
'
Sub Handel_ir
Local Mx As Byte
Local Dx As Long
Local Vx As Byte
Vx = 0
'------------
'--here we move through the eeprom data till we get a match Vx = 1
'--if not Vx = 0
For Mx = 1 To 40
Dx = Code(mx) 'get the contents of eeprom location
If Dx = Datagot Then 'test received data against eeprom
Vx = 1 'set flag
Exit For 'if its the same then exit the for/next
End If
Next Mx
If Vx = 1 Then 'we got a match
'--Mx will be the eeprom location matched the corisponds with
'--a button pressed so now we perform an action for that button
Select Case Mx
Case 1
Print "Button one "
Case 2
Print "Button two "
Case 3
Print "Button three "
End Select
End If
End Sub
'Here we decide what button was pressed and what to do about it
'we could have used just the value here but by using a constant
'we can see better what button it is and we only need change
'it in one place for a diffrent remote
'Sub Handel_ir
' Select Case Recdat(2) 'find the button from its constant
'Case Onoff
'Print "On Off"
'Case Modee
'Print "Mode"
'Case Spekr
' Print "Speaker "
' Case Arrowright
'
' Print "Arrow Right"
' Case Dblarrowleft
' Case Dblarrowright
' Case Eq
' Case Minus
' Case Plus
' Case Zero
' Case Yinyang
' Case Usd
' Case One
' Case Two
'Case Three
'Case Four
'Case Five
'Case Six
'Case Seven
'Case Eight
'Case Nine
'End Select
'End Sub
'---------------------------------------------------
' This decides what to do with commands via rs232
Sub Uartrx
Local L As Byte
Local M As Byte
Local N As Long
Local Lcount As Byte
'--Break up RS232 command with the split command using the space " "
Print
Lcount = Split(uart_command , Getcommands(1) , " ") 'This will chop up the command so we can work with it
M = Val(getcommands(2)) 'assign the number value of Getcommands(2) to M
N = Val(getcommands(3)) 'assign the number value of Getcommands(3) to N
Select Case Getcommands(1)
Case Changecode 'We are going to change something in eeprom
' will be what one to change and
'232commands(3) will be the value
'---Test if M is a valid value
If M > 0 And M < 41 Then
'---Test if N is a valid value
'---Note I show the use of a binary value for M so you can see the 32 bits of the long
If N > 0 And N < &B11111111111111111111111111111111 Then
Code(m) = N 'M is the codes location and N is its value
Print Kode ; Accepted
End If
Else
Print Prompt ; Invalid ; Kode ; Position
End If
' This sends the list of commands to the serial port when the server is sent a Help
'--Note the use of the constants so the words can be changed
Case Help 'notice we use a constant for language changes!
Call Rs232help 'Prints the list of commands
Case Showw
Select Case Getcommands(2)
Case Onn
Show = 1 'turn on data print to terminal
Print Kode ; Showw ; " " ; Onn
Case Offf
Show = 0 'turn off data print to terminal
Print Kode ; showw ; " " ; Offf
End Select
Case Eevalid 'eeprom data valid
Isvalid = 5
Evalid = Isvalid
Case Eeinvalid 'eeprom data invalid
Isvalid = 1
Evalid = Isvalid
Case Record 'record received data in location
'M holds the location
If M > 0 And M < 41 Then 'check its a valid location
Code(m) = Datastor
Else
Print Prompt ; Invalid ; Kode ; Position
End If
Case ""
Case Else
Print Prompt ; Uart_command ; Notincommands 'notice we use constants for language changes!
End Select
End Sub
'------------------------------
'---This print the Help list of commands
Sub Rs232help
Print Help ; " " ; Prints ; This
Print Changecode ; " " ; Changes ; Value ; Of ; Kode
Print Escape ; Aborts ; Entire ; Funktion
Print Backspace ; Deletes ; The ; Last ; Karacter
Print Eevalid ; " " ; Turns ; Onn ; Reacting ; Too ; Dataa ; Sent
Print Eeinvalid ; " " ; Turns ; Offf ; Reacting ; Too ; Dataa ; Sent
Print Record ; " " ; Writes ; The ; Dataa ; Too ; The ; Location
Print Show ; " " ; Onn ; " " ; Prints ; Dataa ; Too ; Terminal
Print Show ; " " ; Offf ; " " ; Turns ; Offf ; " " ; Prints ; Dataa ; Too ; Terminal
End Sub
'this gets called when we receive IR pulses
Int_1isr:
Pulsein Length , Pind , 3 , 1 'here we measure the length of the pulse
'Note many start with a 450 pulse which
'you can use to indicate start BUT NOT ALL DO!
Select Case Length
Case 0 'end of data,
Bx = 3
Case Is < 80 'adjust for timing as seen in
'PROTOCOL_TEST_TIMING
Datagot.px = 0
Case Is < 190
Datagot.px = 1
'Most of the time this is only there to get the receiver to start up
'and is not needed for decode of data
Case Is < 500 'start of transmission
Case Is > 3500 'end block some remotes transmit
'more than one block of data
'but we will not need this second
'block most of the time
'Incr Flag
Px = 0
End Select
Incr Px
Return
|
|
|
Back to top |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Sun Feb 03, 2013 8:09 am Post subject: |
|
|
Now to have this receiver do something I have moved to another board which is a 40 pin ZIF socket with a crystal holder, power socket & switch, a LED with resistor connected to PA0 (LED to +5volts), 10 pin header for programming and header pins connected to the ports. Now IR receiver is still connected to INT 1 I have also connected a speaker to PB1 with a 120ohm resistor and 100uf capacitor in series (see bascom help SOUND for details)
Now when the receiver is sent a code it beeps and code 1 (Record 1) turns the LED off , code 2 (Record 2) turns the LED on , code 3 (Record 3) toggles the LED on & off.
The code has now reached 4K so it is still possible to use the demo version with it so I have posted it.
Note remember to preserve eeprom on chip erase or you will have to enter the codes each time you re-program the chip.
Also I am using a M644 as it was in the draw and a 40 pin chip to fit the board.
Regards Paul
Code: |
'Universal Infra-red remote control receiver
'with command line communication to RS232
'
' The command line enables commands to be sent to the AVR
' so that the value of the codes san be changed It enables you to
' turn on the show code mode which prints the value to the terminal
'
'
'
'
$regfile = "m644def.dat"
$crystal = 8000000
$hwstack = 64
$swstack = 80
$framesize = 64
$baud = 19200
'------------------------------
'----These are the constants for the buttons on the remote
'----these are the values sent
'Const Onoff = 14917
'Const Modee = 14662
'Const Spekr = 14407
'Const Arrowright = 15172
'Const Dblarrowleft = 16192
'Const Dblarrowright = 15427
'Const Eq = 30727
'Const Minus = 27157
'Const Plus = 30217
'Const Zero = 26902
'Const Yinyang = 26137
'Const Usd = 29197
'Const One = 29452
'Const Two = 26392
'Const Three = 8542
'Const Four = 30472
'Const Five = 25372
'Const Six = 9562
'Const Seven = 15682
'Const Eight = 11602
'Const Nine = 13642
'--------------------------------------------------
'---These are prompts for the command line
'---they only need to be changer here if you want
'---some other word or language
Const Prompt = "Ready>>"
Const Changecode = "Changecode"
Const Notincommands = " Unknown Command"
Const Help = "Help"
Const Invalid = "Invalid "
Const Kode = "Code "
Const Position = "Position"
Const Accepted = "Accepted "
Const Aborted = "Aborted"
Const Prints = "Prints "
Const This = "This "
Const Value = "Value "
Const Of = "Of "
Const Changes = "Changes "
Const Aborts = "Aborts "
Const Entire = "Entire "
Const Funktion = "Function "
Const Escape = "Escape "
Const Backspace = "Backspace "
Const Deletes = "Deletes "
Const The = "The "
Const Last = "Last "
Const Karacter = "Character "
Const Showw = "Show"
Const Onn = "On"
Const Offf = "Off"
Const Eevalid = "EEpromvalid"
Const Eeinvalid = "EEprominvalid"
Const Turns = "Turns "
Const Reacting = "Reacting "
Const Sent = "Sent "
Const Dataa = "Data "
Const Too = "To "
Const Record = "Record"
Const Stor = "Stor"
Const Writes = "Writes "
Const Location = "Location "
Const Terminal = "Terminal " "
'----------------------------------------
Dim Pulses As Word , Periods As Word
'----------------------------------------------
Dim Code(40) As Eram Long 'storage for 40 button codes
Dim Getcommands(4) As String * 15 'Here we have an array to chop up the commands from RS232
Dim Evalid As Eram Byte
'--Flag bits 1 or 0
Dim Show As Bit
Dim Isvalid As Byte
'----
Dim A As Byte
Dim Charwaiting As Word
Dim Uart_char As Byte
Dim Uart_command As String * 30 'Needs to be long enough for commands
Dim X As Byte
Dim Length As Word
Dim Karpos As Byte
Dim Datagot As Long
Dim Datastor As Long
Dim Recdat(2)as Word At Datagot Overlay
Dim Bx As Byte
Dim Px As Byte
Declare Sub Uartrx
Declare Sub Handel_ir
Declare Sub Rs232help
Led Alias Porta.0
Config Pina.0 = Output
Config Pind.3 = Input
On Int1 Int_1isr
Enable Int1
Enable Interrupts
'Lets us know the micro is up & running and can talk to the PC
Print Prompt;
Show = 0
Isvalid = Evalid
Pulses = 65 : Periods = 800 'set variables
Speaker Alias Portb.1 'define port pin
Set Led
'Wait 1
'Reset Led
'Wait 1
'Set Led
Do
'-------------------------------------
'--This will create a command line prompt so that
'--we can use rs232 to communicate with the AVR
Charwaiting = Ischarwaiting()
If Charwaiting = 1 Then
Uart_char = Inkey()
'Print Uart_char;
If Len(uart_command) > 30 Then
Uart_char = 13
End If
Select Case Uart_char
Case 27 'the escape character to abort entry
Print Prompt; 'Using a constant will let us change the prompt
Uart_command = ""
Case 8
Print Chr(; 'the backspace
Karpos = Len(uart_command) 'find the length of Uart_command
If Karpos > 0 Then 'if it has characters
Delchar Uart_command , Karpos 'delete last character
End If
Case 13
Call Uartrx
Print Prompt; 'Using a constant will let us change the prompt
Uart_command = ""
Case Else
Uart_command = Uart_command + Chr(uart_char) 'this adds each character to the string
Print Chr(uart_char); 'this echos the commad back to the screen
'so the user can see what they have typed
End Select
End If
If Bx = 3 Then 'we have all the data
Sound Speaker , Pulses , Periods
'Now we shift the data one bit to the right this lines up the
'ID as Recdat(1) and the button data as Recdat(2)
'we have broken the Datagot into two words and used no ram
Shift Datagot , Right , 1
'Print ">>>>>>>>>>>>>>>>>>>" ; Isvalid
'--if the eeprom is loaded with valid data
If Isvalid = 5 Then
Call Handel_ir
End If
'Print the data to the terminal
If Show = 1 Then
Datastor = Datagot
Print Bin(datagot) ; "<<got >>" ; Datagot
Print Bin(recdat(2)) ; "<<Button Data >>" ; Recdat(2)
Print Prompt;
End If
Datagot = 0
Px = 0
Bx = 0
'
End If
Loop
End
'---------------------------
'--This replaces the original sub it now uses the EEPROM
'--contents
'
'
Sub Handel_ir
Local Mx As Byte
Local Dx As Long
Local Vx As Byte
Vx = 0
'------------
'--here we move through the eeprom data till we get a match Vx = 1
'--if not Vx = 0
For Mx = 1 To 40
Dx = Code(mx) 'get the contents of eeprom location
If Dx = Datagot Then 'test received data against eeprom
Vx = 1 'set flag
Exit For 'if its the same then exit the for/next
End If
Next Mx
If Vx = 1 Then 'we got a match
'--Mx will be the eeprom location matched the corisponds with
'--a button pressed so now we perform an action for that button
Select Case Mx
Case 1
Print "Button one "
Set Led
Case 2
Reset Led
Print "Button two "
Case 3
Print "Button three "
Toggle Led
End Select
End If
End Sub
'Here we decide what button was pressed and what to do about it
'we could have used just the value here but by using a constant
'we can see better what button it is and we only need change
'it in one place for a diffrent remote
'Sub Handel_ir
' Select Case Recdat(2) 'find the button from its constant
'Case Onoff
'Print "On Off"
'Case Modee
'Print "Mode"
'Case Spekr
' Print "Speaker "
' Case Arrowright
'
' Print "Arrow Right"
' Case Dblarrowleft
' Case Dblarrowright
' Case Eq
' Case Minus
' Case Plus
' Case Zero
' Case Yinyang
' Case Usd
' Case One
' Case Two
'Case Three
'Case Four
'Case Five
'Case Six
'Case Seven
'Case Eight
'Case Nine
'End Select
'End Sub
'---------------------------------------------------
' This decides what to do with commands via rs232
Sub Uartrx
Local L As Byte
Local M As Byte
Local N As Long
Local Lcount As Byte
'--Break up RS232 command with the split command using the space " "
Print
Lcount = Split(uart_command , Getcommands(1) , " ") 'This will chop up the command so we can work with it
M = Val(getcommands(2)) 'assign the number value of Getcommands(2) to M
N = Val(getcommands(3)) 'assign the number value of Getcommands(3) to N
Select Case Getcommands(1)
Case Changecode 'We are going to change something in eeprom
' will be what one to change and
'232commands(3) will be the value
'---Test if M is a valid value
If M > 0 And M < 41 Then
'---Test if N is a valid value
'---Note I show the use of a binary value for M so you can see the 32 bits of the long
If N > 0 And N < &B11111111111111111111111111111111 Then
Code(m) = N 'M is the codes location and N is its value
Print Kode ; Accepted
End If
Else
Print Prompt ; Invalid ; Kode ; Position
End If
' This sends the list of commands to the serial port when the server is sent a Help
'--Note the use of the constants so the words can be changed
Case Help 'notice we use a constant for language changes!
Call Rs232help 'Prints the list of commands
Case Showw
Select Case Getcommands(2)
Case Onn
Show = 1 'turn on data print to terminal
Print Kode ; Showw ; " " ; Onn
Case Offf
Show = 0 'turn off data print to terminal
Print Kode ; Showw ; " " ; Offf
End Select
Case Eevalid 'eeprom data valid
Isvalid = 5
Evalid = Isvalid
Isvalid = Evalid
Print Isvalid ; "<<valid "
Case Eeinvalid 'eeprom data invalid
Isvalid = 1
Evalid = Isvalid
Print Isvalid ; "<<invalid "
Case Record 'record received data in location
'M holds the location
If M > 0 And M < 41 Then 'check its a valid location
Code(m) = Datastor
Else
Print Prompt ; Invalid ; Kode ; Position
End If
Case ""
Case Else
Print Prompt ; Uart_command ; Notincommands 'notice we use constants for language changes!
End Select
End Sub
'------------------------------
'---This print the Help list of commands
Sub Rs232help
Print Help ; " " ; Prints ; This
Print Changecode ; " " ; Changes ; Value ; Of ; Kode
Print Escape ; Aborts ; Entire ; Funktion
Print Backspace ; Deletes ; The ; Last ; Karacter
Print Eevalid ; " " ; Turns ; Onn ; Reacting ; Too ; Dataa ; Sent
Print Eeinvalid ; " " ; Turns ; Offf ; Reacting ; Too ; Dataa ; Sent
Print Record ; " " ; Writes ; The ; Dataa ; Too ; The ; Location
Print Show ; " " ; Onn ; " " ; Prints ; Dataa ; Too ; Terminal
Print Show ; " " ; Offf ; " " ; Turns ; Offf ; " " ; Prints ; Dataa ; Too ; Terminal
End Sub
'this gets called when we receive IR pulses
Int_1isr:
Pulsein Length , Pind , 3 , 1 'here we measure the length of the pulse
'Note many start with a 450 pulse which
'you can use to indicate start BUT NOT ALL DO!
Select Case Length
Case 0 'end of data,
Bx = 3
Case Is < 80 'adjust for timing as seen in
'PROTOCOL_TEST_TIMING
Datagot.px = 0
Case Is < 190
Datagot.px = 1
'Most of the time this is only there to get the receiver to start up
'and is not needed for decode of data
Case Is < 500 'start of transmission
Case Is > 3500 'end block some remotes transmit
'more than one block of data
'but we will not need this second
'block most of the time
'Incr Flag
Px = 0
End Select
Incr Px
Return
|
|
|
Back to top |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Sun Feb 03, 2013 12:30 pm Post subject: |
|
|
Thus far I have been using the PC to tell the AVR what to do but we can also use a pin to tell it to record so here is code with this method. Pin PD7 is connected to +5V via a 1K resistor the state of this pin is checked and if it is high normal decoding is done but if it is low recording of codes is started to indicate this we get 3 beeps where normal decoding is one beep. When in recording mode the AVR starts at code 1 you press a button on the remote and it gets stored as code 1 this is indicated by two quick beeps the AVR is then ready for code 2 so when the next button is pressed it is stored as code 2 until you reach 40 then it goes to normal decoding but if you remove the gnd from PD7 and reset the AVR you can go back to normal mode at any time. Note the print statements are so I can see the modes working and are not needed.
Regards Paul
Code: |
'Universal Infra-red remote control receiver
'with command line communication to RS232
'
'
'
'
'
$regfile = "m644def.dat"
$crystal = 8000000
$hwstack = 64
$swstack = 80
$framesize = 64
$baud = 19200
'----------------------------------------
'Dim Pulses As Word , Periods As Word
'----------------------------------------------
Dim Code(40) As Eram Long 'storage for 40 button codes
'--Flag bits 1 or 0
Dim Isvalid As Byte
'----
Dim Storing As Byte
Dim A As Byte
Dim X As Byte
Dim Length As Word
Dim Karpos As Byte
Dim Datagot As Long
Dim Datastor As Long
Dim Recdat(2)as Word At Datagot Overlay
Dim Bx As Byte
Dim Px As Byte
Declare Sub Handel_ir
Declare Sub Stor_data
Led Alias Porta.0
Config Pina.0 = Output
Config Pind.3 = Input
Config Pind.7 = Input
On Int1 Int_1isr
Enable Int1
Enable Interrupts
'Lets us know the micro is up & running and can talk to the PC
Print "Ready"
'Pulses = 65 : Periods = 800 'set variables
Speaker Alias Portb.1 'define port pin
Reco Alias Pind.7
If Reco = 0 Then
Sound Speaker , 65 , 1500
Wait 1
Sound Speaker , 65 , 1500
Wait 1
Sound Speaker , 65 , 1500
Storing = 2
Isvalid = 0
A = 1
Print "Storing"
Else
Isvalid = 5
Storing = 0
Sound Speaker , 65 , 1500
Print "normal"
End If
Set Led
Do
If Bx = 3 Then 'we have all the data
Sound Speaker , 65 , 800
'Now we shift the data one bit to the right this lines up the
'ID as Recdat(1) and the button data as Recdat(2)
'we have broken the Datagot into two words and used no ram
Shift Datagot , Right , 1
Datastor = Datagot
'Print ">>>>>>>>>>>>>>>>>>>" ; Isvalid
'--if the eeprom is loaded with valid data
If Isvalid = 5 Then
Print "IR handle"
Call Handel_ir
End If
If Storing = 2 Then
Call Stor_data
End If
'Print the data to the terminal
Datastor = Datagot
'Print Bin(datagot) ; "<<got>>" ; Datagot
'Print Bin(recdat(2)) ; "<<Button Data>>" ; Recdat(2)
'Print Prompt;
Datagot = 0
Px = 0
Bx = 0
'
End If
Loop
End
'---------------------------
'--This replaces the original sub it now uses the EEPROM
'--contents
'
'
Sub Handel_ir
Local Mx As Byte
Local Dx As Long
Local Vx As Byte
Vx = 0
'------------
'--here we move through the eeprom data till we get a match Vx = 1
'--if not Vx = 0
For Mx = 1 To 40
Dx = Code(mx) 'get the contents of eeprom location
If Dx = Datagot Then 'test received data against eeprom
Vx = 1 'set flag
Exit For 'if its the same then exit the for/next
End If
Next Mx
If Vx = 1 Then 'we got a match
'--Mx will be the eeprom location matched the corisponds with
'--a button pressed so now we perform an action for that button
Select Case Mx
Case 1
Print "Button one"
Set Led
Case 2
Reset Led
Print "Button two"
Case 3
Print "Button three"
Toggle Led
Case 4
Print "Button four"
Case 5
Print "Button five"
End Select
Else
Print "No Match"
End If
End Sub
Sub Stor_data
If A < 41 Then 'check its a valid location
Code(a) = Datastor
Sound Speaker , 65 , 800
Waitms 500
Sound Speaker , 65 , 1500
Print "Stored >" ; A ; "<"
Incr A
Else
Isvalid = 5
Storing = 0
End If
End Sub
'this gets called when we receive IR pulses
Int_1isr:
Pulsein Length , Pind , 3 , 1 'here we measure the length of the pulse
'Note many start with a 450 pulse which
'you can use to indicate start BUT NOT ALL DO!
Select Case Length
Case 0 'end of data,
Bx = 3
Case Is < 80 'adjust for timing as seen in
'PROTOCOL_TEST_TIMING
Datagot.px = 0
Case Is < 190
Datagot.px = 1
'Most of the time this is only there to get the receiver to start up
'and is not needed for decode of data
Case Is < 500 'start of transmission
Case Is > 3500 'end block some remotes transmit
'more than one block of data
'but we will not need this second
'block most of the time
'Incr Flag
Px = 0
End Select
Incr Px
Return
|
|
|
Back to top |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Tue Feb 05, 2013 4:12 am Post subject: |
|
|
I have been looking at the task of transmitting Infra-red data what we need to do is generate a 38Khz carrier and turn this on and off but as you will have seen this requires a number of different lengths they are 450us , 170us , 60us , 250us , 4050us and these are just the ones I have measured so far. I first thought about using the AVR to do it all this will require setting up PWM with a timer , varying the timing of the PWM for all these different times and recalculating the values for the registers involved every time the clock frequency is changed , I thought as I did when I worked out the receiving part "It can not be that hard to do?" so I thought why not use the most used chip of them all the NE555 timer as it was made to do this job it can drive up to 200 milliamps of current and go to over 300Khz so after some research I have come up with a circuit it is posted here with the details of the mega48 that I will be using with it to test it out. I will be only adding some relays to some of the M48 pins to switch things on/off. My plan behind transmitting codes is that I want to be able to turn the air conditioners on/off via their infra-red codes with the web server project . Note by starting with the M48 I can go M8 , M168 & M328 just by swapping the chip.
Regards Paul |
|
Back to top |
|
|
six1
Joined: 27 Feb 2009 Posts: 553
|
Posted: Fri Oct 11, 2013 6:50 am Post subject: |
|
|
Hi,
at first i want to say, that the following Code might be useless for most people
This is because of the fact, that only a few People worldwide will have the necessary Hardware.
The Story about:
End of the 70's i was a Radio/Television Technican. 1978 Grundig released the RPC Studio "Compact" Music Center's.
One of them, the RPC600aTP, was a very expensive Unit and i wondered who is able to buy such expensive Electronic Art.
Last Week by a coincidence i saw a RPC600 on eBay for only a few Bucks and bought it
Meanwhile Music Center is in function again. Spare parts as turntable needle DM95 and Belts are availible, but no ultrasonic remote controlls!
These Ultrasonics are very very rarely and not one to get. So i decided to build up a little System with Mega8 and an Infrared Remotcontroll out of the Crawling box.
Best is, that nothing is changed on RPC600. The Mega8 is added and connected to A, B, C, D, E at SAA1025 with 5 Diodes 1N4148; nothing else!
Inspired by Paul's Code!
Now you know, why this Code might be useless for you
Whatever you will do with it, here it is.
best, michael
http://www.radiomuseum.org/r/grundig_hifi_studio_rpc600tprpc_6.html
Code: |
'(
SIX1 2013/10
IR-Remote replacement for ultrasonic remote control from Grundig RPC600 Music Center
IR RX Device: SFH506 -> Output connected to PIND.3
SAA1025
Pin Grundig 1N4148 Pin Mega8
A --|>|--- PC0
B --|>|--- PC1
C --|>|--- PC2
D --|>|--- PC4
E --|>|--- PC3
Mega8 connected to +5V from RPC600, intern RC 8MHz Oscillator
')
$regfile = "m8adef.dat"
$crystal = 8000000
$hwstack = 50
$swstack = 50
$framesize = 100
'generated. Take care that the chip supports all fuse bytes.
$prog &HFF , &HC4 , &HD9 , &H00
'-------------------------------------------------------------------------------
' Declarations
'-------------------------------------------------------------------------------
$baud = 9600
Config Portc = Output
Portc = &HFF
Config Pind.3 = Input
On Int1 Int_1isr
Enable Int1
Dim Length As Word
Dim Datagot As Long
Dim PX as Byte
Dim Recdat(2)as Word At Datagot Overlay
Dim Key As Word
Dim Outbyte As Byte , Outbyte_end As Byte
dim reset_prog as word, res_pos as byte
'Print "Grundig IR Receiver"
Enable Interrupts
' Set Output on both 74ls154 to unused Pin
Portc = &B0_1111
Waitms 1
Portc = &B1_1111
Res_pos = 80
Do
If Reset_prog = Res_pos Then
' Timeout: Reset Outputs on both 74LS154
Portc = &B0_1111
Waitms 1
Portc = &B1_1111
'Print "STOP"
Incr Reset_prog
Elseif Reset_prog < Res_pos Then
Incr Reset_prog
Waitms 1
End If
Loop
End
Int_1isr:
Pulsein Length , Pind , 3 , 1 'Get pulse length
Select Case Length
Case 0 'EOF
Reset_prog = 0
Case Is < 80
Datagot.px = 0
Case Is < 190
Datagot.px = 1
Case Is < 500 'Start of transmission
Datagot = 0
Px = 0
Case Is > 1000 'End of block Signal
Shift Datagot , Right , 1
If Recdat(2) > 0 Then
Key = Recdat(2)
End If
Outbyte = &HFF
Select Case Key
'Sender 1
Case 10582
Outbyte = &B0_1000
'Sender 2
Case 9562
Outbyte = &B0_1001
'Sender 3
Case 8542
Outbyte = &B0_1010
'Sender 4
Case 10837
Outbyte = &B0_1011
'Sender 5
Case 9817
Outbyte = &B1_1000
'Sender 6
Case 8797
Outbyte = &B1_1001
'Sender 7
Case 11092
Outbyte = &B1_1010
'Sender 8
Case 10072
Outbyte = &B1_1011
'Sender 9
Case 9052
Outbyte = &B1_1100
'Sender 10
Case 25627
Outbyte = &B1_1101
'Cassette
Case 32512
Outbyte = &B0_1100
'TA Input
Case 31492
Outbyte = &B0_1101
'TB Input
Case 30472
Outbyte = &B0_1110
'EIN/AUS
Case 8287
Outbyte = &B0_0001
'Laut +
Case 24862
Outbyte = &B1_0010
'Laut -
Case 25117
Outbyte = &B1_0001
'Höhen +
Case 26902
Outbyte = &B0_0100
'Höhen -
Case 27157
Outbyte = &B0_0101
'Bass +
Case 26392
Outbyte = &B0_0010
'Bass -
Case 14662
Outbyte = &B0_0011
'Balance L
Case 15937
Outbyte = &B1_0011
'Balance R
Case 13897
Outbyte = &B1_0101
'Stumm
Case 10327
Outbyte = &B1_0111
'MPX
Case 9307
Outbyte = &B1_0100
End Select
If Outbyte <> &HFF Then
'Print Outbyte.0 ; " " ; Outbyte.1 ; " " ; Outbyte.2 ; " " ; Outbyte.3 ; " " ; Outbyte.4
' negated Logic on Grundig!
Outbyte = Not Outbyte
Portc = Outbyte
End If
Waitms 25
Reset_prog = 0
Datagot = 0
Px = 0
End Select
Incr Px
Return
|
_________________ For technical reasons, the signature is on the back of this message. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|