4.5. Experiment Using SW to shift character to the left or right

In this experiment will print a character on the lcd screen character, and by using a switch then the character can be shifted right and left.

.include “m8535def.inc”
.org 0×0000
;
ldi r16,low(RAMEND)
out SPL,r16
ldi r16,high(RAMEND)
out SPH,r16
;
ldi r16,0b11111111
out ddrc,r16
sbi ddrd,3;rs
sbi ddrd,4;en
cbi ddrb,7
sbi portb,7
;
rcall Init_LCD
main:
ldi r16,0×80
rcall write_inst
ldi r16,’A’
rcall write_data
;
cek:sbis PINB,7
rcall shift_right
sbis PINB,6
rcall shift_left
rjmp cek
;
stop:rjmp stop

Init_LCD:
ldi r16,0b00000001
rcall write_inst
ldi r16,0b00111000
rcall write_inst
ldi r16,0b00001100
rcall write_inst
ldi r16,0b00000110
rcall write_inst
ret
;
write_inst:
cbi portd,3
Out portC,r16
sbi portd,4
rcall delay
cbi portd,4
ret
;
write_data:
sbi portd,3
Out portC,r16
sbi portd,4
rcall delay
cbi portd,4
ret
;
shift_left:
ldi r16,0×18
rcall write_inst
rcall ldelay
ret
;
shift_right:
ldi r16,0x1f
rcall write_inst
rcall ldelay
ret

delay:
; provides some delay so that the LED is visible
; =============================
; delay loop
; 499998 cycles: about 1/2 seconds
; —————————-
; delaying 499995 cycles:
ldi R29, $0f
WGLOOP0: ldi R30, $0f
WGLOOP1: ldi R31, $10
WGLOOP2: dec R31
brne WGLOOP2
dec R30
brne WGLOOP1
dec R29
brne WGLOOP0
ret
LDelay:
; provides some delay so that the LED is visible
; =============================
; delay loop
; 499998 cycles: about 1/2 seconds
; —————————-
; delaying 499995 cycles:
ldi R29, $02
WGLOOP3: ldi R30, $f0
WGLOOP4: ldi R31, $f0
WGLOOP5: dec R31
brne WGLOOP5
dec R30
brne WGLOOP4
dec R29
brne WGLOOP3
ret

This entry was posted in Tutorial AVR Asembly. Bookmark the permalink.

2 Responses to 4.5. Experiment Using SW to shift character to the left or right

  1. Tono says:

    Tutorial yang cukup bagus, tapi apakah bapak punya contoh pemrogramman dengan bahasa C, Trimakasih atas penjelasannya

  2. myturf says:

    Dalam waktu dekat akan kita upayakan contoh-contoh program dalam bahasa C

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>