![]() |
|
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 |
![]() |
#4 |
Đệ tử 2 túi
Tham gia ngày: Feb 2011
Bài gửi: 45
: |
đây là code của chương trình!
code[ // Mo ta phan cung : Dung PIC16F877A - thach anh 20MHz // : Led7seg giao tiep voi PORTD // : Dau ra LM335 dua vao chan AN0 //---------------------------------------------------------------- // Chu thich : // : dung che do Power On Reset // : chuong trinh tham khao cua anh linhnc308 //================================================= ======= #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) #define speak PIN_A1 #use fast_io(d) #byte portd=0x8 int8 low,high,min,max,i,j,low1,high1; int1 do_F; void convert_bcd(int8 x); const char led7seg[12]={0xC0,0xcf,0xa4,0xb0,0x99,0x92,0x83,0xf8,0x80,0x9 0,0x8e,0xc6}; const char quet[3]={0b00100000,0b01000000,0xb10000000}; #INT_EXT void test() { if (do_F == 1) do_F=0; else do_F=1; } //----------------------------------------------------------------- void main() { float value; min =15; //nhiet do min max =35; //nhiet do max do_F =0 ; i = 10 ; set_tris_d(0); trisa = 0xFF; trisb = 0x01; trisc=0x00; portd=0xff; output_low(speak); //==== 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(500); 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); if (do_F==0) { for(j=0;j<25;j++); { PORTD=led7seg[high1]; portc=quet[0]; delay_us(100); portd=0xff; delay_us(30); Portd=led7seg[low1]; portc=quet[1]; delay_us(100); portd=0xff; delay_us(30); portd=led7seg[11]; portc=quet[2]; delay_us(100); portd=0xff; delay_us(30); } } if (do_F==1) { for(j=0;j<25;j++); { PORTD=led7seg[high1]; portc=quet[0]; delay_us(100); portd=0xff; delay_us(30); Portd=led7seg[low1]; portc=quet[1]; delay_us(100); portd=0xff; delay_us(30); portd=led7seg[10]; portc=quet[2]; delay_us(100); portd=0xff; delay_us(30); } } i=0; } if( ( (int8)value > max ) || ( (int8)value < min) ) { output_high(speak); } i++; } } //The End=============================================== ======================== void convert_bcd(int8 x) { low1=x%10; //chia lay phan du, so hang don vi high1=x/10; //tach hang tram va hang chuc low = low + 0x30; high = high + 0x30; } ] thay đổi nội dung bởi: dinhnambkhn, 07-03-2011 lúc 04:56 PM. Lý do: nhầm |
![]() |
![]() |
|
|