• Twitter
  • Facebook
  • Instagram
  • Youtube
  • Email

Sunday, 15 January 2012

Membuat Hello Word Dengan Atmega8535 Assembler

Berikut adalah tutorial membuat Hello Word Pada LCD menggunakan microcontroller ATMEGA 8535 dan berikut ini di tampilkan pada LCD dan menggunakan bahasa Assembly.


Berikut Script Assembler nya :

.include "m8535def.inc"
.equ timer_value = 0xffca
.equ timer_value100 = 0xfbaf
.cseg
.org 0x0000


rjmp main
main: ldi r16,low(RAMEND)
out SPL,r16
ldi r16,high(RAMEND)
out SPH,r16
ldi r16,0xff
out ddra,r16
rcall InitLCD
Start: ldi r17,0x01
rcall SLcd
Loopx: ldi ZL,low(2*text)
ldi ZH,high(2*text)
rcall WM1LCD
ldi ZL,low(2*text2)
ldi ZH,high(2*text2)
rcall WM2LCD
end: rjmp Loopx
;-----------------------
; Write Message to LCD
;-----------------------
WM1LCD: ldi r17,0x80 ;1st line, 1st col
rcall SLcd
rjmp Wr1
WM2LCD: ldi r17,0xC0
rcall SLcd
Wr1: clr r1
LoopWr1: lpm ;load program memory
mov r19,r0
cpi r19,0
brne NextCHR
ret
NextCHR: rcall WLCD ;write character
adiw ZL,1 ;get next char
rjmp LoopWr1
;-----------------------
; Inisialisasi LCD
;-----------------------
InitLCD: ldi r20,8
LoopDelay: rcall delay5mS
dec r20
cpi r20,0
brne LoopDelay
ldi r17,0x03 ;Function set
out PortA,r17
sbi PortA,6 ;E=1
cbi PortA,6 ;E=0
rcall delay5mS
ldi r17,0x03 ;Function set
out PortA,r17
sbi PortA,6 ;E=1
cbi PortA,6 ;E=0
rcall delay100uS
ldi r17,0x02 ;Function set:4 bit operation
out PortA,r17
sbi PortA,6 ;E=1
; rcall delay100uS
cbi PortA,6 ;E=0
ldi r17,0x28 ;Function set:4 bit op;2lines
rcall SLcd
ldi r17,0x08 ;Turn Off LCD
rcall SLcd
ldi r17,0x0C ;Turn On LCD
rcall SLcd
ldi r17,0x01 ;Clear Display
rcall SLcd
ldi r17,0x06 ;Entry mode set; Inc addr
rcall SLcd
ret
;-----------------------
; Rutin kirim instruksi
;-----------------------
SLcd: mov r18,r17
andi r18,$F0 ;Get high nibble
swap r18
out PortA,r18
sbi PortA,6 ;E=1
cbi PortA,6 ;E=0
;
mov r18,r17
andi r18,$0F ;Get low nibble
out PortA,r18
sbi PortA,6 ;E=1
cbi PortA,6 ;E=0
rcall delay100uS
ret
;-----------------------
; Rutin kirim karakter
;-----------------------
WLcd: mov r18,r19
andi r18,$F0 ;Get high nibble
swap r18
out PortA,r18
sbi PortA,4 ;RS=1
sbi PortA,6 ;E=1
cbi PortA,6 ;E=0
;
mov r18,r19
andi r18,$0F ;Get low nibble
out PortA,r18
sbi PortA,4 ;RS=1
sbi PortA,6 ;E=1
cbi PortA,6 ;E=0
rcall delay100uS
ret
;-----------------------
; Rutin delay 5ms
;-----------------------
delay5ms: 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
loop: in r21,TIFR
sbrs r21,TOV1
rjmp loop
ldi r16,0b00000100
out TIFR,r16
ret
;-----------------------
; Rutin 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
out TCCR1B,r16
loop1: in r21,TIFR
sbrs r21,TOV1
rjmp loop1
ldi r16,0b00000100
out TIFR,r16
ret
;text:.db "12345678901234567890", 0
text: .db "-++ Hello Effand ++-",0
text2: .db "Susah ******",0
;create by Effand Bocah Nozh

Untuk Download Rangkaian PCB nya klik disini


Semoga Bermanfaat bagi semua .. 



0 comments:

Post a Comment

Terimakasih Atas Komentar Anda, Salam JOSS dari HMPS TI UNIKAMA

Kontak

Lebih Dekat Dengan Kami


Alamat Kami

Jalan S. Supriadi no. 48 Malang

Telepon

0852-3433-2676 (Ahmad Muhajir)

Website

www.hmpsti.com