PIC Vietnam

Go Back   PIC Vietnam > Robotics > Điều khiển

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 khiển Lý thuyết điều khiển và ứng dụng lý thuyết điều khiển trong những trường hợp thực tế

 
 
Ðiều Chỉnh Xếp Bài
Prev Previous Post   Next Post Next
Old 29-06-2007, 10:50 AM   #1
thanhhai18
Nhập môn đệ tử
 
Tham gia ngày: Apr 2007
Bài gửi: 2
:
giai thich cho minh voi

minh co chuong trinh nay ma khong tung dong lenh y nghia ra sao

Code:
#include <reg52.h>
#include <stdio.h>

void timer0int(void);
char *Puts(char* str);

float read_temp1(void);
float read_temp1_filter(void);


char cputick;
char buffer[24];
char pulseE;

char timer3;
char temp;
char vout;
int x1,x2,x3,x4,x5;

sbit RS=P1^6;
sbit E =P1^4;
sbit RW=P1^5;

sbit CLK=P1^2;
sbit Data=P1^1;
sbit CS=P1^3;

sbit CHG=P3^0;

int readADC(char n)
{
	int k;
	char i,channel;
	k=0;

	CS=0;

	if(n==0) channel= 0x0d;
	else channel=0x0f;

	for (i=0;i<4;i++)
	{
		CLK = 0;

		if(channel&8) Data =1;
		else Data = 0;
		CLK =1;
		channel <<=1;
	}

	Data = 1;
	CLK =0;

	for(i=0; i<12;i++)
	{
		k<<=1;
		CLK =1;
		CLK=0;
		if(Data) k|=1;
		else k &=~1;
	}
		CS =1;

		return k&=0xfff;
}


void timer0int(void) interrupt 1 using 1

{
 TH0 |=0xdc;
 cputick++;
}


pause(int j)
{ int i;
  for (i=0;i<j;i++)
  continue;
}


pulesE()
{
  E =1;
    ;
  E =0;
 }


void delay(int m)
{
	int j;
	for(j=0;j<=m;j++)
	continue;
}

LCDWI (char n)
{   
  RW =0;
  RS=0;
  E =0;
  P0=n;
  E =1;
  E =0;
  pause(50);
}


LCDWD(char n)
{
  RW=0;
  RS=1;
  E=0;
  P0=n;
  E=1;
  E=0;
  pause(50);
}

print_LCD(char a,char *s)
{
LCDWI(a);
while(*s != 0)
LCDWD(*s++);
}


i_LCD()
{
  RS=0;
  E=0;
  P0=0x30;pulesE();delay(10);pulesE();delay(1);pulesE();delay(1);
  P0=0x20;pulesE();pulesE();pulesE();
  LCDWI(0x38);
  LCDWI(0x0c);
  LCDWI(0x06);
  LCDWI(1);
  delay(50);
}

print_ADC()
{
 char buffer[20];
 if(++timer3<50)
 {
  timer3=0;
  sprintf(buffer,"%0.1fC   %0.1fF",read_temp1_filter(),read_temp1_filter()*9/5+32);
  print_LCD(0xc0,buffer);
  }
}

int low_pass_filter1(void)
{
	x5=x4;
	x4=x3;
	x3=x2;
	x2=x1;
	x1=readADC(0);
	return(x1+x2+x3+x4+x5)/5;
}

float read_temp1_filter(void)
{
	return(0.0323*low_pass_filter1()-15.615);
}


void main()
{
 i_LCD();
 print_LCD(0x80,"LCD Thermometer");
 TMOD |= 0x01;
 TR0 = 1;
 cputick = 0;
 EA = 1;
 ET0 = 1;
 
  for(;;)
 {
	while(!TF0)
	continue;
	TF0=0;
	print_ADC();
 }
}
giup minh nha

thay đổi nội dung bởi: falleaf, 29-06-2007 lúc 03:11 PM.
thanhhai18 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à 12:19 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