Help with AT89C51/AT89s52 system.

Status
Not open for further replies.

Vinod Krishnan

Newbie level 4
Joined
Jan 25, 2015
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
53
Hello friends,
1. Let me put it clearly. I am extremely new when it comes to embedded programming and using 8051 Controllers to make a project. I intend to make a project using AT89C51/S51/S52 Microcontrollers. I was wondering whether it is possible to buy a development board which can be directly programmed using USB and not a external programmer? If possible, Please provide a link so I can buy the same. (An Indian Link, preferably)
**broken link removed**
I found this link and I wanna know whether 89C52 can be directly programmed using this board.

2. Let us assume that I am using a sensor(say Ultrasonic or temperature) which senses a value. How can I print its value on my computer screen using an IDE(say Keil). Please help.!

3. In what way is Philips' P89V51RD2 different from the conventional ATMEL controllers. Is the programming syntax more or less the same? I even gathered that flash magic can be used to dump my code directly from a USB port rather than having the need for an External ISP programmer.
 

OKay, Thank you. But may I know how to interface both DS18B20 and an RF433 Module with my 89S52 Microcontroller board? Some informations or links to study on the same will be appreciated. I am new to this. Please help.

- - - Updated - - -

The main Problem I face is that, it seems both DS18B20 and RF433 use the same T1(pin 15). How to circumvent this problem.?
 

I don't think you need to use a timer output specifically to run a 1 wire device. 1 wire doesn't needs clocking. You can establish a communication with any I/O pin you like. However, if you use UART transmit pin for RF433 module, it will be easy for you.
You can google up for 1 wire protocol, check the wikipedia and read DS18B20 datasheet for 1 wire interfacing. ::Link::


I never used any 1 wire device, but based on the configuration you want, and by reading the datasheet it seems that you don't really have to read the ROM or write anything to the configuration register in the RAM. By default, DS18B20 is configured to 12 bit output, which is a good thing as it will give you highest possible resolution for temperature. So all you have to do is follow these steps:
1. Send a RESET pulse.
2. Check for a PRESENCE pulse.
3. Send Convert T [44h] command.
4. Wait for 1 second.
5. Repeat step 1 and 2, then send Read Scratchpad [BEh] command
6. Read first two 8 bits of serial data sequentially with LSB of byte 0.

That's it! Repeat this step with a specific interval, load those two 8bit data in Rn registers and transfer them via RF module. Make sure either the receiving end or the transmitting end divides the temperature data by 16 to convert it in Celsius.
 

Vinod,
89V51 is quite same as 89C51. There is no any change in programing sytex also so you can use assembly as well C language for your controller. You can also program your 89V51 through serial port also unlike 89C51 you need programer.
 

Thanks a lot, friends. Thank you Genovator, The Sensor is working excellently. and thanks dharithothi. I'll keep updating you all if at all I have more queries. Please do help.!
 

Well, Guys, I need some help here. I am stuck with coding the Temperature Sensor.
When it is coded according to the routine asked to follow in the data sheet, it works perfectly
Take a look at this code
Code:
 #include<REGX52.h>
#include<stdio.h>
#include<string.h>
#include<intrins.h>
unsigned char dat,
unsigned char readdata[2];
sbit DQ=P3^3;
unsigned char word1[16];
void init(void)
{
SCON = 0x52;
TMOD = TMOD|0x20;
TH1  = 0xfd;
TR1  = 1;
}
void delay(unsigned int i)	
{
while(i--);
} 

void msdelay(unsigned char d)
{
int i,j;
for(i=0;i<d;++i)
for(j=0;j<1275;++j)
	{}
}
void Init_DS18B20(void)
{
    unsigned char x=0;
    DQ = 1;    
    delay(8);  
    DQ = 0;    
    delay(80); 
    DQ = 1;    
    delay(14);
    x=DQ;      
    delay(20);
}
unsigned char ReadOneChar(void)
{
    unsigned char i=0;
    unsigned char dat = 0;
    for (i=8;i>0;i--)
    {
      DQ = 0; 
      dat>>=1;
      DQ = 1; 
      if(DQ)
      dat|=0x80;
      delay(4);
    }
    return(dat);
}
void WriteOneChar(unsigned char dat)
{
    unsigned char i=0;
    for (i=8; i>0; i--)
    {
      DQ = 0;
      DQ = dat&0x01;
      delay(5);
      DQ = 1;
      dat>>=1;
    }
    delay(4);
}
 void  ReadTemperature(void)
{
    Init_DS18B20();
    WriteOneChar(0xCC); 
    WriteOneChar(0x44); 
    Init_DS18B20();
    WriteOneChar(0xCC); 
    WriteOneChar(0xBE); 	
    readdata[0]=ReadOneChar();
    readdata[1]=ReadOneChar();
}
void Tempprocess() 
{
	unsigned char m;
    unsigned int t;
    float tt;
    unsigned char temp;
    if((readdata[1]&0x80)!=0)
    {
        word1[3]='-';
        t=readdata[1];
        t<<=8;
        t=t|readdata[0];
        t=t-1;
        t=~t;
        t>>=4;
        word1[4]=t/100+48;
        word1[5]=((t/10)%10)+48;
        word1[6]=t%10+48;
        temp=readdata[0];
        temp=temp-1;
        temp=~temp;
        temp=temp&0x0f;
        tt=temp*0.0625;
        word1[7]='.';
        word1[8]=(unsigned char )(tt*10);
        word1[9]=(unsigned char )(tt*100-word1[8]*10);
        word1[10]=(unsigned char )(tt*1000-word1[8]*100-word1[9]*10);
        word1[11]=(unsigned char )(tt*10000-word1[8]*1000-word1[9]*100-word1[10]*10);
        word1[8]+=48;
        word1[9]+=48;
        word1[10]+=48;
        word1[11]+=48;
        word1[12]='C';
 
    }
    else
    {
        word1[3]='+';
        t=readdata[1];
        t<<=8;
        t=t|readdata[0];
        t>>=4;
        word1[4]=t/100+48;
        word1[5]=((t/10)%10)+48;
        word1[6]=t%10+48;
        temp=readdata[0];
        temp=temp&0x0f;
        tt=temp*0.0625;
        word1[7]='.';
        word1[8]=(unsigned char )(tt*10);
        word1[9]=(unsigned char )(tt*100-word1[8]*10);
        word1[10]=(unsigned char )(tt*1000-word1[8]*100-word1[9]*10);
        word1[11]=(unsigned char )(tt*10000-word1[8]*1000-word1[9]*100-word1[10]*10);
        word1[8]+=48;
        word1[9]+=48;
        word1[10]+=48;
        word1[11]+=48;
        word1[12]='C';
    }
		
	  printf("Temperature : ");
		for(m=0;m<12;++m)
		printf("%c",word1[m]);
		printf(" °C\n");
}
 


void main(void)
{
init();
msdelay(100);
for(;;)
{
ReadTemperature();
msdelay(50);
Tempprocess();
msdelay(6000);
}
}
I am getting the temperature value topnotch. Perfectly.
Now my next work is to find the average of n samples taken at m times. So I intended to reduce the code length and tried this,
Code:
include<REGX52.h>
#include<stdio.h>
#include<string.h>
#include<intrins.h>
static float temp_process;
unsigned char dat;
unsigned char readdata[2];
sbit DQ=P3^3;
void init(void)
{
SCON = 0x52;
TMOD = TMOD|0x20;
TH1  = 0xfd;
TR1  = 1;
}
void delay(unsigned char i)	
{
while(i--);
} 
void msdelay(unsigned char d)
{
int i,j;
for(i=0;i<d;++i)
for(j=0;j<1275;++j)
	{}
}
unsigned char Init_DS18B20(void)
{
    DQ = 1;   
    delay(8);  
    DQ = 0;    
    delay(80); 
    DQ = 1;    
    delay(14);      
    return(DQ);
}
unsigned char ReadOneChar(void)
{
    unsigned char i=0;
    unsigned char dat = 0;
    for (i=8;i>0;i--)
    {
      DQ = 0; 
      dat>>=1;
      DQ = 1; 
      if(DQ)
      dat|=0x80;
      delay(4);
    }
    return(dat);
	}
void WriteOneChar(unsigned char dat)
{
    unsigned char i=0;
    for (i=8; i>0; i--)
    {
      DQ = 0;
      DQ = dat&0x01;
      delay(5);
      DQ = 1;
      dat>>=1;
    }
    delay(4);
}
void ReadTemperature(void)
{
    Init_DS18B20();
    WriteOneChar(0xCC); 
    WriteOneChar(0x44); 
    Init_DS18B20();
    WriteOneChar(0xCC); 
    WriteOneChar(0xBE); 
    readdata[0]=ReadOneChar();
    readdata[1]=ReadOneChar();
}
void tempprocess()
{
	  float a;
	  unsigned char m;
      unsigned int t;
    if((readdata[1]&0x80)!=0)
    {
    	t=readdata[1];
        t<<=8;
        t=t|readdata[0];
        t-=1;
        t=~t;
        t>>=4;
        m = readdata[0];
        m=m-1;
        m=~m;
        m=m&0x0f;
			  a = m*0.0625;
        temp_process+=(t+a);
    }
    else 
    {
    	t=readdata[1];
        t<<=8;
        t=t|readdata[0];
        t>>=4;
        m = readdata[0];
        m&=0x0f;
			   a = m*0.0625;
        temp_process+=(t+a);
    }
}
void main(void)
{
	unsigned char str[60];
	unsigned char i;
init();
msdelay(100);
for(;;)
{
	for(i=0;i<100;++i)
	{
ReadTemperature();
msdelay(50);
tempprocess();
msdelay(15000);
	}
	temp_process/=100;
	sprintf(str, "Average Value of temperature = %f \n", temp_process);
	puts(str);
}
}
But now, only 0.0625 is constantly printed. Please help. I would be very grateful
 

Well, I don't work with C language. So its hard for me to read your code. But looking to the result you are getting, it seems either your MCU isn't reading the temperature data, or isn't saving and evaluating it properly. The last 8 or 16bit raw data which is supposed to be divided by 16 is coming out 1 (because 0.0625 x 16 = 1). So you have to check your equation and also the registers you are using to save the raw data. One thing is sure that the temperature data isn't present in the equation. So results are coming out as a constant.
Another thing to be kept in mind is that if you are using DS18B20 in 12bit resolution you have to wait for ~750ms to generate one temperature data. Only then you can command it for recounting.
 
Last edited:

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…