Hi Guys,
I am trying to get back into the assembly boat with PIC's after a long haul with C, I want to see if I can still remember what I used to know!
I have followed Nigel's PIC tutorial 7.7 regarding the Hardware UART,
I have the loop receiving and sending anything in the W register, anybody enlighten me how I can check the incomming data for a string, i.e. Check if the data received is "hello" etc.
I'm sure there was a "simple" way to do it, I just cannot think how.
Thanks
Wilksey
c = UART_get
if c != "h" return
c = UART_get
if c != "e" return
c = UART_get
if c != "l" return
c = UART_get
if c != "l" return
c = UART_get
if c != "o" return
At this point you have received "hello"
Except hhello will not be recognized, because the second char fails the 'e' test and the new test for 'h' only applies to the NEXT char.In pseudo-code:
Code:c = UART_get if c != "h" return c = UART_get if c != "e" return c = UART_get if c != "l" return c = UART_get if c != "l" return c = UART_get if c != "o" return At this point you have received "hello"
Except hhello will not be recognized, because the second char fails the 'e' test and the new test for 'h' only applies to the NEXT char.
Thank you all for your responses!
Nigel, that is what I was looking for, thank you!
Your delay routines say for a 4MHz clock, how can I calculate the values for other OSC speeds, I must admit I dont understand the 0xE7 or the 0x04 for counta and countb, and goto $+2 I'm guessing that means current address + 2 locations?
Hmm, one issue.
I have just realised 9.2 assumes you know what the 4 bytes of the RX register are, but wouldn't I need to look at each byte at a time?
Also, can I use a "function" like your "TEXT" for the LCD, where it just increments the F count to find where in the list it is checking?
byte1
byte2
byte3
byte4
byte5
store1
store2
store3
store4
store5
Loop
call Recv_RS232
call Xmit_RS232
goto Loop
Command1
addwf PCL, f
retlw 'h'
retlw 'e'
retlw 'l'
retlw 'l'
retlw 'o'
retlw 0x00
clrf count ;set counter register to zero
Message movf count, w ;put counter value in W
call Command1 ;get a character from the text table
xorlw 0x00 ;is it a zero?
btfsc STATUS, Z
goto Correct
incf count, f
goto Message
Correct
bsf PORTD, 0
Hi Nigel.
I haven't heard of the PICList delay code generator, is this freely available?
So I have 5 variables to store the data such as:
and 5 variables that hold the value to checkCode:byte1 byte2 byte3 byte4 byte5
Code:store1 store2 store3 store4 store5
The loop consists of:
Code:Loop call Recv_RS232 call Xmit_RS232 goto Loop
I have added the following:
Code:Command1 addwf PCL, f retlw 'h' retlw 'e' retlw 'l' retlw 'l' retlw 'o' retlw 0x00
I have a variable called count like you and have used this:
Code:clrf count ;set counter register to zero Message movf count, w ;put counter value in W call Command1 ;get a character from the text table xorlw 0x00 ;is it a zero? btfsc STATUS, Z goto Correct incf count, f goto Message Correct bsf PORTD, 0
So if it compares correctly it will set RD0 to high.
But I'm a bit confused as to how to get more than one character from the UART before checking, and how to check multiple commands.
So for example, if I wanted to turn on / off 3 /4 channels I wanted to compare the UART against:
ch1on
ch1off
ch2on
ch2off
ch3on
ch3off
ch4on
ch4off
Or if I wanted to check mutliple lengths I guess I could use a terminating char such as 0x00 or 0x0A , 0x0D?
Hi Nigel,
Wouldn't that only allow for a fixed number of input characters if I call the "check_receive" (mock function) 4 times?
I dont suppose you can do dynamic variables like in C with Assembler can you?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?