|
Tài trợ cho PIC Vietnam |
PIC - Thiết kế và Ứng dụng Ý tưởng cho các sản phẩm sử dụng PIC/dsPIC và các sản phẩm của Microchip |
|
Ðiều Chỉnh | Xếp Bài |
28-03-2011, 12:04 AM | #7 |
Đệ tử 6 túi
|
//Đo nhiệt đô hiển thị lên LCD và cảnh báo ở ngưỡng 50 oC//
//Phần cứng như sau: porte:chân điều khiển portb:xuất data RA0:ngõ vào analog(từ LM35) RA1:xuất cảnh báo #include <16f877a.h> #fuses nowdt,noprotect,nolvp,put,hs #use delay(clock=4000000) #byte portb=0x6 #byte porte=0x9 #bit e=0x9.0 #bit rs=0x9.1 #bit rw=0x9.2 int i,x; char mang[]="nhiet do :"; void lenh() { rs=0;rw=0;e=1;e=0; delay_ms(5); } void xuat() { e=1;rs=0;rw=0;e=0; delay_ms(5); } void khoitao() { portb=0x1;lenh(); //xoa LCD portb=0x38;lenh(); //hien thi 2 dong portb=0x0e;lenh(); //bat hien thi portb=0x02;lenh(); //dua con tro ve dau dong// } void doc_ADC() { setup_ADC(ADC_clock_internal); stup_ports(AN0); set_channel(0); delay_ms(1); } void main() { set_tris_a(0b01); set_tris_b(0); set_tris_e(0); khoitao(); for(i=0;i<12;i++) { portb=mang[i]; xuat(); delay_ms(5); } while(1) { doc_ADC(); X=read_ADC(); X=X*2.049 //ADC 10bit & LM35// portb=0x89;lenh();//dua con tro LCD toi vi trí sau chu nhiet do: //ban nen xem lai lenh nay..ko biet co dung vi tri ko nua~. portb=x;xuat(); //canh bao// if(x>50) { RA1=1 // } else { RA1=0;// } }} Trong LCD có ký hiệu "oC" bạn chỉ việc portb=0b00101110;xuat(); //bạn tham khảo thêm bảng mã LCD// Chúc bạn thành công. |
|
|