Re: thermocouple to 8051
this is my code for data aquision...
#include <reg51.h>
sbit start=P3^3;
sbit end=P3^4;
sbit oe=P3^5;
sbit ale=P3^6;
sbit clock=P3^2;
sbit relay1=P1^3;
sbit relay2=P1^4;
sbit relay3=P1^5;
sbit relay4=P1^6;
unsigned char temp;
unsigned char aray[]={'0','1','2','3','4','5','6','7','8','9'};
void delay()
{
int k,l;
for(k=0;k<40;k++)
for(l=0;l<80;l++);
}
void initSerial()
{
TMOD=0x22;
TH1=0xFD;
SCON=0x50;
TR1=1;
EA=1;
ES=1;
}
void usDelay(int a)
{
TH0=256-(a/1.085);
TR0=1;
ET0=1;
}
void timerRoutine() interrupt 1
{
clock=~clock;
}
void sendChar(unsigned char ch)
{
SBUF=ch;
while(!TI);
TI=0;
}
void serialRoutine() interrupt 4
{
if(RI==1)
{
temp=SBUF;
switch(temp)
{
case('a'):
relay1=1;
break;
case('b'):
relay1=0;
break;
case('c'):
relay2=1;
break;
case('d'):
relay2=0;
break;
case('e'):
relay3=1;
break;
case('f'):
relay3=0;
break;
case('g'):
relay4=1;
break;
case('h'):
relay4=0;
}
RI=0;
}
}
void sendReading(unsigned char val)
{
unsigned char l,m;
l=val%10;
m=(val/10)%10;
sendChar(aray[m]);
sendChar(aray[l]);
sendChar(',');
}
void latch()
{
ale=0;
delay();
ale=1;
}
void startConv()
{
delay();
start=0;
delay();
start=1;
}
void wait()
{
while(end==1);
}
void get()
{
delay();
oe=0;
delay();
oe=1;
}
void main()
{
unsigned char sensor=0,reading;
P1=0;
initSerial();
usDelay(50);
while(1)
{
if(sensor==8)
sensor=0;
if(sensor==0)
sendChar('N');
P1=(P1&0xf8)+sensor;
latch();
startConv();
wait();
get();
reading=P2;
sendReading(reading);
sensor++;
}
}
i want to use j type thermocouple instead of lm35
then what changes i should make in circuit and code...
circuit changes as u said but code??
and
i thermocouple temperature ranges in 3 digits temperature
so i need to send 3 digits to max232
void sendReading(unsigned char val)
{
unsigned char l,m;
l=val%10;
m=(val/10)%10;
sendChar(aray[m]);
sendChar(aray[l]);
sendChar(',');
}
then what change should i make??