Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Can someone who knows PicBasic and GLCD comment this code please?

Status
Not open for further replies.

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

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
 
You know what a for next loop is I hope.
"for y = 0 to 83" causes the next part to repeat 84 times with Y= 0,1,2,3,4......80,81,82,83
.....part this repeated 84 times
"next y" end of loop

Inside the loop are two things
...1. A look up function
...2. Call PrintDataLCD I did not look at this but it most likely sends "LcdReg" to the LCD. Like print this variable "LcdReg".

Lookup y, [some data here], var
....the 'y' is a pointer that pick out what part of the [data] is put in the var. var is LcdReg.
....y=0 then the first number is put into LcdReg. If y=1 then the second number is put into LcdReg

It looks to me that you are "printing" to the LCD a table [$FF,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,.......$01,$01,$01,$01,$01,$FF]
then the cursor is moved one location and the second table is sent to the LCD.
 
Hi Ron,

I still don't get why there is an up and down?

If it is doing the same text why do it in two goes?

I understand the DATA@0 part that does the numbers but I am still baffled as to the reasoning for the text.

Al

PS yes I do understand loops. :)
 
Last edited:
do you have a picture of what the display looks like?
The first two look up tables might make borders around the LCD edge.

There is another 'print 84 times' near the bottom of the code. FF,80,80...............80,FF

It might make a line like this:
|______________________________________________________|
 
Last edited:
hi Al,
The Basic and Asm attached files may be of some help.

Eric
 
Hi Guys,

Sorry I have been a while replying but we had a major laundry problem, and as she who must be obeyed wants instant repairs that had to be my priority. Happily now sorted! :)

Anyway Ron here is a photo of the display. I still don't understand the up and down parts.

Eric, I have tried to study the bas file you posted but sadly it makes even less sense than the ones I'm struggling with.

Perhaps I should have started my first GLCD project with a standard GLCD instead of the serial Nokia one, but then again I probably would have still been confused. I thought it would be simple to do what I wanted which is to use the Nokia 3310 to display text. I only decided to use them because of their size, they fit into my latest project plan perfectly, but boy is this GLCD stuff strange!

Thanks Guys, Al
 
UP-side "DIGITAL is the top half of "DIGITAL"
DOWN-side "DIGITAL" is the bottom half of "DIGITAL"

In other words these two tables are the top 16 x 84 pixels of the display. Where it says "DIGITAL".

I used grid paper.

The lookup that "volts" prints "VOLTS" on the LCD.
 
Last edited:
Hi Guys,

Ah! I see what you mean Ron. I was thinking of layering which I sometimes did in Photoshop, moving something like text by one pixel and overprinting it.

All is clear now, but it looks like I will be needing a book of Graphpaper!

Thanks. Al
 
There is a program that does this! I have seen it talked about on this forum. I don't know where.
search for 'graphic' 'LCD' 'fonts' etc.
 
Status
Not open for further replies.

Latest threads

Back
Top