![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
what if you want to receive a message via rs232 and for the micro controller to act upon that message? Like you need to turn off a relay remotely?
__________________
People perish because of lack of knowledge |
|
|
|
|
|
|
(permalink) |
|
Simply program the PIC to act accordingly - check my tutorials for examples.
|
|
|
|
|
|
|
(permalink) |
|
Mr Goodwin,
I have just copied rs232 receive routine and its execllent. I know how to receive a byte using the serial interface. Rcv_RS232 BTFSC PORTB, 7 ;wait for start bit GOTO Rcv_RS232 CALL Start_Delay ;do half bit time delay BTFSC PORTB, 7 ;check still in start bit GOTO Rcv_RS232 MOVLW 0x08 ;set up to read 8 bits MOVWF BITCNT CLRF RCV_BYTE Next_RcvBit CALL Bit_Delay BTFSS PORTB, 7 BCF STATUS , C BTFSC PORTB, 7 BSF STATUS , C RRF RCV_BYTE , f DECFSZ BITCNT , f ;test if all done GOTO Next_RcvBit CALL Bit_Delay MOVF RCV_BYTE, W RETURN I have a string of bytes like 0x23, 0x54, 0xa5, 0x6a, 0x07, 0x15 stored somewhere in memory ( I don't know whether to put these values in tabular form), but I want to compare the received bytes with the above values sequentially and if exactly similar I branch to section of the code. I hope you can assist me in coming up with code to do the comparison.
__________________
People perish because of lack of knowledge |
|
|
|
|
|
|
(permalink) |
|
Check tutorial 5.2 which detects seperate keys, it's easily extended to check for fixed string sequences.
|
|
|
|
|
|
|
(permalink) |
|
I feel that I am failing to understand your tutorial 5.2. Is it possible for you to explain the concept of the code. Or if there is anyone here who can assist I would be grateful.
But consider my suggestion below, assess it and pass you comments. 1 Receive a byte, 2 Save it in a register 3 compare the value in the register with the value in a table RCVMSGTABLE RETLW 0x1E ; start of incoming msg RETLW 0x00 RETLW 0x0C RETLW 0x02 RETLW 0x00 RETLW 0x59 RETLW 0x00 RETLW 0x01 RETLW 0x00 RETLW 0x01 RETLW 0x02 RETLW 0x00 RETLW 0x07 RETLW 0x91 RETLW 0x16 RETLW 0x14 RETLW 0x91 RETLW 0x09 RETLW 0x10 RETLW 0xF0 RETLW 0x00 RETLW 0x00 RETLW 0x00 RETLW 0x00 RETLW 0x15 RETLW 0x00 ;end of incoming msg So when I receive the first byte in RCVBYTE I compare it with 0x1E, the 2nd received byte with 0x00 , the 3rd with 0x0C etc until the end.
__________________
People perish because of lack of knowledge |
|
|
|
|
|
|
(permalink) |
|
Yes, you could keep the string in a table.
|
|
|
|
|
|
|
(permalink) | |
|
Quote:
__________________
People perish because of lack of knowledge |
||
|
|
|
|
|
(permalink) | |
|
Quote:
__________________
People perish because of lack of knowledge |
||
|
|
|
|
|
(permalink) |
|
You can use long tables, that aren't bothered by 256 byte boundaries - check my LED matrix tutorial.
|
|
|
|
|
|
|
(permalink) |
|
Ok thanks let continue with the code
__________________
People perish because of lack of knowledge |
|
|
|
|
|
|
(permalink) |
|
I have this problem of maintaining the 9600 baud rate when receiving the bytes. Will this not have a bearing on the baud rate
__________________
People perish because of lack of knowledge |
|
|
|
|
|
|
(permalink) | |
|
Quote:
The tutorial routines are very old and very well tested. |
||
|
|
|
|
|
(permalink) |
|
You are right that the routines do work. What I am worried about is the time spent doing the comparison of the received byte and the byte in the table, because what happens is I receive a byte then compare it with another before receiving the next and that's where my worry is.
Maybe we could receive the whole message first then do the comparison?
__________________
People perish because of lack of knowledge |
|
|
|
|
|
|
(permalink) | |
|
Quote:
|
||
|
|
|
|
|
(permalink) |
|
As a method of testing my rs232 communication, I connected my pic16f84 to the max232 and pc. In Hyperterminal, I saw ascii characters way different from the Hex files i was transmitting like ¶°ïüĂ●∑
__________________
People perish because of lack of knowledge |
|
|
|
|