View Single Post
Old 26-09-2011, 08:06 PM   #5
anhhungne69
Nhập môn đệ tử
 
Tham gia ngày: Oct 2010
Bài gửi: 4
:
xin sua giup , k biet loi o dau ma mach k chay dc

#include<16F877A.h>
#device *=16
#fuses HS,NOPROTECT,NOLVP,NOWDT,NOBROWNOUT,NOPUT
#USE delay(clock=2000000)
#define TOUCH_PIN pin_a3
#include<touch.c>
void hienthi(int8 a,int8 b,int8 c);
int8 const seg7[10]=
{0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90 };
//chuong trinh chinh
//========================
void main(){
int8 tam1=0,tam2,ss,i;
int8 led1,led2,led3;
int16 nd;
//cai dat chuyen doi nhiet do 9bit
//========================
touch_present();
touch_write_byte(0xcc);// phat lenh skip ROM
touch_write_byte(0x4e);// phat lenh ghi 3byte du lieu to Scratchpad
touch_write_byte(0x0);// ghi 2 byte rong
touch_write_byte(0x0);//
touch_present();
touch_write_byte(0xCC);// skip ROM
touch_write_byte(0x48);//Sao chep Sratchpad vao Eeprom
//====vong lap chuong trinh chinh=====/
while(TRUE){
do{
if(touch_present())
{
touch_write_byte(0xCC);// phat lenh skip ROM
touch_write_byte(0x44);//xuat lenh chuyen doi nhiet do
for(i=0;i<7;++i)
{
hienthi(led1,led2,led3);
}
touch_present();
touch_write_byte(0xCC);
TOUCH_WRITE_BYTE(0xBE);//lenh doc bo o nho nhap
tam1=touch_read_byte();//doc 2 byte nhiet do
tam2=touch_read_byte();
}
}
while(tam1==ss);// so sanh gia tri nhiet do doc duoc voi gia tri truoc do
ss=tam1;
//==chuyen doi nhiet do sang so thap nhan====
nd=make16(tam2,tam1);
nd=nd>>4;//dich phat 4 bit
nd=nd&0x0ff;//lay 8 bit thap
if(bit_test(nd,8))//neu gia tri nhiet do am
{
led3=10;//led3 hien thi dau""-""
nd=~(--nd);//lay bu 2 gia tri nhiet do
nd=nd&0x0ff;// xoa byte cao
}
else// neu gia tri nhiet do duong
{
led3=nd/100;//led3 hien thi so hang tram
nd=nd%100;
}
led2=nd/10;//led2 hien thi so hang chuc
led1=nd%10;//led1 hien thi so hang don vi
}
}
//chuong trinh hien thi_quet led===
void hienthi(int8 a,int8 b,int8 c)
{
output_B(seg7[a]);
output_low(pin_d7);
delay_ms(1);
output_high(pin_d7);
output_B(seg7[b]);
output_low(pin_d6);
delay_ms(1);
output_high(pin_d6);
output_B(seg7[c]);
output_low(pin_d5);
delay_ms(1);
output_high(pin_d5);
}
anhhungne69 vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn