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:
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:
'**************************************************************** '* 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 = 110000 CLKRCON = 0 Include "modedefs.bas" INCLUDE "DT_INTS-14.bas" ; Base Interrupt System INCLUDE "ReEnterPBP.bas" ; Include if using PBP interrupts TRISA = 0000 ANSELA = 00 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 = 111100 TMR1L = 011111 T1CON.0 = 1 ; restart timer ;---[extract ones and show]----------------------------------------------------- ones = value//10 lookup ones, [000000,111001,100100,110000,011001,010010,000010,111000,000000,010000],segment LOW LPIN Shiftout DPIN, CPIN, MSBFIRST,[segment,01] high lpin pause 4 ;---[extract tens and show]----------------------------------------------------- tens = value/10 tens = tens//10 lookup tens, [000000,111001,100100,110000,011001,010010,000010,111000,000000,010000],segment LOW LPIN Shiftout DPIN, CPIN, MSBFIRST,[segment,10] high lpin pause 4 ;---[extract hundreds and show]------------------------------------------------- hundreds = value/100 hundreds = hundreds//10 lookup hundreds, [000000,111001,100100,110000,011001,010010,000010,111000,000000,010000],segment LOW LPIN Shiftout DPIN, CPIN, MSBFIRST,[segment,00] high lpin pause 4 ;---[extract thousands and show]------------------------------------------------ thousands = value/1000 place = 00 lookup thousands, [000000,111001,100100,110000,011001,010010,000010,111000,000000,010000,001000],segment LOW LPIN Shiftout DPIN, CPIN, MSBFIRST,[segment,00] high lpin @ INT_RETURN
Re: SERIN2 Receiving Wrong Data
The sending device has the typical 18F4550 USB setup and it is set to "Define OSC 48". The receiving device is set to "DEFINE OSC 16".
rsocor01 Yesterday, 19:56