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 09-08-2012, 09:29 PM   #1
loveboom3012
Đệ tử 1 túi
 
Tham gia ngày: Jun 2011
Bài gửi: 18
:
Xem giúp mình lỗi code cho lm35 này với

Code:
#include <16f877a.h>
#include <def_877a.h>
#device ADC=10
#fuses nowdt,noprotect,nolvp,hs
#use delay(clock=20000000)
const unsigned char ma7[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
int16 kqadc;
int dem,dv,ch,tr,ng,i;
unsigned char mdv,mch,mtr,mng;
void giaima7doan(int16 tam)
{
	ng=tam/1000;
	tam=tam%1000;
	tr=tam/100;
	tam=tam%100;
	ch=tam/10;
	dv=tam%10;
	mng=ma7[ng];
	mtr=ma7[tr];
	mch=ma7[ch];
	mdv=ma7[dv];
	mch=mch&0x7f;
}
//hien thi quet led
void hienthi()
{
	for(i=0;i<=30;i++)
	{
	output_d(mdv);	output_low(pin_b2);	delay_us(100);	output_high(pin_b2);
	output_d(mch);	output_low(pin_b3);	delay_us(100);	output_high(pin_b3);
	output_d(mtr);	output_low(pin_b4);	delay_us(100);	output_high(pin_b4);
	output_d(0x9c); output_low(pin_b1);	delay_us(100);	output_high(pin_b1);
	output_d(0xc6);	output_low(pin_b0);	delay_us(100);	output_high(pin_b0);	
}
}
void main()
{
	set_tris_A(0b00000001);
	set_tris_D(0x00);
	set_tris_b(0x00);
//	set_tris_C(0x00);
	output_b(0xff);
	setup_ADC(ADC_clock_div_32);
	setup_adc_ports(AN0);
	set_adc_channel(0);
	while(1)
		{
			kqadc=4.887*read_adc();
			giaima7doan(kqadc);
				hienthi();
			if(kqadc>40)
				{
					output_high(pin_c0);
				}
			else
				{
					output_low(pin_c0);
				}	
		
		}
}
theo ý mình coded thì khi nhiệt độ quá 40 độ thì pin RC0 lên mức high, dưới 40 độ thì mức low , nhưng khi mô phỏng thì nhiệt độ chưa tới 40 pin RC0 đã lên mức high rồi, xem giúp mình với !hình đã đính kèm
Hình Kèm Theo
File Type: png picture002.png (53.8 KB, 3 lần tải)
loveboom3012 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:12 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