Picaxe control of Adafruit 14 segment display with I2C backpack

stevesmythe

Senior Member
beer2.jpg
Adafruit sell some nice 4x14-segment displays with an I2C backpack based on the Holtek HT16K33 driver chip. This thread discussed using the same backpack with a 4x7-segment display and I posted another code snippet for controlling an 8x8 LED matrix. The code snippet below shows how to control the 4x14-segment display so that you can show all the letters of the alphabet (upper case are good, lower case not quite so convincing) as well as numbers and some additional characters like + - / \. Connections are the same as the other backpack except that there is an additional "Vi2c" pin to connect to the processor's logic level. So, you could power the LED segments at 5v and the processor at 3.3V. In my case, I just powered both from a 4.5V battery pack.

The module is initialised in the same way as with the other Adafruit devices. Then, to display characters you need to send the starting address 0x00, followed by four two-byte pairs (one pair for each "digit", working from left to right). The first byte for each digit is essentially the traditional 7-segment bit pattern (except that the middle segment is split into two). The second byte consists of the extra segments (e.g. the diagonal ones) needed to form the letters of the alphabet. Then you send the control byte $81 to "latch" the data to the display. As with the other backpack devices, control characters are available to dim and flash the display.

led_matrix_segments.png

I am posting this code to save people the chore of working out which bytes to send for each of the 60-plus displayable characters.
Code:
#picaxe 08m2			' Define PICAXE 08M2
#no_data				' Ignore EEPROM data - loads program faster
SYMBOL countn=b0              ' make symbol for loop counter

Initialize:				' Initialise pins and set up variables
LET dirsC = %00000110		' Make pins C.1 & C.2 outputs; rest as inputs
LET pinsC = %00000000 		' Turn off all outputs on port C
Hi2cSETUP  i2cmaster,%11100000, i2cfast, i2cbyte ' initialise I2C device at $7E (converted to 8 bit address)
PAUSE 1 ; wait 1 ms for the display chip to initialise
Hi2cOUT ($21) ; start clock/oscillator

' data for each character
'   byte1,byte2
'0 = $3f,$0
'1 = $6,$0
'2 = $db,$0
'3 = $cf,$0
'4 = $e6,$0
'5 = $ed,$0
'6 = $fd,$0
'7 = $1,$c
'8 = $ff,$0
'9 = $c7,$8
'. = $0,$40
'+ = $c0,$12
'- = $c0,$0
'/ = $0,$c
'| = $0,$10
'\ = $0,$21
'$ = $8d,$c
'all segments = $3f,$3f
'A $F7,$0
'B $8F,$12
'C $39,$0
'D $F,$12
'E $F9,$0
'F $F1,$0
'G $BD,$0
'H $F6,$0
'I $9,$12
'J $1E,$0
'K $70,$24
'L $38,$0
'M $36,$5
'N $36,$21
'O $3F,$0
'P $F3,$0
'Q $3F,$20
'R $F3,$20
'S $ED,$0
'T $0,$12
'U $3E,$0
'V $30,$C
'W $36,$28
'X $0,$2D
'Y $0,$15
'Z $9,$C
'a $58,$10
'b $78,$20
'c $D8,$0
'd $8E,$8
'e $58,$8
'f $71,$0
'g $8E,$4
'h $70,$10
'i $0,$10
'j $E,$0
'k $0,$36
'l $30,$0
'm $D4,$10
'n $50,$10
'o $DC,$0
'p $70,$1
'q $86,$4
'r $50,$0
's $88,$20
't $78,$0
'u $1C,$0
'v $4,$20
'w $14,$28
'x $C0,$28
'y $C,$28
'z $48,$8







top:
do
countn=0
Hi2cOUT ($80) ; clear the display

' print out the character set four at a time
'0 1 2 3
Hi2cOUT $00,($3f,$0,$6,$0,$db,$0,$cf,$0)
Hi2cOUT ($81) ; latch data to display
pause 1000
'4 5 6 7
Hi2cOUT $00,($e6,$0,$ed,$0,$fd,$0,$1,$c)
Hi2cOUT ($81) ; latch data to display
pause 1000
'8 9 $ all
Hi2cOUT $00,($ff,$0,$e7,$0,$ed,$12,$3f,$3f)
Hi2cOUT ($81) ; latch data to display
pause 1000
'- / . +
Hi2cOUT $00,($0,$40,$c0,$12,$c0,$0,$0,$c)
Hi2cOUT ($81) ; latch data to display
pause 1000
'A B C D
Hi2cOUT $00,($F7,$0,$8F,$12,$39,$0,$F,$12)
Hi2cOUT ($81) ; latch data to display
pause 1000
'E F G H
Hi2cOUT $00,($F9,$0,$F1,$0,$BD,$0,$F6,$0)
Hi2cOUT ($81) ; latch data to display
pause 1000
'I J K L
Hi2cOUT $00,($9,$12,$1E,$0,$70,$24,$38,$0)
Hi2cOUT ($81) ; latch data to display
pause 1000
'M N O P 
Hi2cOUT $00,($36,$5,$36,$21,$3F,$0,$F3,$0)
Hi2cOUT ($81) ; latch data to display
pause 1000
'Q R S T 
Hi2cOUT $00,($3F,$20,$F3,$20,$ED,$0,$1,$12)
Hi2cOUT ($81) ; latch data to display
pause 1000
'U V W X 
Hi2cOUT $00,($3E,$0,$30,$C,$36,$28,$0,$2D)
Hi2cOUT ($81) ; latch data to display
pause 1000
'Y Z all all
Hi2cOUT $00,($0,$15,$9,$C,$3f,$3f,$3f,$3f)
Hi2cOUT ($81) ; latch data to display
pause 1000

'a b c d 
Hi2cOUT $00,($58,$10,$78,$20,$D8,$0,$8E,$8)
Hi2cOUT ($81) ; latch data to display
pause 1000

'e f g h 
Hi2cOUT $00,($58,$8,$71,$0,$8E,$4,$70,$10)
Hi2cOUT ($81) ; latch data to display
pause 1000

'i j k l 
Hi2cOUT $00,($0,$10,$E,$0,$0,$36,$30,$0)
Hi2cOUT ($81) ; latch data to display
pause 1000

'm n o p 
Hi2cOUT $00,($D4,$10,$50,$10,$DC,$0,$70,$1)
Hi2cOUT ($81) ; latch data to display
pause 1000

'q r s t 
Hi2cOUT $00,($86,$4,$50,$0,$88,$20,$78,$0)
Hi2cOUT ($81) ; latch data to display
pause 1000
'u v w x 
Hi2cOUT $00,($1C,$0,$4,$20,$14,$28,$C0,$28)
Hi2cOUT ($81) ; latch data to display
pause 1000
'y z 
Hi2cOUT $00,($C,$20,$48,$8,$0,$0,$0,$0)
Hi2cOUT ($81) ; latch data to display
pause 1000


' write some text
' 8 bytes - 2 bytes per digit

'               L  |   O  |   V  |   E    
Hi2cOUT $00,($38,$0,$3f,$0,$30,$C,$f9,$0)
Hi2cOUT ($81) ; latch data to display
pause 1000

'               B   |    E  |   E   |   R   
Hi2cOUT $00,($8F,$12,$f9,$00,$f9,$00,$f3,$20)
Hi2cOUT ($81) ; latch data to display
pause 1000

Hi2cOUT ($E0) 'dim the display (range $E0 to $EF)
pause 1000
Hi2cOUT ($EF) ' full brightness again
pause 1000
Hi2cOUT ($83) 'blink the display ($83=2Hz blink, $85=1Hz, $87=0.5Hz)
pause 3000

Hi2cOUT ($80) ; clear the display
pause 1000

' make a spinney-round thing!
do while countn<21
	Hi2cOUT $00,($0,$12,$0,$12,$0,$12,$0,$12)
	Hi2cOUT ($81) ; latch data to display
	pause 20
	
	Hi2cOUT $00,($0,$c,$0,$c,$0,$c,$0,$c)
	Hi2cOUT ($81) ; latch data to display
	pause 20
	
	Hi2cOUT $00,($c0,$0,$c0,$0,$c0,$0,$c0,$0)
	Hi2cOUT ($81) ; latch data to display
	pause 20

	Hi2cOUT $00,($0,$21,$0,$21,$0,$21,$0,$21)
	Hi2cOUT ($81) ; latch data to display
	pause 20
	
	countn=countn+1
loop 'till count=20
loop 'back to top:
 
Last edited:
Top