PIC Vietnam

Go Back   PIC Vietnam > Microchip PIC > Cơ bản về vi điều khiển và PIC

Tài trợ cho PIC Vietnam
Trang chủ Đăng Kí Hỏi/Ðáp Thành Viên Lịch Bài Trong Ngày Vi điều khiển

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
Prev Previous Post   Next Post Next
Old 01-11-2012, 09:12 PM   #9
tungtot_vl
Đệ tử 6 túi
 
tungtot_vl's Avatar
 
Tham gia ngày: Jul 2007
Bài gửi: 154
:
tt

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é
File Kèm Theo
File Type: rar New Folder.rar (5.72 MB, 387 lần tải)
tungtot_vl vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
 


Quyền Sử Dụng Ở Diễn Ðàn
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Mở
Smilies đang Mở
[IMG] đang Mở
HTML đang Tắt

Chuyển đến


Múi giờ GMT. Hiện tại là 02:04 AM.


Được sáng lập bởi Đoàn Hiệp
Powered by vBulletin®
Page copy protected against web site content infringement by Copyscape
Copyright © PIC Vietnam