Sources:
http://playground.arduino.cc/Code/PCD8544
http://www.circuitvalley.com/2011/08/no ... -with.html
http://www.botskool.com/tutorials/elect ... ic-18f2520
The first link has this code:
Code: Select all
void LcdString(char *characters)
{
while (*characters)
{
LcdCharacter(*characters++);
}
}
Here is my whole converted code. Its my first time writing a driver, and I dont have the hardware yet. Ive kept most things the same from the sources. I havent yet put in anything for the main loop yet and I double checked the datasheet to make sure Im initializing the display correctly. But once I do get it working, I hope everyone can use it!
Code: Select all
{
*****************************************************************************
* Name : PCD8544.bas *
* Author : Chris S *
* Notice : Copyright (c) 2015 Open Source *
* : All Rights Reserved *
* Date : 8/23/2015 *
* Version : 1.0 *
* Notes : Driver for Nokia 3310 and 5510 *
* : *
*****************************************************************************
}
Module PCD8544
#option SCE = PORTB.2 // Chip Select
#option Reset = PORTB.1 // RS pin
#option DC = PORTB.0 // Datacom
#option SDOUT = PORTC.5 // Data
#option SCLK = PORTE.3 // Clock
Include "system.bas"
Include "SPI.bas"
Public Const
GLCDWidth = 84,
GLCDHeight = 48
Dim
//SDOUT As SPI.WriteByte, //used to be SPIWriteByte As SPI.WriteByte, I dont know why this works.
ChipEnable As SCE.SCE@, //When set high SPI is initialized
RST As Reset.RESET@,
Datacom As DC.DC@, //Command =0, RAMdata = 1
//SPIWriteByte As SDOUT.SDOUT@
X As Byte,
Y As Byte
Const
Extendedmode = %00100001,
LCDVOP = %10110001, // may need to experiment. Other sites show $C8
TempCo = %00000100, //TempCo. Other codes show $06
LCDBias = %00010100,
SimpleMode = %00100000,
NormalMode = %00001100
Const ASCIITable () As Char = //There has to be a easier way. Cue infomercials.
(
$00,$00,$00,$00,$00, // 20 space
$00,$00,$5f,$00,$00, // 21 !
$00,$07,$00,$07,$00, // 22 "
$14,$7f,$14,$7f,$14, // 23 #
$24,$2a,$7f,$2a,$12, // 24 $
$23,$13,$08,$64,$62, // 25 %
$36,$49,$55,$22,$50, // 26 &
$00,$05,$03,$00,$00, // 27 '
$00,$1c,$22,$41,$00, // 28 (
$00,$41,$22,$1c,$00, // 29 )
$14,$08,$3e,$08,$14, // 2a *
$08,$08,$3e,$08,$08, // 2b +
$00,$50,$30,$00,$00, // 2c ,
$08,$08,$08,$08,$08, // 2d -
$00,$60,$60,$00,$00, // 2e .
$20,$10,$08,$04,$02, // 2f /
$3e,$51,$49,$45,$3e, // 30 0
$00,$42,$7f,$40,$00, // 31 1
$42,$61,$51,$49,$46, // 32 2
$21,$41,$45,$4b,$31, // 33 3
$18,$14,$12,$7f,$10, // 34 4
$27,$45,$45,$45,$39, // 35 5
$3c,$4a,$49,$49,$30, // 36 6
$01,$71,$09,$05,$03, // 37 7
$36,$49,$49,$49,$36, // 38 8
$06,$49,$49,$29,$1e, // 39 9
$00,$36,$36,$00,$00, // 3a :
$00,$56,$36,$00,$00, // 3b ;
$08,$14,$22,$41,$00, // 3c <
$14,$14,$14,$14,$14, // 3d =
$00,$41,$22,$14,$08, // 3e >
$02,$01,$51,$09,$06, // 3f ?
$32,$49,$79,$41,$3e, // 40 @
$7e,$11,$11,$11,$7e, // 41 A
$7f,$49,$49,$49,$36, // 42 B
$3e,$41,$41,$41,$22, // 43 C
$7f,$41,$41,$22,$1c, // 44 D
$7f,$49,$49,$49,$41, // 45 E
$7f,$09,$09,$09,$01, // 46 F
$3e,$41,$49,$49,$7a, // 47 G
$7f,$08,$08,$08,$7f, // 48 H
$00,$41,$7f,$41,$00, // 49 I
$20,$40,$41,$3f,$01, // 4a J
$7f,$08,$14,$22,$41, // 4b K
$7f,$40,$40,$40,$40, // 4c L
$7f,$02,$0c,$02,$7f, // 4d M
$7f,$04,$08,$10,$7f, // 4e N
$3e,$41,$41,$41,$3e, // 4f O
$7f,$09,$09,$09,$06, // 50 P
$3e,$41,$51,$21,$5e, // 51 Q
$7f,$09,$19,$29,$46, // 52 R
$46,$49,$49,$49,$31, // 53 S
$01,$01,$7f,$01,$01, // 54 T
$3f,$40,$40,$40,$3f, // 55 U
$1f,$20,$40,$20,$1f, // 56 V
$3f,$40,$38,$40,$3f, // 57 W
$63,$14,$08,$14,$63, // 58 %
$07,$08,$70,$08,$07, // 59 Y
$61,$51,$49,$45,$43, // 5a Z
$00,$7f,$41,$41,$00, // 5b [
$02,$04,$08,$10,$20, // 5c
$00,$41,$41,$7f,$00, // 5d
$04,$02,$01,$02,$04, // 5e
$40,$40,$40,$40,$40, // 5f
$00,$01,$02,$04,$00, // 60
$20,$54,$54,$54,$78, // 61 a
$7f,$48,$44,$44,$38, // 62 b
$38,$44,$44,$44,$20, // 63 c
$38,$44,$44,$48,$7f, // 64 d
$38,$54,$54,$54,$18, // 65 e
$08,$7e,$09,$01,$02, // 66 f
$0c,$52,$52,$52,$3e, // 67 g
$7f,$08,$04,$04,$78, // 68 h
$00,$44,$7d,$40,$00, // 69 i
$20,$40,$44,$3d,$00, // 6a j
$7f,$10,$28,$44,$00, // 6b k
$00,$41,$7f,$40,$00, // 6c l
$7c,$04,$18,$04,$78, // 6d m
$7c,$08,$04,$04,$78, // 6e n
$38,$44,$44,$44,$38, // 6f o
$7c,$14,$14,$14,$08, // 70 p
$08,$14,$14,$18,$7c, // 71 q
$7c,$08,$04,$04,$08, // 72 r
$48,$54,$54,$54,$20, // 73 s
$04,$3f,$44,$40,$20, // 74 t
$3c,$40,$40,$20,$7c, // 75 u
$1c,$20,$40,$20,$1c, // 76 v
$3c,$40,$30,$40,$3c, // 77 w
$44,$28,$10,$28,$44, // 78 %
$0c,$50,$50,$50,$3c, // 79 y
$44,$64,$54,$4c,$44, // 7a z
$00,$08,$36,$41,$00, // 7b
$00,$00,$7f,$00,$00, // 7c
$00,$41,$36,$08,$00, // 7d
$10,$08,$08,$10,$08, // 7e
$78,$46,$41,$46,$78 // 7f
)
Sub SDOUT (Mydata As Byte)
ChipEnable = 0
Mydata = SSPBUF
ChipEnable = 1
End Sub
Sub Clear_LCD () //Writes 0's all across the screen
Dim i As Integer
ChipEnable = 0
Datacom = 1
For i= 0 To 504 //(84*48)/8. The width and height in pixels multiplied and divided by 8
SDOUT($00)
Next
End Sub
Sub Black_LCD () //Make the LCD Black
Dim i As Integer
ChipEnable = 0
Datacom = 1
For i= 0 To 504 //(84*48)/8. The width and height in pixels multiplied and divided by 8
SDOUT($FF)
Next
End Sub
Sub MoveCursor () //I LIKE TO MOVE IT MOVE IT, YOU LIKE TO MOVE IT.
Datacom = 0
Y=Y Or $40 //Row
SDOUT(Y)
X=(X*6) Or $80 //Column
SDOUT (X)
Datacom = 1
End Sub
Sub LCDString (Chars As Char)
While //Something to do with arrays here
LCDCharacter
End Sub
//Serial stream has to consist of the following: Extended mode (H=1), Bias, SetVop, and temp control
// with H=0, it can be Display Control, followed by Y and X Address (set at 0 upon power up)
Sub LCDinit ()
RST = 0 //Reset the LCD since the registers are undefined.
RST = 1 //
ChipEnable = 0 //Start accepting commands
Datacom = 0 //Command Mode
SDOUT(Extendedmode) //Put chip into extended mode
SDOUT(LCDVOP) // may need to experiment. Other sites show $C8
SDOUT(TempCo) //TempCo. Other codes show $06
SDOUT(LCDBias) //LCD bias
SDOUT(SimpleMode) //Basic Mode
SDOUT(NormalMode) //Normal Mode
Clear_LCD()
Black_LCD()
End Sub
SetAsMaster (spiOscDiv4)
LCDinit()
While True //main loop
Wend