Hello All,
I start to play with one of this cheap 4 digit 7 segment display. The display is driven by two 74HC595 which one is for segments and the other is for common cathodes (digits).
Here is the schematic:
Name:  4 bit 7 segment module.jpg
Views: 12744
Size:  166.3 KB

I writed a simple code using Darrel's interrupts. Code multiplexing the digits using TMR1 interrupt.
It works OK, but I think that code is not as elegant. It looks rough, because I'm not a skilled programmer.
Can someone explain to me a better way to do this task?

Here is my code:
Code:
'****************************************************************
'*  Name    : 4 bit 7 segment display                           *
'*  Author  : LouisLouis                                        *
'*  Notice  : Copyright (c) 2018                                *
'*          : All Rights Reserved                               *
'*  Date    : 18. 2. 2018                                       *
'*  Version : 1.0                                               *
'*  Notes   :                                                   *
'*  MCU     : PIC 12F1840                                       *
'****************************************************************

#CONFIG
  __config _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_ON & _FCMEN_ON
  __config _CONFIG2, _WRT_OFF & _PLLEN_ON & _STVREN_ON & _BORV_19 & _LVP_OFF
#ENDCONFIG

DEFINE OSC 32            ; Use internal clock 
OSCCON = %01110000
CLKRCON = 0

Include "modedefs.bas"
INCLUDE "DT_INTS-14.bas" ; Base Interrupt System
INCLUDE "ReEnterPBP.bas" ; Include if using PBP interrupts

TRISA = %000000
ANSELA = %0000  
OPTION_REG.7=0           ; Enable internal pull-ups

LPIN var porta.2         ; Latch
DPIN var porta.4         ; Data
CPIN var porta.5         ; Clock

segment var byte
value var word
place var byte[4]
ones var word
tens var word
hundreds var word
thousands var word

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
    INT_Handler TMR1_INT, _DISP, PBP, yes
  endm
  INT_CREATE ; Creates the interrupt processor
ENDASM

@ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts
T1CON = $1

;---[simple counter 0 - to 9999]------------------------------------------------ 
Main:
for value = 0 to 9999
pause 100
next value
value = 0
GOTO Main

;---[TMR1 - interrupt handler]--------------------------------------------------
DISP:
T1CON.0 = 0                ; stop timer
TMR1H = %11111100
TMR1L = %00011111
T1CON.0 = 1                ; restart timer

;---[extract ones and show]-----------------------------------------------------  
ones = value//10
lookup ones, [%11000000,%11111001,%10100100,%10110000,%10011001,%10010010,%10000010,%11111000,%10000000,%10010000],segment
LOW  LPIN
Shiftout DPIN, CPIN, MSBFIRST,[segment,%0001] 
high lpin

pause 4

;---[extract tens and show]----------------------------------------------------- 
tens =  value/10 
tens = tens//10
lookup tens, [%11000000,%11111001,%10100100,%10110000,%10011001,%10010010,%10000010,%11111000,%10000000,%10010000],segment
LOW  LPIN
Shiftout DPIN, CPIN, MSBFIRST,[segment,%0010] 
high lpin

pause 4

;---[extract hundreds and show]------------------------------------------------- 
hundreds =   value/100
hundreds = hundreds//10
lookup hundreds, [%11000000,%11111001,%10100100,%10110000,%10011001,%10010010,%10000010,%11111000,%10000000,%10010000],segment
LOW  LPIN
Shiftout DPIN, CPIN, MSBFIRST,[segment,%0100] 
high lpin

pause 4

;---[extract thousands and show]------------------------------------------------ 
thousands = value/1000
place = %1000
lookup thousands, [%11000000,%11111001,%10100100,%10110000,%10011001,%10010010,%10000010,%11111000,%10000000,%10010000,%10001000],segment
LOW  LPIN
Shiftout DPIN, CPIN, MSBFIRST,[segment,%1000] 
high lpin

@ INT_RETURN