I was working on the code for an existing project with a 7 segment display. My version uses a different display which required me to adjust the code. Sadly the author had hard coded the numeric values to generate each character. Painful yes.
This example is for a multiplexed display and requires all eight segments (a-g) be selected by the same port. None of the driver code is include.
Now instead of
movlw 39h ;'C'
you can write
movlw _C ;'C'
A nice thing about this is that you freely rearrange the connections between the segment bits on the display and the processor port driving then. When you route the traces between the two it is possible to connect them as you see fit. To fixup your code you only need to adjust the 8 defines.
Should work in C too.
This example is for a multiplexed display and requires all eight segments (a-g) be selected by the same port. None of the driver code is include.
Now instead of
movlw 39h ;'C'
you can write
movlw _C ;'C'
Code:
;
; This code fragment illustrates how to define the
; numerical digits and a few characters for use with a 7
; segment display. You only need to adjust the 8
; _SEG_x defines, the rest is done for you.
;
; Daniel Johnson
; Map LED segments to PORT bit positions, bit0 to bit7. ; This depends on how you circuit is wired
#define _SEG_A 0
#define _SEG_B 1
#define _SEG_C 3
#define _SEG_D 2
#define _SEG_E 6
#define _SEG_F 5
#define _SEG_G 7
#define _SEG_DP 4
;;; ---- no need to change code below this line ----
; map bit positions to bit values
#define _SA (1<<_SEG_A)
#define _SB (1<<_SEG_B)
#define _SC (1<<_SEG_C)
#define _SD (1<<_SEG_D)
#define _SE (1<<_SEG_E)
#define _SF (1<<_SEG_F)
#define _SG (1<<_SEG_G)
#define _SDP (1<<_SEG_DP)
; values to display digits 0 to 9
#define _0 _SA | _SB | _SC | _SD | _SE | _SF
#define _1 _SB | _SC
#define _2 _SA | _SB | _SE | _SD | _SG
#define _3 _SA | _SB | _SC | _SD | _SG
#define _4 _SB | _SC | _SF | _SG
#define _5 _SA | _SC | _SD | _SF | _SG
#define _6 _SA | _SC | _SD | _SE | _SF | _SG
#define _7 _SA | _SB | _SC
#define _8 _SA | _SB | _SC | _SD | _SE | _SF | _SG
#define _9 _SA | _SB | _SC | _SF | _SG
; other characters
#define _C _SA | _SD | _SE | _SF
#define _H _SB | _SC | _SE | _SF | _SG
;...
A nice thing about this is that you freely rearrange the connections between the segment bits on the display and the processor port driving then. When you route the traces between the two it is possible to connect them as you see fit. To fixup your code you only need to adjust the 8 defines.
Should work in C too.
Last edited: