Share My Creation LCD 1602 Large Characters

Custom created large characters for LCD 16x2 display. The 8 available RAM are used, each character is made of 6 normal size characters.
The function CREATE is not in the library so the code is bit banging to include the function, this is why the code is so long.
The project is a voltmeter.
B4X:
Sub Process_Globals
    Public Serial1 As Serial
    Private tmr1 As Timer
    Private d7,d8,d9,d10,rs,en As Pin
    Public anaA0 As Pin
    
    Private s0() As Byte = Array As Byte(31,31,0,0,0,0,0,0)
    Private s1() As Byte = Array As Byte(3,3,3,3,3,3,3,3)   
    Private s2() As Byte = Array As Byte(24,24,24,24,24,24,24,24)   
    Private s3() As Byte = Array As Byte(31,31,0,0,0,0,31,31)   
    Private s4() As Byte = Array As Byte(31,31,0,0,0,0,0,0)   
    Private s5() As Byte = Array As Byte(0,0,0,0,0,0,31,31)   
    Private s6() As Byte = Array As Byte(0,0,0,0,0,0,0,0)   
    Private s7() As Byte = Array As Byte(3,3,3,0,0,0,0,0)   
    
End Sub

Private Sub AppStart
    Serial1.Initialize(9600)
    tmr1.Initialize("tmr1_Tick", 2000)
    tmr1.Enabled = True
    d7.Initialize(7, d7.MODE_OUTPUT)
    d8.Initialize(8, d8.MODE_OUTPUT)
    d9.Initialize(9, d9.MODE_OUTPUT)
    d10.Initialize(10, d10.MODE_OUTPUT)
    rs.Initialize(11, rs.MODE_OUTPUT)    'LCD pin4
    en.Initialize(12, en.MODE_OUTPUT)    'LCD pin6
    anaA0.Initialize(anaA0.A0, anaA0.MODE_INPUT)
    
    lcd_init
    createC(0,s0)
    createC(1,s1)
    createC(2,s2)
    createC(3,s3)
    createC(4,s4)
    createC(5,s5)
    createC(6,s6)
    createC(7,s7)
    
    clear
End Sub

Sub tmr1_Tick
    Dim v As UInt
    Dim i, d(4) As Byte

    v=anaA0.AnalogRead * 5

    For i=0 To 3
        d(i)=v Mod 10
        v=v / 10
    Next
    displayC(1,d(3))
    cursorTo(1,4)
    display(0xA1)
    displayC(5,d(2))
    displayC(8,d(1))
    displayC(11,d(0))

End Sub

Sub displayC(col As Byte, fig As Byte)
 
  Select fig
      Case 0
        cursorTo(0,col)
        display(1)
        display(0)
        display(2)
        cursorTo(1,col)
        display(1)
        display(5)
        display(2)
        
      Case 1
        cursorTo(0,col)
        display(6)
        display(6)
        display(2)
        cursorTo(1,col)
        display(6)
        display(6)
        display(2)
        
      Case 2
        cursorTo(0,col)
        display(7)
        display(3)
        display(2)
        cursorTo(1,col)
        display(1)
        display(5)
        display(6)
      
      Case 3
        cursorTo(0,col)
        display(6)
        display(3)
        display(2)
        cursorTo(1,col)
        display(6)
        display(5)
        display(2)
        
      Case 4
        cursorTo(0,col)
        display(1)
        display(5)
        display(2)
        cursorTo(1,col)
        display(6)
        display(6)
        display(2)
        
      Case 5
        cursorTo(0,col)
        display(1)
        display(3)
        display(6)
        cursorTo(1,col)
        display(6)
        display(5)
        display(2)
        
      Case 6
        cursorTo(0,col)
        display(1)
        display(0)
        display(6)
        cursorTo(1,col)
        display(1)
        display(3)
        display(2)
        
      Case 7
        cursorTo(0,col)
        display(7)
        display(0)
        display(2)
        cursorTo(1,col)
        display(6)
        display(6)
        display(2)
      
      Case 8
        cursorTo(0,col)
        display(1)
        display(3)
        display(2)
        cursorTo(1,col)
        display(1)
        display(5)
        display(2)
        
      Case 9
        cursorTo(0,col)
        display(1)
        display(3)
        display(2)
        cursorTo(1,col)
        display(6)
        display(5)
        display(2)
        

    End Select

End Sub

Sub createC(loc As Byte, charA() As Byte) {
    loc=Bit.And(loc,0x7)
    cmnd(Bit.Or(0x40,Bit.ShiftLeft(loc,3)))
    For i=0 To 7
        display(charA(i))
    Next

End Sub

Sub port(data As Byte)
    If Bit.Get(data,0) = 1 Then d7.DigitalWrite(True) Else d7.DigitalWrite(False)
    If Bit.Get(data,1) = 1 Then d8.DigitalWrite(True) Else d8.DigitalWrite(False)
    If Bit.Get(data,2) = 1 Then d9.DigitalWrite(True) Else d9.DigitalWrite(False)
    If Bit.Get(data,3) = 1 Then d10.DigitalWrite(True) Else d10.DigitalWrite(False)
End Sub

Sub newLine()
    port(12)
    clock
    port(0)
    clock
    Delay(2)
End Sub

Sub cursorTo(line As Byte, c As Byte)
    Dim i As Byte
    
    rs.DigitalWrite(False)    'rs=0
    port(0)
    clock
    port(2)
    clock    'Return home
    Delay(2)
    If line > 0 Then newLine    'If(line){newLine()}
    For i=0 To c-1
        port(1)
        clock
        port(4)
        clock
    Next

End Sub

Sub clock()
    en.DigitalWrite(False)    'en=0
    DelayMicroseconds(25)
    
    en.DigitalWrite(True)    'en=1
    DelayMicroseconds(25)
    en.DigitalWrite(False)    'en=0
    DelayMicroseconds(150)
End Sub

Sub clear()
    rs.DigitalWrite(False)    'rs=0
    port(0)
    clock
    port(1)
    clock     'clear display
    port(0)
    clock
    port(2)
    clock    'Return home
    Delay(2)

End Sub

Sub display(fig As Byte)
    rs.DigitalWrite(True)    'rs=1
    port(Bit.ShiftRight(fig,4))    '=(fig >> 4)
    clock
    port(fig)
    clock
    rs.DigitalWrite(False)    'rs=0
End Sub

Sub cmnd(value As Byte)
    rs.DigitalWrite(False)    'RS=0
    port(Bit.ShiftRight(value,4))    '=(fig >> 4)
    clock
    port(value)    '=cv
    clock
End Sub

Sub lcd_init()
    rs.DigitalWrite(False)    'rs=0
    Delay(100)
    cmnd(0x32)    'init command

    cmnd(0x28)    'function set: 1 line=0, 2 lines=8
    cmnd(12)    'display set:  curzor off=12, curzor on=14, curzor on And flashing=15, curzor And display off=8
    cmnd(1)    'display clear
    Delay(2)
    cmnd(6)    'Entry mode:increment, no shift
    
End Sub
 

Attachments

  • lcd_large.jpg
    lcd_large.jpg
    111.5 KB · Views: 121
  • lcd_large_volt.zip
    1.9 KB · Views: 23
  • lcd_volt.png
    lcd_volt.png
    5.7 KB · Views: 55

Beja

Expert
Licensed User
Longtime User
Custom created large characters for LCD 16x2 display. The 8 available RAM are used, each character is made of 6 normal size characters.
The function CREATE is not in the library so the code is bit banging to include the function, this is why the code is so long.
The project is a voltmeter.
B4X:
Sub Process_Globals
    Public Serial1 As Serial
    Private tmr1 As Timer
    Private d7,d8,d9,d10,rs,en As Pin
    Public anaA0 As Pin
  
    Private s0() As Byte = Array As Byte(31,31,0,0,0,0,0,0)
    Private s1() As Byte = Array As Byte(3,3,3,3,3,3,3,3) 
    Private s2() As Byte = Array As Byte(24,24,24,24,24,24,24,24) 
    Private s3() As Byte = Array As Byte(31,31,0,0,0,0,31,31) 
    Private s4() As Byte = Array As Byte(31,31,0,0,0,0,0,0) 
    Private s5() As Byte = Array As Byte(0,0,0,0,0,0,31,31) 
    Private s6() As Byte = Array As Byte(0,0,0,0,0,0,0,0) 
    Private s7() As Byte = Array As Byte(3,3,3,0,0,0,0,0) 
  
End Sub

Private Sub AppStart
    Serial1.Initialize(9600)
    tmr1.Initialize("tmr1_Tick", 2000)
    tmr1.Enabled = True
    d7.Initialize(7, d7.MODE_OUTPUT)
    d8.Initialize(8, d8.MODE_OUTPUT)
    d9.Initialize(9, d9.MODE_OUTPUT)
    d10.Initialize(10, d10.MODE_OUTPUT)
    rs.Initialize(11, rs.MODE_OUTPUT)    'LCD pin4
    en.Initialize(12, en.MODE_OUTPUT)    'LCD pin6
    anaA0.Initialize(anaA0.A0, anaA0.MODE_INPUT)
  
    lcd_init
    createC(0,s0)
    createC(1,s1)
    createC(2,s2)
    createC(3,s3)
    createC(4,s4)
    createC(5,s5)
    createC(6,s6)
    createC(7,s7)
  
    clear
End Sub

Sub tmr1_Tick
    Dim v As UInt
    Dim i, d(4) As Byte

    v=anaA0.AnalogRead * 5

    For i=0 To 3
        d(i)=v Mod 10
        v=v / 10
    Next
    displayC(1,d(3))
    cursorTo(1,4)
    display(0xA1)
    displayC(5,d(2))
    displayC(8,d(1))
    displayC(11,d(0))

End Sub

Sub displayC(col As Byte, fig As Byte)
 
  Select fig
      Case 0
        cursorTo(0,col)
        display(1)
        display(0)
        display(2)
        cursorTo(1,col)
        display(1)
        display(5)
        display(2)
      
      Case 1
        cursorTo(0,col)
        display(6)
        display(6)
        display(2)
        cursorTo(1,col)
        display(6)
        display(6)
        display(2)
      
      Case 2
        cursorTo(0,col)
        display(7)
        display(3)
        display(2)
        cursorTo(1,col)
        display(1)
        display(5)
        display(6)
    
      Case 3
        cursorTo(0,col)
        display(6)
        display(3)
        display(2)
        cursorTo(1,col)
        display(6)
        display(5)
        display(2)
      
      Case 4
        cursorTo(0,col)
        display(1)
        display(5)
        display(2)
        cursorTo(1,col)
        display(6)
        display(6)
        display(2)
      
      Case 5
        cursorTo(0,col)
        display(1)
        display(3)
        display(6)
        cursorTo(1,col)
        display(6)
        display(5)
        display(2)
      
      Case 6
        cursorTo(0,col)
        display(1)
        display(0)
        display(6)
        cursorTo(1,col)
        display(1)
        display(3)
        display(2)
      
      Case 7
        cursorTo(0,col)
        display(7)
        display(0)
        display(2)
        cursorTo(1,col)
        display(6)
        display(6)
        display(2)
    
      Case 8
        cursorTo(0,col)
        display(1)
        display(3)
        display(2)
        cursorTo(1,col)
        display(1)
        display(5)
        display(2)
      
      Case 9
        cursorTo(0,col)
        display(1)
        display(3)
        display(2)
        cursorTo(1,col)
        display(6)
        display(5)
        display(2)
      

    End Select

End Sub

Sub createC(loc As Byte, charA() As Byte) {
    loc=Bit.And(loc,0x7)
    cmnd(Bit.Or(0x40,Bit.ShiftLeft(loc,3)))
    For i=0 To 7
        display(charA(i))
    Next

End Sub

Sub port(data As Byte)
    If Bit.Get(data,0) = 1 Then d7.DigitalWrite(True) Else d7.DigitalWrite(False)
    If Bit.Get(data,1) = 1 Then d8.DigitalWrite(True) Else d8.DigitalWrite(False)
    If Bit.Get(data,2) = 1 Then d9.DigitalWrite(True) Else d9.DigitalWrite(False)
    If Bit.Get(data,3) = 1 Then d10.DigitalWrite(True) Else d10.DigitalWrite(False)
End Sub

Sub newLine()
    port(12)
    clock
    port(0)
    clock
    Delay(2)
End Sub

Sub cursorTo(line As Byte, c As Byte)
    Dim i As Byte
  
    rs.DigitalWrite(False)    'rs=0
    port(0)
    clock
    port(2)
    clock    'Return home
    Delay(2)
    If line > 0 Then newLine    'If(line){newLine()}
    For i=0 To c-1
        port(1)
        clock
        port(4)
        clock
    Next

End Sub

Sub clock()
    en.DigitalWrite(False)    'en=0
    DelayMicroseconds(25)
  
    en.DigitalWrite(True)    'en=1
    DelayMicroseconds(25)
    en.DigitalWrite(False)    'en=0
    DelayMicroseconds(150)
End Sub

Sub clear()
    rs.DigitalWrite(False)    'rs=0
    port(0)
    clock
    port(1)
    clock     'clear display
    port(0)
    clock
    port(2)
    clock    'Return home
    Delay(2)

End Sub

Sub display(fig As Byte)
    rs.DigitalWrite(True)    'rs=1
    port(Bit.ShiftRight(fig,4))    '=(fig >> 4)
    clock
    port(fig)
    clock
    rs.DigitalWrite(False)    'rs=0
End Sub

Sub cmnd(value As Byte)
    rs.DigitalWrite(False)    'RS=0
    port(Bit.ShiftRight(value,4))    '=(fig >> 4)
    clock
    port(value)    '=cv
    clock
End Sub

Sub lcd_init()
    rs.DigitalWrite(False)    'rs=0
    Delay(100)
    cmnd(0x32)    'init command

    cmnd(0x28)    'function set: 1 line=0, 2 lines=8
    cmnd(12)    'display set:  curzor off=12, curzor on=14, curzor on And flashing=15, curzor And display off=8
    cmnd(1)    'display clear
    Delay(2)
    cmnd(6)    'Entry mode:increment, no shift
  
End Sub

Thank you for that.. the precision is 0.001/volt very precise! all thumps up :)
 
Top