📄 di_3635_source_code_edited.asm
字号:
clr ddigit_1
clr ddigit_10
ret
;*********************************************
;Initializes distance registers values to
;previously stored value in EEPROM
;*********************************************
eeprom_read:
cli
push temp
ldi temp,1
mov eep_addr, temp
rcall eep_nr
mov ddigit_01, eep_reg
ldi temp,2
mov eep_addr, temp
rcall eep_nr
mov ddigit_1, eep_reg
ldi temp,3
mov eep_addr, temp
rcall eep_nr
mov ddigit_10, eep_reg
pop temp
sei
ret
;*********************************************
;Subroutine to read data from eeprom
;eep_addr holds the address of eeprom
;eep_reg holds the data read
;*********************************************
eep_nr:
sbic EECR,EERE
rjmp eep_nr
read:
out EEAR, eep_addr
sbi EECR, EERE
nop
nop
in eep_reg, EEDR
ret
;*********************************************
;Subroutine to write data to eeprom
;eep_addr holds the address of eeprom
;eep_reg holds the data to be written
;*********************************************
eeprom_write:
sbic EECR, EEWE
rjmp eeprom_write
write:
out EEAR,eep_addr
out EEDR,eep_reg
cli
sbi EECR,EEMWE
sbi EECR,EEWE
sei
ret
;**********************************************************
;Init_Lcd: Initializes the 16 X 2 LCD module in 4 bit data
;transfer mode
;**********************************************************
init_lcd:
ldi lcd_cmd, 3
rcall lcd_low_cmd
rcall hi_delay
ldi lcd_cmd, 3
rcall lcd_low_cmd
rcall low_delay
ldi lcd_cmd, 3
rcall lcd_low_cmd
rcall low_delay
ldi lcd_cmd, $28 ; set 4-bit interface
rcall lcd_all_cmd
ldi lcd_cmd, 8 ; set DDRAM address to 00
rcall lcd_all_cmd
ldi lcd_cmd, $0c
rcall lcd_all_cmd
ldi lcd_cmd, 6
rcall lcd_all_cmd ; mode setting
ret
;*****************************************************************
;Print_Lcd: Prints speed and distance on the LCD display module
;*****************************************************************
print_lcd:
ldi lcd_cmd, $80
rcall lcd_all_cmd
ldi temp, 16
mov count, temp
ldi ZH, high(msg1*2)
ldi ZL, low(msg1*2)
more1:
lpm
mov lcd_dat, r0
rcall lcd_all_dat
adiw ZL, 1
dec count
ldi temp, 0
cp count, temp
brne more1
ldi temp, 16
mov count,temp
ldi lcd_cmd, $c0
rcall lcd_all_cmd
more2:
lpm
mov lcd_dat, r0
rcall lcd_all_dat
adiw ZL, 1
dec count
ldi temp, 0
cp count, temp
brne more2
;###########Binary to BCD conversion######################
clr d2
speeddigit: ;hundredth place value of speed
cpi sdigit_1,100
brsh sdigit_cal
rjmp print1
sdigit_cal:
inc d2
subi sdigit_1,100
rjmp speeddigit
print1:
ldi lcd_cmd,$86
rcall lcd_all_cmd
mov lcd_dat,d2
andi lcd_dat,$0f
ori lcd_dat,$30
rcall lcd_all_dat
rcall low_delay
mov c1,sdigit_1
rcall bcd
mov sdigit_1,c1
mov c2,d1
ldi lcd_cmd,$87 ;tenths place value of speed
rcall lcd_all_cmd
mov lcd_dat,c2
andi lcd_dat,$0f
ori lcd_dat,$30
rcall lcd_all_dat
rcall low_delay
ldi lcd_cmd,$88 ;units place value of speed
rcall lcd_all_cmd
andi sdigit_1,$0f
mov lcd_dat,sdigit_1
ori lcd_dat,$30
rcall lcd_all_dat
rcall low_delay
ldi lcd_cmd,$8a ;decimal place value of speed
rcall lcd_all_cmd
andi sdigit_01,$0f
mov lcd_dat,sdigit_01
ori lcd_dat,$30
rcall lcd_all_dat
rcall low_delay
;##################prints distance#############################
mov c1,ddigit_10
rcall bcd
ldi lcd_cmd,$c5 ;ten thousandth place of distance
rcall lcd_all_cmd
rcall low_delay
mov lcd_dat,d1
andi lcd_dat,$0f
ori lcd_dat,$30
rcall lcd_all_dat
rcall low_delay
ldi lcd_cmd,$c6 ;thousandth place of distance
rcall lcd_all_cmd
rcall low_delay
mov lcd_dat,c1
andi lcd_dat,$0f
ori lcd_dat,$30
rcall lcd_all_dat
rcall low_delay
mov c1,ddigit_1
rcall bcd
ldi lcd_cmd,$c7 ;hundredth place value of distance
rcall lcd_all_cmd
rcall low_delay
mov lcd_dat,d1
andi lcd_dat,$0f
ori lcd_dat,$30
rcall lcd_all_dat
rcall low_delay
ldi lcd_cmd,$c8 ;Tenth place value of distance
rcall lcd_all_cmd
rcall low_delay
mov lcd_dat,c1
andi lcd_dat,$0f
ori lcd_dat,$30
rcall lcd_all_dat
rcall low_delay
mov c1,ddigit_01
rcall bcd
ldi lcd_cmd,$c9 ;Units place value of distance
rcall lcd_all_cmd
rcall low_delay
mov lcd_dat,d1
andi lcd_dat,$0f
ori lcd_dat,$30
rcall lcd_all_dat
rcall low_delay
ldi lcd_cmd,$cb ;decimal place of distance
rcall lcd_all_cmd
rcall low_delay
mov lcd_dat,c1
andi lcd_dat,$0f
ori lcd_dat,$30
rcall lcd_all_dat
rcall low_delay
ret
;*********************************************************
;Binary to BCD conversion
;*********************************************************
bcd:
clr d1
bcddigit:
cpi c1,10
brsh bcd_cal
ret
bcd_cal:
inc d1
subi c1,10
rjmp bcddigit
;**********************************************************
;Low_Delay: A 250 us delay
;**********************************************************
low_delay:
push low_del
push hi_del
ldi low_del, 20
ld_hi:
ldi hi_del, 10
loop_in:
dec hi_del
cpi hi_del, 0
brne loop_in
dec low_del
cpi low_del, 0
brne ld_hi
pop hi_del
pop low_del
ret
;**********************************************************
;Hi_Delay: A 5 ms delay
;**********************************************************
hi_delay:
ldi low_del, 25
more_call:
rcall low_delay
dec low_del
cpi low_del, 0
brne more_call
ret
;**********************************************************
;Lcd_Low_Cmd: Sends a command to higher 4 bits of the LCD.
;The command nibble must be in the lower nibble of the
;variable 'lcd_cmd'
;**********************************************************
lcd_low_cmd:
mov temp, lcd_cmd
lsl temp
lsl temp
lsl temp
lsl temp
andi temp, $f0
out PORTB, temp
ori temp, $08
out PORTB, temp
andi temp, $f7
out PORTB, temp
ret
;**********************************************************
;Lcd_All_Cmd: sends an 8 bit command to the LCD
;**********************************************************
lcd_all_cmd:
push lcd_cmd
lsr lcd_cmd
lsr lcd_cmd
lsr lcd_cmd
lsr lcd_cmd
rcall lcd_low_cmd
pop lcd_cmd
andi lcd_cmd, $0f
rcall lcd_low_cmd
rcall low_delay
ret
;**********************************************************
;Lcd_All_Dat: Sends a data byte to the LCD. The data byte
;is stored in variable 'lcd_dat'
;**********************************************************
lcd_all_dat:
push lcd_dat
lsr lcd_dat
lsr lcd_dat
lsr lcd_dat
lsr lcd_dat
andi lcd_dat, $0f
rcall lcdlowdat
pop lcd_dat
andi lcd_dat, $0f
rcall lcdlowdat
rcall low_delay
ret
;**********************************************************
;Lcd_Low_Dat: Sends a data nibble to higher 4 bits of the
;LCD. The data nibble must be in the lower nibble of the
;variable 'lcd_dat'
;**********************************************************
lcdlowdat:
mov temp, lcd_dat
lsl temp
lsl temp
lsl temp
lsl temp
andi temp, $f0
ori temp, $04
out PORTB, temp
ori temp, $08
out PORTB, temp
andi temp, $f7
out PORTB, temp
ret
;**********************************************************
;Message #1
;**********************************************************
msg1: .db "SPEED= . Km/hrDIST= . Km "
; 12345678123456781234567812345678
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -