|
Tài trợ cho PIC Vietnam |
Cơ bản về vi điều khiển và PIC Những bài hướng dẫn cơ bản nhất để làm quen với vi điều khiển PIC |
|
Ðiều Chỉnh | Xếp Bài |
25-04-2013, 12:03 AM | #4 |
Đệ tử 1 túi
Tham gia ngày: Mar 2011
Bài gửi: 17
: |
Mình viết code như sau:
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)){output_b( 0x01);output_d( 0x00);} // tan so lay mau if((ADC>8)&&(ADC<16)){output_b( 0x03);output_d( 0x00);} ;} if((ADC>16)&&(ADC<24)){output_b( 0x07);output_d( 0x00);} if((ADC>24)&&(ADC<32)){output_b( 0x0f);output_d( 0x00);} if((ADC>32)&&(ADC<40)){output_b( 0x1f);output_d( 0x00);} if((ADC>40)&&(ADC<48)){output_b( 0x3f);output_d( 0x00);} if((ADC>48)&&(ADC<56)){output_b( 0x7f);output_d( 0x00);} if((ADC>56)&&(ADC<64)){output_b( 0xff);output_d( 0x00) ;} if((ADC>64)&&(ADC<72)){output_d( 0x01); output_b( 0xff);} if((ADC>72)&&(ADC<80)){output_d( 0x03); output_b( 0xff);} if((ADC>80)&&(ADC<96)){output_d( 0x07); output_b( 0xff);} if((ADC>96)&&(ADC<100)){output_d( 0x0f); output_b( 0xff);} if((ADC>104)&&(ADC<112)){output_d( 0x1f); output_b( 0xff);} if((ADC>112)&&(ADC<120)){output_d( 0x3f); output_b( 0xff);} if((ADC>120)&&(ADC<128)){output_d( 0x7f); output_b( 0xff);} if(ADC>128){portd = 0xff; portb = 0xff;} delay_ms(5); // do nhay nhay theo dieu nhac } } làm theo trong nháy đèn theo nhạc, nhưng mình muốn led lên đến mức cao thì dừng lại vài giây trong khi các led khác rớt xuống , không hiểu diễn tả như vạy các bạn có hiểu không ? ví dụ theo đoạn nhạc led 1,2 3, 4 chớp sáng led 4 là cao nhất dừng lại vài giây trong khi đó led 1,2 ,3 tắt dần xuống , mong các bạn nào biết chỉ dẫn , cám ơn |
|
|