ok peeps - from what i can gather the reason THIS isnt working is cos of the programming.
I'll be the first to admit its a pretty clumsy setup but in my defence i'm a beginner and at its heart its pretty simple but with a lot of repetition.
i basically want to get a 08M2 picaxe to talk to a shift register and then on to (in this case) a seven segment LED (LCD's matrix LED's and all sorts of other stuff comes later)
any help would be greatly appreciated
dom
; Picaxe 08 M2
;Blue Beta seven segment LED via shift register control
; Pin names
; PICAXE 08M2
;pin 1 = +V ;pin 2 = C.5 / serial in / (in) ;pin 3 = C.4 / (in / out / ADC / touch) ;pin 4 = C.3 / (in) ;pin 5 = C.2 / (in / out / ADC / touch / PWM / tune / SRQ / hi2c sda) ;pin 6 = C.1 / (in / out / ADC / touch / hserin / SRI / hi2c scl) ;pin 7 = C.0 / serial out / (out / hserout / DAC) ;pin 8 = 0v / GND
; Digital output
symbol doutpin0 = B.0 ;SRCLK symbol doutpin1 = B.1 ;RCLK symbol doutpin2 = B.2 ;OE symbol doutpin3 = B.4 ;SER
symbol srclk = B.0 symbol rclk = B.1 symbol oe = B.2 symbol ser = B.4
; Digital input (can i double up like this?)
symbol dinpin1 = pinC.1 symbol dinpin2 = pinC.2 symbol dinpin3 = pinC.3 ; symbol dinpin4 = pinC.4 symbol dinpin5 = pinC.5
; Variable symbols ' (byte variables [bx] can store integer numbers between 0 and 255) ; (word variables [wx] can store integer numbers between 0 and 65535) ; (bit variables [bitx] can store single bits - ie 1 or 0)
; ;b12 = counter 0 to 9 ;b13 skipped - it may turn up in "infrain"?
;up to b28
symbol vgap = b2 ;variable gap let vgap = 1 ;vgap = 1 as standard (no real difference)
symbol vgap2 = b3 ;variable gap let vgap2 = 1 ;wait vgap = 1 as standard
symbol counter = b12 let counter = 1
symbol sr1 = bit0 let sr1 = 0 symbol sr2 = bit1 let sr2 = 0 symbol sr3 = bit2 let sr3 = 0 symbol sr4 = bit3 let sr4 = 0 symbol sr5 = bit4 let sr5 = 0 symbol sr6 = bit5 let sr6 = 0 symbol sr7 = bit6 let sr7 = 0 symbol sr8 = bit7 let sr8 = 0
; program start
main:
gosub numcounter
goto main
stop
;gosubs
numcounter: ;0 to 9 for counter = 1 to 10 if counter = 1 then gosub number_one if counter = 2 then gosub number_two if counter = 3 then gosub number_three if counter = 4 then gosub number_four if counter = 5 then gosub number_five if counter = 6 then gosub number_six if counter = 7 then gosub number_seven if counter = 8 then gosub number_eight if counter = 9 then gosub number_nine if counter = 10 then gosub number_ten pause 1000 gosub shift_register next counter return
it just seemed so unwieldy to me. The problem is, I couldn’t figure out how to make it simpler. I did a couple of quick searches for PICAXE shift register. I got some useful hits.
http://www.bristolwatch.com/picaxe/74hc164_demo.htm The code here was pretty easy for me to follow. Understand that a '165 '164 etc are just shift registers. The pins may have different labels, but, they perform the same job as the '595. Make the proper connections and you will be in good shape.
Maybe you could look at the above link and come back here with specific questions?
I believe the Rev-Ed forums have some good info too.
I was hoping to be able to tell you whether you should sign in to the Rev Ed site, but, I can’t look at the posted code yet to be able to say yea or nay.
and using westaust55’s Three 74HC575 to three 7-seg dispays for larger PICAXE.bas program i started to make some headway
(i’m posting the program after the questions so please tell me if i’ve missed out any credit or broken any rules cos it certainly isnt my work and i dont want to upset anyone)
anyway… regarding the “lookup” command - would i be right in thinking he’s abbreviated the eight ones and zeros required for the shift register in hexadecimal? if so how exactly did he separate out the highs and lows so you could send the other signal required by the shift to move it along?
there a whole bunch of other stuff i dont get but im starting here
thanks peeps
dom
; ==================================================================== ; File… Three 74HC575 to three 7-seg dispays for 28X1 or 40X1 ; Purpose… Program to use three cascaded 74HC595 shift registers ; to drive three 7-segment displays ; Author… Westaust55 ; E-mail… ; Started… 24-10-2009 ; Updated… DD-MM-YYYY ; =============================================== ; ; -----[ Program Description ]--------------------------------------------- ; ; A program to drive three 74HC575 to three 7-seg dispays and diplays values ; on three 7-segment displays to show the values from 0.00 thru 0.01 … to 999. ; ; ; -----[ Revision History ]------------------------------------------------ ; A. First written 24-10-2009 ; ; ; -----[ I/O Definitions ]------------------------------------------------- ; ; - - - DIGITAL INPUT PINS - - - ; ; - - - DIGITAL OUTPUT PINS - - - ; SYMBOL RegCl = 3 ; Shift Register Clear - Low to clear SYMBOL OutEn = 4 ; Output Enable. Low to enable Outputs SYMBOL latch = 5 ; latch data to 595 outputs SYMBOL sclk = 6 ; serial clock on pin 4 SYMBOL sdata = 7 ; serial data on pin 1
; ; -----[ Constants ]------------------------------------------------------- ; ; ; ; -----[ Variables ]------------------------------------------------------- ; ; define aliases names for variables used SYMBOL bitcntr = b3 ; control for serial shifting of data out SYMBOL digit = b4 ; extracted digit from 3 digit value 0 - 999 SYMBOL digout = b5 ; encoded value 7-seg display to the output with serial shifting SYMBOL mask = b6 ; SYMBOL decpnt = b7 ; ; -----[ EEPROM Data ]----------------------------------------------------- ; ; ; ; -----[ Initialization ]-------------------------------------------------- ;
Init: Low sclk ; make sure the clock and data lines are low in advance Low sdata Low OutEn ; Enable the 74HC595 outputs High RegCl ; Remove the 74HC595 clear signal decpnt = 0 ; ; ; -----[ Program Code ]---------------------------------------------------- ;
Main: FOR b2 = 1 TO 3 ; three decades to display 0.00 to 9.99, 00.0 to 99.9 and 000. to 999. FOR w0 = 0 to 999 ; range of the display
; Demonstrate use of Output Enable and Clear Signals if count between 500 and 550 IF w0 > 500 AND w0 < 550 THEN If b2 = 1 THEN ; First cycle disable outputs so no display High OutEn ELSEIF b2 = 2 THEN ; Second cycle clear the shift registers Low RegCl ; again the 7-seg displays are all off ENDIF ENDIF IF w0 = 551 THEN ; restore at end of the "feature"demo period LOW OutEn HIGH RegCl ENDIF
; Normal count and display portion of the code
digit = w0 // 10 ; extract units digit IF b2 = 3 THEN decpnt = 1 ENDIF GOSUB ShiftoutMSBFirst ; fetch the bit code for the current digit value and shift out
digit = w0 // 100 / 10 ; extract the tens digit IF b2 = 2 THEN decpnt = 1 ENDIF GOSUB ShiftoutMSBFirst digit = w0 / 100 ; extract the hundreds digit IF b2 = 1 THEN decpnt = 1 ENDIF GOSUB ShiftoutMSBFirst pulsout latch,5
NEXT w0 NEXT b2 GOTO Main ; loop through the values 0.00 to 999 forever
END ; ; -----[ Subroutines ]----------------------------------------------------- ; ShiftoutMSBfirst: ; First find the display code for 7-seg display corresponding to the digit value 0 -9 LOOKUP digit, ($7D,$60,$5E,$7A,$63,$3B,$3F,$70,$7F,$7B), digout ; change $70 to $56 for different “7” appearance IF decpnt = 1 THEN digout = digout OR $80 ; turn on bit 7 for decimal point decpnt = 0 ENDIF ; ; Then shift data out serially - most significant bit first FOR bitcntr = 1 TO 8 ; one loop per bit mask = digout & $80 ; Mask out the MSB LOW sdata IF mask = 0 THEN skipMSB HIGH sdata skipMSB: pulsout sclk,1 ; pulse clock line for 10us digout = digout * 2 ; shift value left ready for next bit
FOR bitcntr = 1 TO 8 ; one loop per bit mask = digout & $80 ; Mask out the MSB LOW sdata IF mask = 0 THEN skipMSB HIGH sdata skipMSB: pulsout sclk,1 ; pulse clock line for 10us digout = digout * 2 ; shift value left ready for next bit
NEXT bitcntr
clocks the bits out to the shift register.
To answer your question, yes, the bits for each 7 segment number is encoded in hexadecimal.
i think i see where you are coming from - damn this guys good - doesnt help in the slightest regarding my own program but i never expected it to - i’m still writing my own programming manual so putting it together like this is still a distance away.
well spotted though - i was looking in completely the wrong section
my time away from here was spent relearning programming (and other stuff) from scratch - my new picaxe / shift register program is utterly different from the one i started this particular forum on.
if you cant find a mistake - start again from a different direction
(its still on paper tho for now as im still writing my programming manual / folder)