Требуется программист в Зеленограде
- обработка данных с датчиков; ColdFire; 40 тыс. e-mail:jobsmp@pochta.ru |
;LCD support module
;----------------------------------------------------------------------------
;Constantes:
.equ CONTRAST = 255
;----------------------------------------------------------------------------
.DSEG ;Data segment
;----------------------------------------------------------------------------
.CSEG ;Code segment
;----------------------------------------------------------------------------
;LCD init:
iLCD: ldi temp,(1<<COM1A1) | (1<<COM1A0) | (1<<WGM10)
out TCCR1A,temp
ldi temp,(1<<CS10) ;CLK/1
out TCCR1B,temp
ldy CONTRAST
out OCR1AL,YL ;contrast PWM
out OCR1AH,YH
ldi Cnt,15
rcall mDel ;initial delay
ldi temp,0x30
rcall LCD_WC ;write command to LCD
ldi Cnt,5
rcall mDel ;delay >4.1mS
ldi temp,0x30
rcall LCD_WC ;write command to LCD
ldi Cnt,100
rcall uDel ;delay >100uS
ldi temp,0x30
rcall LCD_WC ;write command to LCD
ldi Cnt,5
rcall mDel ;delay >4.1mS
ldi temp,0x38 ;FUNCTION SET
rcall LCD_WC ;write command to LCD
ldi Cnt,15
rcall mDel
ldi temp,0x0C ;DISPLAY ON
rcall LCD_WC ;write command to LCD
ldi Cnt,15
rcall mDel
ldi temp,0x06 ;ENTRY MODE SET
rcall LCD_WC ;write command to LCD
ldi Cnt,15
rcall mDel
rcall LCD_CL ;clear LCD
ldi Cnt,15
rcall mDel
rcall LCD_HI ;print splash screen
ret
;----------------------------------------------------------------------------
;Type char:
;Input: temp - char code:
; 0x10 - LCD clear
LCD_CH: push Cnt
cpi temp,0x10
brne ch1
rcall LCD_CL ;clear LCD
rjmp chr
ch1: rcall LCD_WD ;type char
chr: pop Cnt
ret
;----------------------------------------------------------------------------
;Set position:
;Input: YL - Line (1..2)
; YH - Pos (1..16)
LCD_XY: push temp
push Cnt
dec YL
dec YH
ldi temp,0x80
bbrc YL,0,xy1
ori temp,0x40
xy1: add temp,YH
rcall LCD_WC
pop Cnt
pop temp
ret
;----------------------------------------------------------------------------
;Clear LCD:
LCD_CL: ldi temp,0x01 ;DISPLAY CLEAR
rcall LCD_WC ;write command to LCD
ldi Cnt,5
rcall mDel ;delay >1.64mS
ret
;----------------------------------------------------------------------------
;Write command to LCD:
;Input: temp - data byte
LCD_WC: Port_LCD_RS_0 ;RS <- 0
rcall LCD_WR ;write byte to LCD
ret
;----------------------------------------------------------------------------
;Write data to LCD:
;Input: temp - data byte
LCD_WD: Port_LCD_RS_1 ;RS <- 1
rcall LCD_WR ;write byte to LCD
ret
;----------------------------------------------------------------------------
;Write byte to LCD:
;Input: temp - data byte
LCD_WR: Out_Data_temp ;out data
Port_LCD_W_0
Port_LCD_E_1 ;E <- 1
ldi Cnt,2
rcall uDel ;delay 2 uS
Port_LCD_E_0 ;E <- 0
ldi Cnt,50
rcall uDel ;delay 50 uS
ret
;----------------------------------------------------------------------------
;Delay:
;Cnt - delay value, uS (2uS min)
;CAUTION! TIMED CODE!
uDel: dec Cnt
nop
nop
nop
nop
nop
De: dec Cnt
nop
nop
nop
nop
nop
nop
nop
nop
nop
brne De
ret
;----------------------------------------------------------------------------
;Delay:
;Cnt - delay value, mS
mDel: push YL
push YH
mov YH,Cnt
md2: ldi YL,5 ;outer loop, 1mS
md1: ldi Cnt,200 ;inner loop, 200uS
rcall uDel
dec YL
brne md1
rcall mWdog ;restart watchdogs
dec YH
brne md2
pop YH
pop YL
ret
;----------------------------------------------------------------------------
;Print null-terminated string:
;Input: ZH:ZL - pointer to string in FLASH
LCD_ST: lpm temp,Z+
tst temp
breq lstr
rcall LCD_CH ;type char
rjmp LCD_ST
lstr: ret
;----------------------------------------------------------------------------
;Print splash screen:
LCD_HI: ldi YL,1
ldi YH,1
rcall LCD_XY
table Sp1
rcall LCD_ST
ldi YL,2
ldi YH,1
rcall LCD_XY
table Sp2
rcall LCD_ST
ret
;----------------------------------------------------------------------------
; 1234567890123456
Sp1: .db "BC1602E 1-Y-PLCW",0,0
Sp2: .db "Bolymin QC OK 04",0,0
;----------------------------------------------------------------------------