stevesmythe
Senior Member
I couldn't find any Picaxe Basic code examples for controlling this display, but this thread described how to control a 4-digit, 7-segment display that uses the same backpack.
Building on the information in that thread, I have produced the following code that demonstrates how to turn on/off, dim or flash the display and control which pixels are lit up. By giving it its own thread, people searching on the Internet for information on how to control this module (as opposed to the 7-seg version) will find it more easily.
1. After initialising, the starting address ($00) is sent, then (in brackets in the example below), the string of data containing the value for each of the 8 columns, where the "value" is the row value in binary, MSB first. However, the row value is a 16 bit value and only the first 8 bits are physically connected. So, every other byte is ignored. I have put $AA into each of these in the example below, just so they are not confused with anything else.
2. For some reason, the physical row 0 (at the top if you look at the display with the Adafruit logo at the bottom) is wired as the MSB so all the other rows are shifted down.
Building on the information in that thread, I have produced the following code that demonstrates how to turn on/off, dim or flash the display and control which pixels are lit up. By giving it its own thread, people searching on the Internet for information on how to control this module (as opposed to the 7-seg version) will find it more easily.
1. After initialising, the starting address ($00) is sent, then (in brackets in the example below), the string of data containing the value for each of the 8 columns, where the "value" is the row value in binary, MSB first. However, the row value is a 16 bit value and only the first 8 bits are physically connected. So, every other byte is ignored. I have put $AA into each of these in the example below, just so they are not confused with anything else.
2. For some reason, the physical row 0 (at the top if you look at the display with the Adafruit logo at the bottom) is wired as the MSB so all the other rows are shifted down.
Code:
#picaxe 08m2 ' Define PICAXE 08M2
#no_data ' Ignore EEPROM data - loads program faster
Initialise: ' 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
PAUSE 1 ; wait 1 ms for the display chip to initialise
Hi2cOUT ($21) ; start clock/oscillator
' $00 turns off the whole row
Main:
Hi2cOUT ($80) ; clear the display
' turn on all LEDS in each column (%11111111=$FF)
' x = don't care (not connected) but I have used $AA
' start ! col0 x , col1 x , col2 x , col3 x , col4 x , col5 x 'col6 x , col 7 x
Hi2cOUT $00, ($FF, $AA, $FF, $AA, $FF, $AA, $FF, $AA, $FF,$AA, $FF, $AA, $FF,$AA, $FF, $AA)
Hi2cOUT ($81) ; turn on the display
pause 1000
' now draw a smiley face
' xxxx
' x x
'x x x x
'x x
'x x x x
'x xx x
' x x
' xxxx
' columns
'7 6 5 4 3 2 1 0
'0 0 1 1 1 1 0 0 row0
'0 1 0 0 0 0 1 0 row1
'1 0 1 0 0 1 0 1 row2
'1 0 0 0 0 0 0 1 row3
'1 0 1 0 0 1 0 1 row4
'1 0 0 1 1 0 0 1 row5
'0 1 0 0 0 0 1 0 row6
'0 0 1 1 1 1 0 0 row7
'Adafruit logo at bottom
'MOVE TOP ROW (ROW0) TO bottom (MSB) AND SHIFT EVERYTHING ELSE DOWN=>BIT0->BIT7, BIT7->BIT6, BIT6->BIT5
' becomes....
' columns
'7 6 5 4 3 2 1 0
'0 1 0 0 0 0 1 0 row0
'1 0 1 0 0 1 0 1 row1
'1 0 0 0 0 0 0 1 row2
'1 0 1 0 0 1 0 1 row3
'1 0 0 1 1 0 0 1 row4
'0 1 0 0 0 0 1 0 row5
'0 0 1 1 1 1 0 0 row6
'0 0 1 1 1 1 0 0 row7
'Adafruit logo at bottom
'for example, after shifting row 0, column 0 becomes %00011110 or $1E
' start ! col0 x , col1 x , col2 x , col3 x , col4 x , col5 x 'col6 x , col 7 x
Hi2cOUT $00, ($1E, $AA,$21, $AA, $CA, $AA, $D0, $AA, $D0,$AA, $CA, $AA, $21,$AA, $1E, $AA)
Hi2cOUT ($81) ; turn on the 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) ; turn off the display
pause 1000
goto main
Last edited: