📄 cplcd.asm
字号:
;************* AVR program *******************************************
;*
;* Title : LCD Clock display
;* File name : clock display.asm
;* Verion : V01
;* OSC : 4MHz
;* Create date: 2006.02.15
;* Last update: 2006.02.20
;* Author : Sonic
;* Description: The program is suitable for ATmega8L
;*
;*********************************************************************
;*
.include"m8def.inc"
.list
;*
;************************Register definition***************************
.def int_temp = r14
.def next_temp = r15
.def temp = r16
.def delay_temp = r17
.def coodrinate_x = r18
.def coodrinate_y = r19
.def key = r20
.def tempff = r13
.def temp00 = r12
.def temp30 = r21
.def counter_temp = r22
.def high_temp = r23
.def low_temp = r24
;*
;************************I/O ports definition**************************
.equ LCD_DATA_DDR = DDRD
.equ LCD_DATA_PORT = PORTD
.equ LCD_RS_DDR = DDRC
.equ LCD_RS_PORT = PORTC
.equ LCD_EN_DDR = DDRC
.equ LCD_EN_PORT = PORTC
.equ LCD_RW_DDR = DDRC
.equ LCD_RW_PORT = PORTC
.equ LCD_RS = 0X05 ; PC5
.equ LCD_EN = 0X03 ; PC3
.equ LCD_RW = 0X04 ; PC4
.equ COL1 = 0 ; PB0, 列扫描
.equ COL2 = 1 ; PB1
.equ COL3 = 2 ; PB2
.equ COL4 = 3 ; PB3
.equ ROW1 = 4 ; PB4, 行扫描
.equ ROW2 = 5 ; PB5
.equ ROW3 = 0 ; PC0
.equ ROW4 = 1 ; PC1
;*
;***********************program address definition******************************
.equ chatble_one = $0270
.equ chatble_two = $0280
.equ dtpnt = $0290
;*
;**********************program code*********************************************
.cseg
.org $0000
rjmp reset ; reset ports
reti ; INT0 ports( no useing )
reti ; INT1 ports( no useing )
reti ; Timer2 compare ports
reti ; Timer2 overflow
reti ; Timer1 capture ports(no useing )
reti ; Timer1 compare A ports( no useing )
reti ; Timer1 compare B ports
rjmp Timer1_ovf ; Timer1 overflow ports
reti ; Timer0 overflow ports
reti ; SPI ports
reti ; USART RX complete ports( no useing )
reti ; USART Empty ports( no useing )
reti ; USART TX complete ports( no useing )
reti ; ADC ports
reti ; EEPROM ready ports
reti ; Analog comparator ports( no useing )
reti ; TWI ports
reti ; Timer2 inturrupt ports
reti ; Timer0 compare ports
reti ; SPM_ready
.org $0020
reset:
ldi temp, low(ramend) ;set stack address
out spl, temp
ldi temp, high(ramend)
out sph, temp
rcall write_data_x
ser temp
mov tempff, temp
clr temp00
clr counter_temp
ldi temp30, $30
out LCD_DATA_DDR, temp00
out LCD_DATA_PORT, temp00 ; set PD ports as input
sbi LCD_RS_DDR, LCD_RS ; set RS direction as output
sbi LCD_RW_DDR, LCD_RW ; set RW direction as output
sbi LCD_EN_DDR, LCD_EN ; set EN direction as output
cbi LCD_EN_PORT, LCD_EN
sbi LCD_RW_PORT, LCD_RW
cbi LCD_RS_PORT, LCD_RS
ldi temp, $38 ; LCD system funtion set
rcall LCD_write_command ; DL = 1, N = 1, F =0
ldi temp, $0c ; LCD display ON/OFF set
rcall LCD_write_command ; D = 1, C = 0, B = 0
ldi temp, $01 ; LCD display clear
rcall LCD_write_command
ldi temp, $06 ; LCD entry mode set
rcall LCD_write_command ; I/D = 1, S = 0
ldi coodrinate_x, 0 ; col coodrinate X
ldi coodrinate_y, 0 ; row coodrinate Y
ldi zl, low(chatble_one*2) ; set ROM address coursor
ldi zh, high(chatble_one*2)
rcall LCD_write_string ; display character string
ldi coodrinate_x, 0
ldi coodrinate_y, 1
ldi zl, low(chatble_two*2) ; set ROM another address coursor
ldi zh, high(chatble_two*2)
rcall LCD_write_string ; display character string
rcall Read_data_x ; tranfer display LCD data
;ldi coodrinate_x, 0 ; col coodrinate X
;ldi coodrinate_y, 0 ; row coodrinate Y
;subi coodrinate_y, $80
;mov temp, coodrinate_y
;rcall LCD_write_command
;ldi temp, $02 ; coursor return
;rcall LCD_write_command
;*
;************************** key press scan program******************************
key_press_scan:
ldi temp, 0x30 ; set PB4-PB5 ports as output
out ddrb, temp ; set PB0-PB3 ports as input
sbi ddrc, 0
sbi ddrc, 1 ; set PC0-PC1 ports as output
ldi temp, 0x0f
out portb, temp
cbi portc, 0
cbi portc, 1
ldi temp, 20 ; delay time 15us
col_scan_start:
dec temp
brne col_scan_start
sbis pinb, COL1 ; estimate pb0 low voltage level ?
rjmp col_scan_one ; if pb0 low voltage level, turning to col_scan_one
sbis pinb, COL2
rjmp col_scan_two
sbis pinb, COL3
rjmp col_scan_three
sbis pinb, COL4
rjmp col_scan_four
rjmp key_press_scan ; if pb0-pb3 no press key,or turning to key_press_scan
col_scan_one:
ldi key, 12
rjmp row_scan_prepare
col_scan_two:
ldi key, 8
rjmp row_scan_prepare
col_scan_three:
ldi key, 4
rjmp row_scan_prepare
col_scan_four:
ldi key, 0
row_scan_prepare:
ldi temp, 0x0f ; set pb0-pb3 as output
out ddrb, temp ; set pb4-pb5 as input
cbi ddrc, 0
cbi ddrc, 1 ; set pc0-pc1 as input
ldi temp, 0x30
out portb, temp
sbi portc, 0
sbi portc, 1
ldi temp, 20 ; delay time 15us
row_scan_start:
dec temp
brne row_scan_start
sbis pinc, ROW4 ; estimate pb4 low voltage level ?
rjmp row_scan_one ; if pb4 low voltage level, turning to row_scan_one
sbis pinc, ROW3
rjmp row_scan_two
sbis pinb, ROW2
rjmp row_scan_three
sbis pinb, ROW1
rjmp row_scan_four
rjmp key_press_scan ; if pb4-pb5,pc0-pc1 no press key
row_scan_one: ; or turning to key_press_scan
ldi temp, 0
rjmp col_row_finish
row_scan_two:
ldi temp, 1
rjmp col_row_finish
row_scan_three:
ldi temp, 2
rjmp col_row_finish
row_scan_four:
ldi temp, 3
;*
;**************************key deal program*************************************
col_row_finish:
add key, temp
cpi key, 10 ; compare key to 10, if key<10
brlo one_nine_deal ; turning to one_nine_deal
;cpi key, 10 ; compare key to 10, if key=10
;breq coursor_left_deal ; turning to coursor_left_deal
;cpi key, 11 ; compare key to 11, if key=11
; breq coursor_right_deal ; turning to coursor_right_deal
; cpi key, 12
; breq display_go_up_cell ; 显示上一单元的内容
; cpi key, 13
; breq display_go_down_cell
; cpi key, 14
; breq clear_display_LCD ; LCD clear display
cpi key, 15
breq start_timer ; start_timer
rjmp key_press_scan
;*
;**********************key ten deal program************************************
;coursor_left_deal:
; ldi temp, $10 ; set coursor left shift
; rcall LCD_write_command
; rcall delay_loop ; delay about 25ms
;rjmp key_press_scan
;*
;************************ key eleven deal program *****************************
;coursor_right_deal:
; ldi temp, $14 ; set coursor right shift
; rcall LCD_write_command
; rcall delay_loop
; rjmp key_press_scan
;*
;************************start timer program***********************************
start_timer:
ldi temp, $02
out tccr1b, temp ; one/eight frequency
ldi temp, $5e ; 24315 = 65536*8-499973 = $5efb
out tcnt1h, temp
ldi temp, $fb
out tcnt1l, temp
ldi temp, $04 ; toie1 = 1
out timsk, temp
ldi temp, 8 ; interrupt degree
mov int_temp, temp
sei
here:
nop
cli
rcall Read_data_x
nop
sei
rjmp here
;*
;************************digital key deal with program**************************
one_nine_deal:
inc counter_temp
cpi counter_temp, $01 ; if counter_temp = $03
breq high_year_high
cpi counter_temp, $02 ; if counter_temp = $04
breq high_year_low
cpi counter_temp, $03
breq low_year_high
cpi counter_temp, $04
breq low_year_low
cpi counter_temp, $05
breq high_month_deal
cpi counter_temp, $06
breq low_month_deal
cpi counter_temp, $07
breq high_day_deal
cpi counter_temp, $08
breq low_day_deal
cpi counter_temp, $09
breq high_hour_deal
cpi counter_temp, $0a
breq low_hour_deal
cpi counter_temp, $0b
breq high_minute_deal
cpi counter_temp, $0c
breq low_minute_deal
cpi counter_temp, $0d
breq high_sec_deal
cpi counter_temp, $0e
breq low_sec_deal
one_nine_finish:
rcall delay_loop
rjmp key_press_scan
;*
;************************ high year high deal program *************************
high_year_high:
ldi xl, low(dtpnt+6)
ldi xh, high(dtpnt+6)
rcall high_bit_deal
rjmp LCD_data_display ; tranfer display data
;*
;************************ high year low deal program ***************************
high_year_low:
ldi xl, low(dtpnt+6)
ldi xh, high(dtpnt+6)
rcall low_bit_deal
rjmp LCD_data_display ; tranfer display data
;*
;************************ low year high deal program ***************************
low_year_high:
ldi xl, low(dtpnt+5)
ldi xh, high(dtpnt+5)
rcall high_bit_deal
rjmp LCD_data_display ; tranfer display data
;*
;************************ low year low deal program ***************************
low_year_low:
ldi xl, low(dtpnt+5)
ldi xh, high(dtpnt+5)
rcall low_bit_deal
rjmp LCD_data_display ; tranfer display data
;*
;************************ high month deal program ******************************
high_month_deal:
ldi xl, low(dtpnt+4)
ldi xh, high(dtpnt+4)
rcall high_bit_deal
rjmp LCD_data_display ; tranfer display data
;*
;************************ low month deal program *******************************
low_month_deal:
ldi xl, low(dtpnt+4)
ldi xh, high(dtpnt+4)
rcall low_bit_deal
rjmp LCD_data_display ; tranfer display data
;*
;************************ high day deal program ********************************
high_day_deal:
ldi xl, low(dtpnt+3)
ldi xh, high(dtpnt+3)
rcall high_bit_deal
rjmp LCD_data_display ; tranfer display data
;*
;************************ low day deal program ********************************
low_day_deal:
ldi xl, low(dtpnt+3)
ldi xh, high(dtpnt+3)
rcall low_bit_deal
rjmp LCD_data_display ; tranfer display data
;*
;************************ high hour deal program ******************************
high_hour_deal:
ldi xl, low(dtpnt+2)
ldi xh, high(dtpnt+2)
rcall high_bit_deal
rcall Read_data_x ; tranfer display data
rjmp one_nine_finish
;*
;************************ low hour deal program *******************************
low_hour_deal:
ldi xl, low(dtpnt+2)
ldi xh, high(dtpnt+2)
rcall low_bit_deal
rjmp LCD_data_display ; tranfer display data
;*
;************************ high minute deal program ****************************
high_minute_deal:
ldi xl, low(dtpnt+1)
ldi xh, high(dtpnt+1)
rcall high_bit_deal
rjmp LCD_data_display ; tranfer display data
;*
;************************ low minute deal program ****************************
low_minute_deal:
ldi xl, low(dtpnt+1)
ldi xh, high(dtpnt+1)
rcall low_bit_deal
rjmp LCD_data_display ; tranfer display data
;*
;************************ high sec deal program *******************************
high_sec_deal:
ldi xl, low(dtpnt)
ldi xh, high(dtpnt)
rcall high_bit_deal
rjmp LCD_data_display ; tranfer display data
;*
;************************ low sec deal program ********************************
low_sec_deal:
ldi xl, low(dtpnt)
ldi xh, high(dtpnt)
rcall low_bit_deal
;*
;************************ LCD data display program*****************************
LCD_data_display:
rcall Read_data_x ; tranfer display data
rjmp one_nine_finish
;************************ high bit deal program *******************************
high_bit_deal:
swap key
andi key, $f0 ; save high bit
ld temp, x
andi temp, $0f ; save x register low bit
add temp, key
st x, temp
ret
;*
;************************ low bit deal program ********************************
low_bit_deal:
andi key, $0f ; save low bit
ld temp, x
andi temp, $f0 ; save x register high bit
add temp, key
st x, temp
ret
;*
;************************ loop program *****************************************
delay_loop:
ldi temp, $10
rcall delay1500us
dec temp
brne delay_loop+1
ret
;*
;************************ write data to x register*****************************
write_data_x:
ldi xl, low(dtpnt)
ldi xh, high(dtpnt)
ldi temp, $00 ; "00" storage to the address $0130-$0132
st x+, temp
st x+, temp
st x+, temp
ldi temp, $01 ; "01" storage to the address $0133-4
st x+, temp
st x+, temp
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -