PIC Vietnam

Go Back   PIC Vietnam > Microchip PIC > Cơ bản về vi điều khiển và 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

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

Trả lời
 
Ðiều Chỉnh Xếp Bài
Old 04-05-2011, 11:32 AM   #1
thanhchung89
Nhập môn đệ tử
 
Tham gia ngày: May 2011
Bài gửi: 8
:
anh ơi xem hộ em với: chương trình em đã sửa như a nói nhưng mà vẫn ko chạy được a ơi
chương trình e sửa đây này a xem hộ em với nhé:
#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 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;
}

void banphim()
{ max =40;
set_tris_C(3);
set_tris_C(4);
set_tris_C(5);
while(1)
{if (pin_C2 == 0)
LCD_putcmd(0x01);
LCD_putchar("nhap nhiet do:");
{if (pin_C3==0)
max = max + 1;
if (pin_C4 == 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=============================================== ========================
thanhchung89 vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Trả lời


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à 05:33 AM.


Đượ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