PDA

View Full Version : Shiftin pic18f452



TonyA
- 12th August 2009, 18:22
Hi,

I am using pic18f452 and want to connect a 4021B shift register to it.

The shift reg is paralell input (switches) and serial output ----> to the pic.

Now I see that in the pic manual the pic would accept two parameters from the shift register; clock and data.

*However, the 4021B shift register also has a "Latch" pin. Would I just connect the 4021's latch pin to a pin on the pic, and make that pin on the pic toggle high or low?

Thanks for any help.

TonyA

mackrackit
- 12th August 2009, 19:15
Here is a snippet.

In this case the Load would be the same as your Latch.



Clock var PORTB.7
Load var PORTB.6
Data_1 var PORTB.5
'###########
pulsout Load,1
shiftin Data_1,Clock,MSBPre,[keys]

TonyA
- 12th August 2009, 19:50
Ok, I see. Thanks very much.

TonyA
- 12th August 2009, 22:38
It's been awhile since I worked with picbasic pro. I get an error with:

Clock var PORTB.7
Load var PORTB.6
Data_1 var PORTB.5


Don't know why.

Thanks.

TonyA
- 12th August 2009, 23:03
Fixed, I think. I had some kind of conflict with the pin assignments. (I think).

Thanks again.

mackrackit
- 12th August 2009, 23:06
What is the error?
is there more to your code? :) do you like guessing games? :)

Yes, I am a smart _ _ _ ..

EDIT>>>
I need to see if a post was made while I am typing. Or type faster...

TonyA
- 13th August 2009, 13:52
Sorry. I have it all fixed now using your code above. I was pasting it into some old code and wasn't paying attention.

I'll post my code when I get it finished.

Thanks for your help, I appreciate it very much.

TonyA
- 17th August 2009, 21:08
I was wondering if anyone could check my code here and see if there are any boo-boo's.

I am not getting the results I have expected. I am using a 4021 shift register sending serial data out to the pic18F452.

I have buttons connected to the 4021 (parallel to serial chip) and send the bits out to the pic. I just wanted to test it by having the pic receive a byte (%00000001) and then light up an LED.

It worked intermittently, but not really.




'DEFINITIONS'
DEFINE OSC 20
DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 15

'serial registers
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 20h
DEFINE HSER_BAUD 31250

'PORT SETUP'
TRISA = %11111111
ADCON1 = %10000010

'VARIABLES'

keys var byte

A_Button var byte
B_Button var byte
Select_Button var byte
Start_Button var byte
Up_Button var byte
Down_Button var byte
Left_Button var byte
Right_Button var byte


A_Button = %00000001
B_Button = %00000010
Select_Button = %00000100
Start_Button = %00001000
Up_Button = %00010000
Down_Button = %00100000
Left_Button = %01000000
Right_Button = %10000000


''Pin Assignments''
data_in var portb.7
latch var portb.6
clock var portb.5

main:

pulsout latch, 1 'toggle the latch pin
shiftin data_in, clock, 0, [keys]

if keys = A_Button then 'if A button pressed light LED on RB0
high portb.0
pause 1
low portb.0
endif

goto main

mackrackit
- 18th August 2009, 10:38
The pause 1 seems to be to fast to see.
Try having the LED come on for at least 100ms
pause 100