PDA

View Full Version : My serial to parallel attempt



johndoug
- 21st December 2012, 23:46
I have tried to re-write a serial to parallel program found in John Iovine's "PIC Microcontroller Book", in the chapter on serial communication.His program was written in PIC basic, but I wanted to re-write and compile in PICbasic Pro. Nevertheless, even when my program compiled successfully, it did not perform successfully on the circuit board. I used a pic16F84A, a 74LS164 serial-in, parallel-out shift register, a 32.768 Khz crystal, 8 LEDs and 8 330 ohm resistors. I have not inserted the code or schematic as yet but will upload these later. The objective was to send info serially to the 74LS164, which in turn would output the 8 bit number in parallel to 8 LEDs.

johndoug
- 2nd January 2013, 03:02
A brief look at my circuit can be found at this link.
http://www.youtube.com/watch?v=XNILnxIycFQ

My code for this project is below, if loaded successfullly.

' serial out interface
'slow program for visual testing interface
'initialize ports

TRISB = 0 'set portb as output port
b0 var byte
pin0 var byte
start:
b0 = 128 'put number 128 ( 1000 0000) into b0
Gosub serial 'output the No. serially to 74ls164
'pause 1000 'wait 1 sec
b0 = 255 'Put No 255 (1111 1111) into b0
Gosub serial 'output the No. serially to 74ls164
'Pause 1000 'wait 1 sec
b0 = 0 'Put No. 0 (0000 0000) into b0
Gosub serial 'output the No. serially to 74LS164
'Pause 1000 'wait 1 sec
Goto start 'do it again

'serial out routine

serial:
pin0 = portb.7 'bring pin 0 high or low depending
'upon bits
Pulsout 1,1 'Bring CLK line high, then low
'pause 100 'same as above
pin0 = portb.6 'same as above
Pulsout 1,1 'same
'Pause 100 'same
pin0 = portb.5
Pulsout 1,1
'pause 100 'optional delay
pin0 = portb.4
Pulsout 1,1
'pause 100
pin0 = portb.3
Pulsout 1,1
'pause 100
pin0 = portb.2
Pulsout 1,1
'pause 100
pin0 = portb.1
Pulsout 1,1
'pause 100
pin0 = portb.0
Pulsout 1,1
'Pause 100
Low 1
Return

mackrackit
- 2nd January 2013, 08:13
Look at the SHIFTOUT command in the PBP manual. It does the hard work for you.

johndoug
- 4th January 2013, 04:07
Thanks for the direction and tip. I have found out a bit more about about sending and receiving serial information using the PIC. Such commands as serout, hserout and even shiftout. My test was to try synchronous data, and to use a clock. It seems that I could even do away with the 74LS164 and use another PIC chip to receive. That is, a 12F683 could read in some analog voltage, send it out serially and be intercepted by a 16F84, 16F628 or 16F684 and sent out to a 2 or 3 digit 7-segment LED. It may also be an easier task to use the built-in asynchronous serial transfer. I will also be looking at this alternative.

johndoug
- 4th January 2013, 04:15
Thanks. I will look at it the first opportunity I get. My circuit is synchronous transfer, but I will also look at the advantages of asynchronous using other pic commands like serout and serin. I want to further explore these with the 16F84A, 16F628 and 16F684.