![]() |
|
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 |
|
![]() |
#1 |
Nhập môn đệ tử
Tham gia ngày: Dec 2010
Bài gửi: 4
: |
cac huynh xem giup e doan code roi cho em hoi vai cau:
1. em khong thay chuong trinh xuat gia tri nhiet do minh da tinh ra khi nao tren lcd ca ngoai cai lenh xuat dong lenh luc dau, va do la len nao vay? 2. va gia tri chia "x=x/2.049" lay so 2.049 o dau ra vay may huynh? 3. va doan code nay e lay tren mang xuong xem thay no chay dua ra gia tri khong dc dung lam, co huynh nao co the toi uu no hon giup e khong. E cam on cac huynh. #include <16F877a.h> #FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT #device 16F877*16ADC=10 #use delay(clock=4000000) #byte portb=0x06 #byte porta=0x05 #byte portc=0x07 #byte portd=0x08 #byte porte=0x09 #use fast_io(a) #use fast_io(b) #use fast_io(c) #use fast_io(d) #use fast_io(e) #bit rs=portd.0 #bit rw=portd.1 #bit e=portd.2 #byte lcd=portb const char mht[]={'0','1','2','3','4','5','6','7','8','9','-',' '}; const char nd0[]="nhiet do: do C"; const char tn[]="dungdt08B@gmail.com"; int8 i,chuc,dv,tram; int8 y; void doc_ADC(); void hienthi(); void ghilenh(); void ghidata(); void ghilcd(); void main() { float x; set_tris_e(0); set_tris_d(0); set_tris_b(0); lcd=0x80; ghilenh(); for(i=0;i<=15;i++) { lcd=nd0[i]; ghidata(); } lcd=0xc0; ghilenh(); for(i=0;i<=19;i++) { lcd=tn[i]; ghidata(); } while(1) { doc_ADC(); x= read_adc(); x=x/2.049; y=x; hienthi(); } } void hienthi() { if(y<100) { dv=y%10; chuc=y/10; tram=11; if(chuc==0) { chuc=11; } } if(y>=100) { tram=y/100; y=y-100; dv=y%10; chuc=y/10; } lcd =0x38; ghilenh(); lcd=0x0C; ghilenh(); LCD=0x89; ghilenh(); ghilcd(); } void ghilcd() { lcd=mht[tram]; ghidata(); lcd=mht[chuc]; ghidata(); lcd=mht[dv]; ghidata(); } void ghilenh() { rs=0; rw=0; e=1; e=0; delay_ms(10); } void ghidata() { rs=1; rw=0; e=1; e=0; delay_ms(10); } void doc_ADC() { set_tris_a(0b1); setup_ADC(ADC_clock_internal); setup_ADC_ports(AN0_AN1_AN2_AN3_AN4); set_ADC_channel(0); delay_us(1000); } |
![]() |
![]() |
![]() |
#2 |
Nhập môn đệ tử
Tham gia ngày: Feb 2013
Bài gửi: 1
: |
giúp e sửa lỗi đoạn code trên với...code báo sai chỗ void main :(
#include <16f877a.h>
#FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT #device ADC=10 #use delay(clock=200000000) #byte portb=0x06 #byte porta=0x05 #byte portd=0x08 #bit d0=portd.0 #bit d1=portd.1 #use fast_io(a) #use fast_io(b) #use fast_io(d) int8 const LED[]={0xc0,//0 0xc0,//0 0xf9,//1 0xa4,//2 0xb0,//3 0x99,//4 0x92,//5 0x83,//6 0xf8,//7 0x80,//8 0x98,//9 } void main() { int i; int8 x,read,hangchuc,hangdonvi; setup_adc(ADC_CLOCK_INTERNAL); setup_adc_ports(AN0_AN1_VREF_VREF); set_adc_channel(0); delay_us(10); while(1) { x= read_adc(); x= (int16) ((float)read_adc() * 500/1024); read=x; hangchuc=read/10; hangdonvi=read%10; for(i=0;i<=99;i++) { output_low(d0); output_b(LED[hangchuc]); delay_ms(10); output_low(d1); output_b(LED[hangdonvi]); delay_ms(10); } } } |
![]() |
![]() |
![]() |
|
|