![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| I just want to get some opinions on whether or not this code will work for rs-232 communication (at 9600bps) to a PC. ( PIC external ocillator 20mhz ) Code: SendData bcf PORTA,0 ;Send start bit movwf TX_DATA movlw 0x08 movwf BIT_CTR ;Set bit counter to 8 DataLoop call Delay btfss TX_DATA,0 bcf PORTA,0 ;Send a 0 bit btfsc TX_DATA,0 bsf PORTA,0 ;Send a 1 bit rrf TX_DATA,1 decfsz BIT_CTR,1 ;Decrement bit counter goto DataLoop call Delay bsf PORTA,0 ;Send stop bit return ;Should delay either 102.4uS or 102.2uS Delay movlw 0xA9 movwf COUNTER Loop decfsz COUNTER,1 goto Loop return | |
| |
| | (permalink) | |
| Quote:
The delay being slightly out won't make any difference, RS232 is an asyncronous protocol, so it re-sycnronises every data word. | ||
| |
| | (permalink) |
| :idea: If you are using an "rx" routine, don't forget to add a 1/2 bit delay after finding the start bit..... You will need to watch those timings when you ramp up the baud rate, 115200 is reliable at 8mhz..... Another little "tip" on the rx routine to give yourself a little extra processing time...... After you have "rx'd" 8 bits, don't wait 1bit delay (assuming 8,n,1) simply wait until the stop bit arrives, you can then go and process other data, for example storing the rx'd bytebefore returning for the next 1, tricky at high speed without this dodge. Hope this helps!
__________________ Regards MATT! | |
| |
| | (permalink) |
| Thanks for the input. Nigel i just took a look at the link to your tutorials in your signature and it answered alot of my questions about receiving data from the PC. Thanks for a great resource. | |
| |