PIC Vietnam

Go Back   PIC Vietnam > Microchip PIC > Các ngôn ngữ lập trình khác (CCS C, HT PIC,...)

Tài trợ cho PIC Vietnam
Trang chủ Đăng Kí Hỏi/Ðáp Thành Viên Lịch Bài Trong Ngày Vi điều khiển

 
 
Ðiều Chỉnh Xếp Bài
Prev Previous Post   Next Post Next
Old 27-03-2012, 08:25 AM   #1
tranhungdhdt5
Nhập môn đệ tử
 
Tham gia ngày: Dec 2011
Bài gửi: 4
:
Unhappy 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
}
tranhungdhdt5 vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
 


Quyền Sử Dụng Ở Diễn Ðàn
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Mở
Smilies đang Mở
[IMG] đang Mở
HTML đang Tắt

Chuyển đến


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


Được sáng lập bởi Đoàn Hiệp
Powered by vBulletin®
Page copy protected against web site content infringement by Copyscape
Copyright © PIC Vietnam