4.4.Experiment to print string to LCD Character

In this experiment will be printed a sentence or word in a way to print character one at a time on the LCD screen by using a look up table

.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
;
rcall Init_LCD
;
start:
ldi r16,0×01
rcall write_inst
;
ldi zl,low(2*mystring)
ldi zh,high(2*mystring)
rcall line1
rcall write_msg
;
ldi zl,low(2*mystring2)
ldi zh,high(2*mystring2)
rcall line2
rcall write_msg
ending:
rjmp ending
;

write_msg:
loopchar:
lpm
mov r16,r0
cpi r16,0
brne write_char
ret
;
write_char:
rcall write_data
inc zl
rjmp loopchar
;
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
ret
;
shift_right:
ldi r16,0x1f
rcall write_inst
ret
;
line1:
ldi r16,0×80
rcall write_inst
ret
line2:
ldi r16,0xc0
rcall write_inst
ret
;
delay:
ldi R17, $0f
WGLOOP0: ldi R18, $0f
WGLOOP1: ldi R19, $10
WGLOOP2: dec R19
brne WGLOOP2
dec R18
brne WGLOOP1
dec R17
brne WGLOOP0
ret
;
mystring:
.db ” Selamat Datang “,0
mystring2:
.db ” Poltekkes SBY “,0

Posted in Tutorial AVR Asembly | Leave a comment

4.3.Experiment too shift character with BRNE

In the following experiments will be shifted to right a character repeated 20 times using the DEC instruction, CPI, and BRNE

.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
;
rcall Init_LCD
main:
ldi r16,0×80
rcall write_inst
ldi r16,’A’
rcall write_data
;
ldi r17,20
rot:
rcall shift_right
rcall ldelay
dec r17
cpi r17,0
brne rot

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
ret
;
shift_right:
ldi r16,0x1f
rcall write_inst
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

Posted in Tutorial AVR Asembly | Leave a comment

4.2.Experiment to shift character to the right

In this experiment will be printed a character A and is shifted towards the right by using instructions and scroll left scroll right

.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
;
rcall Init_LCD
main:
ldi r16,0×80
rcall write_inst
ldi r16,’A’
rcall write_data
rcall ldelay
rcall shift_right
rcall ldelay
rcall shift_right
rcall ldelay
rcall shift_right
rcall ldelay

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
ret
;
shift_right:
ldi r16,0x1f
rcall write_inst
ret

delay:
; provides some delay so that the LED is visible
; =============================
; delay loop
; 499998 cycles: about 1/2 seconds
; —————————-
; delaying 499995 cycles:
ldi R17, $0f
WGLOOP0: ldi R18, $0f
WGLOOP1: ldi R19, $10
WGLOOP2: dec R19
brne WGLOOP2
dec R18
brne WGLOOP1
dec R17
brne WGLOOP0
ret

Posted in Tutorial AVR Asembly | Leave a comment

4.1. Experiment print character to the LCD Character

In this experiment will be printed characters A and B on the Character LCD line 1, by using port C as input data and controls on the LCD Character using RS = EN = PD3 and PD4

.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
;
rcall Init_LCD
main:
ldi r16,0xC0
rcall write_inst
ldi r16,’A’
rcall write_data
ldi r16,0xC1
rcall write_inst
ldi r16,’B’
rcall write_data

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
;
delay:
; provides some delay so that the LED is visible
; =============================
; delay loop
; 499998 cycles: about 1/2 seconds
; —————————-
; delaying 499995 cycles:
ldi R17, $0f
WGLOOP0: ldi R18, $0f
WGLOOP1: ldi R19, $10
WGLOOP2: dec R19
brne WGLOOP2
dec R18
brne WGLOOP1
dec R17
brne WGLOOP0
ret

Posted in Tutorial AVR Asembly | Leave a comment

3.4. Experiment display 7 segmen with SW

This experiment will be made interaction 7 segment display against the push button switch, so that when the switch SW0 is connected to the PB0 is pressed, the display will show the number 0, so at the time of the switch SW1 is connected to PB1 is pressed, the display will show number 1, on 7 segment

Listing program percobaan 3.4.

.include “m8535def.inc”
.org 0×0000
rjmp main
;
main:
ldi r16,low(RAMEND)
out SPL,r16
ldi r16,high(RAMEND)
out SPH,r16
;
;Inisialisasi port D sebagai output
sbi ddrd,5 ; Konfigurasikan sebagai output pada PORTD,5
sbi ddrd,6 ; Konfigurasikan sebagai output pada PORTD,6
sbi ddrd,7 ; Konfigurasikan sebagai output pada PORTD,7
;
;Inisialisasi portC sebagai output
ldi r16,0b11111111
out ddrc,r16; Konfigurasikan sebagai output pada PORTC
;
;Inisialisasi portB sebagai input dengan pullup resistor
ldi r16,0b00000000
out ddrb,r16
ldi r16,0b11111111
out portb,r16
;
Lagi:
sbis PINB,0
rcall Angka0
sbis PINB,1
rcall Angka1
rjmp Lagi
;
Angka0:
cbi portd,5
cbi portd,6
cbi portd,7
;
ldi r16,0b11000000;Character=0
out Portc,r16
rcall delay
ret
;
Angka1:
cbi portd,5
cbi portd,6
cbi portd,7
;
ldi r16,0b11111001;Character=1
out Portc,r16
rcall delay
ret
;

Posted in Tutorial AVR Asembly | Leave a comment

3.2. Experiment to display string from Look Up Table

In this experiment will be shown 8 pieces on display 7 segment characters, the character number 0 to number 7. Interfacing microcontroller with 7 segments using 74LS138 decoder, with the use of port PortD to address in a decoder, PortC connected to a segment of 8 pieces 7 segment. In this experiment using a table of binary data that has been prepared so that data transmission is called the number that have been diagramed.

Listing program percobaan 3.2.

.include “m8535def.inc”
.org 0×0000
rjmp main
;
main:
ldi r16,low(RAMEND)
out SPL,r16
ldi r16,high(RAMEND)
out SPH,r16
;
;Inisialisasi port D sebagai output
sbi ddrd,5 ; Konfigurasikan sebagai output pada PORTD,5
sbi ddrd,6 ; Konfigurasikan sebagai output pada PORTD,6
sbi ddrd,7 ; Konfigurasikan sebagai output pada PORTD,7
;
;Inisialisasi portC sebagai output
ldi r16,0b11111111
out ddrc,r16; Konfigurasikan sebagai output pada PORTC
;
_7Seg:
cbi portd,5
cbi portd,6
cbi portd,7
;
ldi r16,0;Character=0
rcall Read_Table
out Portc,r16
rcall delay
;
sbi portd,5
cbi portd,6
cbi portd,7
;
ldi r16,1;Character=1
rcall Read_Table
out Portc,r16
rcall delay
;
cbi portd,5
sbi portd,6
cbi portd,7
;
ldi r16,2;Character=2
rcall Read_Table
out Portc,r16
rcall delay
;
sbi portd,5
sbi portd,6
cbi portd,7
;
ldi r16,3;Character=3
rcall Read_Table
out Portc,r16
rcall delay
;
cbi portd,5
cbi portd,6
sbi portd,7
;
ldi r16,4;Character=4
rcall Read_Table
out Portc,r16
rcall delay
;
sbi portd,5
cbi portd,6
sbi portd,7
;
ldi r16,5;Character=5
rcall Read_Table
out Portc,r16
rcall delay
;
cbi portd,5
sbi portd,6
sbi portd,7
;
ldi r16,6;Character=6
rcall Read_Table
out Portc,r16
rcall delay
;
sbi portd,5
sbi portd,6
sbi portd,7
;
ldi r16,7;Character=7
rcall Read_Table
out Portc,r16
rcall delay
;
rjmp _7Seg
;
Read_Table:
ldi R30,low(BIN2ASC_TAB*2) ;Make the Z reg point at the table
ldi R31,high(BIN2ASC_TAB*2) ;preparing for the LPM instruction
add R30,R16 ;Add the calculated offset
brcc AmbilData ;If no carry, then we’re done
inc R31 ;Handle carry
;
AmbilData:
lpm R16,Z ;look up character
ret
;
delay:
; provides some delay so that the LED is visible
; =============================
; delay loop
; 499998 cycles: about 1/2 seconds
; —————————-
; delaying 499995 cycles:
ldi R29, $09
WGLOOP0: ldi R30, $0f
WGLOOP1: ldi R31, $0f
WGLOOP2: dec R31
brne WGLOOP2
dec R30
brne WGLOOP1
dec R29
brne WGLOOP0
ret
;
BIN2ASC_TAB:
; 0 1 2 3 4 5 6 7 8 9
.db $0C0,$0F9,$0A4,$0B0,$99,$92,$82,$0F8,$80,$90

Posted in Tutorial AVR Asembly | Leave a comment

3.1. Experiment to display 2 character to 7 segmen

In this experiment the two characters will be displayed on display 7 segment, the character number 0 and the character number 1. Interfacing microcontroller with 7 segments using 74LS138 decoder, with the use of port PortD to address in a decoder, PortC connected to a segment of 8 pieces 7 segment

Listing program percobaan 3.1.

.include “m8535def.inc”
.org 0×0000
rjmp main
;
main:
ldi r16,low(RAMEND)
out SPL,r16
ldi r16,high(RAMEND)
out SPH,r16
;
;Inisialisasi port D sebagai output
sbi ddrd,5 ; Konfigurasikan sebagai output pada PORTD,5
sbi ddrd,6 ; Konfigurasikan sebagai output pada PORTD,6
sbi ddrd,7 ; Konfigurasikan sebagai output pada PORTD,7
;
;Inisialisasi portC sebagai output
ldi r16,0b11111111
out ddrc,r16; Konfigurasikan sebagai output pada PORTC
;
_7Seg:
cbi portd,5
cbi portd,6
cbi portd,7
;
ldi r16,0b11000000;Character=0
out Portc,r16
rcall delay
;
sbi portd,5
cbi portd,6
cbi portd,7
;
ldi r16,0b11111001;Character=1
out Portc,r16
rcall delay
;
rjmp _7Seg
;

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

Posted in Tutorial AVR Asembly | Leave a comment

2.3. Experiment to turn on/off LED with lacht

.device AT8535
.include “8535def.inc”
;
.org 0×0000
main:
ldi r16,low(RAMEND)
out SPL,r16
ldi r16,high(RAMEND)
out SPH,r16
;
rjmp RESET ;reset vector
;
;* Main program - Command LED (on/off)

RESET:
cbi DDRB, 0 ;input on PORTB,0
sbi PORTB, 0 ;pull-up On
sbi DDRC, 0 ;output on PORTC,0
sbi PORTC, 0 ;LED Off
nop ;settle R=10k of reset

;* Code

wait:
sbi PORTC, 0 ;LED Off
sbis PINB, 0 ;if PINB,0=low -> LED On
rjmp ledon
rjmp wait ;else wait

ledon:
cbi PORTC, 0 ;LED On
sbic PINB, 0 ;if hi -> LED Off
rjmp wait
rjmp ledon ;else keep LED On

Posted in Tutorial AVR Asembly | Leave a comment

2.2. Experiment to turn on/off LED using SW

In this experiment used the SW is connected to the port B bits 0, and connect the LED on port C bit 0.

.include “m8535def.inc”
.org 0×0000
main:
ldi r16,low(RAMEND)
out SPL,r16
ldi r16,high(RAMEND)
out SPH,r16
;
start:
ldi R16,0b11111111
out DDRC,R16
ldi R16,0b11111111
out PORTC,R16
;
cbi DDRB,0
sbi PORTB,0

;
get: sbic PINB,0
rjmp ledOFF
rjmp ledON
;
ledOFF:
sbi PORTC,0
rjmp get
ledON:
cbi PORTC,0
rjmp get

Posted in Tutorial AVR Asembly | Leave a comment

2.1. Experiment to get data SW PortB

In this experiment capture logic 0 and 1 is done by using the Port B 8 bit through the presses of the push button SW1 to SW8, in the hope that if the sw is pressed, the port B will get a logic 0, logic 0 data will be processed by the microcontroller further by using the port C then it can turn on the LED.

.include “m8535def.inc”
.org 0×0000
main:
ldi r16,low(RAMEND)
out SPL,r16
ldi r16,high(RAMEND)
out SPH,r16
;
start:
ldi R16,0b11111111
out DDRC,R16
ldi R16,0b11111111
out PORTC,R16
;
ldi R16,0b00000000
out DDRB,R16
ldi R16,0b11111111
out PORTB,R16
;
get: in R16,PINB
out PORTC,R16
rjmp get

Posted in Tutorial AVR Asembly | Leave a comment