Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 16th April 2007, 09:19 AM   (permalink)
Default

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
emufambirwi is offline  
Reply With Quote
Old 16th April 2007, 09:45 AM   (permalink)
Default

Simply program the PIC to act accordingly - check my tutorials for examples.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Reply With Quote
Old 20th April 2007, 09:08 AM   (permalink)
Default

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
emufambirwi is offline  
Reply With Quote
Old 20th April 2007, 09:12 AM   (permalink)
Default

Check tutorial 5.2 which detects seperate keys, it's easily extended to check for fixed string sequences.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Reply With Quote
Old 20th April 2007, 12:12 PM   (permalink)
Default

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
emufambirwi is offline  
Reply With Quote
Old 20th April 2007, 12:25 PM   (permalink)
Default

Yes, you could keep the string in a table.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Reply With Quote
Old 20th April 2007, 12:55 PM   (permalink)
Default

Quote:
Originally Posted by Nigel Goodwin
Yes, you could keep the string in a table.
I have 2 tables that occupies more than 256 addresses, what problems am I likely to face
__________________
People perish because of lack of knowledge
emufambirwi is offline  
Reply With Quote
Old 20th April 2007, 01:03 PM   (permalink)
Default

Quote:
Originally Posted by Nigel Goodwin
Yes, you could keep the string in a table.
where else could I keep the string
__________________
People perish because of lack of knowledge
emufambirwi is offline  
Reply With Quote
Old 20th April 2007, 01:07 PM   (permalink)
Default

You can use long tables, that aren't bothered by 256 byte boundaries - check my LED matrix tutorial.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Reply With Quote
Old 20th April 2007, 01:53 PM   (permalink)
Default

Ok thanks let continue with the code
__________________
People perish because of lack of knowledge
emufambirwi is offline  
Reply With Quote
Old 23rd April 2007, 08:55 AM   (permalink)
Default

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
emufambirwi is offline  
Reply With Quote
Old 23rd April 2007, 09:39 AM   (permalink)
Default

Quote:
Originally Posted by emufambirwi
I have this problem of maintaining the 9600 baud rate when receiving the bytes. Will this not have a bearing on the baud rate
What do you mean you have a 'problem'?.

The tutorial routines are very old and very well tested.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Reply With Quote
Old 23rd April 2007, 09:59 AM   (permalink)
Default

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
emufambirwi is offline  
Reply With Quote
Old 23rd April 2007, 11:32 AM   (permalink)
Default

Quote:
Originally Posted by emufambirwi
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?
You could do it either way, but bear in mind you've got all the time of a stop bit to do the comparison anyway - and in PIC terms that's lot's and lot's of time!.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Reply With Quote
Old 20th June 2007, 02:17 PM   (permalink)
Default

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
emufambirwi is offline  
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes




All times are GMT. The time now is 11:20 PM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.