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 DS1620 + PIC16F887.

Status
Not open for further replies.

sirbill

Newbie level 1
Joined
Jul 9, 2012
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,288
Dear all,

I got a riddiculous problem with DS1620 and PIC 17F887. When I use PIC C Compier, the code I provided below work well, no problem. However, when I use MikroC, after I download the same code to 16F887, nothing happens. It seems that DS1620 does not work when I compile my code by MikroC. In my code, there is nothing special, just work with ports and that all. I wonder what I have to configure or something like that to make MikroC compile my code correctly.

Please help me, thank
Code:
//#include <16F887.h>
//#include <def_887.h>
//#fuses HS,WDT,NOPROTECT,NOLVP
//#use delay(clock = 12000000)
//#use fast_io (a)
//#use fast_io (b)
//#use fast_io (c)
//#use fast_io (d)
//#use fast_io (e)

//#bit DQ  = 0x08.7
//#bit CLK = 0x08.6
//#bit RST = 0x08.5
#define DQ   PORTA.F1
#define CLK  PORTA.F2
#define RST  PORTA.F3

int read_ds1620(void);
void write_ds1620(unsigned char data1);
void init_temp_ds1620(void);
int temperature, sign;

void main()
{
   TRISB = 0x00;
   init_temp_ds1620();
   while (1)
   {
   RST = 1;
   write_ds1620(0xAA);
   temperature = 0;
   temperature = read_ds1620();
   RST = 0;
   PORTB = temperature;
   //delay_ms(1000);
   }
}

int read_ds1620(void)
{
    int i = 0;
   TRISA = 0x02;
   temperature = 0;
   CLK = 1;
   for (i = 0; i <= 7; ++i)
   {
   CLK = 0;
   if (DQ == 1)
   temperature |= (1 << i);
   //temperature = (temperature << 1);
   CLK = 1;
   }
   CLK = 0;
   if (DQ == 1)
   sign = 1;
   else sign = 0;
   CLK = 1;
   return(temperature);
}

void write_ds1620(unsigned char data1)
{
           int i = 0;
   TRISA = 0x00;

   CLK = 1;
   for (i = 0; i <= 7; ++i)
   {
   DQ = (data1 & 0x01);
   CLK = 0;
   CLK = 1;
   data1 = (data1 >> 1);
   }
}

void init_temp_ds1620(void)
{
      RST = 1;                
      write_ds1620(0x0C);    
      write_ds1620(0x08);
      RST = 0;
      RST = 1;               
      write_ds1620(0xEE);    
      RST = 0;
}
 

hello, I am trying with difficulty as well to read a ds1620 to a pic 18f14k50 ... I did notice in your init_temp-ds1620 function that the second write_ds1620(0x08) ... I can't find 0x08 in the datasheet ... shouldn't it be write 0x0C then 0x00 then EE?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top