AVR单片机C语言程序设计实验指导书-10页word资料 下载本文

}

/**************************/ uint conv(uint i) {

long x; uint y; x=(5000*(long)i)/1023; y=(uint)x; return y; }

void delay(uint k) {

uint i,j;

for(i=0;i

for(j=0;j<1141;j++); } }

/***********************/ void main(void) { init_devices(); Delay_nms(400);

DDRA=0X7F;PORTA=0X7F; DDRC=0XFF;PORTC=0X00; DDRB=0XFF;PORTB=0X00; InitLcd();

ePutstr(1,0,title);

DisplayOneChar(0,1,'A'); DisplayOneChar(1,1,'D'); DisplayOneChar(2,1,'C'); DisplayOneChar(3,1,'7'); DisplayOneChar(4,1,':'); DisplayOneChar(11,1,'.'); DisplayOneChar(15,1,'V'); while(1) { if(cnt>100) {

adc_val=ADC_Convert(); dis_val=conv(adc_val); cnt=0; }

第 9 页

delay(10);

DisplayOneChar(5,1,(adc_val/1000)+0x30); DisplayOneChar(6,1,(adc_val/100)+0x30); DisplayOneChar(7,1,(adc_val/10)+0x30); DisplayOneChar(8,1,(adc_val)+0x30);

DisplayOneChar(10,1,(dis_val/1000)+0x30); DisplayOneChar(12,1,(dis_val/100)+0x30); DisplayOneChar(13,1,(dis_val/10)+0x30); DisplayOneChar(14,1,(dis_val)+0x30); } }

第 10 页