Ambient
New Member
dual 7-segment hex decoder
Finally got all the kinks worked out. Thanks for the help guys. I provided the Eagle CAD PCB and schematic files, just share your results if you make any improvements please. I minimized the top layer traces because I make single sided boards. Enjoy!
This project is simply a hex decoder for one byte input.
Edited: changed some code around to make more usable on other PIC's
Edited 2/05/08: updated pcb design. I had the input header on the pcb upside down, so the bits were reversed. fixed now.
Finally got all the kinks worked out. Thanks for the help guys. I provided the Eagle CAD PCB and schematic files, just share your results if you make any improvements please. I minimized the top layer traces because I make single sided boards. Enjoy!
This project is simply a hex decoder for one byte input.
Code:
;Dual 7-segment hex display driver.
;Sean LeBlanc, 02/04/08
;NOTES:
;PORTC,0 pin is free to use as I/O. PCB design has solder pad or switch option.
;This pin is also AN4, so ADC is available (comment out ADC off code).
List p=16f690
include P16F690.INC
__CONFIG _CP_OFF & _CPD_OFF & _BOR_OFF & _PWRTE_ON & _WDT_OFF & _INTOSCIO & _MCLRE_OFF & _FCMEN_OFF & _IESO_OFF; & _INTRC_OSC_NOCLKOUT
errorlevel -302
;-----------------------VARIABLE REGISTER DEFINITIONS---------------------------
w_temp EQU 0x40 ; variable used for context saving
status_temp EQU 0x41 ; variable used for context saving
pclath_temp EQU 0x22 ; variable used for context saving
Digit1 EQU 0x43
Digit2 EQU 0x44
temp EQU 0x45
org 0x0000
goto Initialize
;***************************Interrupt_Routine**************************
org 0x0004 ; interrupt vector location
movwf w_temp
movf STATUS,W ; move status register into W register
movwf status_temp ; save of contents of STATUS register
movf PCLATH,W ; move pclath register into W register
movwf pclath_temp ; save of contents of PCLATH register
bcf PIR1,TMR2IF ;check which display is off (pin high)
btfsc PORTB,h'05'
goto Display1
btfsc PORTB,h'04'
goto Display2
STATUS_RESTORE
movf pclath_temp,W ; retrieve copy of PCLATH register
movwf PCLATH ; restore pre-isr PCLATH register contents
movf status_temp,W ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,F
swapf w_temp,W ; restore pre-isr W register contents
retfie
;***************************INITIALIZATION*****************************
Initialize
banksel ADCON0 ;BANK 0
movlw b'00000000'
movwf ADCON0 ;ADC off
movlw b'01001100'
movwf T2CON ;TMR2 PreS 1:1, TMR2 PostS 1:10
banksel OSCCON ;BANK 1
movlw b'01000001'
movwf OSCCON ;sets oscillator to 1MHz
bsf PIE1,TMR2IE ;enable Timer2 interrupt
movlw b'00111111'
movwf TRISA ;PORTA I/O setup
movlw b'11000000'
movwf TRISB ;PORTB: RB4-5 outputs for Display select lines, 6 and 7 input
movlw b'00000001'
movwf TRISC ;PORTC: LED output pins
movlw b'11011000'
banksel ANSEL ;BANK 2
clrf ANSEL ;analog disable ANS0-ANS7
clrf ANSELH ;analog disable ANS8-ANS11
banksel INTCON ;BANK 0
bsf INTCON,PEIE
bsf INTCON,GIE
bsf PORTB,h'05'
bcf PORTB,h'04'
main
nop
nop
goto $-1 ;idle loop
Display1
movf PORTB,W
andlw b'11000000'
iorwf PORTA,W
movwf temp
swapf temp,W
andlw h'0F' ;Most Significant Nibble
call Table
movwf Digit1
bsf PORTB,h'04' ;disable display 2
movf Digit1,W
movwf PORTC
bcf PORTB,h'05' ;enable display 1
goto STATUS_RESTORE
Display2
movf temp,W
andlw h'0F' ;Least Significant Nibble
call Table
movwf Digit2
bsf PORTB,h'05' ;disable display 1
movf Digit2,W
movwf PORTC
bcf PORTB,h'04' ;enable display 2
goto STATUS_RESTORE
Table
andlw b'00001111'
addwf PCL,F
;PORTC 76543210
;Segment abcdefgh, active low, Common Anode setup
retlw b'00000010' ;0
retlw b'10011110' ;1
retlw b'00100100' ;2
retlw b'00001100' ;3
retlw b'10011000' ;4
retlw b'01001000' ;5
retlw b'01000000' ;6
retlw b'00011110' ;7
retlw b'00000000' ;8
retlw b'00011000' ;9
retlw b'00010000' ;A
retlw b'11000000' ;B
retlw b'01100010' ;C
retlw b'10000100' ;D
retlw b'01100000' ;E
retlw b'01110000' ;F
END
;+++++++++++++++++++PORTC Pinout+++++++++++++++
;++++++++++++++++ _a_ +++++++++++
;++++++++++++++++ | | +++++++++++
;++++++++++++++++ f|_g_|b +++++++++++
;++++++++++++++++ | | +++++++++++
;++++++++++++++++ e| |c +++++++++++
;++++++++++++++++ h -d- +++++++++++
;++++++++++++++++++++++++++++++++++++++++++++++
Edited: changed some code around to make more usable on other PIC's
Edited 2/05/08: updated pcb design. I had the input header on the pcb upside down, so the bits were reversed. fixed now.
Attachments
Last edited: