' {$STAMP BS2} ' {$PBASIC 2.5} ' ========================================================================= ' File...... JumboDigits ' Purpose... Parallel LCD Display Demo - Jumbo Digits by using custom characters ' Author.... O.A.A. ' E-Mail.... info@osmanardali.com ' Started... Jan 2008 ' ' -----[ Program Description ]---------------------------------------------- ' ' This program demonstrates displaying Jumbo Charaters in a HD44780 compatible ' Parallel LCD by using custom characters. ' When using the standart 5x7 font, the LCD will hold up to eight custom characters. ' Four custom characters are assigned to a 2x2 region for each digit hence only ' 2 digits may be displayed. ' This code works with the BS2, BS2e and BS2sx ' -----[ Constants ]------------------------------------------------------------ ' NoCmd CON $00 ' No command ClrLCD CON $01 ' clear the LCD CursrHm CON $02 ' move cursor to home position CursrLf CON $10 ' move cursor left CuRSRRT CON $14 ' move cursor right DispLf CON $18 ' shift displayed chars left DispRt CON $1C ' shift displayed chars right DDRam CON $80 ' Display Data RAM control CGRam CON $40 ' Custom character RAM Line1 CON $80 ' DDRAM address of line 1 Line2 CON $C0 ' DDRAM address of line 2 CLines CON 8 '------[ I/O Definitions ]-------------------------------------------------- E PIN 0 ' Enable Pin For LCD RW PIN 2 ' R/W Pin For LCD RS PIN 3 ' LCD Register Select LCDpins VAR OUTB ' 4-bit LCD data ' 0 = Instruction, 1 = Text '------[ Variables ]-------------------------------------------------------- Number VAR Word ' 3 digits to be displayed in LCD dNum VAR Nib ' Digit number ' 100's digit = 2 , 10's = 1 , 1's = 0 char VAR Byte ' Character To Send To LCD inst VAR char ' Instruction To Send To LCD charP VAR Byte ' Character Pos.(Line1:0-15,Line2:16-31) idx VAR Byte ' loop counter jdx VAR Byte ' loop counter digit VAR Byte ' digit dsply VAR Byte(3) ' Number currently displayed '------[ EEPROM Data ]------------------------------------------------------ ' ' Custom character definitions ' N_0_11 DATA $0F,$1F,$1C,$18,$18,$18,$18,$18 N_0_12 DATA $1C,$1E,$0E,$06,$06,$06,$06,$06 N_0_21 DATA $1E,$1E,$1E,$1E,$1E,$1E,$1F,$0F N_0_22 DATA $06,$06,$06,$06,$06,$0E,$1E,$1C N_1_11 DATA $03,$03,$03,$03,$03,$03,$03,$03 N_1_12 DATA $00,$00,$00,$00,$00,$00,$00,$00 N_1_21 DATA $0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F N_1_22 DATA $00,$00,$00,$00,$00,$00,$00,$00 N_2_11 DATA $0F,$1F,$18,$00,$00,$00,$00,$00 N_2_12 DATA $1C,$1E,$0E,$06,$06,$06,$06,$06 N_2_21 DATA $0F,$1E,$1E,$1E,$1E,$1E,$1E,$1F N_2_22 DATA $1E,$1C,$00,$00,$00,$00,$1E,$1E N_3_11 DATA $1F,$1F,$00,$00,$00,$00,$1F,$1F N_3_12 DATA $18,$1C,$1C,$0C,$0C,$0C,$1C,$1C N_3_21 DATA $00,$00,$00,$00,$00,$00,$1F,$1F N_3_22 DATA $1E,$1E,$1E,$1E,$1E,$1E,$1E,$1C N_4_11 DATA $1E,$1E,$1E,$1E,$1E,$1E,$1E,$1E N_4_12 DATA $00,$00,$00,$00,$00,$00,$06,$06 N_4_21 DATA $1F,$1F,$00,$00,$00,$00,$00,$00 N_4_22 DATA $1E,$1E,$06,$06,$06,$06,$06,$06 N_5_11 DATA $1F,$1F,$1E,$1E,$1E,$1E,$1F,$1F N_5_12 DATA $1E,$1E,$00,$00,$00,$00,$1C,$1E N_5_21 DATA $00,$00,$00,$00,$00,$18,$1F,$0F N_5_22 DATA $06,$06,$06,$06,$06,$0E,$1E,$1C N_6_11 DATA $0F,$1F,$1C,$18,$18,$18,$1F,$1F N_6_12 DATA $00,$00,$00,$00,$00,$00,$1C,$1E N_6_21 DATA $1E,$1E,$1E,$1E,$1E,$1F,$1F,$0F N_6_22 DATA $06,$06,$06,$06,$06,$0E,$1E,$1C N_7_11 DATA $1F,$1F,$18,$00,$00,$00,$00,$00 N_7_12 DATA $1E,$1E,$06,$06,$06,$06,$06,$06 N_7_21 DATA $00,$00,$00,$00,$00,$00,$00,$00 N_7_22 DATA $1E,$1E,$1E,$1E,$1E,$1E,$1E,$1E N_8_11 DATA $07,$0F,$0E,$0C,$0C,$0E,$0F,$1F N_8_12 DATA $18,$1C,$1C,$0C,$0C,$1C,$1C,$1E N_8_21 DATA $18,$18,$18,$18,$18,$1C,$1F,$0F N_8_22 DATA $1E,$1E,$1E,$1E,$1E,$1E,$1E,$1C N_9_11 DATA $0F,$1F,$1C,$18,$18,$1C,$1F,$0F N_9_12 DATA $1C,$1E,$0E,$06,$06,$0E,$1E,$1E N_9_21 DATA $00,$00,$00,$00,$00,$00,$00,$00 N_9_22 DATA $1E,$1E,$1E,$1E,$1E,$1E,$1E,$1E DATA "Hello ! " ' Message To Send To LCD '------[ Initialization ]--------------------------------------------------- Initialize: LOW RW ' Set LCD To Write Mode OUTS = %0000000000000000 ' Set All Output Low DIRS = %0000000011111101 ' Set I/O Direction PAUSE 500 dsply(0) = 11 dsply(1) = 11 dsply(2) = 11 Number = 500 ' Set initial "seed" value GOSUB Init_Lcd ' Initialize The LCD Display '------[ Program Code ]----------------------------------------------------- Main: FOR idx = 0 TO 7 ' Read and display READ (320+idx), char ' the greetings message GOSUB Send_Text PAUSE 100 NEXT PAUSE 2000 inst = ClrLCD ' Clears LCD GOSUB Send_Inst PAUSE 250 DO RANDOM Number ' Generate random Number ' Send number to LCD FOR dNum = 0 TO 2 digit = Number DIG dNum IF digit = dsply(dNum) THEN GOTO Next_dNum IF dNum = 2 THEN charP = 18 GOSUB DDRAM_Address LOOKUP digit,["0","1","2","3","4","5","6","7","8","9"],char GOSUB Send_Text GOTO Next_dNum ENDIF GOSUB Update_Digit Next_dNum: NEXT PAUSE 1000 LOOP END '------[ Subroutines ]------------------------------------------------------ Init_Lcd: LCDpins = %0011 ' Reset The LCD PULSOUT E,1 ' Send Command 3 Times PAUSE 5 PULSOUT E,1 PULSOUT E,1 LCDpins = %0010 ' Set To N_4_bit Operation PULSOUT E,1 inst = %00101000 ' Fuction Set (2-Line Mode) GOSUB Send_Inst inst = %00001100 ' Disp on, crsr off, blink off GOSUB Send_Inst inst = %00000110 ' inc crsr, no disp shift GOSUB Send_Inst inst = ClrLCD ' Clears LCD GOSUB Send_Inst PAUSE 250 '--------------------------------------------------------------------------- Send_Inst: LOW RS ' Set Instruction Mode LCDpins = inst.HIGHNIB ' Send High Nibble PULSOUT E,1 LCDpins = inst.LOWNIB ' Send Low Nibble PULSOUT E,1 HIGH RS ' Set LCD Back To Text Mode RETURN '--------------------------------------------------------------------------- Send_Text: LCDpins = Char.HIGHNIB ' Send High Nibble PULSOUT E,1 LCDpins = Char.LOWNIB ' Send Low Nibble PULSOUT E,1 RETURN '--------------------------------------------------------------------------- DDRAM_Address: Line_1: IF charP > 15 THEN GOTO Line_2 inst = Line1+charP GOSUB Send_Inst RETURN Line_2: inst = Line2+charP-16 GOSUB Send_Inst RETURN '--------------------------------------------------------------------------- Update_Digit: inst = CGRam + (dNum*4*8) ' Point to the CGRAM Address GOSUB Send_Inst FOR idx = 0 TO 3 FOR jdx = 0 TO (CLines-1) READ ((((4*digit)+idx)*8) + jdx), char ' Get digit data GOSUB Send_Text ' Write to LCD CGRAM NEXT NEXT FOR idx = 0 TO 3 IF idx < 2 THEN charP = 5-(2*dNum) + idx IF idx > 1 THEN charP = 21-(2*dNum) + idx - 2 GOSUB DDRAM_Address char = (dnum*4) + idx GOSUB Send_Text NEXT dsply(dNum) = digit RETURN '---------------------------------------------------------------------------