Shop OBEX P1 Docs P2 Docs Learn Events
shift register question — Parallax Forums

shift register question

prozach7prozach7 Posts: 5
edited 2008-09-13 00:13 in General Discussion
I am using a 74hc595 shift register to drive a few·7 seg displays.· My question is, how do I blank out the displays without using the reset on the 595.· I put all zeros into the data field on my program but this seems to confuse the register.· Is there something I can do in the code to turn off all the segments without using the reset?

Thanks in advance,

Zach

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-12 03:24
    You'll need to post a schematic and attach your source code to a message. Normally, if you shift out zeros, that should clear the shift register and blank out the segments. If that's not working, there must be something "funny" about your setup and we'll need to see it as best as possible.
  • prozach7prozach7 Posts: 5
    edited 2008-09-12 18:10
    Here is the code I am using.· I can control all the leds fine but can not blank out the display by using all· zeros in the data.· You can see I have tried this with score_1 and score_2.· everything lights up when it gets to that command.






    ' =========================================================================
    '
    '·· File...... tick tock
    '·· Purpose... control 7 seg leds
    '·· Author....· Zachary Coxe
    '·· E-mail....· zcoxe@hotmail.com
    '·· Started...· Sept 11, 2008
    '·· Updated...· Ongoing
    '
    ' =========================================================================

    '
    ' Program Description
    '

    '
    ' Device Settings
    '
    DEVICE········· SX28, OSCHS2, TURBO, STACKX, OPTIONX, PROTECT
    FREQ··········· 50_000_000

    '
    ' IO Pins
    '
    DISPLAY_REGISTER_DATA ··VAR RC.3
    DISPLAY_REGISTER_CLOCK ··VAR RC.4
    DISPLAY_REGISTER_LATCH ··VAR RC.5

    '
    ' Constants
    '
    BAUD CON "T9600"
    '
    ' Variables
    X ··VAR BYTE
    'Y··VAR BYTE
    COIN_ENTERED ·VAR BYTE
    COIN_OVERFLOW ·VAR BYTE
    MAX_SHOTS ·VAR BYTE
    SHOTS_REMAINING VAR BYTE
    SCORE··VAR BYTE
    INTERRUPT_STAGE VAR BYTE
    WKPENDING VAR BYTE
    TICKET_MULTIPLIER VAR BYTE
    FREEBIE· VAR BYTE
    TICKETS_COUNTED VAR BYTE
    VENDOR_COIN_MAX ·VAR BYTE
    VENDOR_SHOT_PER_COIN ·VAR BYTE
    VENDOR_SHOT_PER_COIN_1 ·VAR BYTE
    VENDOR_SHOT_PER_COIN_2 ·VAR BYTE
    SCORE_1 ··VAR BYTE
    SCORE_2 ··VAR BYTE
    SHOTS_REMAINING_1 ·VAR BYTE
    SHOTS_REMAINING_2 ·VAR BYTE
    'VARIABLES FOR LED DISPLAY
    LED_DISPLAY VAR BYTE(7)
    ·'BYTE 0 = VENDOR_SHOT_PER_COIN_1
    ·'BYTE 1 = VENDOR_SHOT_PER_COIN_2
    ·'BYTE 2 = VENDOR_COIN_MAX
    ·'BYTE 3 = SCORE_1
    ·'BYTE 4 = SCORE_2
    ·'BYTE_5 = SHOTS_REMAINING_1
    ·'BYTE_6 = SHOTS_REMAINING_2
    ·'BYTE_7 = COINS_INSERTED

    '
    · INTERRUPT
    '

    ' =========================================================================
    · PROGRAM Start
    ' =========================================================================
    Pgm_ID:
    · DATA· "SX/B Template", 0

    '
    ' Subroutines / Jump Table
    '
    OUTPUT_LEDS SUB

    '
    ' Program Code
    START:
    '

    SCORE_1 = 1
    SCORE_2 = 1
    GOSUB OUTPUT_LEDS
    PAUSE 100
    SCORE_1 = 2
    SCORE_2 = 2
    GOSUB OUTPUT_LEDS
    PAUSE 100
    SCORE_1 = 3
    SCORE_2 = 3
    GOSUB OUTPUT_LEDS
    PAUSE 100
    SCORE_1 = 4
    SCORE_2 = 4
    GOSUB OUTPUT_LEDS
    PAUSE 100
    SCORE_1 = 5
    SCORE_2 = 5
    GOSUB OUTPUT_LEDS
    PAUSE 100
    SCORE_1 = 7
    SCORE_2 = 7
    GOSUB OUTPUT_LEDS
    PAUSE 100
    SCORE_1 = 0
    SCORE_2 = 0
    GOSUB OUTPUT_LEDS
    PAUSE 100

    GOTO START
    END

    '#######################################################################
    '######### SUB ROUTINES············································· ###
    '#######################################################################
    OUTPUT_LEDS:
    'CONVERT VARIABLES TO LED MAPS

    ·READ VARIABLE_TO_LED_CONVERSION + SCORE_1, LED_DISPLAY(3)
    ·READ VARIABLE_TO_LED_CONVERSION + SCORE_2, LED_DISPLAY(4)
    ·READ VARIABLE_TO_LED_CONVERSION + SHOTS_REMAINING_1, LED_DISPLAY(5)
    ·READ VARIABLE_TO_LED_CONVERSION + SHOTS_REMAINING_2, LED_DISPLAY(6)
    ·READ VARIABLE_TO_LED_CONVERSION + COIN_ENTERED, LED_DISPLAY(7)

    · 'UPDATE DISPLAY TO REFLECT VALUES
    ·SHIFTOUT DISPLAY_REGISTER_DATA, DISPLAY_REGISTER_CLOCK, MSBFIRST, LED_DISPLAY(7)
    ·SHIFTOUT DISPLAY_REGISTER_DATA, DISPLAY_REGISTER_CLOCK, MSBFIRST, LED_DISPLAY(6)
    ·SHIFTOUT DISPLAY_REGISTER_DATA, DISPLAY_REGISTER_CLOCK, MSBFIRST, LED_DISPLAY(5)
    ·SHIFTOUT DISPLAY_REGISTER_DATA, DISPLAY_REGISTER_CLOCK, MSBFIRST, LED_DISPLAY(4)
    ·SHIFTOUT DISPLAY_REGISTER_DATA, DISPLAY_REGISTER_CLOCK, MSBFIRST, LED_DISPLAY(3)
    ·PULSOUT DISPLAY_REGISTER_LATCH,1
    RETURN





    VARIABLE_TO_LED_CONVERSION:
    ·'······· .gfedcba
    ·· ·DATA· %00000000········· ' 0
    ··· ·DATA· %00000001······························ ' 1
    · ·DATA· %00000011······························ ' 2
    · ·DATA· %00000111······························ ' 3
    · ·DATA· %00001111······························ ' 4
    · ·DATA· %00011111······························ ' 5
    · ·DATA· %00111111······························ ' 6
    · ·DATA· %01111111······························ ' 7
    ·

    ··············
  • T&E EngineerT&E Engineer Posts: 1,396
    edited 2008-09-12 18:17
    Take a look at the SX/B Example (Help) for the Thermometer. It uses PUT to push blanks into arrays. I'm using something like this in a current design.
    ' ========================================================================='' File...... THERMOMETER.SXB' Purpose... Dual-mode digital thermometer' Author.... (c) Parallax, Inc. -- All Rights Reserved' E-mail.... support@parallax.com' Started...' Updated... 05 JUL 2006'' =========================================================================' -------------------------------------------------------------------------' Program Description' -------------------------------------------------------------------------'' Displays the temperature from a DS1620 thermo chip on a multiplexed 7-' segment display. The display is multiplexed by interrupt code so that' no additional components are required. A mode input allows the temper-' ature to be displayed in Celsius or Fahrenheit.'' When the temperature falls below 0C (32F) "-Lo-" is displayed. When the' temp is above 49C (120 F) "-Hi-" is displayed.' -------------------------------------------------------------------------' Device Settings' -------------------------------------------------------------------------DEVICE 		SX28, OSC4MHZ, TURBO, STACKX, OPTIONXFREQ 		4_000_000ID 		"THERMO"' -------------------------------------------------------------------------' IO Pins' -------------------------------------------------------------------------DQ 		PIN 	RC.7 			' DS1620.1Clock 		PIN 	RC.6 			' DS1620.2Rst 		PIN 	RC.5 			' DS1620.3DispMode 	PIN 	RC.4 			' display mode, C or FSegs 		PIN 	RB 			' display segmentsDigCtrl 	PIN 	RA 			' digit control (cathode)' -------------------------------------------------------------------------' Constants' -------------------------------------------------------------------------Blank 		CON 	%00000000 		' blank displayDash 		CON 	%01000000 		' pattern for "-"Ltr_C 		CON 	%00111001 		' pattern for "C"Ltr_F 		CON 	%01110001 		' pattern for "F"Ltr_L 		CON 	%00111000 		' pattern for "L"Ltr_o 		CON 	%01011100 		' pattern for "o"Ltr_H 		CON 	%01110110 		' pattern for "H"Ltr_i 		CON 	%00010000 		' pattern for "i"TC 		CON 	0 			' mode = CelsiusTF 		CON 	1 			' mode = Fahrenheit' *** DS1620 Commands ***RdTmp 		CON 	$AA 			' read temperatureWrHi 		CON 	$01 			' write TH (high temp)WrLo 		CON 	$02 			' write TL (low temp)RdHi 		CON 	$A1 			' read THRdLo 		CON 	$A2 			' read TLStartC 		CON 	$EE 			' start conversionStopC 		CON 	$22 			' stop conversionWrCfg 		CON 	$0C 			' write config registerRdCfg 		CON 	$AC 			' read config register' -------------------------------------------------------------------------' Variables' -------------------------------------------------------------------------display 	VAR 	Byte(4) 		' multiplexed segmentsdigPntr 	VAR 	Byte 			' digit pointerdigLimit 	VAR 	Byte 			' 0 - 3theTemp 	VAR 	Byte 			' temperaturetSign 		VAR 	Byte 			' sign in bit 0work 		VAR 	BytetmpB1 		VAR 	Byte 			' subroutine work varstmpB2 		VAR 	BytetmpW1 		VAR 	Word' ========================================================================= INTERRUPT 200' =========================================================================' Points to next digit of display every 5 milliseconds (200 times/sec).ISR_Start:  INC digPntr 					' point to next digit  IF digPntr < digLimit THEN Update_Segs 	' update digit  digPntr = 0 					' wrap if neededUpdate_Segs:  Segs = Blank 					' blank segs  READ DigMap + digPntr, DigCtrl 		' select display element  Segs = display(digPntr) 			' output new digit segsISR_Exit:  RETURNINT' ========================================================================= PROGRAM Start' =========================================================================' -------------------------------------------------------------------------' Subroutines' -------------------------------------------------------------------------INIT_1620 	SUB 	0 			' initialize DS1620RD_1620 	FUNC 	1 			' get temp from DS1620NEW_DISPLAY 	SUB 	2 			' update display' -------------------------------------------------------------------------' Program Code' -------------------------------------------------------------------------Start:  DigCtrl = %1111 				' disable all digits  TRIS_A = %0000 				' make dig pins outputs  Segs = Blank 					' clear seg drivers  TRIS_B = %00000000 				' make seg pins outputs  TRIS_C = %10011111 				' clock and rst are outputs  INIT_1620  PUT display(0), Blank, Blank, Blank, Blank 	' clear display  digLimit = 4 					' use all digits (1 - 4)  digPntr = 3Main:  DO    theTemp = RD_1620 				' read temperature    NEW_DISPLAY theTemp, tSign 			' display value    PAUSE 500 					' delay between reads  LOOP' -------------------------------------------------------------------------' Subroutine Code' -------------------------------------------------------------------------' Initialize DS1620 for free-run mode and for use with a host CPUSUB INIT_1620  Rst = 1 					' select device  SHIFTOUT DQ, Clock, LSBFIRST, WrCfg 		' write to config register  SHIFTOUT DQ, Clock, LSBFIRST, %00000010 	' with CPU; free-run  Rst = 0 					' deselect device  PAUSE 10 					' allow DS1620 EE to write  Rst = 1 					' reselect  SHIFTOUT DQ, Clock, LSBFIRST, StartC 		' start conversion  Rst = 0 					' deselectENDSUB' -------------------------------------------------------------------------' Use: theTemp = RD1620' -- returns temp in whole degrees C in 'theTemp'FUNC RD_1620  Rst = 1 					' select device  SHIFTOUT DQ, Clock, LSBFIRST, RdTmp 		' send read temp command  SHIFTIN DQ, Clock, LSBPRE, tmpB1 		' get temp (C x 0.5)  SHIFTIN DQ, Clock, LSBPRE, tSign\1 		' get sign bit  Rst = 0 					' deselect device  tmpB1 = tmpB1 + tmpB1.0 			' round up  tmpB1 = tmpB1 >> 1 				' remove half bit  RETURN tmpB1ENDFUNC' -------------------------------------------------------------------------' Use: NEW_DISPLAY temperature, sign' -- puts 'temperature' in display (pass value in degrees C)' -- display mode (C or F) controlled by RC.4 inputSUB NEW_DISPLAY  tmpB1 = __PARAM1 				' temperature  tmpB2 = __PARAM2 				' sign bit  IF tmpB2 = 1 THEN 				' negative temp?    digLimit = 4    PUT display(0), Dash, Ltr_o, Ltr_L, Dash 	' show "-Lo-"    GOTO Display_Done  ENDIF  IF tmpB1 > 49 THEN 				' too high?    digLimit = 4    PUT display(0), Dash, Ltr_i, Ltr_H, Dash 	' show "-Hi-"    GOTO Display_Done  ENDIFCheck_Mode:  IF DispMode = TC THEN 			' check mode input switch    display(0) = Ltr_C  ELSE    display(0) = Ltr_F    tmpW1 = tmpB1 */ $1CC 			' temp x 1.8 (9/5)    tmpB1 = tmpW1_LSB + 32  ENDIFSet_Display: 					' blank leading zeros  digLimit = 2 					' 1-digit temp  IF tmpB1 < 10 THEN Show_Temp  INC digLimit 					' 2-digit temp  IF tmpB1 < 100 THEN Show_Temp  INC digLimit 					' 3-digit tempShow_Temp:  tmpB2 = tmpB1 / 100 				' get hundreds digit  tmpB1 = __REMAINDER 				' save 10's and 1's  READ SegMap + tmpB2, display(3) 		' get segment map 100's  tmpB2 = tmpB1 / 10 				' get 10's digit  tmpB1 = __REMAINDER 				' save 1's  READ SegMap + tmpB2, display(2) 		' get segment map for 10's  READ SegMap + tmpB1, display(1) 		' get segment map for 1'sDisplay_Done:ENDSUB' =========================================================================' User Data' =========================================================================SegMap: ' segments maps'       .gfedcba  DATA %00111111 				' 0  DATA %00000110 				' 1  DATA %01011011 				' 2  DATA %01001111 				' 3  DATA %01100110 				' 4  DATA %01101101 				' 5  DATA %01111101 				' 6  DATA %00000111 				' 7  DATA %01111111 				' 8  DATA %01100111 				' 9DigMap: 					' digit select map  DATA %11111110  DATA %11111101  DATA %11111011  DATA %11110111  
    
  • JonnyMacJonnyMac Posts: 9,214
    edited 2008-09-12 19:18
    With SX/B you should preset the clock line before SHIFTOUT is used; unlike the BASIC Stamp, SX/B does not assume that you're using a low-to-high clock pulse and simply inverts the clock line from its initial state. I've attached '595 test program that may be helpful.

    Also, by wrapping SHIFTOUT in a subroutine you will save a lot of code space. You might end up with a section of code that looks like this:

    ...
      FOR idx = 7 TO 4 STEP -1
        OUT_595 ledDisplay(idx), NoLatch
      NEXT
      OUT_595 ledDisplay(3)
      ENDSUB
    
  • prozach7prozach7 Posts: 5
    edited 2008-09-13 00:13
    Jonny,

    That did it. Thanks for your help

    zach
Sign In or Register to comment.