DogFlu66
Member
Giant numbers on alphanumeric display.
Writing large numbers on a 2x16 alphanumeric display
This time I leave you a function to use large numbers on an alphanumeric screen, I hope you like it.
Video:
Big Numbers on Lcd 2x16.
Writing large numbers on a 2x16 alphanumeric display
This time I leave you a function to use large numbers on an alphanumeric screen, I hope you like it.
Code:
'*************************************************************
'Writing large numbers in alphanumeric display 2x16.
'By COS, 02/2023
'Pic Basic Compiler (PSI), v8.38, Pic16F88
'*************************************************************
'Generation of patterns
'2x3 digit proportional numbers
'Enlarges the numbers contained in the variable number.
'-------------------------------------------------------------
Define CONFIG = 0x2f70
Define CONFIG2 = 0x3ffc
Define CLOCK_FREQUENCY = 8 'Oscilador a 8Mhz
Define SIMULATION_WAITMS_VALUE = 1 'Activate for simulation.
'Include "_FuncionesPic16F88.bas"
'--------------------------------------------------------------
AllDigital
ConfigPin PORTA = Output
ConfigPin PORTB = Output
'Configuration lcd ports. -------------------------------------
Define LCD_BITS = 4 'Data bus length to 4bits
Define LCD_DREG = PORTA 'Data bus: puerto A
Define LCD_DBIT = 0 'Least significant bit of the data bus.
Define LCD_RSREG = PORTB 'Rs control bit on port B
Define LCD_RSBIT = 7 'RS bit on RB7 pin.
Define LCD_EREG = PORTB 'E control bit on port B.
Define LCD_EBIT = 6 'E pin on RB6 pin
Define LCD_COMMANDUS = 2000 'Wait after each command in uSec.
Define LCD_DATAUS = 100 'Wait after sending a data to the LCD in uSec.
Define LCD_INITMS = 50 'Wait during display initialization in mSec.
'---------------------------------------------------------------------
Lcdinit 'Lcd withou cursor
'---------------------------------------------------------------------
'Initialize characters in the lcd CGRam for big numbers.
Call _IntStrNBig()
Lcdout "Patrones:"
Lcdcmdout LcdLine2Home
Lcdout 0, 1, 2, 3, 4, 5, 6, 7, 255 'Display the new characters.
WaitMs 3000
Lcdcmdout LcdClear 'Clear LCD
'*********************************************************************
void_main:
'Variables
Dim _String As String
Dim numero As Long
Dim x As Bit
x = 1
numero = 0
While x 'Main loop
_String = #numero 'Transform numeric variable to string type.
Call _StrNBig(_String, 1) 'Write bit number.
Lcdcmdout LcdLine2Pos(_StrNBig) 'Move cursor
Lcdout #numero 'Write a number in normal size.
numero++ 'Increment then number.
WaitMs 100
Wend
End
'*********************************************************************
'Creates the new characters and saves them in then Lcd CGRam.
Proc _IntStrNBig()
Lcddefchar 0, %11111, %11111, %11111, 0, 0, 0, 0, 0 'Upper horizontal bar.
Lcddefchar 1, 0, 0, 0, 0, 0, %11111, %11111, %11111 'Bottom horizontal bar.
Lcddefchar 2, %11111, %11111, %11111, 0, 0, 0, %11111, %11111 'Bars h. upper and lower.
Lcddefchar 3, %11100, %11110, %11110, %11110, %11110, %11110, %11110, %11100 'Right arrow
Lcddefchar 4, %00111, %01111, %01111, %01111, %01111, %01111, %01111, %00111 'Left arrow
Lcddefchar 5, %00000, %00000, %00000, %00000, %00000, %00011, %00111, %01111 'All full.
Lcddefchar 6, %00011, %00111, %01111, 0, 0, 0, 0, 0 'Short top horizotal bar.
Lcddefchar 7, 0, 0, 0, 0, 0, %11000, %11100, %11110 'Short bottom horizotal bar.
Lcdcmdout LcdClear 'Clear LCD
End Proc
'**********************************************************************
'Function that enlarges the numeric characters of a string
'Limited string length, written for 2-line lcd
'_String: numeric string to write.
'Xpos: Starting position to print on the LCD
'_strngrandes: Returns the next position to print
'Call _StrNBig(String, position To print)
'*********************************************************************
Function _StrNBig(_String As String, _Xpos As Byte) As Byte
Dim _data As Byte 'Mask
Dim _index As Byte 'Index mask.
Dim _x As Byte 'Character position of then string.
Dim _bucle As Bit 'Loop check.
_bucle = True
_x = 0
'Loop
While _bucle = True
Lcdcmdout LcdLine1Pos(_Xpos) 'Lcd cursor position.
For _index = 0 To 5 'Upper and lower mask print control loop.
If _String(_x) = "0" Then _data = LookUp(4, 0, 3, 4, 1, 3), _index 'Mask for "0"
If _String(_x) = "1" Then _data = LookUp(6, 255, " ", 5, 255, 7), _index 'Mask for "1"
If _String(_x) = "2" Then _data = LookUp(6, 2, 3, 4, 1, 7), _index 'Mask for "2"
If _String(_x) = "3" Then _data = LookUp(6, 2, 3, 5, 1, 3), _index 'M. for "3"
If _String(_x) = "4" Then _data = LookUp(4, 1, 255, " ", " ", 255), _index 'M. for "4"
If _String(_x) = "5" Then _data = LookUp(4, 2, 0, 5, 1, 3), _index 'M. "5"
If _String(_x) = "6" Then _data = LookUp(4, 2, " ", 4, 1, 3), _index 'M. for "6"
If _String(_x) = "7" Then _data = LookUp(6, 0, 3, " ", 255, " "), _index 'M. for "7"
If _String(_x) = "8" Then _data = LookUp(4, 2, 3, 4, 1, 3), _index 'M. for "8"
If _String(_x) = "9" Then _data = LookUp(4, 2, 3, " ", " ", 255), _index 'M. for "9"
Lcdout _data 'Printe current mask.
If _index = 2 Then
Lcdcmdout LcdLine2Pos(_Xpos) 'Sets position on line 2
_Xpos = _Xpos + 3 'Position of the new digit.
Endif
Next _index
_x++ 'Next digit to print.
If _String(_x) = 0 Then 'If end of string?.
_StrNBig = _Xpos 'Function returns the next position to write to the lcd.
Exit 'End, it returns.
Endif
Wend
End Function
Video:
Big Numbers on Lcd 2x16.
Last edited: