Sound level ccs compiler ses seviye göstergesi pic programlama
#include <18f4520.h>
#DEVICE ADC=8
#fuses HS,NOLVP,NOWDT,NOPROTECT
#use delay(clock=20000000)
signed int16 deger;
int16 basladeger=0;
int k=0;
void baslama();
void main() {
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_INTERNAL);
baslama();
while (TRUE) {
set_adc_channel(0);
delay_us(10);
if (input(PIN_C0)>0) baslama();
deger = read_adc();
if ((deger-basladeger)<0) deger=0;
deger=(deger-basladeger)*20;
if (deger<32)
output_d(0b1);
else if (deger<64)
output_d(0b11);
else if (deger<96)
output_d(0b111);
else if (deger<128)
output_d(0b1111);
else if (deger<160)
output_d(0b11111);
else if (deger<192)
output_d(0b111111);
else if (deger<224)
output_d(0b1111111);
else
output_d(0b11111111);
if (deger>128) delay_ms(200);
}
}
void baslama() {
delay_ms(1000);
basladeger=0;
for (k=0;k<100;k++)
{
set_adc_channel(0);
delay_us(10);
basladeger+=read_adc();
}
basladeger = (basladeger/100);
}
Hiç yorum yok:
Yorum Gönder
Her yorum bilgidir. Araştırmaya devam...