PDA

View Full Version : PC - PIC problem...



menhwa
- 18th February 2006, 05:54
if i send character 'a' from PC to PIC, what data will be read by the PIC?
$61, or %01100001 ?
i connect the serial port from PC to oscilloscope, the trace show that the signal of 10000110, means that data forms by 0 and 1 when transfering, but what data will be read by PIC?
$61, or %01100001 ?

thanks for ur help...

Dwayne
- 20th February 2006, 20:42
Since your serial port only reads ones and zeros, it will receive the binary number. It is up to you do have the proper "shift" to place it into a 8 bit integer, or use the Serin command. Making sure you either flip the bits or us a MAX chip to make the ASCII readable.

Remember to keep the baud rate slow, until communication is established.


Dwayne

Melanie
- 20th February 2006, 20:57
If you send an ASCII 'a' to the PIC... what will the BYTE variable in the PIC (as received by SERIN, or SERIN2, or HSERIN or DEBUGIN) contain?

1. An ASCII 'a'
2. A BINARY value of %01100001
3. A DECIMAL value of 97
4 A HEX value of $61

The answer is ALL OF THE ABOVE.

This is because ASCII 'a' = %01100001 = 97 = $61

It's ALL THE SAME Data, it just differs in how you express it, in ASCII, in DECIMAL, in BINARY or in HEXADECIMAL. So your BYTE with a received 'a' will...

If MyByte=$61 then goto TRUE_OK
If MyByte=%01100001 then goto TRUE_OK
If MyByte=97 then goto TRUE_OK

All the above statements are THE SAME and IDENTICAL in their execution. It's up to you if you want to express any value in BINARY or HEX or DECIMAL in PICBasic... all are freely interchangeable at will. You can mix any or all on a line or at any point within your program. Data is Data is Data... a Number is a Number is a Number... how you view it or handle it, in whatever Base, is up to you.

To expand a little further, when you send your ASCII 'a' and view it on your scope, you may see more than just 01100001 transitions from High to Low (or actually inverted), because there may also be Parity bits and Stop bits... but amongst it all will be your 01100001 sequence. The PIC at it's input pin will see those High-Low Transitions, and if you are using the appropriate command, translate those into your pre-assigned variables.