Driving an OLED with a Picaxe microcontroller using the I2C bus
While designing the LCD and OLED display portions of our newest controllers, we found that there was simply no documentation to be found on how to interface a Picaxe to the OLED SSD1306 based display using the I2C data bus. These little displays offer great resolution at a great price and can be a real asset to your project, so I just wanted to share what we originally devolped, that others might have this information as well to further the knowledge base in DIY electronics.
The code below is a very basic example of how to interface these two. The Picaxe has a limited amount of memory, so some concesssions had to be made. In our case, we decided not to include the lower case characters. However, if our project is small, there is enough code space to add additional font items.
Please link back to this site if you would like to share this code.
Enjoy your projects!
' Example of how to use a SSD1306 based Oled DISPLAY with a Picaxe
' A 20x2 was used in this design, but any picaxe having SDA/SDL will work but may require pin tweaking
' 1/22/15 -- Craig Allen -- CCS Software/Coleman Air, INC
' http://colemanAir.us
' Portions of this code were derived from the ADA Fruit Library used with the Arduino
' You may copy and use this code in your projects free of charge.
SYMBOL TWI_BUFFER_LENGTH = 32
SYMBOL SSD1306_LCDWIDTH = 128
SYMBOL SSD1306_LCDHEIGHT = 64
SYMBOL SSD1306_SETCONTRAST =0x81
SYMBOL SSD1306_DISPLAYALLON_RESUME =0xA4
SYMBOL SSD1306_DISPLAYALLON =0xA5
SYMBOL SSD1306_NORMALDISPLAY =0xA6
SYMBOL SSD1306_INVERTDISPLAY =0xA7
SYMBOL SSD1306_DISPLAYOFF =0xAE
SYMBOL SSD1306_DISPLAYON =0xAF
SYMBOL SSD1306_SETDISPLAYOFFSET =0xD3
SYMBOL SSD1306_SETCOMPINS =0xDA
SYMBOL SSD1306_SETVCOMDETECT =0xDB
SYMBOL SSD1306_SETDISPLAYCLOCKDIV =0xD5
SYMBOL SSD1306_SETPRECHARGE =0xD9
SYMBOL SSD1306_SETMULTIPLEX =0xA8
SYMBOL SSD1306_SETLOWCOLUMN =0x00
SYMBOL SSD1306_SETHIGHCOLUMN =0x10
SYMBOL SSD1306_SETSTARTLINE =0x40
SYMBOL SSD1306_MEMORYMODE =0x20
SYMBOL SSD1306_COLUMNADDR =0x21
SYMBOL SSD1306_PAGEADDR =0x22 ; Page 0-7 represents line 0 - 7
SYMBOL SSD1306_COMSCANINC =0xC0
SYMBOL SSD1306_COMSCANDEC =0xC8
SYMBOL SSD1306_SEGREMAP =0xA0 | 1
SYMBOL SSD1306_CHARGEPUMP =0x8D
SYMBOL SSD1306_EXTERNALVCC =0x1
SYMBOL SSD1306_SWITCHCAPVCC =0x2
;Scrolling SYMBOLs
SYMBOL ACTIVATE_SCROLL =0x2F
SYMBOL DEACTIVATE_SCROLL =0x2E
SYMBOL SET_VERTICAL_SCROLL_AREA =0xA3
SYMBOL RIGHT_HORIZONTAL_SCROLL =0x26
SYMBOL LEFT_HORIZONTAL_SCROLL =0x27
SYMBOL VERT_AND_RIGHT_HORIZONTAL =0x29
SYMBOL VERT_AND_LEFT_HORIZONTAL =0x2A
;**************************************************************
;
SYMBOL SSD1306_ADDR = $3C << 1 ; this is the I2C address ($78)
' b0-b3 are used for temp loops
SYMBOL DispNum = W2
SYMBOL row = b6
SYMBOL col = b7
SYMBOL temp = b11
SYMBOL aByte = b12
SYMBOL index = b13
main:
'20X2 bit0-bit7 = C.0, C.6, C.7, B.0, B.1 B.5, B.6, B.7
' i2c requires pullups (either internal or extranl) on the SDA/SDL pins
pullup %10100000 ;enable pullups on b.5/b.7
GOSUB InitialiseLcd ; Initialise the LCD
mainloop:
gosub ADA_FruitLogo
pause 5000
gosub Display_Font
pause 5000
gosub clearDisplay
row = 3
col = 10
gosub setposition
eeprom 31, ("0123456789 TEST")
eeprom 46, ("HELLO WORLD")
for index = 31 TO 45
read index,aByte
gosub displayChar;
next index
row = 5
col = 2
gosub setposition
for index = 46 to 56
read index,aByte
gosub displayChar;
next index
DispNum = 32016 ' Display any word sized number.
row = 6
col = 8
gosub setposition
gosub displayNum
row = 1 ' Display in top yellow section.
col = 1
gosub setposition
eeprom 57, ("HIGH TEMP - ")
for index = 57 to 68
read index,aByte
gosub displayChar;
next index
DispNum = 180
gosub displayNum
abyte = "C"
gosub displayChar
pause 10000
goto mainloop
' INITIALIZE LCD
' -----------------------------------------------------------------
'
InitialiseLcd:
' initialize I2C
PAUSE 500
i2cslave SSD1306_ADDR, i2cfast, i2cbyte
for index = 0 TO 23
read index,aByte
gosub DirectSendCmd
next
eeprom 0, (SSD1306_DISPLAYOFF); ; 0xAE
eeprom 1, (SSD1306_SETDISPLAYCLOCKDIV); ; 0xD5
eeprom 2, (0x80); ; the suggested ratio 0x80
eeprom 3, (SSD1306_SETMULTIPLEX); ; 0xA8
eeprom 4, (0x3F);
eeprom 5, (SSD1306_SETDISPLAYOFFSET); ; 0xD3
eeprom 6, (0x0); ; no offset
eeprom 7, (SSD1306_SETSTARTLINE); ; line #0
eeprom 8, (SSD1306_CHARGEPUMP); ; 0x8D
eeprom 9, (0x14); ; INTERNAL VCC
eeprom 10, (SSD1306_MEMORYMODE); ; 0x20
eeprom 11, (0x00); ; Horiz mode. 0x0 act like ks0108
eeprom 12, (SSD1306_SEGREMAP);
eeprom 13, (SSD1306_COMSCANDEC);
eeprom 14, (SSD1306_SETCOMPINS); ; 0xDA
eeprom 15, (0x12);
eeprom 16, (SSD1306_SETCONTRAST); ; 0x81
eeprom 17, (0xCF) ; INTERNAL VCC
eeprom 18, (SSD1306_SETPRECHARGE); ; 0xd9
eeprom 19, (0xF1) ; INTERNAL VCC
eeprom 20, (SSD1306_SETVCOMDETECT); ; 0xDB
eeprom 21, (0x40);
eeprom 22, (SSD1306_DISPLAYALLON_RESUME); ; 0xA4
eeprom 23, (SSD1306_DISPLAYON); ; 0xA4
'eeprom 24, (SSD1306_DISPLAYALLON); ; 0xA5
return
' SEND INIT CMD BYTE - SEND CMD BYTE - SEND DATA BYTE
' -----------------------------------------------------------------
'
SetPosition:
'20 line x 4 rows is accompished by wrapping the text on each line past 20 characters to two lines down (not next line down). Position 20 (dec) is row 3, col 1
abyte= SSD1306_PAGEADDR
GOSUB DirectSendCmd
abyte = row
GOSUB DirectSendCmd
abyte = 7
GOSUB DirectSendCmd
abyte= SSD1306_COLUMNADDR
col = col * 5 'columns per character
GOSUB DirectSendCmd
abyte = col
GOSUB DirectSendCmd
abyte = 127
GOSUB DirectSendCmd
return
DISPLAY_FONT:
gosub cleardisplay
eeprom 25, (SSD1306_COLUMNADDR)
eeprom 26, (0) ; ;Column start address (0 = reset)
eeprom 27, (127) ;Column end address (127 = reset)
eeprom 28, (SSD1306_PAGEADDR)
eeprom 29, (0) ;Page start address (0 = reset)
eeprom 30, (7) ;Page end address
for index = 25 TO 30
read index,aByte
gosub DirectSendCmd
next
Writei2c (0x40, 0x00, 0x07, 0x00, 0x07, 0x00)
Writei2c (0x40, 0x14, 0x7F, 0x14, 0x7F, 0x14)
Writei2c (0x40, 0x24, 0x2A, 0x7F, 0x2A, 0x12)
Writei2c (0x40, 0x23, 0x13, 0x08, 0x64, 0x62)
Writei2c (0x40, 0x36, 0x49, 0x56, 0x20, 0x50)
Writei2c (0x40, 0x00, 0x08, 0x07, 0x03, 0x00)
Writei2c (0x40, 0x00, 0x1C, 0x22, 0x41, 0x00)
Writei2c (0x40, 0x00, 0x41, 0x22, 0x1C, 0x00)
Writei2c (0x40, 0x2A, 0x1C, 0x7F, 0x1C, 0x2A)
Writei2c (0x40, 0x08, 0x08, 0x3E, 0x08, 0x08)
Writei2c (0x40, 0x00, 0x80, 0x70, 0x30, 0x00)
Writei2c (0x40, 0x08, 0x08, 0x08, 0x08, 0x08)
Writei2c (0x40, 0x00, 0x00, 0x60, 0x60, 0x00)
Writei2c (0x40, 0x20, 0x10, 0x08, 0x04, 0x02)
Writei2c (0x40, 0x3E, 0x51, 0x49, 0x45, 0x3E)
Writei2c (0x40, 0x00, 0x42, 0x7F, 0x40, 0x00) ; 00
Writei2c (0x40, 0x72, 0x49, 0x49, 0x49, 0x46)
Writei2c (0x40, 0x21, 0x41, 0x49, 0x4D, 0x33)
Writei2c (0x40, 0x18, 0x14, 0x12, 0x7F, 0x10)
Writei2c (0x40, 0x27, 0x45, 0x45, 0x45, 0x39)
Writei2c (0x40, 0x3C, 0x4A, 0x49, 0x49, 0x31)
Writei2c (0x40, 0x41, 0x21, 0x11, 0x09, 0x07)
Writei2c (0x40, 0x36, 0x49, 0x49, 0x49, 0x36)
Writei2c (0x40, 0x46, 0x49, 0x49, 0x29, 0x1E)
Writei2c (0x40, 0x00, 0x00, 0x14, 0x00, 0x00)
Writei2c (0x40, 0x00, 0x40, 0x34, 0x00, 0x00)
Writei2c (0x40, 0x00, 0x08, 0x14, 0x22, 0x41)
Writei2c (0x40, 0x14, 0x14, 0x14, 0x14, 0x14)
Writei2c (0x40, 0x00, 0x41, 0x22, 0x14, 0x08)
Writei2c (0x40, 0x02, 0x01, 0x59, 0x09, 0x06)
Writei2c (0x40, 0x3E, 0x41, 0x5D, 0x59, 0x4E)
Writei2c (0x40, 0x7C, 0x12, 0x11, 0x12, 0x7C)
Writei2c (0x40, 0x7F, 0x49, 0x49, 0x49, 0x36)
Writei2c (0x40, 0x3E, 0x41, 0x41, 0x41, 0x22)
Writei2c (0x40, 0x7F, 0x41, 0x41, 0x41, 0x3E)
Writei2c (0x40, 0x7F, 0x49, 0x49, 0x49, 0x41)
Writei2c (0x40, 0x7F, 0x09, 0x09, 0x09, 0x01)
Writei2c (0x40, 0x3E, 0x41, 0x41, 0x51, 0x73)
Writei2c (0x40, 0x7F, 0x08, 0x08, 0x08, 0x7F)
Writei2c (0x40, 0x00, 0x41, 0x7F, 0x41, 0x00)
Writei2c (0x40, 0x20, 0x40, 0x41, 0x3F, 0x01)
Writei2c (0x40, 0x7F, 0x08, 0x14, 0x22, 0x41)
Writei2c (0x40, 0x7F, 0x40, 0x40, 0x40, 0x40)
Writei2c (0x40, 0x7F, 0x02, 0x1C, 0x02, 0x7F)
Writei2c (0x40, 0x7F, 0x04, 0x08, 0x10, 0x7F)
Writei2c (0x40, 0x3E, 0x41, 0x41, 0x41, 0x3E)
Writei2c (0x40, 0x7F, 0x09, 0x09, 0x09, 0x06)
Writei2c (0x40, 0x3E, 0x41, 0x51, 0x21, 0x5E)
Writei2c (0x40, 0x7F, 0x09, 0x19, 0x29, 0x46)
Writei2c (0x40, 0x26, 0x49, 0x49, 0x49, 0x32)
Writei2c (0x40, 0x03, 0x01, 0x7F, 0x01, 0x03)
Writei2c (0x40, 0x3F, 0x40, 0x40, 0x40, 0x3F)
Writei2c (0x40, 0x1F, 0x20, 0x40, 0x20, 0x1F)
Writei2c (0x40, 0x3F, 0x40, 0x38, 0x40, 0x3F)
Writei2c (0x40, 0x63, 0x14, 0x08, 0x14, 0x63)
Writei2c (0x40, 0x03, 0x04, 0x78, 0x04, 0x03)
Writei2c (0x40, 0x61, 0x59, 0x49, 0x4D, 0x43) ; Z
Writei2c (0x40, 0x00, 0x7F, 0x41, 0x41, 0x41)
Writei2c (0x40, 0x02, 0x04, 0x08, 0x10, 0x20)
Writei2c (0x40, 0x00, 0x41, 0x41, 0x41, 0x7F)
Writei2c (0x40, 0x04, 0x02, 0x01, 0x02, 0x04)
Writei2c (0x40, 0x40, 0x40, 0x40, 0x40, 0x40)
Writei2c (0x40, 0x00, 0x03, 0x07, 0x08, 0x00)
Writei2c (0x40, 0x20, 0x54, 0x54, 0x78, 0x40)
Writei2c (0x40, 0x7F, 0x28, 0x44, 0x44, 0x38)
Writei2c (0x40, 0x38, 0x44, 0x44, 0x44, 0x28)
Writei2c (0x40, 0x38, 0x44, 0x44, 0x28, 0x7F)
Writei2c (0x40, 0x38, 0x54, 0x54, 0x54, 0x18)
Writei2c (0x40, 0x00, 0x08, 0x7E, 0x09, 0x02)
Writei2c (0x40, 0x18, 0xA4, 0xA4, 0x9C, 0x78)
Writei2c (0x40, 0x7F, 0x08, 0x04, 0x04, 0x78)
Writei2c (0x40, 0x00, 0x44, 0x7D, 0x40, 0x00)
Writei2c (0x40, 0x20, 0x40, 0x40, 0x3D, 0x00)
Writei2c (0x40, 0x7F, 0x10, 0x28, 0x44, 0x00)
Writei2c (0x40, 0x00, 0x41, 0x7F, 0x40, 0x00)
Writei2c (0x40, 0x7C, 0x04, 0x78, 0x04, 0x78)
Writei2c (0x40, 0x7C, 0x08, 0x04, 0x04, 0x78)
Writei2c (0x40, 0x38, 0x44, 0x44, 0x44, 0x38)
Writei2c (0x40, 0xFC, 0x18, 0x24, 0x24, 0x18)
Writei2c (0x40, 0x18, 0x24, 0x24, 0x18, 0xFC)
Writei2c (0x40, 0x7C, 0x08, 0x04, 0x04, 0x08)
Writei2c (0x40, 0x48, 0x54, 0x54, 0x54, 0x24)
Writei2c (0x40, 0x04, 0x04, 0x3F, 0x44, 0x24)
Writei2c (0x40, 0x3C, 0x40, 0x40, 0x20, 0x7C)
Writei2c (0x40, 0x1C, 0x20, 0x40, 0x20, 0x1C)
Writei2c (0x40, 0x3C, 0x40, 0x30, 0x40, 0x3C)
Writei2c (0x40, 0x44, 0x28, 0x10, 0x28, 0x44)
Writei2c (0x40, 0x4C, 0x90, 0x90, 0x90, 0x7C)
Writei2c (0x40, 0x44, 0x64, 0x54, 0x4C, 0x44)
Writei2c (0x40, 0x00, 0x08, 0x36, 0x41, 0x00)
Writei2c (0x40, 0x00, 0x00, 0x77, 0x00, 0x00)
Writei2c (0x40, 0x00, 0x41, 0x36, 0x08, 0x00)
Writei2c (0x40, 0x02, 0x01, 0x02, 0x04, 0x02)
Writei2c (0x40, 0x3C, 0x26, 0x23, 0x26, 0x3C)
Writei2c (0x40, 0x1E, 0xA1, 0xA1, 0x61, 0x12)
Writei2c (0x40, 0x3A, 0x40, 0x40, 0x20, 0x7A)
Writei2c (0x40, 0x38, 0x54, 0x54, 0x55, 0x59)
Writei2c (0x40, 0x21, 0x55, 0x55, 0x79, 0x41)
return
DirectSendCmd:
' Commands are preceeded by a 0 filled byte
writei2c (0,abyte)
return
ClearDisplay:
b0 = SSD1306_LCDWIDTH
FOR b1 = 0 to b0
' 0x40 = 01000000 (C/O = 0, D/C = 1) -- Not a command, but data follows.
' Clear 16 columns at a time
writei2c(0x40,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
next b1
for index = 25 TO 30
read index,aByte
gosub DirectSendCmd
next
return
ADA_FruitLogo:
for index = 25 TO 30
read index,aByte
gosub DirectSendCmd
pause 5
next
' These values were copied from the ADA_Fruit Library to demonstrate the bitmap capability
; Line 0 (page 0)
WriteI2C (0X40,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
WriteI2C (0X40,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
WriteI2C (0X40,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
WriteI2C (0X40,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80)
WriteI2C (0X40,0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
WriteI2C (0X40,0x00, 0x80, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
WriteI2C (0X40,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
WriteI2C (0X40,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
; Line 1 (page 1)
WriteI2C (0X40,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
WriteI2C (0X40,0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xF8, 0xE0, 0x00, 0x00, 0x00, 0x00)
WriteI2C (0X40,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80)
WriteI2C (0X40,0x80, 0x80, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0xFF)
WriteI2C (0X40,0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00)
WriteI2C (0X40,0x80, 0xFF, 0xFF, 0x80, 0x80, 0x00, 0x80, 0x80, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x80, 0x80)
WriteI2C (0X40,0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x8C, 0x8E, 0x84, 0x00, 0x00, 0x80, 0xF8)
WriteI2C (0X40,0xF8, 0xF8, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
WriteI2C (0X40,0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xE0, 0xE0, 0xC0, 0x80)
WriteI2C (0X40,0x00, 0xE0, 0xFC, 0xFE, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00)
WriteI2C (0X40,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0xC7, 0x01, 0x01)
WriteI2C (0X40,0x01, 0x01, 0x83, 0xFF, 0xFF, 0x00, 0x00, 0x7C, 0xFE, 0xC7, 0x01, 0x01, 0x01, 0x01, 0x83, 0xFF)
WriteI2C (0X40,0xFF, 0xFF, 0x00, 0x38, 0xFE, 0xC7, 0x83, 0x01, 0x01, 0x01, 0x83, 0xC7, 0xFF, 0xFF, 0x00, 0x00)
WriteI2C (0X40,0x01, 0xFF, 0xFF, 0x01, 0x01, 0x00, 0xFF, 0xFF, 0x07, 0x01, 0x01, 0x01, 0x00, 0x00, 0x7F, 0xFF)
WriteI2C (0X40,0x80, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x7F, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x01, 0xFF)
WriteI2C (0X40,0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
WriteI2C (0X40,0x03, 0x0F, 0x3F, 0x7F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE7, 0xC7, 0xC7, 0x8F)
WriteI2C (0X40,0x8F, 0x9F, 0xBF, 0xFF, 0xFF, 0xC3, 0xC0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xFC, 0xFC)
WriteI2C (0X40,0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xF8, 0xF8, 0xF0, 0xF0, 0xE0, 0xC0, 0x00, 0x01, 0x03, 0x03, 0x03)
WriteI2C (0X40,0x03, 0x03, 0x01, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01)
WriteI2C (0X40,0x03, 0x01, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01, 0x03, 0x03, 0x00, 0x00)
WriteI2C (0X40,0x00, 0x03, 0x03, 0x00, 0x00, 0x00, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01)
WriteI2C (0X40,0x03, 0x03, 0x03, 0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x01, 0x03, 0x01, 0x00, 0x00, 0x00, 0x03)
WriteI2C (0X40,0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
writei2c (0x40,0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x1F, 0x0F)
Writei2c (0x40,0x87, 0xC7, 0xF7, 0xFF, 0xFF, 0x1F, 0x1F, 0x3D, 0xFC, 0xF8, 0xF8, 0xF8, 0xF8, 0x7C, 0x7D, 0xFF)
Writei2c (0x40,0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x0F, 0x07, 0x00, 0x30, 0x30, 0x00, 0x00)
Writei2c (0x40,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
Writei2c (0x40,0x00, 0x00, 0x00, 0x00, 0xFE, 0xFE, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
Writei2c (0x40,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xC0, 0x00)
Writei2c (0x40,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00)
Writei2c (0x40,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
Writei2c (0x40,0x00, 0xC0, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x7F, 0x3F, 0x1F)
Writei2c (0x40,0x0F, 0x07, 0x1F, 0x7F, 0xFF, 0xFF, 0xF8, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xF8, 0xE0)
Writei2c (0x40,0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00)
Writei2c (0x40,0x00, 0xFC, 0xFE, 0xFC, 0x0C, 0x06, 0x06, 0x0E, 0xFC, 0xF8, 0x00, 0x00, 0xF0, 0xF8, 0x1C, 0x0E)
Writei2c (0x40,0x06, 0x06, 0x06, 0x0C, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00, 0x00, 0x00, 0xFC)
Writei2c (0x40,0xFE, 0xFC, 0x00, 0x18, 0x3C, 0x7E, 0x66, 0xE6, 0xCE, 0x84, 0x00, 0x00, 0x06, 0xFF, 0xFF, 0x06)
Writei2c (0x40,0x06, 0xFC, 0xFE, 0xFC, 0x0C, 0x06, 0x06, 0x06, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00, 0xC0, 0xF8)
Writei2c (0x40,0xFC, 0x4E, 0x46, 0x46, 0x46, 0x4E, 0x7C, 0x78, 0x40, 0x18, 0x3C, 0x76, 0xE6, 0xCE, 0xCC, 0x80)
Writei2c (0x40,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
Writei2c (0x40,0x00, 0x00, 0x00, 0x00, 0x01, 0x07, 0x0F, 0x1F, 0x1F, 0x3F, 0x3F, 0x3F, 0x3F, 0x1F, 0x0F, 0x03)
Writei2c (0x40,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00)
Writei2c (0x40,0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x03, 0x07, 0x0E, 0x0C)
Writei2c (0x40,0x18, 0x18, 0x0C, 0x06, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x01, 0x0F, 0x0E, 0x0C, 0x18, 0x0C, 0x0F)
Writei2c (0x40,0x07, 0x01, 0x00, 0x04, 0x0E, 0x0C, 0x18, 0x0C, 0x0F, 0x07, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00)
Writei2c (0x40,0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x07)
Writei2c (0x40,0x07, 0x0C, 0x0C, 0x18, 0x1C, 0x0C, 0x06, 0x06, 0x00, 0x04, 0x0E, 0x0C, 0x18, 0x0C, 0x0F, 0x07)
Writei2c (0x40,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
Writei2c (0x40,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
Writei2c (0x40,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
Writei2c (0x40,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
Writei2c (0x40,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
Writei2c (0x40,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
Writei2c (0x40,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
Writei2c (0x40,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
return
' STANDARD FONT
' This is the ASCII Font Table starting at space and ending at Z -- lower case is not included (not enough memory)
' The first 8 are in program direct writes
'table (0x00, 0x00, 0x00, 0x00, 0x00) ' Space
'table (0x00, 0x00, 0x5F, 0x00, 0x00) ' !
'table (0x00, 0x07, 0x00, 0x07, 0x00) ' "
'table (0x14, 0x7F, 0x14, 0x7F, 0x14) ' #
'table (0x24, 0x2A, 0x7F, 0x2A, 0x12) ' $
'table (0x23, 0x13, 0x08, 0x64, 0x62) ' %
'table (0x36, 0x49, 0x56, 0x20, 0x50) ' &
'table (0x00, 0x08, 0x07, 0x03, 0x00) ' '
table (0x00, 0x1C, 0x22, 0x41, 0x00) ' (
table (0x00, 0x41, 0x22, 0x1C, 0x00) ' )
table (0x2A, 0x1C, 0x7F, 0x1C, 0x2A) ' *
table (0x08, 0x08, 0x3E, 0x08, 0x08) ' +
table (0x00, 0x80, 0x70, 0x30, 0x00) ' ,
table (0x08, 0x08, 0x08, 0x08, 0x08) ' -
table (0x00, 0x00, 0x5F, 0x00, 0x0) ' .
table (0x20, 0x10, 0x08, 0x04, 0x02) ' /
table (0x3E, 0x51, 0x49, 0x45, 0x3E) ' 0
table (0x00, 0x42, 0x7F, 0x40, 0x00) ; 1
table (0x72, 0x49, 0x49, 0x49, 0x46)
table (0x21, 0x41, 0x49, 0x4D, 0x33)
table (0x18, 0x14, 0x12, 0x7F, 0x10)
table (0x27, 0x45, 0x45, 0x45, 0x39)
table (0x3C, 0x4A, 0x49, 0x49, 0x31)
table (0x41, 0x21, 0x11, 0x09, 0x07)
table (0x36, 0x49, 0x49, 0x49, 0x36)
table (0x46, 0x49, 0x49, 0x29, 0x1E)
table (0x00, 0x00, 0x14, 0x00, 0x00)
table (0x00, 0x40, 0x34, 0x00, 0x00)
table (0x00, 0x08, 0x14, 0x22, 0x41)
table (0x14, 0x14, 0x14, 0x14, 0x14)
table (0x00, 0x41, 0x22, 0x14, 0x08)
table (0x02, 0x01, 0x59, 0x09, 0x06)
table (0x3E, 0x41, 0x5D, 0x59, 0x4E)
table (0x7C, 0x12, 0x11, 0x12, 0x7C)
table (0x7F, 0x49, 0x49, 0x49, 0x36)
table (0x3E, 0x41, 0x41, 0x41, 0x22)
table (0x7F, 0x41, 0x41, 0x41, 0x3E)
table (0x7F, 0x49, 0x49, 0x49, 0x41)
table (0x7F, 0x09, 0x09, 0x09, 0x01)
table (0x3E, 0x41, 0x41, 0x51, 0x73)
table (0x7F, 0x08, 0x08, 0x08, 0x7F)
table (0x00, 0x41, 0x7F, 0x41, 0x00)
table (0x20, 0x40, 0x41, 0x3F, 0x01)
table (0x7F, 0x08, 0x14, 0x22, 0x41)
table (0x7F, 0x40, 0x40, 0x40, 0x40)
table (0x7F, 0x02, 0x1C, 0x02, 0x7F)
table (0x7F, 0x04, 0x08, 0x10, 0x7F)
table (0x3E, 0x41, 0x41, 0x41, 0x3E)
table (0x7F, 0x09, 0x09, 0x09, 0x06)
table (0x3E, 0x41, 0x51, 0x21, 0x5E)
table (0x7F, 0x09, 0x19, 0x29, 0x46)
table (0x26, 0x49, 0x49, 0x49, 0x32)
table (0x03, 0x01, 0x7F, 0x01, 0x03)
table (0x3F, 0x40, 0x40, 0x40, 0x3F)
table (0x1F, 0x20, 0x40, 0x20, 0x1F)
table (0x3F, 0x40, 0x38, 0x40, 0x3F)
table (0x63, 0x14, 0x08, 0x14, 0x63)
table (0x03, 0x04, 0x78, 0x04, 0x03)
table (0x61, 0x59, 0x49, 0x4D, 0x43) ; Z
DisplayChar:
temp = abyte - " "
if temp< 8 then
if temp=0 then
writei2c(0x40, 0x00, 0x00, 0x00, 0x00, 0x00) ' space
elseif temp=1 then
writei2c(0x40, 0x00, 0x00, 0x5F, 0x00, 0x00) ' !
elseif temp=2 then
writei2c(0x40, 0x00, 0x07, 0x00, 0x07, 0x00) ' "
elseif temp=3 then
writei2c(0x40, 0x14, 0x7F, 0x14, 0x7F, 0x14) ' #
elseif temp=4 then
writei2c(0x40, 0x24, 0x2A, 0x7F, 0x2A, 0x12) ' $
elseif temp=5 then
writei2c(0x40, 0x23, 0x13, 0x08, 0x64, 0x62) ' %
elseif temp=6 then
writei2c(0x40, 0x36, 0x49, 0x56, 0x20, 0x50) ' &
elseif temp=7 then
writei2c(0x40, 0x00, 0x08, 0x07, 0x03, 0x00) ' '
endif
return
endif
temp = temp - 8
temp = temp * 5
b1 = temp + 4
for b0 = temp to b1
readtable b0, aByte
writeI2C(0x40,abyte)
next b0
return
DisplayNum:
' Words are always 5 chars long, but may be zero led.
b3 = 1
for b2 = 0 to 4
temp = 4-b2
aByte = DispNum DIG temp + "0"
if aByte="0" and b3=1 then
goto DisplayNumCont ' Don't show leading spaces
elseif abyte<>"0" and b3=1 then
b3=0
endif
GOSUB DisplayChar
DisplayNumCont:
next b2
return
Click here to download the .bas file
If you are interested in how to link a 1602 or 2004 LCD display, please let me know and I will post that code as well.
|