PIC Vietnam

PIC Vietnam (http://www.picvietnam.com/forum/index.php)
-   Các ngôn ngữ lập trình khác (CCS C, HT PIC,...) (http://www.picvietnam.com/forum/forumdisplay.php?f=12)
-   -   xin các bác giải thích giùm em đoạn code này ạ (http://www.picvietnam.com/forum/showthread.php?t=13649)

tranhungdhdt5 27-03-2012 08:25 AM

xin các bác giải thích giùm em đoạn code này ạ
 
#define nut_1 pin_b0
#define led_1 pin_c0
#define led_2 pin_c1
#define tang pin_c2
#define giam pin_c3
#define set pin_c4
#define output_led_1(x) output_bit(led_1, x) // Lenh dieu khien chan led_1
#define output_led_2(x) output_bit(led_2, x) // Lenh dieu khien chan led_2
// Chuong trinh chinh.
void main (void)
{
//khai bao bien
int8 value; //bien chua gia tri cua bo ADC 8 bit
int8 error;
int8 count;
int8 tam; //bien xac dinh nhiet do C va do F
int8 tam1;
float t_max_f; //bien chua gia tri set nhiet do max
int8 t_max_c; //bien chua gia tri set nhiet do max
float do_f;
int8 do_c;

AD_Init();
error=3; //nhiet do sai so
lcd_init(); // Khoi dong C.LCD 2x16.
tam=0;
count=0;
lcd_gotoxy(1,1);
lcd_putc("THAM KHAO");
while(1)
{
// output_led_1(1);
// output_led_2(0);
//kiem tra xem co chuyen tu do C sang do F
if(!input(nut_1))
{
delay_ms(100);
tam1=input(nut_1);
}
else
tam1=1;
if(tam1==0&&tam==0)
tam=1;
else if(tam1==0&&tam==1)
tam=0;


value=read_adc();
do_c = value*2+error;
do_f = do_c*1.8+32;
lcd_gotoxy(1,1);
if(tam==1)
printf(lcd_putc,"Nhiet do:%5.0fF",do_f);
else
printf(lcd_putc,"Nhiet do:%5dC",do_c);
delay_us(20);

if (!input(set)) //kiem tra nut nhan set nhiet do max
{
delay_ms(100);
do
{
if (!input(tang))
{
count++; //tang nhiet do max 1 do
delay_ms(100);
}
else
{
if (!input(giam))
count--; //giam nhiet do max 1 do
delay_ms(100);
}
lcd_gotoxy(1,1);
if (tam==1)
{
t_max_f=count;
printf(lcd_putc,"Nhiet do:%5.0fF",t_max_f);
delay_us(20);
}
else
{
t_max_c=count;
printf(lcd_putc,"Nhiet do:%5dC",t_max_c);
delay_us(20);
}

}
while (input(nut_1));
delay_us(20);
}
// kiem tra va set trang thai led 1 va led 2
if (do_c<=t_max_c)
{
output_led_1(0);
output_led_2(0);
}
else
{
output_led_2(0);
output_led_1(1);
}
}
}
//ham adc
void AD_Init(void) //initialize A/D converter
{
setup_adc_ports(sAN0); //set analog input ports: A0,A1,A3
setup_adc(ADC_CLOCK_INTERNAL); //using internal clock
set_adc_channel(0); //input Analog at pin A0
delay_us(20); //sample hold time
}

qloi 15-04-2012 09:42 PM

Đây là code đo nhiệt độ có kiểm soát thôi mà. từng dòng đã có giải thich rồi.chổ nào không hiểu thì bạn có thể hỏi mình


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

Tên diễn đàn: vBulletin Version 3.8.11
Được sáng lập bởi Đoàn Hiệp.
Copyright © PIC Vietnam