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 CCS Technical Support

1Wire DS18S20- Scratchpad Problem

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







1Wire DS18S20- Scratchpad Problem
PostPosted: Tue Apr 26, 2005 12:16 pm     Reply with quote

Hi,

I have a problem witch the Scratchpad, it only shows ZEROS Confused
-I'm not using a Touch Sensor,
-and I have a seperat Tx and Rx Pin

-Can somebody help me with my little Program:

Code:

#include <16f870.h>

#use delay(clock=4000000)
#fuses XT,NOWDT,NOLVP

//DS1820 Commandos
#define SKIP_ROM           0xCC /* 204*/

#define CONVERT_T          0x44 /*68*/
#define READ_SCRATCHPAD    0xBE /*190*/

#define Rx_DS18S20 PIN_C4 // Rx TempSensor
#define Tx_DS18S20 PIN_C5 // Tx TempSensor

char D_Presence;
char D_ShortCircuit;

enum BITSTELLE { Bit0=1,BIT1=2,BIT2=4,BIT3=8,BIT4=16,BIT5=32,BIT6=64,BIT7=128 };

#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

int temp_1,temp_2;
long int null,eins;
int scratchpad[8];


void D_Reset(void)
{
   set_tris_c(0x99);
   output_low(Tx_DS18S20); // Pin des DS18S20 auf low setzen
   delay_us(480);
   output_high(Tx_DS18S20); // Pin des DS18S20 auf high setzen
   delay_us(40);
   D_Presence = input(Rx_DS18S20);
   delay_us(350);
   D_ShortCircuit = input(Rx_DS18S20);
   delay_us(60);
}

void temp_init()
{
   output_low(Tx_DS18S20);    // Pin des DS18S20 auf low setzen
   delay_us(480);             // 480us warten
   while (input(Rx_DS18S20)); // pruefen ob der 1-wire bus auf low gezogen wird,
   delay_ms(5);
}

void temp_send(unsigned char code)
{  int n=0;

   for(; n < 8; n++)
   {  if(bit_test(code,n))
      {
         output_low(Tx_DS18S20); //sende 0
         delay_us(2); //int write slot
         output_high(Tx_DS18S20); //send 1
      }
      else
      {
         output_low(Tx_DS18S20); //sende 0
      }
      delay_us(65); //duration für 1 und fertig
      output_high(Tx_DS18S20);
      delay_us(2);
   }
   delay_us(100); //1 Millisekunde
}

unsigned char temp_read(void)
{  unsigned char in=0,j=0;

   delay_us(400);
   for(; j < 8; j++)
   {
      delay_us(1);
      output_low(Tx_DS18S20); // init read
      delay_us(3);
      if (input(Rx_DS18S20)) bit_set(in,j);
      delay_us(60);
   }
   return(in);
}


void main()
{  int i;

   printf("Hallo\r\n");

   D_Reset();
   printf("Presence:%d  ShortCircuit:%d\r\n",D_Presence,D_ShortCircuit);

   while(1)
  {   temp_init();
      temp_send(SKIP_ROM);
      temp_send(CONVERT_T);
      delay_ms(500);              //warten bis Temp Convert abgeschlossen ist...

      temp_send(SKIP_ROM);
      temp_send(READ_SCRATCHPAD);
     
      for (i=0; i<8;i++)
      {  scratchpad[i] = temp_read();
         printf("i:%d/v:%d %d %d",i,scratchpad[i],D_Presence,D_ShortCircuit);
      }

      printf("Temperatur: %d, %02u C\r\n",temp_2,temp_1);
      delay_ms(500);
   }
}



THANK YOU so much Exclamation
Almeida
Guest







erro
PostPosted: Mon Oct 09, 2006 10:03 am     Reply with quote

My friend, the ds18s20 have one port to TX and RX, (PIN_2 from DS18S20).
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