With this code you should be able t talk to the AVR via realterm compile it and load into the 644 it works so only a hardware problem will stop it. If you type Help it should send back the commands also all you type will be sent back to the screen.
Regards Paul
[code:1:abf3ca46d5]
'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 = "m644pdef.dat"
$crystal = 8000000
$hwstack = 64
$swstack = 80
$framesize = 64
$baud = 2400
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
[/code:1:abf3ca46d5]
↧