PDA

View Full Version : Another Shiftout question



Srigopal007
- 18th August 2004, 04:58
okay ppl. I just want to know if my usage of shiftout is actually correct.. I looked at the PBP manual and they had an example which I found useful but not sure if I am using it correctly. In my program I use this format.
SHIFTOUT DATAPIN, CLOCKPIN, MODE, [VAR\bits]

PORTC.6 is where I send my data out while PORTB.3 is where I generate the clock and and data is transfered when clock goes high. which presumes MODE 1. and my goal is to send 16 bits through Portc.6

below is a sample code from my program ...

One problem which I am seeing is that i dont notice any changes in the outputs {LEDS}. is it because I am using an external clock which is 20Mhz . How can I notice the changes between the two shiftout that I am sending. Dont konw where or how I can slow things down besides using a slower clock .. but that is something I dont want to do. so please help. Also if there are any mistakes that I have in my program please mention them.

----------------program stars here--------------
INCLUDE "modedefs.bas"

i VAR BYTE
Flag1 VAR BYTE
Flag2 VAR BYTE
Count_send VAR BYTE
Latch VAR PortB.0
Chip_Enable VAR PortB.1
slug1 VAR WORD
slug2 VAR WORD
TRISC =%00000000
TRISB =%00000000
slug1 =$4676 'data that need to be sent out
slug2 =$7777 'data that need to be sent out

start:
Low Latch
High Chip_Enable
Count_send = 0
While(Latch == 0) && (Chip_Enable == 1)
Count_send = Count_send + 1 'counter to keep track of what data is sent out
if(Count_send == 1) then SEND1 'first data need to be sent out
if(Count_send == 1) then SET_FLAG

if(Count_send == 2) then SEND2 'second data need to be sent out
if(Count_send == 2) then SET_FLAG
if(Count_send == 2) then RESET_COUNT

if(Latch == 1) then
Low Chip_Enable 'activating the chip
Low Latch 'data is being latched
High Chip_Enable
endif
Wend

SEND1:
For i = 1 to 100 'repeating the signal for 100 times
ShiftOut PortC.6, Portb.3, [slug1\16]
Next i
return

SEND2:
For i = 0 to 100 'repeating the signal for 100 times
ShiftOut PortC.6, Portb.3, [slug2\16]
Next i
return

SET_FLAG:
High Latch
return

RESET_COUNT:
COUNT_SEND = 0
return

Hawkesy
- 20th September 2004, 12:04
I am no expert but maybe you could try the shift_pauseus command that will slow your shift clock down, however it is in micro seconds, so you may not see any changes.

Cheers

Dwayne
- 20th September 2004, 16:25
One problem which I am seeing is that i dont notice any changes in the outputs {LEDS}. is it because I am using an external clock which is 20Mhz .

I didn't take a real close look at your code, but at the speed your little chip is doing, LED's ain't going to cut it. Unless their is someway to do at least pause longer than 1/30th of a second. 1/30th of a second (if I remember correctly) is the frame rate on TV's. And TV's actions seems smooth to our eyes. I am sure your chip is running a whale of a lot faster. Can you scope it with a trigger and memory? Just send one slug and scope it... that way you can verify trans?. I would suggest putting the LED's on your *receiver*. And see what the receiver is receiving. Or just send the slug 00000001, and see if the receiver lights up only one LED after the send.

Dwayne

Bruce
- 21st September 2004, 23:07
Using RETURN in your sub-routines won't work unless you're using GOSUB to get to them.

if(Count_send == 2) then RESET_COUNT

The above is the same as using --

if(Count_send ==2) THEN GOTO RESET_COUNT

The GOTO is "implied" in the 1st version even though it's not physically inserted. GOSUB is what you'll need to use if you're using RETURN in all your sub-routines.

RETURN pops the return address from the stack so it knows where to RETURN to. Unless you've used GOSUB, you haven't pushed any return address onto the stack.