|
.include"m8def.inc"
.dseg
.org 0xa0
seda:.byte 1
sedb:.byte 1
sedc:.byte 1
xzla:.byte 1
xzlb:.byte 1
xzlc:.byte 1
dyad:.byte 1
dlad:.byte 1
.org 0x60
stack:.byte 0x9f
.cseg
rjmp start
.org 0x09
rjmp jkmk
start:
;**************
;输入端口
sbi portd,2
sbi portd,3
;***********
clr r16
sts xzla,r16
ldi r16,0x80
sts seda,r16
;****************
;定义t0
ldi r16,0b00000001
out timsk,r16
ldi r16,0b00000010
out tccr0,r16
;定义t2
ldi r16,0x05
out ocr2,r16
ldi r16,0b01101001
out tccr2,r16
;************
main:
sei
ldi r16,0xd0
out spl,r16
rjmp main
jkmk:
ldi r16,0x80
out tcnt0,r16
rcall admk
cpi r16,0x80 ;电压低于--,不充
brsh jkmk00
rjmp jkmk05
; 不充
;**************
jkmk00: ;电压在00x80--------0x90
sbi ddrb,3
cpi r16,0x90
brsh jkmk01
;============ ;预充
rcall admk11
cpi r16,0x40
brsh jkmk02
cpi r16,0x3e
brsh jkmk06
rcall jia
reti
jkmk01:
cpi r16,0xba ;be以上,衡压
brsh jkmk03
;==================
rcall admk11
cpi r16,0xd0 ;大充
brsh jkmk02
cpi r16,0xce
brsh jkmk06
rcall jia
reti
jkmk02:
rcall jan
reti
jkmk03:
cpi r16,0xc4 ;停充
brsh jkmk05
cpi r16,0xc1
brsh jkmk02
cpi r16,0xc0
brsh jkmk06
rcall jia
reti
jkmk05:
cbi ddrb,3
reti
jkmk06:
reti
admk: ;电压采样子程序
;ad定义
;通道5----0101
;adc1---------0001
cbi adcsra,aden
ldi r16,(1<<adlar)|(1<<mux0)
out admux,r16
ldi r16,(1<<aden)|(1<<adsc)
out adcsra,r16
admk00:
sbic adcsra,adsc
rjmp admk00
in r16,adch
sts dyad,r16
ret
admk11: ;电流采样
cbi adcsra,aden
ldi r16,(1<<adlar)|(1<<mux1)
out admux,r16
ldi r16,(1<<aden)|(1<<adsc)
out adcsra,r16
admk12:
sbic adcsra,adsc
rjmp admk12
in r16,adch
sts dlad,r16
ret
;**************
jia: ;加PWM输出
clc
in r17,ocr2
cpi r17,0xfa
brsh jia00
inc r17
out ocr2,r17
jia00:
ret
;****************减少PWM输出
jan:
in r17,ocr2
cpi r17,0x03
brlo jan00
dec r17
out ocr2,r17
jan00:
ret |
|