Hi, I’ve been trying to connect my color LCD (the Nokia knockoff) to my Mega128 without any success. Spent all last Saturday afternoon trying to get it to even flicker on, but no success. I’m using BASCOM-AVR (Basic) to program it. I tried to port the sample code Sparkfun made, and I think I’ve got it mostly right but maybe someone with better eyes (eyes that can read C) can tell me where I’m wrong?
Here’s my source code (there may be a few various debugging efforts still in the code), it’s pretty much a straight port from the example source code SparkFun provides:
Declare Sub Snd_cmd(byval Lcdcmd As Word)
Declare Sub Snd_data(byval Lcddata As Word)
Declare Sub Put_pix(byval Color As Word, Byval X As Word , Byval Y As Word)
Dim I As Word
Dim B As Word
Const Dison = &HAF
Const Disoff = &HAE
Const Disnor = &HA6
Const Disinv = &HA7
Const Comscn = &HBB
Const Disctl = &HCA
Const Slpin = &H95
Const Slpout = &H94
Const Paset = &H75
Const Caset = &H15
Const Datctl = &HBC
Const Rgbset8 = &HCE
Const Ramwr = &H5C
Const Ramrd = &H5D
Const Ptlin = &HA8
Const Ptlout = &HA9
Const Rmwin = &HE0
Const Rmwout = &HEE
Const Ascset = &HAA
Const Scstart = &HAB
Const Oscon = &HD1
Const Oscoff = &HD2
Const Pwrctr = &H20
Const Volctr = &H81
Const Volup = &HD6
Const Voldown = &HD7
Const Tmpgrd = &H82
Const Epctin = &HCD
Const Epcout = &HCC
Const Epmwr = &HFC
Const Epmrd = &HFD
Const Epsrrd1 = &H7C
Const Epsrrd2 = &H7D
Const No_op = &H25
Config Portd.7 = Output 'Led
Config Portb.0 = Output 'Cs
Config Portb.1 = Output 'Clk
Config Portb.2 = Output 'Mosi
Config Portb.4 = Output 'Lcd_reset
Led Alias Portd.7
Cs Alias Portb.0
Clk Alias Portb.1
Mosi Alias Portb.2
Lcd_reset Alias Portb.4
Led = 1
Cs = 1
Lcd_reset = 1
Waitms 10
'Reset The Display.
Lcd_reset = 0
Waitms 1
Lcd_reset = 1
Waitms 20
Snd_cmd Disctl
Snd_data &H03
Snd_data &H32
Snd_data &H12
Snd_data &H00
Snd_cmd Comscn
Snd_data &H01
Snd_cmd Oscon
Snd_cmd Slpout
Snd_cmd Volctr
Snd_data 5
Snd_data &H01
Snd_cmd Pwrctr
Snd_data &H0F
Waitms 100
Snd_cmd Disinv
Snd_cmd Datctl
Snd_data &H00
Snd_data 0
Snd_data &H01
Snd_data &H00
Snd_cmd Rgbset8
'Color Table
'RED
Snd_data 0
Snd_data 2
Snd_data 4
Snd_data 6
Snd_data 8
Snd_data 10
Snd_data 12
Snd_data 15
'GREEN
Snd_data 0
Snd_data 2
Snd_data 4
Snd_data 6
Snd_data 8
Snd_data 10
Snd_data 12
Snd_data 15
'BLUE
Snd_data 0
Snd_data 4
Snd_data 9
Snd_data 15
Snd_cmd No_op
Snd_cmd Paset
Snd_data 2
Snd_data 131
Snd_cmd Caset
Snd_data 0
Snd_data 131
Snd_cmd Ramwr
'Make the background turn green
For I = 0 To 18000
Snd_data 28
Next I
Snd_cmd Dison
Waitms 200
For I = 1 To 160
Snd_cmd Volup
Waitms 2
Next I
'Draw a 2 pixel line on the left side of the screen.
For B = 20 To 100
Put_pix 120 , B , 20
Next B
For B = 20 To 100
Put_pix 120 , B , 21
Next B
Led = 0
End
'*******************************************************************************
'****************************** SUBROUTINES ************************************
'*******************************************************************************
Sub Snd_cmd(byval Lcdcmd As Word)
Cs = 0
'Get the data to the most significant byte + 1 bit (first bit is a 0 to make it a command) then shiftout
Shift Lcdcmd , Left , 7
'Shiftout datapin, clockpin, variable, option (MSB on rising edge), #of bits, delay (in uS)
Shiftout Mosi , Clk , Lcdcmd , 1 , 9 , 2
Cs = 1
End Sub
'*******************************************************************************
Sub Snd_data(byval Lcddata As Word)
Cs = 0
'Get the data to the most significant byte + 1 bit (first bit must be a 1 to make it a data byte) then shiftout
Shift Lcddata , Left , 7
Lcddata = Lcddata + &B1000_0000_0000_0000
'Shiftout datapin, clockpin, variable, option (MSB on rising edge), #of bits, delay (in uS)
Shiftout Mosi , Clk , Lcddata , 1 , 9 , 2
Cs = 1
End Sub
'*******************************************************************************
Sub Put_pix(color As Word , X As Word , Y As Word)
X = X + 2 'for some reason starts at 2
Snd_cmd &H75 'page start/end ram
Snd_data X
Snd_data 132
Snd_cmd &H15 'colum start/end ram
Snd_data Y
Snd_data 131
Snd_cmd &H5C 'write some crap
Snd_data Color
End Sub
I think the problem is in the snd_cmd and snd_data subroutines. I’m not experienced with SPI, but from what I can tell, it should be putting the bits out in the right order. I’m also not very good at reading C code … Maybe someone can look at the C example and tell me what’s wrong?
Any help greatly appreciated.
Thanks,
Brad