|
求教关于AT89C51cc02的ADC转换程序
[复制链接]
ADC程序: signal void ADC_Input(unsigned char channels, float max) //这段函数为什么最后main函数并没有引用? {
unsigned char i;
float x; while(1) {
x=(x+0.25)%max; //float为什么还可以用%。。。
for(i=0;i<channels; i++)
{
switch(i)
{
case 0: AIN=(x+0.0)%max; break; //这些语句完全不懂。。。
case 1: AIN=(x+0.1)%max; break;
case 2: AIN=(x+0.2)%max; break;
case 3: AIN=(x+0.3)%max; break;
case 4: AIN=(x+0.4)%max; break;
case 5: AIN=(x+0.5)%max; break;
case 6: AIN=(x+0.6)%max; break;
case 7: AIN=(x+0.7)%max; break;
case 8: AIN=(x+0.8)%max; break;
case 9: AIN=(x+0.9)%max; break;
case 10: AIN=(x+1.0)%max; break;
case 11: AIN=(x+1.1)%max; break;
case 12: AIN=(x+1.2)%max; break;
case 13: AIN=(x+1.3)%max; break;
case 14: AIN=(x+1.4)%max; break;
case 15: AIN=(x+1.5)%max; break;
}
}
swatch(0.01); //这是什么函数?时钟?怎么没有申明?
} }
#include<stdio.h> sfr ADCON =0xF3; sfr ADCF=0xF6; sfr ADCLK=0xF2; sfr ADDH=0xF5; sfr ADDL=0xF4;
sfr SCON=0x98; sfr TMOD=0x89; sfr TH1=0x8D; sfr TR1=0x88^6; sfr TI=0x98^1;
void init_ADC(void) {
ADCF=0xFF; //开启了8个模拟信号输入通道
ADCLK=0x1F;
ADCON |=0x20; }
unsigned read_ADC(unsigned char channel) {
ADCON&=~0x07; //为什么还要用~,直接用0xF8不就行吗?
ADCON |=0x07&channel;
ADCON= |=0x08;
while(ADCON&0x08);
return(((unsigned)ADDH<<2)|(ADDL&3)); }
void main(void) {
unsigned char i;
SCON=0x50;
TMOD=|0x20;
TH1=221;
TR1=1;
TI=1 //为什么TI要设成1?
init_ADC();
while(1) {
for(i=0;i<8;i++)
{
printf(“Channel%u=%4u\n”,(unsigned)i,read_ADC(i)); //为什么用%4u和(unsigned)?
}
} }
//这个函数是8个通道同时转换?
|
|