Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

AT89C51 Digital Thermometer with LCD - help with code in C

Status
Not open for further replies.

dallurajan

Newbie level 1
Joined
Oct 9, 2009
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
kathmandu
Activity points
1,287
help plz

i am doing project on the digital thermometer using LM 35, ADC 0804, AT89C51 and LCD . plz help me with the source code in C.
 

help plz

Pseudocode is as follows in the description:
First: Amplify and adjust LM35 resolution to your ADC resolution (lm35 resolution is 10mV/ºC)


1 - Set system frequency of your microcontroller (using your PLL Module if you have it)
2 - Set ADC to the channel that you want is really simple if you use it a microcontroller with adc.
3 - Read samples every "n" msec
4 - Convert ADC value to temperature using its resolution, i.e. if my ADC and sensor are amplified to couple the same resolution (i will use 20mV/C) then a 320mV are 16ºC if my adc is 5V max and i have my adc value is 0x10... my equation would be-
T = ADCvalue
5 - You must use a Hex to dec routine to display on your LCD
 

May be this sample program can help you:
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();
 }
}
 

hi
here is the code in for digital thermometer using microcontroller

//Program to make a digital thermometer with display in centigrade scale

Code:
#include<reg51.h>
#define port P3
#define adc_input P1
#define dataport P0
#define sec 100
sbit rs = port^0;
sbit rw = port^1;
sbit e = port^2;

sbit wr= port^3;
sbit rd= port^4;
sbit intr= port^5;

int test_intermediate3=0, test_final=0,test_intermediate1[10],test_intermediate2[3]={0,0,0};

void delay(unsigned int msec )
{
int i ,j ;
for(i=0;i<msec;i++)
  for(j=0; j<1275; j++);
}

void lcd_cmd(unsigned char item)  //Function to send command to LCD
{
dataport = item;
rs= 0;
rw=0;
e=1;
delay(1);
e=0;
return;
}

void lcd_data(unsigned char item) //Function to send data to LCD
{
dataport = item;
rs= 1;
rw=0;
e=1;
delay(1);
e=0;
//delay(100);
return;
}

void lcd_data_string(unsigned char *str)  // Function to send string to LCD
{
int i=0;
while(str[i]!='\0')
{
  lcd_data(str[i]);
  i++;
  delay(10);
}
return;
}

void shape()     // Function to create the shape of degree
{
lcd_cmd(64);
lcd_data(2);
lcd_data(5);
lcd_data(2);
lcd_data(0);
lcd_data(0);
lcd_data(0);
lcd_data(0);
lcd_data(0);
}
     
void convert()    // Function to convert the values of ADC into numeric value to be sent to LCD
{
int s;
test_final=test_intermediate3;
lcd_cmd(0xc1); 
delay(2);
lcd_data_string("TEMP:");
s=test_final/100;
test_final=test_final%100;
lcd_cmd(0xc8);
if(s!=0)
lcd_data(s+48);
else
lcd_cmd(0x06);
s=test_final/10;
test_final=test_final%10;
lcd_data(s+48);
lcd_data(test_final+48);
lcd_data(0);
lcd_data('c');
lcd_data(' ');
delay(2);
}

void main()
{
int i,j;
adc_input=0xff;
lcd_cmd(0x38); 
lcd_cmd(0x0c);  //Display On, Cursor  Blinking
delay(2);
lcd_cmd(0x01);  // Clear Screen
delay(2);

while(1)
{
  for(j=0;j<3;j++)
  {
   for(i=0;i<10;i++)
   {
    delay(1);
    rd=1;
    wr=0;
    delay(1);
    wr=1;
    while(intr==1);
    rd=0;
    lcd_cmd(0x88);
    test_intermediate1[i]=adc_input/10;
    delay(1);
    intr=1;
   }
   for(i=0;i<10;i++)
   test_intermediate2[j]=test_intermediate1[i]+test_intermediate2[j];
  }

test_intermediate2[0]=test_intermediate2[0]/3;
test_intermediate2[1]=test_intermediate2[1]/3;
test_intermediate2[2]=test_intermediate2[2]/3;
test_intermediate3=test_intermediate2[0]+test_intermediate2[1]+test_intermediate2[2];
shape();
convert();
}
}
you can also check this link out for **broken link removed**
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top