📄 f8.asm
字号:
.include "c:\mydocu~1\error.asm"
.include "c:\appnotes\4433def.inc"
.org $000
rjmp main
.org $006
rjmp timer0
.org $007
rjmp SPI_TXC
.org $00d
MAIN:;********************************************************
;
; initialize MCU system
;
sbi PORTB,2
sbi DDRB,2
sbi PORTB,2
sbi DDRB,2 ;disnable LM311 output PWM pulse and prevent MOSFET from working
sbi DDRD,0
cbi PORTD,0
sbi DDRD,0
cbi PORTD,0 ; define PD0 output 0 to ensure relay close POWER ON
ser r16
out DDRC,r16 ;portc is output mode and turn off all LEDS
ldi r17,$df
out SPL,r17
ldi r25,$80
out SREG,r25 ;Enable globle interrupt
ldi r20,$00
out ADCSR,r20 ;Disnable ADC
ldi r17,$0f
out WDTCR,r17;enable wacthdog
wdr ;reset wachdog
ldi r17,$02
out TIMSK,r17;enable timer0 overflow
sbi DDRB,3 ;set MOSI(PB.3) output mode whwn SPI is master.
sbi DDRB,5 ;set SCK (PB.5) output mode when SPI is master
sbi DDRB,2 ;set SS output mode so that this byte cann't
;influence SPI master work mode .
ldi r17,0b11111100
out SPCR,r17 ;set SPIE,SPE,MSTR,CPOL,CPHA ,reset the others
; ldi r25,$80
; out GIMSK,r25 ;enable INT1
;
;**********************************************************
;
;main programme is used to output PWM wave and display LED
;r26 is used to record time value
;r27 is used to record magnetic field trength
;
sbi DDRD,0
cbi PORTD,0 ;close power relay
rcall flash_ram
ldi r17,$02
rcall read
cpi r16,250
brlo continue
stop: ldi r21,$00
mov r2,r21
rjmp E0
continue:clr r17
rcall read
mov r26,r16
inc r17
rcall read
mov r27,r16
cpi r27,$05
brpl larger
rjmp small
larger: ldi r27,$00
rjmp m_d
small : cpi r27,-4
brmi larger ;if last time r27 in EEPROM >90 or <10 reset r27=0 system defaut
m_d: rcall m_leddisp
rcall t_leddisp
rcall load_test ;make software adapt load and test if load isn`t connect
k3:sbic PIND,6
rjmp k4
rcall delay
sbic PIND,6
rjmp k3
rcall delay1
rjmp md
k4:sbic PIND,7
rjmp m_d ;if k3,k4 are not press down display last time r26,r27 value
rcall delay
sbic PIND,7
rjmp k4
rcall delay1
cd: clt
ldi r17,120
mov r8,r17 ;set PWM output original work condition
ldi r17,$00
out TCNT0,r17;timer0 up count FF
ldi r17,$05
out TCCR0,r17;CK/1024 and star counting
clr r2
clr r3
clr r4
cbi PORTB,2
sbi DDRB,2
cbi PORTB,2
sbi DDRB,2 ;enable LM311 ouput PWM pulse
disp: wdr
rcall pwm_output
mov r18,r2
cpi r18,255 ; if timer0 overflow 255 times t=256*256*1024/8MHz
breq again
rjmp disp
again: inc r4
ldi r19,215 ;cycle time is 0.5 hour (30')
cp r4,r19
breq d_t
clr r2
rjmp disp
d_t: rcall define_time
inc r3
nop ; r24 is selected to define time value
cp r3,r24 ; this instruction is used to confirm PWM output time
breq stop_pwm
clr r4
clr r2
rjmp disp
stop_pwm: clr r17
out TCCR1B,r17
out TCCR0,r17
rcall delay1
clr r17
mov r16,r26
rcall write
inc r17
mov r16,r27
rcall write
inc r17
rcall read
inc r16
rcall write
rcall delay
power_off:sbi DDRD,0
sbi PORTD,0 ; define PD0 output 1 to ensure relay open POWER OFF
sbi DDRD,0
sbi PORTD,0
rjmp power_off
;---------------------------------------------------------------;
md: wdr
m_wait_k1: rcall m_leddisp
sbic PIND,4
rjmp m_k2_press
rcall delay
sbic PIND,4
rjmp m_wait_k1
compare: inc r27
cpi r27,$05
brpl addset_r27 ;k1 press down 4 times display "90" and cann't increase again
rcall m_leddisp
rcall delay1
sbic PIND,7
rjmp m_wait_k1
rcall delay
sbic PIND,7
rjmp m_wait_k1
rjmp cd
addset_r27: ldi r27,4
m_k2_press:sbic PIND,5
rjmp m_k4_press
rcall delay
sbic PIND,5
rjmp m_k2_press
min_comp: nop
dec r27
cpi r27,-4
brmi minset_r27 ; k2 press down 4 times display "10" and cann't decrease again
rcall m_leddisp
rcall delay1
sbic PIND,7
rjmp m_k2_press
rcall delay
sbic PIND,7
rjmp m_k2_press
rjmp cd
minset_r27: ldi r27,-4
m_k4_press: sbic PIND,7
rjmp k3_again
rcall delay
sbic PIND,7
rjmp m_k4_press
rjmp cd
rcall delay2
k3_again: sbic PIND,6
rjmp m_wait_k1
rcall delay
sbic PIND,6
rjmp k3_again
rcall delay1
t_wait_k1: rcall t_leddisp
sbic PIND,4
rjmp t_k2_press
rcall delay
sbic PIND,4
rjmp t_wait_k1
t_compare: inc r26
cpi r26,13
brpl taddset_r26 ;k1 press down 4 times display "90" and cann't increase again
rcall t_leddisp
rcall delay1
sbic PIND,7
rjmp t_wait_k1
rcall delay
sbic PIND,7
rjmp t_wait_k1
rjmp cd
taddset_r26: ldi r26,12
t_k2_press:sbic PIND,5
rjmp t_k4_press
rcall delay
sbic PIND,5
rjmp t_k2_press
tmin_comp: nop
dec r26
cpi r26,-3
brmi tminset_r26 ; k2 press down 4 times display "10" and cann't decrease again
rcall t_leddisp
rcall delay1
sbic PIND,7
rjmp t_k2_press
rcall delay
sbic PIND,7
rjmp t_k2_press
rjmp cd
tminset_r26: ldi r26,-3
t_k4_press: sbic PIND,7
rjmp t_k3_again
rcall delay
sbic PIND,7
rjmp t_k4_press
rjmp cd
t_k3_again: sbic PIND,6
rjmp t_wait_k1
rcall delay
sbic PIND,6
rjmp t_k3_again
rcall delay1
rjmp m_wait_k1
SPI_TXC: sbi SPCR,4
reti
timer0: inc r2
reti
delay:ldi r21,$01
d2:ldi r22,$01
d1:ldi r23,$0ff
d0:dec r23
;wdr
brne d0
dec r22
brne d1
dec r21
brne d2
ret
delay1:ldi r21,$8
d21:ldi r22,$0ff
d11:ldi r23,$0ff
d01:dec r23
wdr
brne d01
dec r22
brne d11
dec r21
brne d21
ret
delay2:ldi r21,$01
d22:ldi r22,$01
d12:ldi r23,$0ff
d02:dec r23
wdr
push r21
push r22
push r23
rcall m_leddisp
rcall t_leddisp
pop r23
pop r22
pop r21
brne d02
dec r22
brne d12
dec r21
brne d22
ret
delay3:ldi r21,$15
d23:ldi r22,$0ff
d13:ldi r23,$0ff
d03:dec r23
wdr
brne d03
dec r22
brne d13
dec r21
brne d23
ret
read: sbic EECR,EEWE
rjmp read
out EEAR,r17
sbi EECR,EERE ;this instruction need 4 cycles and halt CPU 2 cycles
sbi EECR,EERE
in r16,EEDR ;
ret
write: sbic EECR,EEWE
rjmp write
out EEAR,r17 ;write time value r26 into EEPROM
out EEDR,r16
sbi EECR,EEMWE
sbi EECR,EEWE
ret
;------------------------------------------------------
t_leddisp: wdr
wdr
cpi r26,-3
brne time_60
time_30 : nop
;----------------------
ldi r20,$00 ; r20 is content of display word
out SPDR , r20
ldi r17,0b0000100 ; display byte PC.2
out PORTC,r17
rcall delay
rcall turn_off
; ---------------------display PC.2 first byte of time value
ldi r20 ,$4f
out SPDR , r20
ldi r17,0b00001000 ; display byte PC.3
out PORTC,r17 ;PC.3 output 1 ,
rcall delay
rcall turn_off
;-------------------display PC.3 second byte of time value
rcall b4_d0
ret
;-------------------- ; PC.4 display "0"
time_60: cpi r26,-2
brne time_90
;----------------------
ldi r20,$00
out SPDR , r20
ldi r17,0b0000100 ; display byte PC.2
out PORTC,r17
rcall delay
rcall turn_off
; ---------------------display PC.2 first byte of time value
ldi r20 ,$7d
out SPDR , r20
ldi r17,0b00001000 ; display byte PC.3
out PORTC,r17
rcall delay
rcall turn_off
;-------------------display PC.3 second byte of time value
rcall b4_d0
ret
;-------------------- ; PC.4 display "0"
time_90: cpi r26,-1
brne time_120
;----------------------
ldi r20,$00
out SPDR , r20
ldi r17,0b0000100 ; display byte PC.2
out PORTC,r17
rcall delay
rcall turn_off
; ---------------------display PC.2 first byte of time value
ldi r20 ,$6f
out SPDR , r20
ldi r17,0b00001000 ; display byte PC.3
out PORTC,r17
rcall delay
rcall turn_off
;-------------------display PC.3 second byte of time value
rcall b4_d0
ret
;-------------------- ; PC.4 display "0"
time_120: cpi r26,0
brne time_150
;----------------------
ldi r20,$06
out SPDR , r20
ldi r17,0b0000100 ; display byte PC.2
out PORTC,r17
rcall delay
rcall turn_off
; ---------------------display PC.2 first byte of time value
ldi r20 ,$5b
out SPDR , r20
ldi r17,0b00001000 ; display byte PC.3
out PORTC,r17
rcall delay
rcall turn_off
;-------------------display PC.3 second byte of time value
rcall b4_d0
ret
;-------------------- ; PC.4 display "0"
time_150: cpi r26,1
brne time_180
;----------------------
ldi r20,$06
out SPDR , r20
ldi r17,0b0000100 ; display byte PC.2
out PORTC,r17
rcall delay
rcall turn_off
; ---------------------display PC.2 first byte of time value
ldi r20 ,$6d
out SPDR , r20
ldi r17,0b00001000 ; display byte PC.3
out PORTC,r17
rcall delay
rcall turn_off
;-------------------display PC.3 second byte of time value
rcall b4_d0
ret
;-------------------- ; PC.4 display "0"
time_180: cpi r26,2
brne time_210
;----------------------
ldi r20,$06
out SPDR , r20
ldi r17,0b0000100 ; display byte PC.2
out PORTC,r17
rcall delay
rcall turn_off
; ---------------------display PC.2 first byte of time value
ldi r20 ,$7f
out SPDR , r20
ldi r17,0b00001000 ; display byte PC.3
out PORTC,r17
rcall delay
rcall turn_off
;-------------------display PC.3 second byte of time value
rcall b4_d0
ret
;-------------------- ; PC.4 display "0"
time_210: cpi r26,3
brne time_240
;----------------------
ldi r20,$5b
out SPDR , r20
ldi r17,0b0000100 ; display byte PC.2
out PORTC,r17
rcall delay
rcall turn_off
; ---------------------display PC.2 first byte of time value
ldi r20 ,$06
out SPDR , r20
ldi r17,0b00001000 ; display byte PC.3
out PORTC,r17
rcall delay
rcall turn_off
;-------------------display PC.3 second byte of time value
rcall b4_d0
ret
;-------------------- ; PC.4 display "0"
time_240: cpi r26,4
brne time_270
;----------------------
ldi r20,$5b
out SPDR , r20
ldi r17,0b0000100 ; display byte PC.2
out PORTC,r17
rcall delay
rcall turn_off
; ---------------------display PC.2 first byte of time value
ldi r20 ,$66
out SPDR , r20
ldi r17,0b00001000 ; display byte PC.3
out PORTC,r17
rcall delay
rcall turn_off
;-------------------display PC.3 second byte of time value
rcall b4_d0
ret
;-------------------- ; PC.4 display "0"
time_270: cpi r26,5
brne time_300
;----------------------
ldi r20,$5b
out SPDR , r20
ldi r17,0b0000100 ; display byte PC.2
out PORTC,r17
rcall delay
rcall turn_off
; --------------------display PC.2 first byte of time value
ldi r20 ,$07
out SPDR , r20
ldi r17,0b00001000 ; display byte PC.3
out PORTC,r17
rcall delay
rcall turn_off
;-------------------display PC.3 second byte of time value
rcall b4_d0
ret
;-------------------- ; PC.4 display "0"
time_300: cpi r26,6
brne time_330
;----------------------
ldi r20,$4f
out SPDR , r20
ldi r17,0b0000100 ; display byte PC.2
out PORTC,r17
rcall delay
rcall turn_off
; --------------------display PC.2 first byte of time value
ldi r20 ,$3f
out SPDR , r20
ldi r17,0b00001000 ; display byte PC.3
out PORTC,r17
rcall delay
rcall turn_off
;-------------------display PC.3 second byte of time value
rcall b4_d0
ret
;-------------------- ; PC.4 display "0"
time_330: cpi r26,7
brne time_360
;----------------------
ldi r20,$4f
out SPDR , r20
ldi r17,0b0000100 ; display byte PC.2
out PORTC,r17
rcall delay
rcall turn_off
; --------------------display PC.2 first byte of time value
ldi r20 ,$4f
out SPDR , r20
ldi r17,0b00001000 ; display byte PC.3
out PORTC,r17
rcall delay
rcall turn_off
;-------------------display PC.3 second byte of time value
rcall b4_d0
ret
;-------------------- ; PC.4 display "0
time_360: cpi r26,8
brne time_390
;----------------------
ldi r20,$4f
out SPDR , r20
ldi r17,0b0000100 ; display byte PC.2
out PORTC,r17
rcall delay
rcall turn_off
; --------------------display PC.2 first byte of time value
ldi r20 ,$7d
out SPDR , r20
ldi r17,0b00001000 ; display byte PC.3
out PORTC,r17
rcall delay
rcall turn_off
;-------------------display PC.3 second byte of time value
rcall b4_d0
ret
;-------------------- ; PC.4 display "0
time_390: cpi r26,9
brne time_420
;----------------------
ldi r20,$4f
out SPDR , r20
ldi r17,0b0000100 ; display byte PC.2
out PORTC,r17
rcall delay
rcall turn_off
; --------------------display PC.2 first byte of time value
ldi r20 ,$6f
out SPDR , r20
ldi r17,0b00001000 ; display byte PC.3
out PORTC,r17
rcall delay
rcall turn_off
;-------------------display PC.3 second byte of time value
rcall b4_d0
ret
;-------------------- ; PC.4 display "0
time_420: cpi r26,10
brne time_450
;----------------------
ldi r20,$66
out SPDR , r20
ldi r17,0b0000100 ; display byte PC.2
out PORTC,r17
rcall delay
rcall turn_off
; --------------------display PC.2 first byte of time value
ldi r20 ,$5b
out SPDR , r20
ldi r17,0b00001000 ; display byte PC.3
out PORTC,r17
rcall delay
rcall turn_off
;-------------------display PC.3 second byte of time value
rcall b4_d0
ret
;-------------------- ; PC.4 display "0
time_450: cpi r26,11
brne time_480
;----------------------
ldi r20,$66
out SPDR , r20
ldi r17,0b0000100 ; display byte PC.2
out PORTC,r17
rcall delay
rcall turn_off
; --------------------display PC.2 first byte of time value
ldi r20 ,$6d
out SPDR , r20
ldi r17,0b00001000 ; display byte PC.3
out PORTC,r17
rcall delay
rcall turn_off
;-------------------display PC.3 second byte of time value
rcall b4_d0
ret
;-------------------- ; PC.4 display "0
time_480: cpi r26,12
breq led
rjmp t_leddisp
;----------------------
led: ldi r20,$66
out SPDR , r20
ldi r17,0b0000100 ; display byte PC.2
out PORTC,r17
rcall delay
rcall turn_off
; --------------------display PC.2 first byte of time value
ldi r20 ,$7f
out SPDR , r20
ldi r17,0b00001000 ; display byte PC.3
out PORTC,r17
rcall delay
rcall turn_off
;-------------------display PC.3 second byte of time value
rcall b4_d0
ret
;-------------------- ; PC.4 display "0
b4_d0: ldi r20,$3f
out SPDR , r20
ldi r17,0b00010000
out PORTC,r17
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -