Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

12f683 - Shifting with 74HC595 HELP please!

Status
Not open for further replies.

SwingeyP

Member
Hello again.

Can anyone explain this weird happening please.

The attached code is running on a 12f683.
If you run this in simulation with the LED tool connected as follows:

LED 1 - RED - GPIO 0 - Latch
LED 2 - Green - GPIO 1 - Data
LED 3 - Yellow - GPIO 5 - Clock


On first pass I get what I expect. The 8 ones are sent on the data line (ds) clocked each time and then latched.
Second and all other passes is where it all goes wrong.
second pass one 1
all other passes - 0

Why isn't mydata(o) reinstated as 11111111?

No idea with this one guys.

Regards - Paul
Code:
'- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
'LEDSWINGEY - Written by Paul Swingewood (M0TVU)
'27/11/2014   - PIC 12f683
'--------------------------------------------------------------------------
'An arcade machine led flashing sequence
'--------------------------------------------------------------------------
'Revision history
'27/11/14 initial code written.

'---------------------------------------------------------------
'DEFININTIONS
'---------------------------------------------------------------

Define SIMULATION_WAITMS_VALUE = 1



Define CONFIG = 0x3d74  'Int Oscillator'
Define CLOCK_FREQUENCY = 8
AllDigital
TRISIO = %000100

'NOTE GP2 IS USED FOR INTERUPT!!!
'74HC595 Pins are in brackets

'---------------------______   _____
'--------------------(     (__)     )---------------------
'Vdd               O (1            8) O Vss
'--------------------(      1       )---------------------
'GP5    STCP (12)  O (2     2      7) O GP0   SHCP (11)
'--------------------(      f       )---------------------
'GP4               O (3     6      6) O GP1   DS (14)
'--------------------(      8       )---------------------
'GP3               O (4     3      5) O INTERUPT
'--------------------(______________)---------------------


'select the PIC pins

Symbol sh_cp = GPIO.0  'Latch
Symbol ds = GPIO.1  'Data
Symbol st_cp = GPIO.5  'Clock

Dim x As Byte
Dim bt As Byte
Dim mydata(4) As Word

mydata(0) = %11111111  'Dummy test data
mydata(1) = %00000000  'Dummy test data
mydata(2) = %10101010  'Dummy test data
mydata(3) = %01010101  'Dummy test data

'change the (x) to show different WORD patterns
'use the Sim Scope set for Display for Normal, use Zoom
'select PORT pins on scope to suit
start:
'For x = 0 To 1
    mydata = mydata(0)
    Gosub xmitdata
'Next x
Goto start
End                                              

xmitdata:

ds = mydata.7
WaitMs 1000
st_cp = 1  'clock it
WaitMs 1000
st_cp = 0

For bt = 0 To 6  '7 bits to follow
    mydata = ShiftLeft(mydata, 1)
    ds = mydata.7  'data goes high
    WaitMs 1000
    st_cp = 1  'clock it
    WaitMs 1000
    st_cp = 0
Next bt

sh_cp = 1
WaitMs 1000  'latch the data
sh_cp = 0

Return
 

Attachments

  • BlinkinThing_27_11_14.bas
    2.3 KB · Views: 313
I would be very suspicious of the line, mydata = mydata(0) as mydata is defined as an array. How the compiler will handle a variable with the same name as an array might be a problem.

Mike.
 
Doh! - Fixed it!

Sorry guys, wood for trees and all that. Can't have MyData= Mydata(o) and expect it to sort it out. Data=Mydata(0) is the way :)

I'm and eejut!

Regards - Paul
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top