|
;*************************************************************************
;*
;* Test firmware for LCD module
;*
;* board clock freq = 4Mhz (one cycle is 250nS)
;*
;*************************************************************************
.nolist
.include "2313def.inc"
.list
.listmac
; registers definition
.equ LCD_RS = pd5
.equ LCD_RW = pd4
.equ LCD_E = pd6
.def tmp1 = r23
.def tmp2 = r24
.def tmp3 = r25
.def tmp4 = r26
.def tmp5 = r27
.def i_sr = r28 ; used to store SREG
.cseg
.org 0x00
rjmp Reset
rjmp Int_0
;
;*** Interrupt handlers **************************************************
;
Int_0:
reti
;
;*** Reset vector ********************************************************
;
Reset:
ldi tmp1,low(RAMEND) ; init stack ptr
out SPL,tmp1
ser tmp1
out ddrb, tmp1 ; setting up all PORTB pins for output
ser tmp1 ; setting up all PORTD pins for output
out ddrd, tmp1
cli
Main:
ldi tmp2, 0xff ; wait some time
rcall Delay
ldi tmp2, 0xff ; wait some time
rcall Delay
ldi tmp2, 0xff ; wait some time
rcall Delay
ldi tmp2, 0xff ; wait some time
rcall Delay
ldi tmp2, 0b00111100 ; LCD on, 8-bit, 2 line mode
rcall FunctionLCD
rcall WaitLCD
ldi tmp2, 0b00111100 ; LCD on, 8-bit, 2 line mode
rcall FunctionLCD
rcall WaitLCD
ldi tmp2, 0b00001111 ; LCD on, cursor on, blink on
rcall FunctionLCD
rcall WaitLCD
ldi tmp2, 0b00000110 ; inc mode, shift off
rcall FunctionLCD
rcall WaitLCD
ldi tmp2, 0x01 ; Clear LCD
rcall FunctionLCD
rcall WaitLCD
ldi tmp2, 0x02 ; Set cursor home
rcall FunctionLCD
rcall WaitLCD
m_001:
ldi tmp2, 0b10000000 ; set DDRAM address
rcall FunctionLCD
rcall WaitLCD
ldi tmp2, 'A'
rcall WriteLCD
rcall WaitLCD
ldi tmp2, 'B'
rcall WriteLCD
rcall WaitLCD
ldi tmp2, 'C'
rcall WriteLCD
rcall WaitLCD
ldi tmp2, 'D'
rcall WriteLCD
rcall WaitLCD
rjmp m_001
;
;*** Write LCD ************************
;
; parameter is in tmp2
WriteLCD:
sbi PORTD, LCD_RS ; set mode 1_0
cbi PORTD, LCD_RW
out PORTB, tmp2
nop
nop
nop
nop
nop
nop
nop
nop
rcall Delay2
sbi PORTD, LCD_E
nop
nop
nop
nop
nop
nop
nop
nop
rcall Delay2
cbi PORTD, LCD_E
rcall Delay2
ret
;
;*** Function set LCD ************************
;
; parameter is in tmp2
FunctionLCD:
cbi PORTD, LCD_RS ; set mode 0_0
cbi PORTD, LCD_RW
out PORTB, tmp2
nop
nop
nop
nop
nop
nop
nop
nop
rcall Delay2
sbi PORTD, LCD_E
nop
nop
nop
nop
nop
nop
nop
nop
rcall Delay2
cbi PORTD, LCD_E
nop
nop
nop
nop
rcall Delay2
ret
;
;*** Read LCD ************************
;
; parameter in tmp2
ReadLCD:
clr tmp1
out ddrb, tmp1 ; setting up all PORTB pins for input
cbi PORTD, LCD_RS ; set mode 0_0
sbi PORTD, LCD_RW
sbi PORTD, LCD_E
nop
nop
nop
nop
in tmp2, PORTB
nop
nop
cbi PORTD, LCD_E
nop
nop
nop
nop
ser tmp1
out ddrb, tmp1 ; setting up all PORTB pins for output
ret
;
;*** Wait LCD ************************
;
;
WaitLCD:
rcall ReadLCD
rcall Delay2
andi tmp2, 0x80
tst tmp2
brne WaitLCD
ret
;
;*** Delay ***************************************************************
;
; 317uS x tmp2
Delay:
lbl1:
ser tmp3
lbl2: nop
nop
dec tmp3
brne lbl2
dec tmp2
brne lbl1
ret
;
;*** Delay2 **************************************************************
;
; approx. 1uS at 4 Mhz
Delay2:
ser tmp1
d_001:
dec tmp1
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
brne d_001
ret
;*************************************************************************
.eseg
.db 255
;
;*** End of file *********************************************************
;
E-mail: info@telesys.ru