4 bit 7 segment display with two 74HC595


Results 1 to 24 of 24

Threaded View

  1. #9
    Join Date
    May 2013
    Location
    australia
    Posts
    2,645


    Did you find this post helpful? Yes | No

    Default Re: 4 bit 7 segment display with two 74HC595

    Could you point to an example of that?
    me too
    I have never had to do that and can find no mention of that short coming anywhere


    anyways here is my take on the 7 seg display
    if you have a chip with mssp why waste time and code space when the hardware can do it for you

    I cheated a bit and did it in asm for speed and size gains
    no nasty pauses , all gone
    my displays are common anode so the data is inverted see comments

    Code:
    '****************************************************************
    '*  Name    : 4 bit 7 segment display                           *
    '*  Author  : RICHARD                                           *
    '*  Notice  :                                                   *
    '*          :                                                   *
    '*  Date    : 18. 2. 2018                                       *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*  MCU     : PIC 16F1825 @32MHZ                                *
    '****************************************************************
    #CONFIG
                 __config        _CONFIG1,    _FOSC_INTOSC & _CP_OFF & _WDTE_ON  &  _PWRTE_ON  &  _MCLRE_ON  & _CLKOUTEN_OFF
                  __config      _CONFIG2, _PLLEN_OFF & _LVP_OFF
    #ENDCONFIG
    
     goto overasm
     asm
    timer1  = TMR1L 
     
    seg_val       
        addwf   PCL, F                  
        retlw  0xc0;0B11000000     0  
        retlw  0xf9;0B11111001     1     
        retlw  0xa4;0B10100100     2
        retlw  0xb0;0B10110000     3
        retlw  0x99;0B10011001     4
        retlw  0x92;0B10010010     5                     
        retlw  0x82;0B10000010     6
        retlw  0xf8;0B11111000     7
        retlw  0x80;0B10000000     8  
        retlw  0x90;0B10010000     9
     endasm
    
     overasm:
    DEFINE OSC 32            ; Use internal clock 
    ANSELC=0
    SSP1CON1=$22  
    SSP1STAT=$40
    OSCCON=$f0
    
    INCLUDE "DT_INTS-14.bas" ; Base Interrupt System
    
    TRISC = %11101010
    LPIN var portc.4         ; Latch
    DPIN var portc.2         ; Data  SDO
    CPIN var portc.0         ; Clock SCK
    segment var byte
    value var word
    d_index var byte
    buff var byte[5]
    tmp var byte             
    d_pointer      var byte  
    timer1 var word ext
    timer1_reload con    1543      ;8mS
    ASM
    INT_LIST macro ; IntSource, Label, Type, ResetFlag?
        INT_Handler TMR1_INT, _DISP, ASM, yes
      endm
      INT_CREATE ; Creates the interrupt processor
    ENDASM
    @ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts
    T1CON = $1
    d_index=0
    ;---[simple counter 0 - to 9999]------------------------------------------------ 
    Main:
    for value = 0 to 9999
    arraywrite buff ,[dec4 value]
    pause 100
    next value
    value = 0
    GOTO Main
    ;---[TMR1 - interrupt handler]--------------------------------------------------
    DISP:
    asm
        MOVE?CT 0, T1CON, TMR1ON ; 1 stop timer
        MOVLW LOW(_timer1_reload) ; 1 Add TimerReload to the 
        ADDWF TMR1L,F ; 1 value in Timer1
        BTFSC STATUS,C ; 1/2
        INCF TMR1H,F ; 1
        MOVLW HIGH(_timer1_reload) ; 1
        ADDWF TMR1H,F ; 1
        MOVE?CT 1, T1CON, TMR1ON ; 1 start timer
        MOVE?CB  high _buff, FSR0H         ;load highbyte 
        MOVE?CB  low  _buff, FSR0L         ;load low byte
        MOVE?BA  _d_index  
        ADDWF  FSR0L,F
        MOVLW 0X30
        SUBWF INDF0,W
        L?CALL seg_val
        MOVE?AB _segment
        MOVE?BB  _d_index ,_tmp
        BANKSEL   _tmp
        MOVLW 1
        ADDWF  _tmp,F
        BANKSEL   _d_pointer
        CLRF _d_pointer
        BSF STATUS ,C
    N_BIT 
        BANKSEL   _d_pointer
        RLF    _d_pointer,F
        BCF STATUS ,C
        BANKSEL   _tmp
        DECFSZ  _tmp,F
        GOTO N_BIT 
        MOVLW 1
        BANKSEL  _d_index
        ADDWF  _d_index,F
        MOVLW 3 
        ANDWF  _d_index,F
        BANKSEL  LATC
        BCF LATC ,4
        BANKSEL PIR1
        BCF     PIR1,3 
        BANKSEL  _segment
        COMF    _segment,W  ;COMMENT USED TO INVERT DATA FOR COMMON ANODE DISPLAY
        BANKSEL SSP1BUF
        movwf   SSP1BUF
        BANKSEL PIR1
        BTFSs   PIR1,3
        GOTO    $-1
        BANKSEL  _d_pointer
        COMF    _d_pointer,W ; ;COMMENT USED FOR COMMON ANODE DISPLAY
        BANKSEL PIR1
        BCF     PIR1,3 
        BANKSEL SSP1BUF
        movwf   SSP1BUF
        BANKSEL PIR1
        BTFSs   PIR1,3
        GOTO    $-1
        BANKSEL  LATC
        BSF LATC ,4
        BANKSEL 0
        INT_RETURN
    endasm
    Last edited by richard; - 19th February 2018 at 11:18. Reason: convert to english instead of gibberish
    Warning I'm not a teacher

Similar Threads

  1. 7 segment display
    By lerameur in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 13th January 2015, 13:24
  2. 1 Pin 7-Segment Display
    By Mike, K8LH in forum Schematics
    Replies: 0
    Last Post: - 23rd November 2009, 12:35
  3. 7-segment display with P16F84
    By spitfire in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 3rd March 2009, 19:22
  4. Display Using Cascaded 74hc595
    By charudatt in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 7th December 2004, 06:05
  5. Multiplex two 7 segment display
    By Fernando Santos in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 20th July 2003, 13:26

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts