sirbill
Newbie level 1
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
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;
}