CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

DS1620

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest
Guest







DS1620
PostPosted: Fri Mar 24, 2006 8:29 am     Reply with quote

Hi everyone,

I am having some difficulty and i was hoping someone may be able to help.

I am reading a temperature using a DS1620 chip and the PIC16f877 - i am using rs232 to output the value and viewing it using hyperterminal - the output i am getting is quite riduculous - it is saying the temperature is 511??? Shocked

If anyone can offer any advice this would be great beacause this problem has me stumped!!

My code is listed below:

#include <16f877.h>
#device ADC=10
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
# use delay (clock = 4000000)
#use rs232(baud=9600,xmit=PIN_C6, rcv=PIN_C7,parity=N,stream=PC)
#fuses XT,NOWDT,NOPROTECT,PUT,NOLVP
#byte PORTC = 7
#byte PORTA = 5
#bit DQ = PORTA.3
#bit CLK = PORTA.2
#bit RST = PORTA.1

void DS1620_write(unsigned int Data)
{

unsigned int i;
set_tris_a(0xF1); /*Set TRISA to Pattern 11110001 */
CLK = 1;
for (i=1; i<=8; i++)
{
DQ = (Data & 1);
CLK = 0;
CLK = 1;
Data = Data >> 1;
}
}

long DS1620_read(void)
{
long Data;
long Temp;
int i;
set_tris_a(0xF2); /*Set TRISA to Pattern 11110010 */
CLK = 1;
Data = 0;
Temp = 1;
for (i=1; i<=9; i++)
{
CLK = 0;
if (DQ == 1) Data += Temp;
Temp = Temp * 2;
CLK = 1;
}
RST = 0;
return(Data);
}

void main()
{
while(1)
{
long temperature = 0;
setup_adc_ports(NO_ANALOGS);
RST = 0;
delay_us(10);
RST = 1;
DS1620_write(0xEE);
delay_ms(750);
DS1620_write(0xAA);
temperature = DS1620_read();
delay_ms(750);
fprintf(PC, "\n\rTemperature = %ld", temperature);
delay_ms(5000);
}
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 24, 2006 2:59 pm     Reply with quote

Have you looked at sample drivers ?
I found these quickly with http://www.google.com

Compare your code to these drivers and look for differences.
http://www.phanderson.com/printer/ds1620/ds1620.html
http://www.rentron.com/CCS_C/SERLED_C.htm
http://www.piclist.com/images/boards/temp-hum/code/lcd.c
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri Mar 24, 2006 3:50 pm     Reply with quote

I don't know the DS1620 but I had a quick look at your code and noticed some oddities.
Code:
long DS1620_read(void)
{
long Data;
long Temp;
int i;
set_tris_a(0xF2); /*Set TRISA to Pattern 11110010 */
CLK = 1;
Data = 0;
Temp = 1;
for (i=1; i<=9; i++)
{
CLK = 0;
if (DQ == 1) Data += Temp;
Temp = Temp * 2;
CLK = 1;
}
RST = 0;
return(Data);
}

1) By calling set_tris_a(0xF2) you make the RST line an input, but at the end of the function you set RST=0 which suggests you want it to be an output. In DS1620_write() you use the value 0xF1 which is more likely what you intended.
2) You don't have a set_tris_a() at the start of your main so there is a good chance your reset toggle isn't working. You only need to call set_tris_a() once in your program, calling it multiple times only makes it more difficult to maintain your program (see the error of point 1)
3) Your direction of shifting bits in is the inverse of the direction you are shifting bits out in the DS1620_write function. Most likely the direction used in DS1620 is the correct direction.
4) You set RST-0 at the end of the function but you didn't set it 1 to start with.

This was just to start with, very likely there are more issues. I suggest you give your code another serious inspection.
Guest
Guest







PostPosted: Mon Mar 27, 2006 11:14 am     Reply with quote

Many Thanks- have got this up and running.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group