0
It works! It works!
Victory at last!
Well, not quite, but at least I'm part-way there now!
Yet another GLCD arrived in the post this morning and as soon as I'd shredded it from it's bubble-wrapped envelope, I had a series of pins soldered on to it and had it connected up to my breadboard.
This time it's a LM6038B from Mainline.
A quick read through the datasheet and it looks ok: it's a ribbon-based display ready-mounted on a PCB, with all the nasty charge-pump capacitors and all that nonsense already in place. So you can just shove 3v onto the power/lcd pins and the backlight shares a 0v pin with the display controller, so only one ground connection needed!
The display supports the usual 6800 and 8080 parallel interface, as well as a serial interface. Great. But then I came across this in the datasheet:
1.5 Jumper functions
That's right. Serial mode by default.
The jumpers are actually little solder blobs on the back of the display, so in theory they can be changed. Given that I'd been told that this display used a KS0108-compatible library, it was tempting to give it a go.
But then, I thought rather than screw up yet another display and get no further on, it might be fun/torture to get this working as-is, using the serial interface.
Here's the datasheet
Here's the Oshonsoft PIC18 Basic code to get an 18F2455 mirochip working with the display using PORTA and SPI communication. Simply wire up the microchip pins to the corresponding pins on the display. The only thing to look out for is SPI_SDO - I set this to a pin on PORTB as it's not used for this example - data is sent to the display, not read back from it. Any way, here it is:
AllDigital
'Config PORTA = Output
Symbol glcd_cs1 = PORTA.0
Symbol glcd_res = PORTA.1
Symbol glcd_a0 = PORTA.2
Symbol glcd_sclk = PORTA.3
Symbol glcd_si = PORTA.4
Define SPI_SCK_REG = PORTA 'defines the port where sck line is connected To
Define SPI_SCK_BIT = 3 'defines the pin where sck line is connected To
Define SPI_SDI_REG = PORTA 'defines the port where sdi line is connected To
Define SPI_SDI_BIT = 4 'defines the pin where sdi line is connected To
Define SPI_SDO_REG = PORTB 'defines the port where sdo line is connected To
Define SPI_SDO_BIT = 4 'defines the pin where sdo line is connected To
Define SPI_CS_REG = PORTA 'defines the port where cs line is connected To
Define SPI_CS_BIT = 0 'defines the pin where cs line is connected To
Dim glcdbyte As Byte 'the byte to send to the display
Dim glcdline As Byte 'used to set the current line number of the display
Dim i As Byte 'general use variable
Dim j As Byte
Dim character(6) As Byte 'array of character font slices
Dim charbyte As Byte 'the character to send to the GLCD
Dim ilcd As Byte
Dim jlcd As Byte
Dim klcd As Byte
Dim invertchar As Bit
Config PORTC = Output
High PORTC.2
WaitMs 1000
SPIPrepare
Low PORTC.2
Gosub glcdinititalise
Gosub glcdclearscreen
High PORTC.2
glcdline = 0
Gosub glcdsetline
For i = 0 To 17
charbyte = LookUp("HOLY CRAP IT WORKS"), i
Gosub pickcharacter
Gosub drawcharacter
Next i
End
glcdinititalise:
'reset pin is pulled low via 6.2k resistor
'wait for power to stabilise
WaitMs 100
'set reset pin high
High glcd_res
WaitMs 10
glcdbyte = 0xa2 'LCD bias=1/9
Gosub glcdsendcommand
glcdbyte = 0xa0 'no flip on x direction
Gosub glcdsendcommand
glcdbyte = 0xc8 'flip on y direction
Gosub glcdsendcommand
glcdbyte = 0x40 'init line=0
Gosub glcdsendcommand
glcdbyte = 0x2c 'power control voltage convertor on
Gosub glcdsendcommand
WaitMs 50
glcdbyte = 0x2e 'power control voltage regulator on
Gosub glcdsendcommand
WaitMs 50
glcdbyte = 0x2f 'power control voltage follower on
Gosub glcdsendcommand
WaitMs 50
glcdbyte = 0x25 'regulator resistor select
Gosub glcdsendcommand
'contrast control:
glcdbyte = 0x81 'set reference voltage mode
Gosub glcdsendcommand
glcdbyte = 0x20 'set reference voltage resistor
Gosub glcdsendcommand
glcdbyte = 0xaf 'turn on the display
Gosub glcdsendcommand
glcdbyte = 0xb0 'set page address=0
Gosub glcdsendcommand
glcdbyte = 0x10 'set column address upper 4bit=0
Gosub glcdsendcommand
glcdbyte = 0x04 'set column address lower 4bit=4
Gosub glcdsendcommand
Return
glcdsenddata:
SPICSOn
High glcd_a0
SPISend glcdbyte
WaitUs 1
SPICSOff
Return
glcdsendcommand:
SPICSOn
Low glcd_a0
SPISend glcdbyte
WaitUs 1
SPICSOff
Return
glcdclearscreen:
For glcdline = 0 To 7
Gosub glcdsetline
glcdbyte = 0
For j = 0 To 129
Gosub glcdsenddata
Next j
Next glcdline
Return
glcdsetline:
glcdbyte = 10110000b
glcdbyte = glcdbyte + glcdline
Gosub glcdsendcommand
glcdbyte = 0x10 'set column address upper 4bit=0
Gosub glcdsendcommand
glcdbyte = 0x04 'set column address lower 4bit=4
Gosub glcdsendcommand
WaitMs 1
Return
pickcharacter:
Select Case charbyte
character(5) = 0 'check for this condition when drawing the letter
Case 0, 48 '0
character(0) = 120
character(1) = 164
character(2) = 148
character(3) = 120
character(4) = 0
Case 1, 49 '1
character(0) = 1
character(1) = 136
character(2) = 252
character(3) = 128
character(4) = 0
Case 2, 50 '2
character(0) = 200
character(1) = 164
character(2) = 164
character(3) = 152
character(4) = 0
Case 3, 51 '3
character(0) = 68
character(1) = 148
character(2) = 148
character(3) = 108
character(4) = 0
Case 4, 52 '4
character(0) = 32
character(1) = 48
character(2) = 40
character(3) = 252
character(4) = 0
Case 5, 53 '5
character(0) = 92
character(1) = 148
character(2) = 148
character(3) = 100
character(4) = 0
Case 6, 54 '6
character(0) = 120
character(1) = 148
character(2) = 148
character(3) = 96
character(4) = 0
Case 7, 55 '7
character(0) = 4
character(1) = 196
character(2) = 52
character(3) = 12
character(4) = 0
Case 8, 56 '8
character(0) = 104
character(1) = 148
character(2) = 148
character(3) = 104
character(4) = 0
Case 9, 57 '9
character(0) = 72
character(1) = 148
character(2) = 148
character(3) = 120
character(4) = 0
Case 32 'space
character(0) = 1
character(1) = 1
character(2) = 1
character(3) = 1
character(4) = 1
Case 65 'A
character(0) = 248
character(1) = 36
character(2) = 36
character(3) = 248
character(4) = 0
Case 66 'B
character(0) = 252
character(1) = 148
character(2) = 148
character(3) = 104
character(4) = 0
Case 67 'C
character(0) = 120
character(1) = 132
character(2) = 132
character(3) = 72
character(4) = 0
Case 68 'D
character(0) = 252
character(1) = 132
character(2) = 132
character(3) = 120
character(4) = 0
Case 69 'E
character(0) = 252
character(1) = 148
character(2) = 148
character(3) = 132
character(4) = 0
Case 70 'F
character(0) = 252
character(1) = 20
character(2) = 20
character(3) = 4
character(4) = 0
Case 71 'G
character(0) = 120
character(1) = 132
character(2) = 164
character(3) = 232
character(4) = 0
Case 72 'H
character(0) = 252
character(1) = 16
character(2) = 16
character(3) = 252
character(4) = 0
Case 73 'I
character(0) = 132
character(1) = 252
character(2) = 132
character(3) = 0
character(4) = 0
Case 74 'J
character(0) = 96
character(1) = 128
character(2) = 132
character(3) = 124
character(4) = 0
Case 75 'K
character(0) = 252
character(1) = 16
character(2) = 40
character(3) = 196
character(4) = 0
Case 76 'L
character(0) = 252
character(1) = 128
character(2) = 128
character(3) = 128
character(4) = 0
Case 77 'M
character(0) = 252
character(1) = 8
character(2) = 48
character(3) = 8
character(4) = 252
Case 78 'N
character(0) = 252
character(1) = 8
character(2) = 16
character(3) = 252
character(4) = 0
Case 79 'O
character(0) = 120
character(1) = 132
character(2) = 132
character(3) = 120
character(4) = 0
Case 80 'P
character(0) = 252
character(1) = 36
character(2) = 36
character(3) = 24
character(4) = 0
Case 81 'Q
character(0) = 120
character(1) = 132
character(2) = 164
character(3) = 120
character(4) = 128
Case 82 'R
character(0) = 252
character(1) = 36
character(2) = 36
character(3) = 216
character(4) = 0
Case 83 'S
character(0) = 72
character(1) = 148
character(2) = 164
character(3) = 72
character(4) = 0
Case 84 'T
character(0) = 4
character(1) = 252
character(2) = 4
character(3) = 0
character(4) = 0
Case 85 'U
character(0) = 124
character(1) = 128
character(2) = 128
character(3) = 252
character(4) = 0
Case 86 'V
character(0) = 28
character(1) = 96
character(2) = 128
character(3) = 96
character(4) = 28
Case 87 'W
character(0) = 252
character(1) = 64
character(2) = 48
character(3) = 64
character(4) = 252
Case 88 'X
character(0) = 196
character(1) = 40
character(2) = 16
character(3) = 40
character(4) = 196
Case 89 'Y
character(0) = 76
character(1) = 144
character(2) = 144
character(3) = 124
character(4) = 0
Case 90 'Z
character(0) = 196
character(1) = 164
character(2) = 148
character(3) = 140
character(4) = 0
Case 91 'up/down
character(0) = 0
character(1) = 0
character(2) = 80
character(3) = 216
character(4) = 80
Case 92 'sand saver
character(0) = 0
character(1) = 0
character(2) = 144
character(3) = 168
character(4) = 72
Case 93 'arrow
character(3) = 1
character(0) = 248
character(1) = 112
character(2) = 32
character(4) = 0
Case 94 'hyphen
character(0) = 0
character(1) = 16
character(2) = 16
character(3) = 16
character(4) = 0
Case 58 ':
character(0) = 1
character(1) = 216
character(2) = 216
character(3) = 0
character(4) = 0
Case 47 '/
character(0) = 192
character(1) = 48
character(2) = 12
character(3) = 0
character(4) = 0
Case 62 '>
character(0) = 124
character(1) = 56
character(2) = 16
character(3) = 0
character(4) = 0
Case 40 '(
character(0) = 0
character(1) = 0
character(2) = 120
character(3) = 132
character(4) = 0
Case 41 ')
character(0) = 132
character(1) = 120
character(2) = 0
character(3) = 0
character(4) = 0
Case Else 'turn into a space
character(0) = 1
character(1) = 1
character(2) = 1
character(3) = 1
character(4) = 1
EndSelect
Return
drawcharacter:
'at this point, we should have: charbyte containing the character index
'which has been "passed" into pickcharacter which has populated the
'array called "character" - 5 pixels wide, possibly more
'so we keep sending each byte to the GLCD until we hit a sequence
'of two empty (zero) bytes
ilcd = 0
jlcd = 0
While ilcd < 5
klcd = character(ilcd)
If invertchar = 1 Then klcd = klcd Xor 255
'send one byte (column of 8 pixels) to the display
If character(ilcd) = 1 Then
'this is the special character to say "blank"
If invertchar = 1 Then
glcdbyte = 255
Else
glcdbyte = 0
Endif
Else
glcdbyte = klcd
Endif
Gosub glcdsenddata
'move on to the next column of data within the character
ilcd = ilcd + 1
Wend
Return
Here's the end result:
Now if only there were some way I could keep this and use a second set of serial (SPI) lines to send/receive data to the eeprom chip. That'd be a massive leap forward....
Well, not quite, but at least I'm part-way there now!
Yet another GLCD arrived in the post this morning and as soon as I'd shredded it from it's bubble-wrapped envelope, I had a series of pins soldered on to it and had it connected up to my breadboard.
This time it's a LM6038B from Mainline.
A quick read through the datasheet and it looks ok: it's a ribbon-based display ready-mounted on a PCB, with all the nasty charge-pump capacitors and all that nonsense already in place. So you can just shove 3v onto the power/lcd pins and the backlight shares a 0v pin with the display controller, so only one ground connection needed!
The display supports the usual 6800 and 8080 parallel interface, as well as a serial interface. Great. But then I came across this in the datasheet:
1.5 Jumper functions
JP1 | JP2 | JP3 | JP4 | Interfacemode |
---|---|---|---|---|
close | open | close | close | 6800 mode |
open | close | close | close | 8080 mode |
open | close | open | close | serial mode (default) |
That's right. Serial mode by default.
The jumpers are actually little solder blobs on the back of the display, so in theory they can be changed. Given that I'd been told that this display used a KS0108-compatible library, it was tempting to give it a go.
But then, I thought rather than screw up yet another display and get no further on, it might be fun/torture to get this working as-is, using the serial interface.
Here's the datasheet
Here's the Oshonsoft PIC18 Basic code to get an 18F2455 mirochip working with the display using PORTA and SPI communication. Simply wire up the microchip pins to the corresponding pins on the display. The only thing to look out for is SPI_SDO - I set this to a pin on PORTB as it's not used for this example - data is sent to the display, not read back from it. Any way, here it is:
AllDigital
'Config PORTA = Output
Symbol glcd_cs1 = PORTA.0
Symbol glcd_res = PORTA.1
Symbol glcd_a0 = PORTA.2
Symbol glcd_sclk = PORTA.3
Symbol glcd_si = PORTA.4
Define SPI_SCK_REG = PORTA 'defines the port where sck line is connected To
Define SPI_SCK_BIT = 3 'defines the pin where sck line is connected To
Define SPI_SDI_REG = PORTA 'defines the port where sdi line is connected To
Define SPI_SDI_BIT = 4 'defines the pin where sdi line is connected To
Define SPI_SDO_REG = PORTB 'defines the port where sdo line is connected To
Define SPI_SDO_BIT = 4 'defines the pin where sdo line is connected To
Define SPI_CS_REG = PORTA 'defines the port where cs line is connected To
Define SPI_CS_BIT = 0 'defines the pin where cs line is connected To
Dim glcdbyte As Byte 'the byte to send to the display
Dim glcdline As Byte 'used to set the current line number of the display
Dim i As Byte 'general use variable
Dim j As Byte
Dim character(6) As Byte 'array of character font slices
Dim charbyte As Byte 'the character to send to the GLCD
Dim ilcd As Byte
Dim jlcd As Byte
Dim klcd As Byte
Dim invertchar As Bit
Config PORTC = Output
High PORTC.2
WaitMs 1000
SPIPrepare
Low PORTC.2
Gosub glcdinititalise
Gosub glcdclearscreen
High PORTC.2
glcdline = 0
Gosub glcdsetline
For i = 0 To 17
charbyte = LookUp("HOLY CRAP IT WORKS"), i
Gosub pickcharacter
Gosub drawcharacter
Next i
End
glcdinititalise:
'reset pin is pulled low via 6.2k resistor
'wait for power to stabilise
WaitMs 100
'set reset pin high
High glcd_res
WaitMs 10
glcdbyte = 0xa2 'LCD bias=1/9
Gosub glcdsendcommand
glcdbyte = 0xa0 'no flip on x direction
Gosub glcdsendcommand
glcdbyte = 0xc8 'flip on y direction
Gosub glcdsendcommand
glcdbyte = 0x40 'init line=0
Gosub glcdsendcommand
glcdbyte = 0x2c 'power control voltage convertor on
Gosub glcdsendcommand
WaitMs 50
glcdbyte = 0x2e 'power control voltage regulator on
Gosub glcdsendcommand
WaitMs 50
glcdbyte = 0x2f 'power control voltage follower on
Gosub glcdsendcommand
WaitMs 50
glcdbyte = 0x25 'regulator resistor select
Gosub glcdsendcommand
'contrast control:
glcdbyte = 0x81 'set reference voltage mode
Gosub glcdsendcommand
glcdbyte = 0x20 'set reference voltage resistor
Gosub glcdsendcommand
glcdbyte = 0xaf 'turn on the display
Gosub glcdsendcommand
glcdbyte = 0xb0 'set page address=0
Gosub glcdsendcommand
glcdbyte = 0x10 'set column address upper 4bit=0
Gosub glcdsendcommand
glcdbyte = 0x04 'set column address lower 4bit=4
Gosub glcdsendcommand
Return
glcdsenddata:
SPICSOn
High glcd_a0
SPISend glcdbyte
WaitUs 1
SPICSOff
Return
glcdsendcommand:
SPICSOn
Low glcd_a0
SPISend glcdbyte
WaitUs 1
SPICSOff
Return
glcdclearscreen:
For glcdline = 0 To 7
Gosub glcdsetline
glcdbyte = 0
For j = 0 To 129
Gosub glcdsenddata
Next j
Next glcdline
Return
glcdsetline:
glcdbyte = 10110000b
glcdbyte = glcdbyte + glcdline
Gosub glcdsendcommand
glcdbyte = 0x10 'set column address upper 4bit=0
Gosub glcdsendcommand
glcdbyte = 0x04 'set column address lower 4bit=4
Gosub glcdsendcommand
WaitMs 1
Return
pickcharacter:
Select Case charbyte
character(5) = 0 'check for this condition when drawing the letter
Case 0, 48 '0
character(0) = 120
character(1) = 164
character(2) = 148
character(3) = 120
character(4) = 0
Case 1, 49 '1
character(0) = 1
character(1) = 136
character(2) = 252
character(3) = 128
character(4) = 0
Case 2, 50 '2
character(0) = 200
character(1) = 164
character(2) = 164
character(3) = 152
character(4) = 0
Case 3, 51 '3
character(0) = 68
character(1) = 148
character(2) = 148
character(3) = 108
character(4) = 0
Case 4, 52 '4
character(0) = 32
character(1) = 48
character(2) = 40
character(3) = 252
character(4) = 0
Case 5, 53 '5
character(0) = 92
character(1) = 148
character(2) = 148
character(3) = 100
character(4) = 0
Case 6, 54 '6
character(0) = 120
character(1) = 148
character(2) = 148
character(3) = 96
character(4) = 0
Case 7, 55 '7
character(0) = 4
character(1) = 196
character(2) = 52
character(3) = 12
character(4) = 0
Case 8, 56 '8
character(0) = 104
character(1) = 148
character(2) = 148
character(3) = 104
character(4) = 0
Case 9, 57 '9
character(0) = 72
character(1) = 148
character(2) = 148
character(3) = 120
character(4) = 0
Case 32 'space
character(0) = 1
character(1) = 1
character(2) = 1
character(3) = 1
character(4) = 1
Case 65 'A
character(0) = 248
character(1) = 36
character(2) = 36
character(3) = 248
character(4) = 0
Case 66 'B
character(0) = 252
character(1) = 148
character(2) = 148
character(3) = 104
character(4) = 0
Case 67 'C
character(0) = 120
character(1) = 132
character(2) = 132
character(3) = 72
character(4) = 0
Case 68 'D
character(0) = 252
character(1) = 132
character(2) = 132
character(3) = 120
character(4) = 0
Case 69 'E
character(0) = 252
character(1) = 148
character(2) = 148
character(3) = 132
character(4) = 0
Case 70 'F
character(0) = 252
character(1) = 20
character(2) = 20
character(3) = 4
character(4) = 0
Case 71 'G
character(0) = 120
character(1) = 132
character(2) = 164
character(3) = 232
character(4) = 0
Case 72 'H
character(0) = 252
character(1) = 16
character(2) = 16
character(3) = 252
character(4) = 0
Case 73 'I
character(0) = 132
character(1) = 252
character(2) = 132
character(3) = 0
character(4) = 0
Case 74 'J
character(0) = 96
character(1) = 128
character(2) = 132
character(3) = 124
character(4) = 0
Case 75 'K
character(0) = 252
character(1) = 16
character(2) = 40
character(3) = 196
character(4) = 0
Case 76 'L
character(0) = 252
character(1) = 128
character(2) = 128
character(3) = 128
character(4) = 0
Case 77 'M
character(0) = 252
character(1) = 8
character(2) = 48
character(3) = 8
character(4) = 252
Case 78 'N
character(0) = 252
character(1) = 8
character(2) = 16
character(3) = 252
character(4) = 0
Case 79 'O
character(0) = 120
character(1) = 132
character(2) = 132
character(3) = 120
character(4) = 0
Case 80 'P
character(0) = 252
character(1) = 36
character(2) = 36
character(3) = 24
character(4) = 0
Case 81 'Q
character(0) = 120
character(1) = 132
character(2) = 164
character(3) = 120
character(4) = 128
Case 82 'R
character(0) = 252
character(1) = 36
character(2) = 36
character(3) = 216
character(4) = 0
Case 83 'S
character(0) = 72
character(1) = 148
character(2) = 164
character(3) = 72
character(4) = 0
Case 84 'T
character(0) = 4
character(1) = 252
character(2) = 4
character(3) = 0
character(4) = 0
Case 85 'U
character(0) = 124
character(1) = 128
character(2) = 128
character(3) = 252
character(4) = 0
Case 86 'V
character(0) = 28
character(1) = 96
character(2) = 128
character(3) = 96
character(4) = 28
Case 87 'W
character(0) = 252
character(1) = 64
character(2) = 48
character(3) = 64
character(4) = 252
Case 88 'X
character(0) = 196
character(1) = 40
character(2) = 16
character(3) = 40
character(4) = 196
Case 89 'Y
character(0) = 76
character(1) = 144
character(2) = 144
character(3) = 124
character(4) = 0
Case 90 'Z
character(0) = 196
character(1) = 164
character(2) = 148
character(3) = 140
character(4) = 0
Case 91 'up/down
character(0) = 0
character(1) = 0
character(2) = 80
character(3) = 216
character(4) = 80
Case 92 'sand saver
character(0) = 0
character(1) = 0
character(2) = 144
character(3) = 168
character(4) = 72
Case 93 'arrow
character(3) = 1
character(0) = 248
character(1) = 112
character(2) = 32
character(4) = 0
Case 94 'hyphen
character(0) = 0
character(1) = 16
character(2) = 16
character(3) = 16
character(4) = 0
Case 58 ':
character(0) = 1
character(1) = 216
character(2) = 216
character(3) = 0
character(4) = 0
Case 47 '/
character(0) = 192
character(1) = 48
character(2) = 12
character(3) = 0
character(4) = 0
Case 62 '>
character(0) = 124
character(1) = 56
character(2) = 16
character(3) = 0
character(4) = 0
Case 40 '(
character(0) = 0
character(1) = 0
character(2) = 120
character(3) = 132
character(4) = 0
Case 41 ')
character(0) = 132
character(1) = 120
character(2) = 0
character(3) = 0
character(4) = 0
Case Else 'turn into a space
character(0) = 1
character(1) = 1
character(2) = 1
character(3) = 1
character(4) = 1
EndSelect
Return
drawcharacter:
'at this point, we should have: charbyte containing the character index
'which has been "passed" into pickcharacter which has populated the
'array called "character" - 5 pixels wide, possibly more
'so we keep sending each byte to the GLCD until we hit a sequence
'of two empty (zero) bytes
ilcd = 0
jlcd = 0
While ilcd < 5
klcd = character(ilcd)
If invertchar = 1 Then klcd = klcd Xor 255
'send one byte (column of 8 pixels) to the display
If character(ilcd) = 1 Then
'this is the special character to say "blank"
If invertchar = 1 Then
glcdbyte = 255
Else
glcdbyte = 0
Endif
Else
glcdbyte = klcd
Endif
Gosub glcdsenddata
'move on to the next column of data within the character
ilcd = ilcd + 1
Wend
Return
Here's the end result:
Now if only there were some way I could keep this and use a second set of serial (SPI) lines to send/receive data to the eeprom chip. That'd be a massive leap forward....
Post a Comment