PIC Vietnam

Go Back   PIC Vietnam > Microchip PIC > PIC - Thiết kế và Ứng dụng

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

PIC - Thiết kế và Ứng dụng Ý tưởng cho các sản phẩm sử dụng PIC/dsPIC và các sản phẩm của Microchip

 
 
Ðiều Chỉnh Xếp Bài
Prev Previous Post   Next Post Next
Old 26-09-2011, 09:24 PM   #2
anhhungne69
Nhập môn đệ tử
 
Tham gia ngày: Oct 2010
Bài gửi: 4
:
minh cung lam mach nhu z ma dung lap trinh ccs , minh cung da viet code nhung chay k

#include<16F877A.h>
#device *=16
#fuses HS,NOPROTECT,NOLVP, NOWDT, NOBROWNOUT,NOPUT
#USE delay(clock=2000000)
#define TOUCH_PIN pin_a0
#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 2byte du lieu to Scratchpad
touch_write_byte(0x33);// ghi 2 byte Trong
touch_write_byte(0x33);//
touch_write_byte(0x1f);// cau hinh cho thanh ghi nhiet do (do phan giai 9 bit)
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);
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 nho nhap
tam1=touch_read_byte();//doc 2 byte nhiet do
tam2=touch_read_byte();//doc 2 byte nhiet do
}
}
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,7))//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);
}
Hình Kèm Theo
File Type: png Untitled.png (46.3 KB, 17 lần tải)
anhhungne69 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à 11:11 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