📄 cplcd.asm
字号:
ldi temp, $06 ; "06" storage to the address $0135
st x+, temp
ldi temp, $20 ; "20" storage to the address $0136
st x, temp
sbiw xl, 7
ret
;*
;************************Read data x register program***************************
Read_data_x:
ldi xl, low(dtpnt)
ldi xh, high(dtpnt)
ld temp, x+ ; data tranfer to temp
rcall LCD_display_sec ; tranfer second display
ld temp, x+
rcall LCD_display_minute ; tranfer minute display
ld temp, x+
rcall LCD_display_hour ; tranfer hour display
ld temp, x+
rcall LCD_display_day ; tranfer day display
ld temp, x+
rcall LCD_display_month ; tranfer month display
ld temp, x+
rcall LCD_display_low_year ; tranfer low year display
ld temp, x
rcall LCD_display_high_year ; tranfer high year display
ret
;*
;************************LCD display sec program********************************
LCD_display_sec:
mov next_temp, temp
ldi coodrinate_x, $0a
ldi coodrinate_y, 1
subi coodrinate_y, $40
add coodrinate_y, coodrinate_x
mov temp, coodrinate_y
rcall LCD_write_command
mov temp, next_temp
andi temp, $0f
add temp, temp30
rcall LCD_write_data
ldi coodrinate_x, $09
ldi coodrinate_y, 1
subi coodrinate_y, $40
add coodrinate_y, coodrinate_x
mov temp, coodrinate_y
rcall LCD_write_command
mov temp, next_temp
swap temp
andi temp, $0f
add temp, temp30
rcall LCD_write_data
ret
;*
;************************LCD display minute program*****************************
LCD_display_minute:
mov next_temp, temp
ldi coodrinate_x, $07
ldi coodrinate_y, 1
subi coodrinate_y, $40
add coodrinate_y, coodrinate_x
mov temp, coodrinate_y
rcall LCD_write_command
mov temp, next_temp
andi temp, $0f
add temp, temp30
rcall LCD_write_data
ldi coodrinate_x, $06
ldi coodrinate_y, 1
subi coodrinate_y, $40
add coodrinate_y, coodrinate_x
mov temp, coodrinate_y
rcall LCD_write_command
mov temp, next_temp
swap temp
andi temp, $0f
add temp, temp30
rcall LCD_write_data
ret
;*
;************************LCD display hour program******************************
LCD_display_hour:
mov next_temp, temp
ldi coodrinate_x, $04
ldi coodrinate_y, 1
subi coodrinate_y, $40
add coodrinate_y, coodrinate_x
mov temp, coodrinate_y
rcall LCD_write_command
mov temp, next_temp
andi temp, $0f
add temp, temp30
rcall LCD_write_data
ldi coodrinate_x, $03
ldi coodrinate_y, 1
subi coodrinate_y, $40
add coodrinate_y, coodrinate_x
mov temp, coodrinate_y
rcall LCD_write_command
mov temp, next_temp
swap temp
andi temp, $0f
add temp, temp30
rcall LCD_write_data
ret
;*
;************************LCD display day program********************************
LCD_display_day:
mov next_temp, temp
ldi coodrinate_x, $0c
ldi coodrinate_y, 0
subi coodrinate_y, $80
add coodrinate_y, coodrinate_x
mov temp, coodrinate_y
rcall LCD_write_command
mov temp, next_temp
andi temp, $0f
add temp, temp30
rcall LCD_write_data
ldi coodrinate_x, $0b
ldi coodrinate_y, 0
subi coodrinate_y, $80
add coodrinate_y, coodrinate_x
mov temp, coodrinate_y
rcall LCD_write_command
mov temp, next_temp
swap temp
andi temp, $0f
add temp, temp30
rcall LCD_write_data
ret
;*
;************************LCD display month program********************************
LCD_display_month:
mov next_temp, temp
ldi coodrinate_x, $09
ldi coodrinate_y, 0
subi coodrinate_y, $80
add coodrinate_y, coodrinate_x
mov temp, coodrinate_y
rcall LCD_write_command
mov temp, next_temp
andi temp, $0f
add temp, temp30
rcall LCD_write_data
ldi coodrinate_x, $08
ldi coodrinate_y, 0
subi coodrinate_y, $80
add coodrinate_y, coodrinate_x
mov temp, coodrinate_y
rcall LCD_write_command
mov temp, next_temp
swap temp
andi temp, $0f
add temp, temp30
rcall LCD_write_data
ret
;*
;************************LCD display low year program***************************
LCD_display_low_year:
mov next_temp, temp
ldi coodrinate_x, $06
ldi coodrinate_y, 0
subi coodrinate_y, $80
add coodrinate_y, coodrinate_x
mov temp, coodrinate_y
rcall LCD_write_command
mov temp, next_temp
andi temp, $0f
add temp, temp30
rcall LCD_write_data
ldi coodrinate_x, $05
ldi coodrinate_y, 0
subi coodrinate_y, $80
add coodrinate_y, coodrinate_x
mov temp, coodrinate_y
rcall LCD_write_command
mov temp, next_temp
swap temp
andi temp, $0f
add temp, temp30
rcall LCD_write_data
ret
;*
;************************LCD display high year program**************************
LCD_display_high_year:
mov next_temp, temp
ldi coodrinate_x, $04
ldi coodrinate_y, 0
subi coodrinate_y, $80
add coodrinate_y, coodrinate_x
mov temp, coodrinate_y
rcall LCD_write_command
mov temp, next_temp
andi temp, $0f
add temp, temp30
rcall LCD_write_data
ldi coodrinate_x, $03
ldi coodrinate_y, 0
subi coodrinate_y, $80
add coodrinate_y, coodrinate_x
mov temp, coodrinate_y
rcall LCD_write_command
mov temp, next_temp
swap temp
andi temp, $0f
add temp, temp30
rcall LCD_write_data
ret
;*
;**********************write instruction****************************************
LCD_write_command:
sbi LCD_EN_PORT, LCD_EN
rcall delay1us
busy:
sbic pind, 7
rjmp busy
ldi delay_temp, $3c ; about delay 1.5ms
rcall delay1500us
cbi LCD_RW_PORT, LCD_RW ; write instruction
out LCD_DATA_DDR, tempff ; set pb as output
out LCD_DATA_PORT, temp
sbi LCD_EN_PORT, LCD_EN ; open LCD_EN
rcall delay1us ; delay 1us
cbi LCD_EN_PORT, LCD_EN ; close LCD_EN
sbi LCD_RW_PORT, LCD_RW
out LCD_DATA_DDR, temp00
out LCD_DATA_PORT, temp00
ret
;*
;**********************delay 1500us program*************************************
delay1500us:
push delay_temp
delay1500us_next:
push delay_temp
delay1500us_three:
dec delay_temp
brne delay1500us_three
pop delay_temp
dec delay_temp
brne delay1500us_next
pop delay_temp
ret
;*
;***********************delay 1us program***************************************
delay1us:
ldi delay_temp, 2
dec delay_temp
brne delay1us+1
ret
;*
;************************LCD display string program*****************************
LCD_write_string:
tst coodrinate_y
brne add_address_0xc0
subi coodrinate_y, 0x80 ; address y+$80
rjmp deal_string
add_address_0xc0:
subi coodrinate_y, 0x40 ; address y+$c0
deal_string:
mov temp, coodrinate_y
add temp, coodrinate_x
rcall LCD_write_command
deal_string_loop:
lpm
tst r0
breq end_ret
mov temp, r0
rcall LCD_write_data ; tranfer LCD_write_data
subi zl, 255
sbci zh, 255 ; address ZL + 1
rjmp deal_string_loop
end_ret:
ret
;*
;************************LCD write data program*********************************
LCD_write_data:
rcall delay100us ; tranfer delay 100us
sbi LCD_RS_PORT, LCD_RS ; RS = 1,
cbi LCD_RW_PORT, LCD_RW ; RW = 0, write data
out LCD_DATA_DDR, tempff
out LCD_DATA_PORT, temp
sbi LCD_EN_PORT, LCD_EN ; E= 1, open LCD_EN
rcall delay1us
cbi LCD_EN_PORT, LCD_EN ; E = 0, close LCD_EN
sbi LCD_RW_PORT, LCD_RW ; RW = 1
cbi LCD_RS_PORT, LCD_RS ; RS = 0, busy check
out LCD_DATA_DDR, temp00
out LCD_DATA_PORT, temp00
ret
;*
;************************delay 80us program*************************************
delay100us:
ldi delay_temp, 150
dec delay_temp
brne delay100us+1
ret
;*
;***************************** timer one program ******************************
timer1_ovf:
push high_temp
push low_temp
in next_temp, sreg ; save sreg register content
dec int_temp
brne int_end_ret ; if int_temp != 0 ,and tranfer!
in low_temp, tcnt1l ; Read old number
in high_temp, tcnt1h
subi low_temp, $05
sbci high_temp, $a1
subi low_temp, $ff
sbci high_temp, $ff
out tcnt1h, high_temp
out tcnt1l, low_temp
ldi temp, 8
mov int_temp, temp
rcall clock_deal
int_end_ret:
pop low_temp
pop high_temp
out sreg, next_temp
reti
;*
;***************************** clock deal program ******************************
clock_deal:
push temp
push next_temp
push xh
push xl
ldi xl, low(dtpnt)
ldi xh, high(dtpnt)
rcall timer_dhm3_deal ; tranfer sec unit add 1
cpi temp, $60
brne finish_ret
rcall timer_dhm_deal ; tranfer minute unit add 1
cpi temp, $60
brne finish_ret
rcall timer_dhm_deal ; tranfer hour unit add 1
cpi temp, $24
brne finish_ret
rcall timer_dhm_deal ; tranfer day unit add 1
subi temp, $29
brcs finish_ret
brne test_30_day
adiw xl, 1 ; entry month unit
ld temp, x ; tranfer month unit the data
cpi temp, 2 ; the data = 2 ?
brne finish_ret
adiw xl, 1 ; entry low year unit
ld temp, x
tst temp
brne check_year_deal
adiw xl, 1 ; entry high year unit
ld temp, x
check_year_deal:
swap temp
andi temp, $0f
mov next_temp, temp
lsl next_temp ; data*2
lsl next_temp ; data*4
add temp, next_temp ; data*5
lsl temp ; data*10
ld next_temp, x
add temp, next_temp ; low year (high year) conversion binary
andi temp, $03
breq finish_ret
rjmp next_month_deal
test_30_day:
subi temp, 7
brne test_31_day
adiw xl, 1 ; entry month unit
ld temp, x
cpi temp, 2 ; month unit compare data to 2
brne finish_ret
rjmp next_month_deal
test_31_day:
dec temp
brne next_month_deal
adiw xl, 1 ; entry month unit
ld temp, x
subi temp, 8 ; month unit data decrease eight
brcc bit_month_deal
inc temp
bit_month_deal:
sbrs temp, 0
rjmp finish_ret
next_month_deal:
LDI xl, LOW(dtpnt+3)
LDI xh, HIGH(dtpnt+3) ;指向日
LDI temp, 1 ;
RCALL timer_dhm1_deal ;日置为1,月加1
CPI temp, $13
BRNE finish_ret
LDI temp, 1 ;月变为13,改为1
RCALL timer_dhm1_deal ;年十个位加1调整,可能有$99+1=$A0
CPI temp,$A0
BRNE finish_ret ;
RCALL timer_dhm_deal ;年千百位加1调整
finish_ret:
POP xl
POP xh
POP next_temp
POP temp
RET
timer_dhm_deal:
CLR temp ;秒,分,时单元清除,高位加1
timer_dhm1_deal:
ST X+, temp
timer_dhm3_deal:
LD temp, X
INC temp ;
CPI temp, $0A ;个位BCD码若未变成$0A
BRHS timer_dhm2_deal ;例如$58+1=$59,不须调整
SUBI temp, $FA ;否则做减$FA调整:例如$49+1-$FA=$50
timer_dhm2_deal:
ST X, temp ;并将调整结果送回
RET
;*******************************************************************************
.org $0270
.db $20, $20, $20, $20, $20, $20, $20, $b0
.db $20, $20, $b0, $20, $20, $20, $20, $00
.org $0280
.db $20, $20, $20, $20, $20, $3a, $20, $20
.db $3a, $20, $20, $20, $20, $20, $20, $00
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -