Instead of reading the HSERIN as STRING, read it as a DEC in to your WORD variable. Also you can use an interupt to know when you have data. If you got the interupt to work on your counter, you are close to getting it to work on data input. Darell Taylor interupts make it pretty easy. What you need is something like this at the begining:
Code:
INCLUDE "DT_INTS-18.bas" ; Base Interrupt System
INCLUDE "ReEnterPBP-18.bas" ; Include if using PBP interrupts
INCLUDE "Elapsed_INT-18.bas" ; Elapsed Timer Routines
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _ClockCount, PBP, yes
INT_Handler TMR0_INT, _ToggleLED1, PBP, yes
INT_Handler RX_INT, _Check_Command, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
T0CON = %10001000
@ INT_ENABLE TMR1_INT
@ INT_ENABLE TMR0_INT
@ INT_ENABLE RX_INT
When the Pic recieves data it will set the RX_INT flag and jump to the _Check_Command Sub, the pic will save a some data in the UART, so you don't need to be waiting for the data to come, just need to get it when it does. The Check_Command sub looks like this:
Code:
Check_Command:
hserin 10,No_Cmd,[Dec In_Val]
'*******************************************************
'Cool code goes here, I was reading single digit numbers and had
'if statements to reply with different information, FYI calling another sub
'in an interupt sub was breaking the code. So be carefull jumping out
'and expecting things to work as normal on return.
'********************************************************
@ INT_RETURN
'******************************************
'Shouldn't make it to No_Cmd, since there was data on RX to get into
'this sub. The Int_Return above should jump you back to your code
'after you get your command
'******************************************
No_Cmd:
HSEROUT [10,"Made it to No_Cmd: I'm broke",10]
'***************************
'Don't know if disabling the RX_INT and enabling is needed
'I was trying to fix the issue of calling a sub from an interupt sub
'and thought this might help.
'***************************
@ INT_DISABLE RX_INT
@ INT_ENABLE RX_INT
@ INT_RETURN
I have seen examples of reading strings if data on a single HSERIN command, I haven't ventured that far myself, but you should find examples if you search this forum, I'm sure that's where I saw it.
Just to summerize, I used this to read single numbers 1-9 and had if statements for the code to react to, I didn't do math, so I might just be lucky that it worked.
Have Fun
Shane
Bookmarks