Program Menampilkan text ke LCD dengan AVR ATmega8535 menggunakan bahasa Assembler AVR Studio

berikut adalah contoh program menampilkan text ke LCD 16×2 menggunakan bahasa Assembler

karena bahasa assembler adalah bahasa yang paling pas untuk pemula mikrokontroller agar kita bisa benar2 paham akan isi mikrokontroller yang kita pelajari…mungkin sudah banyak contohnya juga di internet,,,yah pengen sharing az…moga ntr banyak waktu untuk share proyek2 mikrokontroller yang telah saya buat,,,,

dengan konfigurasi port PORT D sebagai port tampilan ke LCD

MIkro    //   LCD Port

PORTD,0   ;DATA0

PORTD,1    ;DATA1

PORTD,2    ;DATA2

PORTD,3    ;DATA3

PORTD,5    ;R/W

PORTD,7   ;RS

PORTD,6    ;E


.include"C:\Program Files\Atmel\AVR Tools\AvrAssembler2\Appnotes\m8535def.inc"
.equ timer_value=0xffca
.equ timer_value100=0xfbaf

.org 0x0000
rjmp main

main:
LDI R16,LOW(RAMEND)
OUT SPL,R16
LDI R16,HIGH(RAMEND)
OUT SPH,R16

LDI R16,0XFF
LDI R19,0X00

OUT DDRB,R16
OUT DDRC,R16
OUT DDRD,R16

OUT PORTA,R16

OUT PORTB,R19
OUT PORTC,R19
OUT PORTD,R19

RCALL INIT_LCD

START:
LDI R17,0X01

RCALL KIRIM_PERINTAH

LDI ZL,LOW(2*SUHU)
LDI ZH,HIGH(2*SUHU)

RCALL BARIS1
RCALL KIRIMPESAN_LCD

LDI ZL,LOW(2*MY)
LDI ZH,HIGH(2*MY)

RCALL BARIS2
RCALL KIRIMPESAN_LCD

END:
RJMP END

;===========================
;KIRIM PESAN LCD
;===========================

KIRIMPESAN_LCD:
CLR R1

LOOPKIRIMPESAN_LCD:
LPM
MOV R17,R0
CPI R17,0
BRNE KIRIM_LCD
RET

KIRIM_LCD:
RCALL KIRIM_KARAKTER
ADIW ZL,1
RJMP LOOPKIRIMPESAN_LCD

;=================================
; INISIALISASI LCD
;=================================

INIT_LCD:
CBI PORTD,5 ;R/W
SBI PORTD,7 ;RS
CBI PORTD,6 ;E
LDI R20,8

LOOPDELAY:
RCALL DELAY5
DEC R20
CPI R20,0
BRNE LOOPDELAY

LDI R17,0X30
RCALL KIRIM_PERINTAH
RCALL DELAY5

LDI R17,0X30
RCALL KIRIM_PERINTAH
RCALL DELAY100US

LDI R17,0X30
RCALL KIRIM_PERINTAH

LDI R17,0X20
RCALL KIRIM_PERINTAH

LDI R17,0X28
RCALL KIRIM_PERINTAH

LDI R17,0X08
RCALL KIRIM_PERINTAH

LDI R17,0X01
RCALL KIRIM_PERINTAH

LDI R17,0X0E
RCALL KIRIM_PERINTAH

LDI R17,0X06
RCALL KIRIM_PERINTAH
SBI PORTB,3
RET

KIRIM_PERINTAH:
CBI PORTD,7
CBI PORTD,5
RCALL KIRIM_DATALCD
SWAP R17
RCALL KIRIM_DATALCD
RCALL DELAY5
RET

KIRIM_KARAKTER:
SBI PORTD,7
CBI PORTD,5
RCALL KIRIM_DATALCD
SWAP R17
RCALL KIRIM_DATALCD
RCALL DELAY5
RET

KIRIM_DATALCD:
SBI PORTD,6
OUT PORTC,R17
CBI PORTD,6
RET

;==========================
;PINDAH BARIS 2
;==========================

BARIS2:
LDI R17,0XC0
RCALL KIRIM_PERINTAH
RET

;==========================
;PINDAH BARIS 1
;==========================

BARIS1:
LDI R17,0X02
RCALL KIRIM_PERINTAH
RET

;==========================
; GESER DISPLAY KANAN
;==========================

GESERDISPLAY_KANAN:
LDI R17,0X1F
RCALL KIRIM_PERINTAH
RET

;==========================
; GESER DISPLAY KIRI
;==========================

GESERDISPLAY_KIRI:
LDI R17,0X18
RCALL KIRIM_PERINTAH
RET

;===========================
;GESER KURSOR KIRI
;===========================

GESERKURSOR_KIRI:
LDI R17,0X10
RCALL KIRIM_PERINTAH
RET

;===============================
;GESER KURSOR KANAN
;===============================

GESERKURSOR_KANAN:
LDI R17,0X14
RCALL KIRIM_PERINTAH
RET

;=============================
;DELAY 5MS
;=============================

DELAY5:
ldi r16,0b00000100
out timsk,r16
ldi r16,high(timer_value)
out tcnt1h,r16
ldi r16,low(timer_value)
out tcnt1l,r16
ldi r16,0b00000101
out tccr1b,r16

looptimer:
in r17,tifr
sbrs r17,tov1
rjmp looptimer
ldi r16,0b00000100
out tifr,r16
ret

;===========================
;DELAY 100uS
;===========================

DELAY100US:
ldi r16,0b00000100
out timsk,r16
ldi r16,high(timer_value100)
out tcnt1h,r16
ldi r16,low(timer_value100)
out tcnt1l,r16
ldi r16,0b00000001 ;(tanpa prescaler)
out tccr1b,r16

looptimer3:
in r17,tifr
sbrs r17,tov1
rjmp looptimer3
ldi r16,0b00000100
out tifr,r16
ret

SUHU:
.DB "SUHU",0

MY:
.DB "17C",0

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s