prev next

29/10/12

(LCD) Liquid Crystal Display 8bit

Posted on 08.02 by tris KT

LCD banyak dipakai sebagai alat keluaran. Dengan menggunakan LCD tampilan alat menjadi semakin bertambah professional. LCD kebanyakan di’otaki’ oleh prosesor buatan Hitachi yaitu HD44780. Pena-pena pada LCD umumnya disusun demikian.

Pin Guna
  1. GND
  2. +5V
  3. Contrast
  4. RS
  5. R/W
  6. E
  7. D0
  8. D1
  9. D2
  10. D3
  11. D4
  12. D5
  13. D6
  14. D7
  15. + Backlight ( jika ada )
  16. – Backlight ( jika ada )
Pin 3 secara sederhana dapat dihubungkan dengan GND.
Pada LCD 1 x 16 tiap karakter memiliki alamat sendiri-sendiri sebagai berikut.


Beberapa instruksi yang berguna adalah.

Operasi                 Instruksi word              Guna
Function set           0x38                           8 bit, 5 x7
Display on/off        0x0C                           Display on tanpa kursor
                            0x0F                            Display on kursor berkedip dikiri
Clear Display         0x01                            Clear display ( blank )
Entry mode           0x06                             Increment mode


Program berikut akan menampilkan kata Hello di LCD.

;=======LCD8.ASM=======================================
list p=16c84
radix hex
;------------------------------------------------------------
; cpu equates (memory map)
indf equ 0x00
status equ 0x03
fsr equ 0x04
porta equ 0x05
portb equ 0x06
count1 equ 0x0c
count2 equ 0x0d
trisa equ 0x85
trisb equ 0x86
;------------------------------------------------------------
; bit equates
z equ 2
rp0 equ 5
;------------------------------------------------------------
org 0x000
;
start bsf status,rp0 ;switch to bank 1
movlw b'00000000' ;outputs
movwf trisa
movwf trisb
bcf status,rp0 ;switch back to bank 0
movlw b'00000000' ;all outputs low
movwf porta
movwf portb
call blanks ;fill display RAM with blanks
call hello ;create message in display RAM
call del_5 ;allow lcd time to initialize itself
call initlcd ;initialize display
call disp16 ;send 16 characters to display
circle goto circle ;done
;------------------------------------------------------------
blanks movlw 0x10 ;count=16
movwf count1
movlw 0x20 ;first display RAM address
movwf fsr ;indexed addressing
movlw 0x20 ;ascii blank
store movwf indf ;store in display RAM location
; pointed to by file select register
decfsz count1,f ;16?
goto incfsr ;no
return ;yes, done
incfsr incf fsr,f ;increment file select register
goto store
;------------------------------------------------------------
hello movlw 'H'
movwf 0x20
movlw 'E'
movwf 0x21
movlw 'L'
movwf 0x22
movlw 'L'
movwf 0x23
movlw 'O'
movwf 0x24
return
;------------------------------------------------------------
initlcd bcf porta,1 ;E line low
bcf porta,2 ;RS line low, set up for control
call del_125 ;delay 125 microseconds
movlw 0x38 ;8-bit, 5X7
movwf portb ;0011 1000
call pulse ;pulse and delay
movlw 0x0c ;display on, cursor off
movwf portb ;0000 1100
call pulse
movlw 0x06 ;increment mode, no display shift
movwf portb ;0000 0110
call pulse
call del_5 ;delay 5 milliseconds - required
; before sending data
return
;------------------------------------------------------------
disp16 bcf porta,1 ;E line low
bcf porta,2 ;RS line low, set up for control
call del_125 ;delay 125 microseconds
movlw 0x80 ;control word = address first half
movwf portb
call pulse ;pulse and delay
bsf porta,2 ;RS=1, set up for data
call del_125 ;delay 125 microseconds
movlw 0x20 ;initialze file select register
movwf fsr
getchar movf 0x00,w ;get character from display RAM
; location pointed to by file select
; register
movwf portb
call pulse ;send data to display
movlw 0x27 ;8th character sent?
subwf fsr,w ;subtract w from fsr
btfsc status,z ;test z flag
goto half ;set up for last 8 characters
movlw 2f ;test number
subwf fsr,w
btfsc status,z ;test z flag
return ;16 characters sent to lcd
incf fsr,f ;move to next character location
goto getchar
half bcf porta,2 ;RS=0, set up for control
call del_125 ;delay 125 microseconds
movlw 0xc0 ;control word = address second half
movwf portb
call pulse ;pulse and delay
bsf porta,2 ;RS=1, set up for data
incf fsr,f ;increment file select register to
; select next character
call del_125 ;delay 125 microseconds
goto getchar
;------------------------------------------------------------
del_125 movlw 0x2a ;approx 42x3 cycles (decimal)
movwf count1 ;load counter
repeat decfsz count1,f ;decrement counter
goto repeat ;not 0
return ;counter 0, ends delay
;------------------------------------------------------------
del_5 movlw 0x29 ;decimal 40
movwf count2 ;to counter
delay call del_125 ;delay 125 microseconds
decfsz count2,f ;do it 40 times = 5 milliseconds
goto delay
return ;counter 0, ends delay
;------------------------------------------------------------
pulse bsf porta,1 ;pulse E line
nop ;delay
bcf porta,1
call del_125 ;delay 125 microseconds
return
;------------------------------------------------------------
end
;------------------------------------------------------------
;at blast time, select:
; memory unprotected
; watchdog timer disabled (default is enabled)
; standard crystal (using 4 MHz osc for test) XT
; power-up timer on
;============================================================

No Response to " (LCD) Liquid Crystal Display 8bit"

Komentar Anda