Selasa, 08 September 2009

Program Pembacaan data pada ADC :

4. Program Pembacaan data pada ADC :
unsigned char baca_ADC(void)
{
unsigned char data_ADC = 0;
P2 = 0xFF;
ADC_CS = 0;
ADC_RD = 1;
ADC_WR = 1;
ADC_WR = 0;
delay(1);
ADC_WR = 1;
while(ADC_INT);
ADC_RD = 0;
delay(20);
data_ADC = ADC;
return data_ADC;
}
unsigned char ADC_rate(void)
{
unsigned char data_ADC,i;
data_ADC = baca_ADC();
for(i=0;i<100;i++) // Untuk i = 0 jika < 100 maka akan looping
data_ADC = (data_ADC/2) + (baca_ADC()/2);
return data_ADC; // Kembali ke data ADC
}
void viewADC()
{
unsigned char ADdata;
unsigned absorb;
unsigned hsl;
ADdata = ADC_rate();
if(ADdata>99) ADdata=100;
absorb = absorbance[ADdata];
hsl = hasil[ADdata];

Tidak ada komentar:

Posting Komentar