.module adc.c
.area text(rom, con, rel)
.dbfile E:\icc\iccavr\mega8\mega8\DAC\adc.c
.dbfunc e delay_us _delay_us fV
; time -> R16,R17
.even
_delay_us::
.dbline -1
.dbline 15
; /******************************************/
; /* 广州天河双龙电子公司 */
; /* http://www.sl.com.cn */
; /* ADC驱动程序 */
; /* 作者:ntzwq@wx88.net */
; /* 2002年5月11日 */
; /* 目标MCU:MEGA8 晶振:外部(EXT) 8MHZ */
; /******************************************/
; #include
; unsigned int adc_rel;//AD转换结果
; unsigned char adc_mux;//AD通道
; extern unsigned int adc_old;
; /* 微秒级延时程序 */
; void delay_us(int time)
; {
L2:
.dbline 17
; do
; {
.dbline 18
; time--;
subi R16,1
sbci R17,0
.dbline 19
; }
L3:
.dbline 20
; while (time>1);
ldi R24,1
ldi R25,0
cp R24,R16
cpc R25,R17
brlt L2
.dbline -2
.dbline 21
; }
L1:
.dbline 0 ; func end
ret
.dbsym r time 16 I
.dbend
.dbfunc e delay_ms _delay_ms fV
; time -> R20,R21
.even
_delay_ms::
rcall push_gset1
movw R20,R16
.dbline -1
.dbline 24
; /* 毫秒级延时程序 */
; void delay_ms(unsigned int time)
; {
rjmp L7
L6:
.dbline 26
.dbline 27
ldi R16,1000
ldi R17,3
rcall _delay_us
.dbline 28
subi R20,1
sbci R21,0
.dbline 29
L7:
.dbline 25
; while(time!=0)
cpi R20,0
cpc R20,R21
brne L6
X0:
.dbline -2
.dbline 30
; {
; delay_us(1000);
; time--;
; }
; }
L5:
rcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r time 20 i
.dbend
.dbfunc e adc_init _adc_init fV
.even
_adc_init::
.dbline -1
.dbline 33
; //ADC初始化
; void adc_init(void)
; {
.dbline 34
; DDRC=0x00;
clr R2
out 0x14,R2
.dbline 35
; PORTC=0x00;
out 0x15,R2
.dbline 36
; ADCSRA = 0x00;
out 0x6,R2
.dbline 37
; ADMUX =(1 lds R24,_adc_mux
andi R24,15
ori R24,64
out 0x7,R24
.dbline 38
; ACSR =(1 ldi R24,128
out 0x8,R24
.dbline 39
; ADCSRA=(1 ldi R24,206
out 0x6,R24
.dbline -2
.dbline 40
; }
L9:
.dbline 0 ; func end
ret
.dbend
.area vector(rom, abs)
.org 28
rjmp _adc_isr
.area text(rom, con, rel)
.dbfile E:\icc\iccavr\mega8\mega8\DAC\adc.c
.area bss(ram, con, rel)
.dbfile E:\icc\iccavr\mega8\mega8\DAC\adc.c
L11:
.blkb 2
.area text(rom, con, rel)
.dbfile E:\icc\iccavr\mega8\mega8\DAC\adc.c
.dbfunc e adc_isr _adc_isr fV
.dbsym s i L11 i
.even
_adc_isr::
st -y,R2
st -y,R3
st -y,R16
st -y,R17
st -y,R18
st -y,R19
st -y,R24
st -y,R25
st -y,R30
in R2,0x3f
st -y,R2
.dbline -1
.dbline 44
; //ADC完成中断
; #pragma interrupt_handler adc_isr:iv_ADC
; void adc_isr(void)
; {
.dbline 46
; static unsigned i;
; adc_rel+=ADC&0x3ff;
in R24,0x4
in R25,0x5
andi R25,3
lds R2,_adc_rel
lds R3,_adc_rel+1
add R2,R24
adc R3,R25
sts _adc_rel+1,R3
sts _adc_rel,R2
.dbline 47
; ADMUX=(1 lds R24,_adc_mux
andi R24,15
ori R24,64
out 0x7,R24
.dbline 48
; ADCSRA|=(1 sbi 0x6,6
.dbline 49
; if (i lds R24,L11
lds R25,L11+1
cpi R24,63
ldi R30,0
cpc R25,R30
brsh L12
.dbline 50
; i++;
adiw R24,1
sts L11+1,R25
sts L11,R24
rjmp L13
L12:
.dbline 52
.dbline 53
ldi R18,6
ldi R19,0
lds R16,_adc_rel
lds R17,_adc_rel+1
rcall lsr16
sts _adc_old+1,R17
sts _adc_old,R16
.dbline 54
clr R2
clr R3
sts L11+1,R3
sts L11,R2
.dbline 55
sts _adc_rel+1,R3
sts _adc_rel,R2
.dbline 56
L13:
.dbline -2
.dbline 57
; else
; {
; adc_old=adc_rel/64;//64点平均滤波
; i=0;
; adc_rel=0;
; }
; }
L10:
ld R2,y+
out 0x3f,R2
ld R30,y+
ld R25,y+
ld R24,y+
ld R19,y+
ld R18,y+
ld R17,y+
ld R16,y+
ld R3,y+
ld R2,y+
.dbline 0 ; func end
reti
.dbend
.area bss(ram, con, rel)
.dbfile E:\icc\iccavr\mega8\mega8\DAC\adc.c
_adc_mux::
.blkb 1
.dbsym e adc_mux _adc_mux c
_adc_rel::
.blkb 2
.dbsym e adc_rel _adc_rel i