?? main.c.130217130618
字號:
#include "includes.h"
unsigned int mega16_ad(void)
{
unsigned int addata;
DDRA&=~BIT(PA0);
PORTA&=~BIT(PA0);
SFIOR=0;
ADMUX=0x40;
ADCSR=0X80;
ADCSRA=(1<<ADEN)|(1<<ADSC)|(1<<ADIE)|(1<<ADPS2)|(1<<ADPS1) ;//64分頻
//ADCSR|=BIT(ADSC);
while(!ADCSR&(BIT(ADIF)));
addata=addata+ADCH*256;
ADCSR|=BIT(ADIF);
ADCSR=0x00;
return addata;
}
void main()
{
float j;
unsigned int count;
unsigned int Vref=50000;
unsigned char *value1 = "0.000 V";
unsigned int addata;
unsigned char *test = "The Voltage is: ";
unsigned char i=0;
Init_LCD();
LCD_DisplayString(1,1,test);
while(1)
{
for(i;i<8;i++)
{
addata = mega16_ad()+addata;
}
addata=addata/8;
j = (float)(((float)((Vref/1024)))*addata)/1000.00;
count = j*100;
value1[0] = count /1000+0x30;
count = count %1000;
value1[2] = count /100+0x30;
count = count %100;
value1[3] = count /10 + 0x30;
value1[4] = count %10 + 0x30;
LCD_DisplayString(2,1,value1);
delay_nms(1000);
}
}
/*
unsigned char *test = "The Voltage is: ";
unsigned char *value = "0.000 V";
float j;
unsigned int count;
unsigned int Vref=50000;
*/
/*
//unsigned char temp[]="zhm";
unsigned char *test = "The Voltage is: ";
Init_LCD();
init_adc();
LCD_DisplayString(1,1,test);
//LCD_DisplayString(2,1,value);
SREG |= (1<<7);
//LCD_DisplayString(2,1,temp);
//temp=ReadADC();
*/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -