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.

Problem with 89s52 and ds1621 interface

Status
Not open for further replies.

rvs

Junior Member level 1
Joined
May 10, 2012
Messages
17
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,440
Friend of mine is having problem with interfacing 89s52 and ds1621 temperature sensors. He took this diagram https://www.8051projects.info/circuit.asp?im=data&desc=PC-BASED-DATA-LOGGER-(AT89S52-+-VB) and changed LED segments to LCD. Added programming port (but that is not relevant).
He got LCD showing text and numbers, that he wrote (he took some codes from Internet for that), but can't get it showing temperature.

Original code is in here
View attachment Logger.txt

His diagram is here
**broken link removed**

All help is welcome!
 

This project is located here, and working fine :

https://www.8051projects.info/proj.asp?ID=52

Data.zip file contains PC software writen in VB and original source code in assembler.

data1.GIF
 

Attachments

  • data.zip
    69.4 KB · Views: 86

We know, that it works fine with LED segments. But we have to use LCD screen and we can't figure out, how to alter original code so that instead of sending data to LED segments it would send it to LCD.
 

In this school project we were told to take a working program from Internet and edit it a bit and then make it work. Our teacher can't help us, because he doesn't know anything about these things, so we have to find out everything on our own.

We made this code, but it still isn't showing temperature. It shows '-1'. We added two resistors 4K7 - one between supply power and first pin and supply power and second pin of ds1621.
Code:
#include<stdio.h>
#include<string.h>
#include<Regx52.h>

int temperature;
#define HIGH 0x01 // Active High Signal
#define LOW 0x00 // Active Low Signal
#define TRUE 0x01 // Active High State
#define FALSE 0x00 // Active Low State





void ready(void);
void command(int);
void display(char *);
void i2c_stop (void);
void i2c_start (void);
void i2c_write (unsigned char);
unsigned char i2c_read (void);
void convert (unsigned char);


#define DATA P1_6 // Serial data
#define CLOCK P1_7 // Serial clock



void main (void)
{
int tmp;
char str[16];
bit flag = FALSE;
unsigned char ch;
void command (int);
void display (char *);
command(0x3c);
command(0x0c);
command(0x06);
while(1)
{
i2c_start();
i2c_write(0x90);
i2c_write(0xEE);
i2c_stop();
i2c_start();
i2c_write(0x90);
i2c_write(0xAA);
i2c_start();
i2c_write(0x91);
ch = i2c_read();
//ch=0x31;
i2c_stop();
temperature = 0;
convert(ch);


 if(flag == FALSE)
{
flag = TRUE;
tmp = temperature;
}

else
{
if(tmp != temperature)
{
tmp = temperature;
}  

sprintf(str,"%s%d%s","T:",tmp," Kraadi");
command(0x01);
command(0x80);
display(str);
}
}
}



	void command(int a)
{
void ready(void);
ready();
P0=a;
P3_6=0x00;
P3_5=0x00;
P3_7=0x01;
P3_7=0x00;
}












void display(char *str)
{
unsigned int i;
for(i=0;i<=strlen(str)-1;++i)
{
if(i == 16)
command(0xc0);
if(i == 32)
command(0x80);
ready();
P0 = str[i];
P3_6 = 0x01;
P3_5 = 0x00;
P3_7 = 0x01;
P3_7 = 0x00;
}}


void ready(void)
{
P3_7=0x00;
P0=0xff;
P3_6=0x00;
P3_5=0x01;
while(P0_7)
{
P3_7=0x00;
P3_7=0x01;
}
P3_7=0x00;
}


//Delay Servive Routine
void delay_time (void)
{
unsigned int i;
for(i=0;i<100;i++);
}



void i2c_start (void)
{
DATA = HIGH;
delay_time();
CLOCK = HIGH;
delay_time();
DATA = LOW;
CLOCK = LOW;
}
//I2C Stop Function
void i2c_stop (void)
{
unsigned char i;
CLOCK = LOW;
DATA = LOW;
CLOCK = HIGH;
delay_time();
DATA = HIGH;
i = DATA;
}
//I2C Data Write Function
void i2c_write (unsigned char j)
{
unsigned char i;
for(i=0;i<8;i++)
{
DATA = ((j & 0x80) ? 1 : 0);
j <<= 1;
CLOCK = HIGH;
delay_time();
CLOCK = LOW;
}
i = DATA;
CLOCK = HIGH;
delay_time();
CLOCK = LOW;
}
//I2C Data Read Function
unsigned char i2c_read (void)
{
unsigned char i,j;
j = 0;
i = DATA;
for(i=0;i<8;i++)
{
j <<= 1;
CLOCK = HIGH;
j |= DATA;
delay_time();
CLOCK = LOW;
}
return j;
}
//Binary to Decimal Conversion Function
void convert (unsigned char ch)
{

char x;

unsigned char arr[8]={128,64,32,16,8,4,2,1};

if(((ch & 0x80) ? 1 : 0)==0)
{
for(x=0;x<8;++x)
{
if(((ch & 0x80) ? 1 : 0))
temperature = temperature + arr[x] * ((ch & 0x80) ? 1 : 0);
ch <<= 1;
}
}
else					
{
ch=~ch;
ch=ch+1;
for(x=0;x<8;++x)
{
if(((ch & 0x80) ? 1 : 0))
temperature = temperature + arr[x] * ((ch & 0x80) ? 1 : 0);
ch <<= 1;
}
temperature=-temperature;
}}

Can anyone tell me what are we doing wrong, it seems that 89s52 can't get any info from ds1621.
 

In zip file that tpetar gave, there was .a51 file, it shows multiple errors when we tried to make .hex file.
Undefinied symbol/lable: FLAGS (about 8 errors) - how should we define FLAGS?
Invalid instruction -> SCL_HIGH (about 6 errors) - how should we change that?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top