bigal_scorpio
Active Member
Hi to all,
I am presently experimenting with a Nokia 3310 LCD screen (84 x 48 pixel) and have built a couple of projects from the net.
My problem is that I can't get my head around the basic program parts that actually write to the GLCD.
I have posted the code below and would be very happy if someone could explain the program a bit better by comments or just explaining actually how the data gets to particular locations and how the characters are formed. Particularly the part that is commented UP-side "DIGITAL" and DOWN-side "DIGITAL"
I am truly baffled here and really need a bit of help.
Thanks. Al
I am presently experimenting with a Nokia 3310 LCD screen (84 x 48 pixel) and have built a couple of projects from the net.
My problem is that I can't get my head around the basic program parts that actually write to the GLCD.
I have posted the code below and would be very happy if someone could explain the program a bit better by comments or just explaining actually how the data gets to particular locations and how the characters are formed. Particularly the part that is commented UP-side "DIGITAL" and DOWN-side "DIGITAL"
I am truly baffled here and really need a bit of help.
Thanks. Al
Code:
'******************************************************************
'* Voltmeter using 12F675 & Nokia 3310 display *
'* Version 2.1 : for U_in =< 50 Volts *
'* By Niculescu Dan , august 2009 *
'******************************************************************
'@ DEVICE PIC12F675, intrc_osc_noclkout, wdt_off, mclr_off
DEFINE OSC 4
DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50
CMCON = 7
TRISIO = %000001
INTCON = 0
IOC = 0
GPIO = 0
ANSEL = %00000001
ADCON0.6 = 1
ADCON0.7 = 1
D_C var GPIO.2
SDIN var GPIO.4
SCK var GPIO.5
LcdReg var byte
x var byte
y var byte
z var byte
a var byte
PosX var byte
PosY var byte
Chr var byte
LcdData var byte
Offset var byte
Char var byte
adval var word
w1 var word
vt var word
cnt var byte
grup var word
DATA @0,$3E,$51,$49,$45,$3E,_ ';// 0
$00,$42,$7F,$40,$00,_ ';// 1
$42,$61,$51,$49,$46,_ ';// 2
$21,$41,$45,$4B,$31,_ ';// 3
$18,$14,$12,$7F,$10,_ ';// 4
$27,$45,$45,$45,$39,_ ';// 5
$3C,$4A,$49,$49,$30,_ ';// 6
$01,$71,$09,$05,$03,_ ';// 7
$36,$49,$49,$49,$36,_ ';// 8
$06,$49,$49,$29,$1E,_ ';// 9
$08,$08,$3E,$08,$08,_ ';// +
$08,$08,$08,$08,$08,_ ';// -
$00,$60,$60,$00,$00 ';// .
pause 100
LcdReg = %00100001 'LCD Extended Commands.
call PrintCtrlLcd
LcdReg = $B6 'Set LCD Vop (Contrast).Initial $c5
call PrintCtrlLcd
LcdReg = %00000110 'Set Temp coefficent.
call PrintCtrlLcd
LcdReg = %00010011 'LCD bias mode 1:48.
call PrintCtrlLcd
LcdReg = %00100000 'LCD Standard Commands
call PrintCtrlLcd
LcdReg = $0C 'LCD in normal mode. $0D inverse
call PrintCtrlLcd
Call CursorHome
Gosub LCD_Clear
'===================== READING VOLTAGE ==============================
Main:
CALL BORDER_LINE
vt=0
grup=0
for cnt = 1 to 20
adcin 0, adval
vt=adval * 3300
vt=div32 1023
grup=vt+grup
pause 10
next cnt
w1=grup / 20
w1=w1 * 100
'~~~~~~~~~~~~~~~~~ setting cursor for display the voltage
LcdReg = %10000000 + 15 ' cursor X
call PrintCtrlLcd
LcdReg = %01000011 ' cursor Y
call PrintCtrlLcd
'~~~~~~~~~~~~~~~~~ now display results
if (w1 dig 4) => 1 then
Char = (w1 dig 4)
call PrintChar
endif
Char = (w1 dig 3)
call PrintChar
Char = 12
call PrintChar
Char = (w1 dig 2)
call PrintChar
Pause 100
Goto Main
'================== L C D ===========================================
CursorHome: LcdReg = %10000000 ' cursor Home
call PrintCtrlLcd
LcdReg = %01000000 ' cursor Home
call PrintCtrlLcd
return
PrintChar: offset = Char * 5
for a = 1 to 5
read offset, LcdReg
call PrintDataLcd
offset = offset + 1
next a
LcdReg = 0
call PrintDataLcd
return
PrintCtrlLcd: D_C = 0
PrintDataLcd: for x = 1 to 8
SDIN = LcdReg.7
SCK = 1
LcdReg = LcdReg << 1
SCK = 0
next x
D_C = 1
return
LCD_Clear:
PosX=0:PosY=0:Gosub LCD_GotoXY
D_C = 1
FOR Chr=1 TO 252
LcdData=0:Gosub LCD_ByteOut
LcdData=0:Gosub LCD_ByteOut
next Chr
return
LCD_GotoXY:
D_C = 0
LcdData=%01000000 | PosY :Gosub LCD_ByteOut
LcdData=%10000000 | PosX :Gosub LCD_ByteOut
return
LCD_ByteOut:
SHIFTOUT SDIN,SCK,1,[LcdData]
return
Border_line:
'~~~~~~~~~~~~~~~~~ RAND 0
LcdReg = %10000000 ' cursor X
call PrintCtrlLcd
LcdReg = %01000000 ' cursor Y
call PrintCtrlLcd
for y = 0 to 83
LOokup y, [$FF,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,_ ' UP-side "DIGITAL"
$01,$01,$01,$F9,$F9,$F9,$09,$09,$F9,$F9,$F1,$01,_
$01,$F9,$F9,$F9,$01,$01,$F1,$F9,$F9,$09,$09,$19,_
$19,$11,$01,$01,$F9,$F9,$F9,$01,$09,$09,$09,$F9,$F9,$F9,_
$09,$09,$09,$01,$F1,$F9,$F9,$09,$09,$F9,$F9,$F1,$01,$01,_
$F9,$F9,$F9,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,_
$01,$01,$01,$01,$01,$FF] ,LcdReg
call PrintDataLcd
next y
'~~~~~~~~~~~~~~~~~ RAND 1
LcdReg = %10000000 ' cursor X
call PrintCtrlLcd
LcdReg = %01000001 ' cursor Y
call PrintCtrlLcd
for y = 0 to 83
LOokup y, [$FF,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,_ ' DOWN-side "DIGITAL"
$00,$00,$00,$1F,$1F,$1F,$10,$10,$1F,$1F,$0F,$00,$00,_
$1F,$1F,$1F,$00,$00,$0F,$1F,$1F,$10,$11,$1F,$1F,_
$0F,$00,$00,$1F,$1F,$1F,$00,$00,$00,$00,$1F,$1F,$1F,$00,_
$00,$00,$00,$1F,$1F,$1F,$01,$01,$1F,$1F,$1F,$00,$00,$1F,$1F,_
$1F,$10,$10,$10,$10,$00,$00,$00,$00,$00,$00,$00,_
$00,$00,$00,$00,$00,$FF] ,LcdReg
call PrintDataLcd
next y
'=================================== RAND 2
LcdReg = %10000000 ' cursor X
call PrintCtrlLcd
LcdReg = %01000010 ' cursor Y
call PrintCtrlLcd
LOokup 0, [$FF] , LcdReg
call PrintDataLcd
LcdReg = %10000000 + 83 ' cursor X
call PrintCtrlLcd
LcdReg = %01000010 ' cursor Y
call PrintCtrlLcd
LOokup 0, [$FF] , LcdReg
call PrintDataLcd
'=================================== RAND 3
LcdReg = %10000000 ' cursor X
call PrintCtrlLcd
LcdReg = %01000011 ' cursor Y
call PrintCtrlLcd
LOokup 0, [$FF] , LcdReg
call PrintDataLcd
LcdReg = %10000000 + 48 ' cursor X
call PrintCtrlLcd
LcdReg = %01000011 ' cursor Y
for y = 0 to 35
LOokup y, [$18,$38,$60,$60,$38,$18,_ ' "VOLT"
$00,$30,$78,$48,$78,$30,_
$00,$78,$78,$40,$40,_
$00,$08,$08,$78,$78,$08,$08,$00,_
$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$FF] ,LcdReg
call PrintDataLcd
next y
'=================================== RAND 4
LcdReg = %10000000 ' cursor X
call PrintCtrlLcd
LcdReg = %01000100 ' cursor Y
call PrintCtrlLcd
LOokup 0, [$FF] , LcdReg
call PrintDataLcd
LcdReg = %10000000 + 83 ' cursor X
call PrintCtrlLcd
LcdReg = %01000100 ' cursor Y
call PrintCtrlLcd
LOokup 0, [$FF] , LcdReg
call PrintDataLcd
'=================================== JOS
LcdReg = %10000000 ' cursor X
call PrintCtrlLcd
LcdReg = %01000101 ' cursor Y
call PrintCtrlLcd
for y = 0 to 83
LOokup y, [$FF,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,_
$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,_
$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,_
$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,_
$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,_
$80,$80,$80,$80,$80,$80,$80,$80,$FF] ,LcdReg
call PrintDataLcd
next y
Return
'=======================================================================
End 'of program