prev next

29/10/12

LCD Terminal AppMod

Posted on 08.40 by tris KT

2 Line x 8 Karakter Modul LCD dengan Tombol Penggunaan

Pengantar
LCD Terminal AppMod menyediakan metode yang sederhana dan nyaman menghubungkan karakter standar LCD Parallax AppMod, bersama dengan empat tombol untuk pengguna-masukan. Kombinasi ini memungkinkan pengguna untuk membuat antarmuka pengguna yang bersih dan efisien untuk aplikasi BASIC Stamp dan Javelin

Fitur
  • 2 x 8 modul LCD, menggunakan Hitachi HD44780 compatible controller
  • Kontras kontrol pot
  • 4 tombol untuk input pengguna
  • Dapat digunakan dengan LCD kedua pada papan demo Parallax BS2p 
Catatan: LCD AppMod perangkat lunak demonstrasi dapat didownload dari www.parallax.com.

BASIC Stamp 2 Application
Aplikasi Stamp berikut BASIC menunjukkan banyak kemampuan LCD dan bagaimana pengguna dapat membaca dan menghilangkan bounce tombol pengguna modul. Program ini agak unik karena kompatibel dengan setiap modul BASIC Stamp 2, tidak ada perubahan yang diperlukan. Jika Anda mencoba untuk menjalankan Program pada sesuatu selain BS2 standar, compiler akan menanyakan apakah Anda ingin menjalankan pada diinstal Stamp (BS2e, BS2sx, BS2p, atau BS2pe). Jika Anda melakukannya, program ini akan berjalan tanpa masalah.

Dalam rangka untuk memungkinkan program ini, mengambil keuntungan dari fitur built-in LCD dari keluarga BS2p, arahan kompilasi bersyarat digunakan. Arahan kompilasi bersyarat dievaluasi sebelum Program dikompilasi dan di-download ke BASIC Stamp, sehingga hanya bagian-bagian yang berhubungan dengan BASIC Stamp diinstal akan di-download, bukan daftar keseluruhan.

Program ini cukup mudah, dan menggunakan trik perangkat lunak sederhana untuk menggulir string melalui window (delapan karakter) dari LCD. Masuk dan keluar dari string difasilitasi oleh pelapis string dengan ruang pada kedua ujung. 

' -----[ I/O Definitions ]-------------------------------------------------
E PIN 1 ' LCD Enable (1 = enabled)
RW PIN 2 ' Read/Write\
RS PIN 3 ' Reg Select (1 = char)
LcdDirs VAR DIRB ' dirs for I/O redirection
LcdBusOut VAR OUTB
LcdBusIn VAR INB
' -----[ Constants ]-------------------------------------------------------
#DEFINE _LcdReady = ($STAMP = BS2P) OR ($STAMP = BS2PE)
LcdCls CON $01 ' clear the LCD
LcdHome CON $02 ' move cursor home
LcdCrsrL CON $10 ' move cursor left
LcdCrsrR CON $14 ' move cursor right
LcdDispL CON $18 ' shift chars left
LcdDispR CON $1C ' shift chars right
LcdDDRam CON $80 ' Display Data RAM control
LcdCGRam CON $40 ' Character Generator RAM
LcdLine1 CON $80 ' DDRAM address of line 1
LcdLine2 CON $C0 ' DDRAM address of line 2
LcdScrollTm CON 250 ' LCD scroll timing (ms)
' -----[ Variables ]-------------------------------------------------------
addr VAR Word ' address pointer
crsrPos VAR Byte ' cursor position
char VAR Byte ' character sent to LCD
idx VAR Byte ' loop counter
scan VAR Byte ' loop counter
buttons VAR Nib
btnA VAR buttons.BIT0 ' left-most button
btnB VAR buttons.BIT1
btnC VAR buttons.BIT2
btnD VAR buttons.BIT3 ' right-most
btnDemo VAR Byte ' loop counter
' -----[ EEPROM Data ]-----------------------------------------------------
CC0 DATA $0E, $1F, $1C, $18, $1C, $1F, $0E, $00 ' char 0
CC1 DATA $0E, $1F, $1F, $18, $1F, $1F, $0E, $00 ' char 1
CC2 DATA $0E, $1F, $1F, $1F, $1F, $1F, $0E, $00 ' char 2
Smiley DATA $00, $0A, $0A, $00, $11, $0E, $06, $00 ' smiley
Msg1 DATA "PARALLAX", 0
Msg2 DATA " BASIC STAMP ", 3, " ", 0
Msg3 DATA "Type =", 0
Msg4 DATA "Buttons:", 0
StampId0 DATA " BS2", 0
StampId1 DATA " BS2e", 0
StampId2 DATA "BS2sx", 0
StampId3 DATA " BS2p", 0
StampId4 DATA "BS2pe", 0
' -----[ Initialization ]--------------------------------------------------
Initialize:
NAP 5 ' let LCD self-initialize
DIRL = %11111110 ' setup pins for LCD
LCD_Init:
#IF _LcdReady #THEN
LCDCMD E, 110000 : PAUSE 5 ' 8-bit mode
LCDCMD E, 110000 : PAUSE 0
LCDCMD E, 110000 : PAUSE 0
LCDCMD E, 100000 : PAUSE 0 ' 4-bit mode
LCDCMD E, 101000 : PAUSE 0 ' 2-line mode
LCDCMD E, 001100 : PAUSE 0 ' no crsr, no blink
LCDCMD E, 000110 ' inc crsr, no disp shift
#ELSE
LcdBusOut = 11 ' 8-bit mode
PULSOUT E, 3 : PAUSE 5
PULSOUT E, 3 : PAUSE 0
PULSOUT E, 3 : PAUSE 0
LcdBusOut = 10 ' 4-bit mode
PULSOUT E, 3
char = 101000 ' 2-line mode
GOSUB LCD_Command
char = 001100 ' on, no crsr, no blink
GOSUB LCD_Command
char = 000110 ' inc crsr, no disp shift
GOSUB LCD_Command
#ENDIF
Download_Chars: ' download custom chars
char = LcdCGRam ' point to CG RAM
GOSUB LCD_Command ' prepare to write CG data
FOR idx = CC0 TO (Smiley + 7) ' build 4 custom chars
READ idx, char ' get byte from EEPROM
GOSUB LCD_Write_Char ' put into LCD CG RAM
NEXT
' -----[ Program Code ]----------------------------------------------------
Main:
char = LcdCls ' clear the LCD
GOSUB LCD_Command
PAUSE 500
Write_Parallax:
addr = Msg1 ' point to message
GOSUB LCD_Put_String ' write it
Scroll_Message:
crsrPos = LcdLine2 ' scroll on line 2
addr = Msg2 ' point to msg
GOSUB LCD_Scroll_String ' scroll it
Pac_Man: ' Pac-Man animation
FOR idx = 0 TO 7 ' cover 8 characters
FOR scan = 0 TO 4 ' 5 characters in animation
char = LcdLine1 + idx ' position cursor
GOSUB LCD_Command
LOOKUP scan, [0, 1, 2, 1, " "], char ' select "frame"
GOSUB LCD_Write_Char ' write animation character
PAUSE 75 ' delay between chars
NEXT
NEXT
Show_Stamp_Type:
char = LcdCls ' clear the LCD
GOSUB LCD_Command
PAUSE 100
addr = Msg3 ' display "Type ="
GOSUB LCD_Put_String
char = LcdLine2 + 3 ' move cursor to 2nd line
GOSUB LCD_Command
#SELECT $STAMP ' check type at compile
#CASE BS2
addr = StampId0
#CASE BS2E
addr = StampId1
#CASE BS2SX
addr = StampId2
#CASE BS2P
addr = StampId3
#CASE BS2PE
addr = StampId4
#ENDSELECT
GOSUB LCD_Put_String ' display type on LCD
PAUSE 2000
Show_Buttons:
char = LcdCls ' clear the LCD
GOSUB LCD_Command
PAUSE 100
addr = Msg4 ' write "Buttons:"
GOSUB LCD_Put_String
FOR btnDemo = 1 TO 100
GOSUB LCD_Get_Buttons ' read/debounce buttons
char = LcdLine2 + 2 ' show on 2nd line
GOSUB LCD_Command
FOR idx = 0 TO 3 ' display buttons
IF buttons.LOWBIT(idx) THEN
char = "A" + idx ' button letter if pressed
ELSE
char = "-" ' otherwise dash
ENDIF
GOSUB LCD_Write_Char
NEXT
NEXT
GOTO Main ' run demo again
END
' -----[ Subroutines ]-----------------------------------------------------
' Writes stored (in DATA statement) zero-terminated string to LCD
' -- position LCD cursor
' -- point to 0-terminated string (first location in 'addr')
LCD_Put_String:
DO
READ addr, char
IF (char = 0) THEN EXIT
GOSUB LCD_Write_Char
addr = addr + 1
LOOP
RETURN
' Scroll a message across LCD line
' -- set starting position in 'crsrPos'
' -- point to 0-terminated string (first location in 'addr')
' -- strings should be padded with eight spaces on each end
LCD_Scroll_String:
DO
char = crsrPos ' move to start of window
GOSUB LCD_Command
FOR idx = 0 TO 7 ' write chars in window
READ (addr + idx), char
IF (char = 0) THEN EXIT ' stop if end of string
GOSUB LCD_Write_Char
NEXT
IF (char = 0) THEN EXIT
addr = addr + 1 ' scroll
PAUSE LcdScrollTm
LOOP
RETURN
' Send command to LCD
' -- put command byte in 'char'
LCD_Command: ' write command to LCD
#IF _LcdReady #THEN
LCDCMD E, char
RETURN
#ELSE
LOW RS
GOTO LCD_Write_Char
#ENDIF
' Write character to current cursor position
' -- but byte to write in 'char'
LCD_Write_Char: ' write character to LCD
#IF _LcdReady #THEN
LCDOUT E, 0, [char]
#ELSE
LcdBusOut = char.HIGHNIB ' output high nibble
PULSOUT E, 3 ' strobe the Enable line
LcdBusOut = char.LOWNIB ' output low nibble
PULSOUT E, 3
HIGH RS ' return to character mode
#ENDIF
RETURN
' Reads byte from LCD
' -- put byte address in 'addr'
' -- returns byte read in 'char'
LCD_Read_Char: ' read character from LCD
#IF _LcdReady #THEN
LCDIN E, addr, [char]
#ELSE
char = addr ' move cursor
GOSUB LCD_Command
HIGH RS ' data command
HIGH RW ' read
LcdDirs = 00 ' make LCD bus inputs
HIGH E
char.HIGHNIB = LcdBusIn ' get high nibble
LOW E
HIGH E
char.LOWNIB = LcdBusIn ' get low nibble
LOW E
LcdDirs = %1111 ' return data lines to
outputs
LOW RW
#ENDIF
RETURN
' Read and debounce the LCD AppMod buttons
LCD_Get_Buttons:
LcdDirs = 00 ' make LCD bus inputs
buttons = %1111 ' assume all pressed
FOR scan = 1 TO 10
buttons = buttons & LcdBusIn ' make sure button held
PAUSE 5 ' debounce 10 x 5 ms
NEXT
LcdDirs = %1111 ' return bus to outputs
RETURN
Menggunakan AppMod LCD dengan Demo BS2p
Demo BS2p dengan konektor AppMod juga memiliki koneksi LCD khusus. LCD AppMod
dapat digunakan pada Boards Demo BS2p, bahkan jika LCD primer diinstal. Masalahnya diatasi dengan
menugaskan terpisah Aktifkan baris untuk setiap LCD: Papan demo menggunakan P0 sebagai pin Aktifkan; LCD AppMod menggunakan P1.

Sumber Tambahan (tersedia di www.parallax.com):
  • StampWorks: Proyek 11?? 14
  • Kacang & Aplikasi Stamp Volts # 31: Demystifying Karakter berbasis LCD
  • Stamp versi 1 DASAR (fitur terbatas karena batasan ruang code)
  • Versi Stamp Javelin, lengkap dengan file kelas LcdTerminal

No Response to "LCD Terminal AppMod"

Komentar Anda