.module LCD+AD.C
.area text(rom, con, rel)
.dbfile F:\李鹏飞\sl-avrad-m16\LCD+AD\LCD+AD.C
.dbfunc e adctoasc _adctoasc fpc
; char_p -> R10,R11
; i -> R12
; temp -> R14,R15
; adc -> R10,R11
.even
_adctoasc::
xcall push_gset5x
movw R10,R16
.dbline -1
.dbline 22
; /******************************************************
; 双龙电子公司http://www.sl.com.cn
; AT90S8535--AD转换演示程序(ICCAVR)
; 作者:詹卫前
; 使用注意:1、应包含头文件slavr.h
; 2、在工程选项中的Additional Lib中填入slavr
; 使用编译器使用附加库文件libslavr.a
; 3、使用SL-AVRAD实验设备
; 接线说明:1、PA.0(PIN40)处接电平指示LED的短路块跳开
; 2、A/D和VX之间的短路块闭合
; 3、AREF(PIN32)和AVCC(PIN30)接VCC
; 4、AGND(PIN31)接GND
; *******************************************************/
; #include
; #include
; #include
; unsigned int ad_con;//存放PA0的AD转换结果
; unsigned char adcval[6];//存放电压ASCII码
; /* 将AD结果转换成电压 */
; #define vref 497
; unsigned char * adctoasc(unsigned int adc)
; {
.dbline 26
; unsigned int temp;
; unsigned char i;
; unsigned char *char_p;
; temp=(unsigned int)(((unsigned long)((unsigned long)adc*vref))/1024);
movw R2,R10
clr R4
clr R5
ldi R24,241
ldi R25,1
ldi R26,0
ldi R27,0
st -y,R5
st -y,R4
st -y,R3
st -y,R2
movw R16,R24
movw R18,R26
xcall empy32u
ldi R24,10
ldi R25,0
st -y,R24
xcall lsr32
movw R14,R16
.dbline 27
; for(i=0;i clr R12
xjmp L5
L2:
.dbline 28
.dbline 29
mov R2,R12
clr R3
ldi R30,3
ldi R31,0
sub R30,R2
sbc R31,R3
ldi R24, ldi R25,>_adcval
add R30,R24
adc R31,R25
ldi R18,10
ldi R19,0
movw R16,R14
xcall mod16u
movw R24,R16
adiw R24,48
std z+0,R24
.dbline 30
ldi R18,10
ldi R19,0
movw R16,R14
xcall div16u
movw R14,R16
.dbline 31
L3:
.dbline 27
inc R12
L5:
.dbline 27
mov R24,R12
cpi R24,3
brlo L2
.dbline 32
; {
; adcval[3-i]=temp%10+0x30;
; temp=temp/10;
; }
; adcval[0]=adcval[1];
lds R2,_adcval+1
sts _adcval,R2
.dbline 33
; adcval[1]='.';
ldi R24,46
sts _adcval+1,R24
.dbline 34
; adcval[4]='V';
ldi R24,86
sts _adcval+4,R24
.dbline 35
; adcval[5]=0;
clr R2
sts _adcval+5,R2
.dbline 36
; char_p=adcval;
ldi R24, ldi R25,>_adcval
movw R10,R24
.dbline 37
; return char_p;
movw R16,R24
.dbline -2
L1:
xcall pop_gset5x
.dbline 0 ; func end
ret
.dbsym r char_p 10 pc
.dbsym r i 12 c
.dbsym r temp 14 i
.dbsym r adc 10 i
.dbend
.area vector(rom, abs)
.org 56
jmp _adc_isr
.area text(rom, con, rel)
.dbfile F:\李鹏飞\sl-avrad-m16\LCD+AD\LCD+AD.C
.dbfunc e adc_isr _adc_isr fV
; temp -> R16,R17
.even
_adc_isr::
st -y,R2
st -y,R3
st -y,R16
st -y,R17
st -y,R30
in R2,0x3f
st -y,R2
.dbline -1
.dbline 42
; }
; /* AD转换程序 */
; #pragma interrupt_handler adc_isr:15
; void adc_isr(void)
; {
.dbline 43
; unsigned int temp=0;
clr R16
clr R17
xjmp L12
L11:
.dbline 45
subi R16,255 ; offset = 1
sbci R17,255
L12:
.dbline 44
; while(temp cpi R16,6
ldi R30,0
cpc R17,R30
brlo L11
.dbline 46
; temp++;
; ad_con=ADC;
in R2,0x4
in R3,0x5
sts _ad_con+1,R3
sts _ad_con,R2
.dbline 48
;
; ADCSRA|=(1 sbi 0x6,6
.dbline -2
.dbline 49
; }
L10:
ld R2,y+
out 0x3f,R2
ld R30,y+
ld R17,y+
ld R16,y+
ld R3,y+
ld R2,y+
.dbline 0 ; func end
reti
.dbsym r temp 16 i
.dbend
.dbfunc e main _main fV
.even
_main::
.dbline -1
.dbline 52
; //将AD转换结果转换成电压数值,然后在LCD上显示
; void main(void)
; {
.dbline 53
; MCUCR=0;
clr R2
out 0x35,R2
.dbline 54
; ADMUX=0x01;//0通道
ldi R24,1
out 0x7,R24
.dbline 55
; ADCSRA=(1 ldi R24,222
out 0x6,R24
.dbline 56
; lcd_init();
xcall _lcd_init
.dbline 57
; SEI();
sei
xjmp L16
L15:
.dbline 59
.dbline 60
clr R18
ldi R16,2
xcall _lcd_gotoxy
.dbline 61
ldi R16, ldi R17,>L18
xcall _lcd_puts
.dbline 62
ldi R18,1
ldi R16,2
xcall _lcd_gotoxy
.dbline 63
ldi R16, ldi R17,>L19
xcall _lcd_puts
.dbline 64
ldi R18,1
ldi R16,10
xcall _lcd_gotoxy
.dbline 65
lds R16,_ad_con
lds R17,_ad_con+1
xcall _adctoasc
xcall _lcd_puts
.dbline 66
ldi R16,500
ldi R17,1
xcall _delay_ms
.dbline 67
xcall _lcd_clear
.dbline 68
L16:
.dbline 58
xjmp L15
X0:
.dbline -2
.dbline 69
; while(1)
; {
; lcd_gotoxy(2,0);
; lcd_puts("AD--Converter");
; lcd_gotoxy(2,1);
; lcd_puts("Voltage:");
; lcd_gotoxy(10,1);
; lcd_puts(adctoasc(ad_con));
; delay_ms(500);
; lcd_clear();
; }
; }
L14:
.dbline 0 ; func end
ret
.dbend
.area bss(ram, con, rel)
.dbfile F:\李鹏飞\sl-avrad-m16\LCD+AD\LCD+AD.C
_adcval::
.blkb 6
.dbsym e adcval _adcval A[6:6]c
_ad_con::
.blkb 2
.dbsym e ad_con _ad_con i
.area data(ram, con, rel)
.dbfile F:\李鹏飞\sl-avrad-m16\LCD+AD\LCD+AD.C
L19:
.blkb 9
.area idata
.byte 'V,'o,'l,'t,'a,'g,'e,58,0
.area data(ram, con, rel)
.dbfile F:\李鹏飞\sl-avrad-m16\LCD+AD\LCD+AD.C
L18:
.blkb 14
.area idata
.byte 'A,'D,45,45,'C,'o,'n,'v,'e,'r,'t,'e,'r,0
.area data(ram, con, rel)
.dbfile F:\李鹏飞\sl-avrad-m16\LCD+AD\LCD+AD.C