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

Require to code DS1820 with rfpic12F675

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



Joined: 02 May 2006
Posts: 3

View user's profile Send private message

Require to code DS1820 with rfpic12F675
PostPosted: Tue May 02, 2006 11:32 am     Reply with quote

Hi every body,
I'm a new user in PIC. I am trying to use the DS1820 temperature sensor to measure temperature connect to rfpic12F675.
I want to read the temperature and show the results on Hypertyminal
[/b]
sodapopeiei



Joined: 02 May 2006
Posts: 3

View user's profile Send private message

my code ds1820
PostPosted: Wed May 03, 2006 5:06 am     Reply with quote

please check my code ds1820. it doesn't show the results on Hypertyminal . i doesn't understand.


#include <12F675.h>
#use delay(clock=4000000)
#fuses NOWDT,INTRC
#use rs232(baud=9600,xmit=PIN_A2,rcv=PIN_A3)
#define Sensor PIN_A0

int Sensor_Reset(void);
int Sensor_Write(int data);
void Sensor_read(void);
int Temp_H[8],Temp_L[8],i;

void main(){
int temp;
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
printf("\r\nWaiting for a Sensor...\r\n");
while (TRUE) {
while(!Sensor_Reset()) ;
Sensor_Write(0xCC);
Sensor_Write(0x44);
delay_ms(200);
if(Sensor_Reset()){
Sensor_Write(0xCC);
Sensor_Write(0xBE);
Sensor_read();

temp=((Temp_H[0]*64)+(Temp_H[1]*32)+(Temp_H[2]*16)+(Temp_H[3]*8)+(Temp_H[4]*4)+(Temp_H[5]*2)+(Temp_H[6]*1)+(Temp_H[7]?0.51:0.01));
printf("\n\rTemp: %d C\n\r",Temp);
// printf("\n\rTemp: %2.1f C%d%d%d%d%d%d%d%d\n\r",(Temp_L[7]?(-1*Temp):Temp),Temp_L[0],Temp_L[0],Temp_L[2],Temp_L[3],Temp_L[4],Temp_L[5],Temp_L[6],Temp_L[7]);
delay_ms(1000);
}
}
}

int Sensor_Reset(void){
int present;
output_low(Sensor);
delay_us(500);
output_float(Sensor);
delay_us(5);
if(!input(Sensor))
return(FALSE);
delay_us(65);
present=!input(Sensor);
delay_us(240);
if(present)
return(TRUE);
else
return(FALSE);
}


int Sensor_Write(int data){
for(i=1;i<=8;++i){
output_low(Sensor);
delay_us(10);
if(shift_right(&data,1,0)){
output_high(Sensor);
delay_us(10);
}
else{
output_low(Sensor);
delay_us(10);
}
delay_us(50);
output_high(Sensor);
delay_us(50);
}
return(TRUE);
}

void Sensor_read(void){
for(i=0;i<8;i++) {
output_low(Sensor);
delay_us(14);
output_float(Sensor);
delay_us(5);
Temp_H[7-i]=input(Sensor);
delay_us(100);
}
}
Storic



Joined: 03 Dec 2005
Posts: 182
Location: Australia SA

View user's profile Send private message Send e-mail

PostPosted: Wed May 03, 2006 4:05 pm     Reply with quote

Are you getting any thing on hyperterminal. ie ("Temp:" )

ANdrew
_________________
What has been learnt if you make the same mistake? Wink
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