Trích:
Nguyên văn bởi tungtot_vl
chương trình Equalizer cho các bác đây
// Equalizer do nhay 16 bit
#include<16f877.h>
#fuses NOWDT,PUT,hs,NOPROTECT,NOBROWNOUT NOLVP
#device 16f877*=16 ADC=8
#use delay(clock=20000000)
#use fast_io(a)
#use fast_io(b)
#byte portb = 0x06
#use fast_io(d)
#byte portd=0x08
void main()
{ int l,i,a;
int ADC;
set_tris_A(0x0f);
set_tris_b(0x00);
set_tris_d(0x00);
enable_interrupts(global);
setup_ADC(ADC_clock_internal);
setup_adc_ports( ALL_ANALOG );
set_ADC_channel(0);
portb = 0x00;portd = 0x00;
while(1)
{ ADC = read_ADC();
if((ADC>4)&&(ADC<8)){portb = 0x01;portd = 0x00;} // tan so lay mau
if((ADC>8)&&(ADC<16)){portb = 0x03;portd = 0x00;}
if((ADC>16)&&(ADC<24)){portb = 0x07;portd = 0x00;}
if((ADC>24)&&(ADC<32)){portb = 0x0f;portd = 0x00;}
if((ADC>32)&&(ADC<40)){portb = 0x1f;portd = 0x00;}
if((ADC>40)&&(ADC<48)){portb = 0x3f;portd = 0x00;}
if((ADC>48)&&(ADC<56)){portb = 0x7f;portd = 0x00;}
if((ADC>56)&&(ADC<64)){portb = 0xff; portd = 0x00;}
if((ADC>64)&&(ADC<72)){portd = 0x01; portb = 0xff;}
if((ADC>72)&&(ADC<80)){portd = 0x03; portb = 0xff;}
if((ADC>80)&&(ADC<96)){portd = 0x07; portb = 0xff;}
if((ADC>96)&&(ADC<100)){portd = 0x0f; portb = 0xff;}
if((ADC>104)&&(ADC<112)){portd = 0x1f; portb = 0xff;}
if((ADC>112)&&(ADC<120)){portd = 0x3f; portb = 0xff;}
if((ADC>120)&&(ADC<128)){portd = 0x7f; portb = 0xff;}
if(ADC>128){portd = 0xff; portb = 0xff;}
delay_ms(5); // do nhay nhay theo dieu nhac
}
}
//the end
có kèm theo chương trình test protues các chú chạy thử để xem nhé
các này đã chạy thự tế rồi không phải lo gì
trong PIC có bao nhiêu chân ADC thì có thể làm được bấy nhiêu kênh. chương trình này mình làm có 1 kênh. các kênh khách các chú tự làm thử nhé
|
có thể chia nhỏ các khoảng adc nữa ra để làm thêm led không bác nhỉ. mà cái này là nháy theo biên độ phải ko bác