Question About Using SEROUT Instruction with PIC Processor
bobledoux
Posts: 187
I’m using the Serout instruction to send a data byte to a PIC microprocessor. The PIC has 8 LED’s wired to display the data byte. Communication is working, but I’m not getting the expected results.
My question is: Am I using the right format to send the binary value 10000000, which is decimal value 128? I want the 8 LEDS, powered by the PIC, to all be off except the one at the high bit end. The instruction I am using at 2400 baud is:
Serout 12, 396, [noparse][[/noparse]BIN8 128]
My question is: Am I using the right format to send the binary value 10000000, which is decimal value 128? I want the 8 LEDS, powered by the PIC, to all be off except the one at the high bit end. The instruction I am using at 2400 baud is:
Serout 12, 396, [noparse][[/noparse]BIN8 128]
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
4 digit serial LED
http://hometown.aol.com/newzed/index.html
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
4 digit serial LED
http://hometown.aol.com/newzed/index.html
·
You probably just want to send the 128 by itself.
SEROUT 12, Baud, [noparse][[/noparse]leds]
Where Baud is a constant defining speed and mode (true or inverted), and leds is a value that corresponds to the desired output.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
It works. when I change [noparse][[/noparse]BIN 128] to [noparse][[/noparse]128]
Here is the basic process in case others want to try:
This is a one way communication with the Stamp transmitting at 2400 baud to a PIC 12F508. The bit width at this baudrate is 417 microseconds.
The link between the Stamp and PIC has a pullup resistor-4.7K.
The PIC program is written in assembly language so let me describe the steps:
A. The program sits in a loop waiting for the Stamp to pull the serial line low. Pulling the line low signifies the beginning of the serial start bit.
B. The PIC delays 208 microseconds to place it into the middle of the start bit. It then tests the line to see if it is still low. If the line has gone high, a false start has taken place and the PIC program returns to step A.
C. If the line remains low after the 208 microseconds in step B, the PIC begins 9 loops. In each loop the following steps are performed.
C1 the data line is read and its high (1) or low (0) status is placed in the data output byte.
C2 the data output byte is rotated right 1 bit.
C3 a delay of 417 microseconds is made to move to the next bit.
The loop beginning at step C1 is repeated a total of 9 times because the first bit read is the start bit. The 9th loop passes the start bit out of the data output byte.
There is a demo in the SX/B help file that shows how to receive a byte like this in an interrupt and place that byte into a 16-byte circular buffer. SX/B is very similar to PBASIC, and allows assembly instructions to be mixed in.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
If you are using an external pull-up resistor, then you may want to experiment with the 'open' mode (add $8000 to the BaudMode value) of the BS2 SEROUT command. The 'open' modes only drive the pin to one state, and let it 'float' to the other state. This 'float' part requires the external pull-up resistor. Check out the manual for inverted vs non-inverted and 'open' to find which state is driven vs. floated.