|
' {$STAMP BS2sx}
' {$PBASIC 2.5}
'*************************************
'Programma:test_modulo_lcd.bsx
'Versione: 1.0
'Collaudo modulo LCD
'*************************************
' -----[ definizione dei pin ]-----
E PIN 0 ' Enable Pin For LCD
RW PIN 2 ' R/W Pin For LCD
RS PIN 3 ' LCD Register Select
' 0 = Instruction, 1 = Text
' -----[ Variables ]-----------
char VAR Byte ' Character To Send To LCD
inst VAR char ' Induction To Send To LCD
index VAR Word ' Character Pointer
temp VAR Byte ' Temp Variable
' -----[ EEPROM Data ]-------
DATA "PROVA LCD Adriano Gandolfo" ' Messaggio da inviare al LCD
' -----[ Initialization ]----
Initialize:
LOW RW ' Set LCD To Write Mode
OUTS = %0000000000000000 ' Set All Output Low
DIRS = %0000000011111111 ' Set I/O Direction
GOSUB Init_Lcd ' Initialize The LCD Display
' -----[ Programma ]----
Main:
FOR temp = 0 TO 32 ' 32 Caratteri
IF temp = 15 THEN ' Ricerca fine linea
GOSUB Next_Line ' Salta alla nuova linea
ENDIF
READ temp, char ' Lelle il prossimo carattere dalla EEPROM
GOSUB Send_Text ' Invia il carattere al display LCD
NEXT
END
' -----[ Subroutines ]-----
Init_Lcd:
PAUSE 200
OUTS = %00110000 ' Reset The LCD
PULSOUT E,1 ' Send Command Three Times
PAUSE 10
PULSOUT E,1
PAUSE 10
PULSOUT E,1
PAUSE 10
OUTS = %00100000 ' Set To 4-bit Operation
PULSOUT E,1
Inst = %00101000 ' Function Set (2-Line Mode)
GOSUB Send_Inst
Inst = %00001110 ' Turn On Cursor
GOSUB Send_Inst
Inst = %00000110 ' Set Auto-Increment
GOSUB Send_Inst
Inst = %00000001 ' Clears LCD
GOSUB Send_Inst
Inst = 14 ' Set Cursor To Underline
GOSUB Send_Inst
RETURN
Send_Inst:
LOW RS ' Set Instruction Mode
OUTB = Inst.HIGHNIB ' Send High Nibble
PULSOUT E,1
OUTB = Inst.LOWNIB ' Send Low Nibble
PULSOUT E,1
HIGH RS ' Set LCD Back To Text Mode
RETURN
Send_Text:
OUTB = Char.HIGHNIB ' Send High Nibble
PULSOUT E,1
OUTB = char.LOWNIB ' Send Low Nibble
PULSOUT E,1
PAUSE 100
RETURN
Next_Line:
Inst = 128+64 ' Move Cursor To Line 2
GOSUB Send_Inst
RETURN |