|
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 |
04-05-2011, 09:06 AM | #3 |
Nhập môn đệ tử
Tham gia ngày: May 2011
Bài gửi: 8
: |
uhm, em đã post cả chương trình rùi mà!!! nhưng chương trình đó chưa có phần nút bấm! em đã làm nhưng phần chương trình đó của e ko chạy.em post lại chương trình này:
#include <16F877A.h> #include <def_877a.h> #device *=16 adc=10 #FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT,NOLVP, NOCPD, NOWRT #use delay(clock=20000000) #include <lcd_lib_4bit.c> // Thu vien ham cho LCD int8 low,high,min,max,i; int1 do_F; void convert_bcd(int8 x); #INT_EXT #define nut1 PIN_C2 #define nut2 PIN_C3 #define nut3 PIN_C4 void test() { if (do_F == 1) do_F=0; else do_F=1; } void banphim() { max =40; if (nut1 == 0) LCD_putcmd(0x01); LCD_putchar("nhap nhiet do:"); {if (nut2==0) max = max + 1; if (nut3 == 0) max = max - 1;} } //----------------------------------------------------------------- void main() { float value; min =0; //nhiet do mim // max =40; //nhiet do max do_F =0 ; i = 10 ; trisa = 0xFF; trisb = 0x01; output_low(pin_C0); output_low(pin_C1); LCD_init(); LCD_putcmd(0x01); LCD_putchar("do_nhiet_do:"); LCD_putcmd(0xC0); LCD_putchar("cho ty nhe ..."); //==== Khoi tao cho ngat ngoai============================================= == enable_interrupts (INT_EXT); ext_int_edge(H_TO_L); enable_interrupts (GLOBAL); //=========== Khoi tao che do cho bo ADC===================================== setup_adc_ports(AN0); setup_adc(ADC_CLOCK_INTERNAL); delay_us(10);// Lay mau nhiet do lan dau tien value=(float)read_adc(); value = (value - 558.5)/2.048; // For 5V supply // value = (value - 754.8)/2.048; // For 3.7V Supply // value = (value - 698.2)/2.048; // For 4V supply convert_bcd((int8)value); // Tach so tram, chuc, donvi de hien thi len LED 7 delay_ms(100); LCD_putcmd(0xC0); LCD_putchar("Ok "); delay_ms(100); while(1) { if (i==10) { value = read_adc(); value=(value-558.5)/2.048; if (do_F==1) value=1.8*value+32; convert_bcd((int8)value); LCD_putcmd(0xC0); printf(LCD_putchar,"Nhiet do la:"); LCD_putchar(high); LCD_putchar(low); if (do_F==0) printf(LCD_putchar," C"); else printf(LCD_putchar," F"); i=0; } if ( (int8)value <= max & min <=(int8)value) output_high(pin_C1); else output_low(pin_C1); if( ( (int8)value > max )|| ( (int8)value < min)) output_high(pin_C0); else output_low(pin_C0); i++; } } //The End=============================================== ======================== void convert_bcd(int8 x) { low=x%10; //chia lay phan du, so hang don vi high=x/10; //tach hang tram va hang chuc low = low + 0x30; high = high + 0x30; } phần chương trình con void ban_phim() ấy nó ko chạy mong mọi người giúp đỡ |
|
|