View previous topic :: View next topic |
Author |
Message |
noobprogrammer
Joined: 20 May 2008 Posts: 5
|
hi all |
Posted: Thu May 22, 2008 12:43 am |
|
|
does anybody has the lcd.c file for this? |
|
|
meereck
Joined: 09 Nov 2006 Posts: 173
|
Re: hi all |
Posted: Thu May 22, 2008 12:13 pm |
|
|
noobprogrammer wrote: | does anybody has the lcd.c file for this? |
You can either use default CCS driver located in PICC/drivers folder, or you can use PCM Programmer's flexible LCD driver - http://ccsinfo.com/forum/viewtopic.php?t=24661 |
|
|
xokolatecake
Joined: 09 Mar 2007 Posts: 14
|
|
Posted: Wed Jun 04, 2008 9:15 am |
|
|
Hi!
Regarding scanan post, what does this little piece do?:
Code: | //for 10 bit resolution mod
onewire_write(0xCC);
onewire_write(0x4E);
onewire_write(125);
onewire_write(-55); //this should be done for proper working of DS18B20
onewire_write(127);
onewire_reset();
onewire_write(0xCC);
onewire_write(0x48);
delay_ms(15);
|
He issues a write scratchpad command, then sends the 3bytes and then copies the scratchpad to eeprom...what for?
And why it should be done for proper DS18B20 work?
I'm having trouble using a DS18B20, all it gives me is the power up state temperature reading: 0x0550->85ºdegrees. Any ideas of what the problem may be?
Code: |
#include <18F4525.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES HS //High speed Osc (> 4mhz)
#FUSES NOPROTECT //Code not protected from reading
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES BROWNOUT //Reset when brownout detected
#FUSES BORV21 //Brownout reset at 2.1V
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES LVP //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES NOPBADEN //PORTB pins are configured as digital I/O on RESET
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES MCLR //Master Clear pin enabled
#use delay(clock=20000000)
#use rs232(baud=115200, xmit=PIN_C6, rcv=PIN_C7, stream=PC)
//ds18b20 pin
#define DS18B20_IO PIN_A0
int1 ds18b20_initialization(void){
int1 ready;
output_low(DS18B20_IO);
delay_us(488); //min 480us
output_float(DS18B20_IO);
delay_us(72); //15 - 60us for device to respond
ready=!input(DS18B20_IO);
delay_us(424);
return ready;
}
void ds18b20_write_bit(int8 b){
output_low(DS18B20_IO);
if(b == 1){
delay_us(2); //min 1
output_float(DS18B20_IO);
}
delay_us(125);
output_float(DS18B20_IO);
}
void ds18b20_write_byte(int8 B){
int8 i, aux;
for(i=0; i<8; i++){
aux = B >> i; //aux equals B shifted i times to the right
aux &= 0x01; //least significant bit survives
ds18b20_write_bit(aux);
}
delay_us(120);
}
int1 ds18b20_read_bit(void){
output_low(DS18B20_IO);
delay_us(2); //min 1us
output_float(DS18B20_IO);
delay_us(8);
return(input(DS18B20_IO)); //next a delay of 60 to 120us must be done!
}
int8 ds18b20_read_byte(void){
int8 i, result=0x00;
for(i=0; i<8; i++){
if(ds18b20_read_bit())
result |= (0x01 << i);
delay_us(125);
}
return result;
}
void main() {
int8 i;
int8 scratchpad_data[9];
signed int16 temp=0x0000;
float temperature;
int8 busy =0;
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF|ADC_TAD_MUL_0);
setup_psp(PSP_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
setup_oscillator(False);
port_b_pullups(FALSE);
output_float(DS18B20_IO);
delay_ms(1000);
printf("DS18B20 1-wire temperature sensor\r\n");
while(1){
for(i=0; i<9; i++)
scratchpad_data[i]=0x00;
ds18b20_write_byte(0xCC);
ds18b20_write_byte(0x4E);
ds18b20_write_byte(125);
ds18b20_write_byte(-55); //this should be done for proper working of DS18B20
ds18b20_write_byte(127);
ds18b20_initialization();
ds18b20_write_byte(0xCC);
ds18b20_write_byte(0x48);
delay_ms(15);
if(ds18b20_initialization()){
ds18b20_write_byte(0xCC); //skip ROM command
ds18b20_write_byte(0x44); //convert temperature command
//output_float(DS18B20_IO);
delay_ms(800); //max conversion time for 12bit resolution=750ms
/*while (busy == 0){
printf("waiting...\r\n");
busy = ds18b20_read_byte();
}
busy=0;*/
ds18b20_initialization();
ds18b20_write_byte(0xCC); //skip ROM command
ds18b20_write_byte(0xBE); //read scratch pad command
for(i=0; i<2; i++){
scratchpad_data[i]=ds18b20_read_byte();
printf("scratchpad_data[%d]=%X\r\n", i, scratchpad_data[i]);
}
temp=make16(scratchpad_data[1], scratchpad_data[0]);
//temperature = temperature/16;
//calculate the whole number part
temperature = (temp >> 4) & 0x00FF;
//calculate the fractional part
if(temp & 0x0001) temperature = temperature + 0.06250;
if(temp & 0x0002) temperature = temperature + 0.12500;
if(temp & 0x0004) temperature = temperature + 0.25000;
if(temp & 0x0008) temperature = temperature + 0.50000;
printf("temperature reading: %7.3fdegrees C (%X%X)\r\n", temperature, scratchpad_data[1], scratchpad_data[0]);
}
else{
printf("DS18B20 failed to initialize\r\n");
}
delay_ms(5000);
}
} |
Thanks* |
|
|
xokolatecake
Joined: 09 Mar 2007 Posts: 14
|
|
Posted: Wed Jun 04, 2008 10:40 am |
|
|
Sorry guys!..i was so mad with the time i wasted on this i didn't noticed that i was using a DS18B20P, the (only) parasitic power version of DS18B20!
So my problem was not in the software but on the hardware, although i made a few adjustments to the delays duration and added the strong pull up control maxim recomends in the datasheet!
Will post the code for future reference. Again this is meant for DS18B20-PAR, don't make the same mistake i did!;P
Code: |
#include <18F4525.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES HS //High speed Osc (> 4mhz)
#FUSES NOPROTECT //Code not protected from reading
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES BROWNOUT //Reset when brownout detected
#FUSES BORV21 //Brownout reset at 2.1V
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES LVP //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES NOPBADEN //PORTB pins are configured as digital I/O on RESET
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES MCLR //Master Clear pin enabled
#use delay(clock=20000000)
#use rs232(baud=115200, xmit=PIN_C6, rcv=PIN_C7, stream=PC)
//ds18b20 pin
#define DS18B20_IO PIN_B0
#define DS18B20_PU PIN_B1
int1 ds18b20_initialization(void){
int1 ready;
output_low(DS18B20_IO);
delay_us(490); //min 480us
output_float(DS18B20_IO);
delay_us(75); //15 - 60us for device to respond
ready=!input(DS18B20_IO);
delay_us(415);
return ready;
}
void ds18b20_write_bit(int8 b){
output_low(DS18B20_IO);
if(b == 1){
delay_us(5); //min 1us
output_float(DS18B20_IO);
}
delay_us(65);
output_float(DS18B20_IO);
delay_us(2); //min 1us between write slots
}
void ds18b20_write_byte(int8 B){
int8 i, aux;
for(i=0; i<8; i++){
aux = B >> i; //aux equals B shifted i times to the right
aux &= 0x01; //least significant bit survives
ds18b20_write_bit(aux);
}
//delay_us(120);
}
int1 ds18b20_read_bit(void){
output_low(DS18B20_IO);
delay_us(3); //min 1us
output_float(DS18B20_IO);
delay_us(5);
return(input(DS18B20_IO)); //next a delay of 60 to 120us must be done!
}
int8 ds18b20_read_byte(void){
int8 i, result=0x00;
for(i=0; i<8; i++){
if(ds18b20_read_bit())
result |= (0x01 << i);
delay_us(65);
}
return result;
}
void main() {
int8 i;
int8 scratchpad_data[9];
signed int16 temp=0x0000;
float temperature;
int8 busy =0;
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF|ADC_TAD_MUL_0);
setup_psp(PSP_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
setup_oscillator(False);
port_b_pullups(FALSE);
output_float(DS18B20_IO);
output_low(DS18B20_PU);
delay_ms(1000);
printf("DS18B20 1-wire temperature sensor\r\n");
while(1){
if(ds18b20_initialization()){
ds18b20_write_byte(0xCC); //skip ROM command
ds18b20_write_byte(0x44); //convert temperature command
output_float(DS18B20_IO);
output_high(DS18B20_PU);
delay_ms(800); //max conversion time for 12bit resolution=750ms
/*while (busy == 0){
printf("waiting...\r\n");
busy = ds18b20_read_byte();
}
busy=0;*/
output_low(DS18B20_PU);
ds18b20_initialization();
ds18b20_write_byte(0xCC); //skip ROM command
ds18b20_write_byte(0xBE); //read scratch pad command
for(i=0; i<2; i++){
scratchpad_data[i]=ds18b20_read_byte();
printf("scratchpad_data[%d]=%X\r\n", i, scratchpad_data[i]);
}
temp=make16(scratchpad_data[1], scratchpad_data[0]);
//temperature = temperature/16;
//calculate the whole number part
temperature = (temp >> 4) & 0x00FF;
//calculate the fractional part
if(temp & 0x0001) temperature = temperature + 0.06250;
if(temp & 0x0002) temperature = temperature + 0.12500;
if(temp & 0x0004) temperature = temperature + 0.25000;
if(temp & 0x0008) temperature = temperature + 0.50000;
printf("temperature reading: %7.3fdegrees C (%X%X)\r\n", temperature, scratchpad_data[1], scratchpad_data[0]);
}
else{
printf("DS18B20 failed to initialize\r\n");
}
delay_ms(5000);
}
} |
See ya!:D |
|
|
azakuri
Joined: 02 Aug 2008 Posts: 4
|
|
Posted: Tue Sep 02, 2008 6:40 am |
|
|
i'm still wonder if i use 2 ds18s20 and pic16f877, do i need to make a major changes in this coding...... |
|
|
Aurbo
Joined: 07 Apr 2008 Posts: 49
|
|
Posted: Wed Oct 01, 2008 6:05 pm |
|
|
If I wanted to convert this to Fahrenheit I'd need to convert the "whole number part"
Code: | //calculate the whole number part
temperature = (temp >> 4) & 0x00FF;
//convert to Fahrenheit
temperature=((temperature*9)/5)+32;
|
I believe that is right above
The part I've stuck on is getting the fractional part converted
I'm tempted to go this route but I'm unsure if it correct or proper coding.
Code: | //calculate the fractional part
if((((temp*9)/5)+32) & 0x0001) temperature = temperature + 0.06250;
if((((temp*9)/5)+32) & 0x0002) temperature = temperature + 0.12500;
if((((temp*9)/5)+32) & 0x0004) temperature = temperature + 0.25000;
if((((temp*9)/5)+32) & 0x0008) temperature = temperature + 0.50000;
|
|
|
|
HTAluvBeBeo
Joined: 23 Feb 2008 Posts: 35
|
|
Posted: Tue Nov 11, 2008 8:49 am |
|
|
Can I use a normal BJT and pullup resistor instead of a MOSFET in
parasite power mode ? Thank you all for reply my noob question. |
|
|
HTAluvBeBeo
Joined: 23 Feb 2008 Posts: 35
|
|
Posted: Thu Nov 13, 2008 6:26 am |
|
|
xokolatecake wrote: | Sorry guys!..i was so mad with the time i wasted on this i didn't noticed that i was using a DS18B20P, the (only) parasitic power version of DS18B20!
So my problem was not in the software but on the hardware, although i made a few adjustments to the delays duration and added the strong pull up control maxim recomends in the datasheet!
Will post the code for future reference. Again this is meant for DS18B20-PAR, don't make the same mistake i did!;P
See ya!:D |
Would you like to help me about the hardware for ds18b20p. A simple schematic will help me much. I am bad at electronics. Which MOSFET should I use?
Thank you all! |
|
|
soulraven
Joined: 08 Feb 2009 Posts: 72 Location: campulung muscel
|
|
Posted: Sat Feb 14, 2009 12:13 pm |
|
|
I tried the code below, go, only 2 questions that I
1. Below 0 degrees Celsius shows error displays 250 degrees Celsius
2. How can I adjust for sensors 3-4
xokolatecake wrote: | Hi!
Regarding scanan post, what does this little piece do?:
Code: | //for 10 bit resolution mod
onewire_write(0xCC);
onewire_write(0x4E);
onewire_write(125);
onewire_write(-55); //this should be done for proper working of DS18B20
onewire_write(127);
onewire_reset();
onewire_write(0xCC);
onewire_write(0x48);
delay_ms(15);
|
He issues a write scratchpad command, then sends the 3bytes and then copies the scratchpad to eeprom...what for?
And why it should be done for proper DS18B20 work?
I'm having trouble using a DS18B20, all it gives me is the power up state temperature reading: 0x0550->85ºdegrees. Any ideas of what the problem may be?
Code: |
#include <18F4525.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES HS //High speed Osc (> 4mhz)
#FUSES NOPROTECT //Code not protected from reading
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES BROWNOUT //Reset when brownout detected
#FUSES BORV21 //Brownout reset at 2.1V
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES LVP //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES NOPBADEN //PORTB pins are configured as digital I/O on RESET
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES MCLR //Master Clear pin enabled
#use delay(clock=20000000)
#use rs232(baud=115200, xmit=PIN_C6, rcv=PIN_C7, stream=PC)
//ds18b20 pin
#define DS18B20_IO PIN_A0
int1 ds18b20_initialization(void){
int1 ready;
output_low(DS18B20_IO);
delay_us(488); //min 480us
output_float(DS18B20_IO);
delay_us(72); //15 - 60us for device to respond
ready=!input(DS18B20_IO);
delay_us(424);
return ready;
}
void ds18b20_write_bit(int8 b){
output_low(DS18B20_IO);
if(b == 1){
delay_us(2); //min 1
output_float(DS18B20_IO);
}
delay_us(125);
output_float(DS18B20_IO);
}
void ds18b20_write_byte(int8 B){
int8 i, aux;
for(i=0; i<8; i++){
aux = B >> i; //aux equals B shifted i times to the right
aux &= 0x01; //least significant bit survives
ds18b20_write_bit(aux);
}
delay_us(120);
}
int1 ds18b20_read_bit(void){
output_low(DS18B20_IO);
delay_us(2); //min 1us
output_float(DS18B20_IO);
delay_us(8);
return(input(DS18B20_IO)); //next a delay of 60 to 120us must be done!
}
int8 ds18b20_read_byte(void){
int8 i, result=0x00;
for(i=0; i<8; i++){
if(ds18b20_read_bit())
result |= (0x01 << i);
delay_us(125);
}
return result;
}
void main() {
int8 i;
int8 scratchpad_data[9];
signed int16 temp=0x0000;
float temperature;
int8 busy =0;
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF|ADC_TAD_MUL_0);
setup_psp(PSP_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
setup_oscillator(False);
port_b_pullups(FALSE);
output_float(DS18B20_IO);
delay_ms(1000);
printf("DS18B20 1-wire temperature sensor\r\n");
while(1){
for(i=0; i<9; i++)
scratchpad_data[i]=0x00;
ds18b20_write_byte(0xCC);
ds18b20_write_byte(0x4E);
ds18b20_write_byte(125);
ds18b20_write_byte(-55); //this should be done for proper working of DS18B20
ds18b20_write_byte(127);
ds18b20_initialization();
ds18b20_write_byte(0xCC);
ds18b20_write_byte(0x48);
delay_ms(15);
if(ds18b20_initialization()){
ds18b20_write_byte(0xCC); //skip ROM command
ds18b20_write_byte(0x44); //convert temperature command
//output_float(DS18B20_IO);
delay_ms(800); //max conversion time for 12bit resolution=750ms
/*while (busy == 0){
printf("waiting...\r\n");
busy = ds18b20_read_byte();
}
busy=0;*/
ds18b20_initialization();
ds18b20_write_byte(0xCC); //skip ROM command
ds18b20_write_byte(0xBE); //read scratch pad command
for(i=0; i<2; i++){
scratchpad_data[i]=ds18b20_read_byte();
printf("scratchpad_data[%d]=%X\r\n", i, scratchpad_data[i]);
}
temp=make16(scratchpad_data[1], scratchpad_data[0]);
//temperature = temperature/16;
//calculate the whole number part
temperature = (temp >> 4) & 0x00FF;
//calculate the fractional part
if(temp & 0x0001) temperature = temperature + 0.06250;
if(temp & 0x0002) temperature = temperature + 0.12500;
if(temp & 0x0004) temperature = temperature + 0.25000;
if(temp & 0x0008) temperature = temperature + 0.50000;
printf("temperature reading: %7.3fdegrees C (%X%X)\r\n", temperature, scratchpad_data[1], scratchpad_data[0]);
}
else{
printf("DS18B20 failed to initialize\r\n");
}
delay_ms(5000);
}
} |
Thanks* |
|
|
|
Alioshag
Joined: 23 Feb 2009 Posts: 5
|
Pls Help!! |
Posted: Mon Feb 23, 2009 3:32 am |
|
|
I used the code posted by scanan and all what I get on the serial port
is "Temperature =10.6"
I'm using a PIC16F628A and a DS18S20P.
is this DS18S20P compatible with DS18S20 or DS18B20?
pls answer to me. |
|
|
Alioshag
Joined: 23 Feb 2009 Posts: 5
|
DS18S20 and DS18S20P |
Posted: Mon Feb 23, 2009 7:34 pm |
|
|
are these two sensors incompatible?
I get only one constant temperature even if I heat the sensor
|
|
|
pyu
Joined: 04 Feb 2009 Posts: 51
|
|
|
Alioshag
Joined: 23 Feb 2009 Posts: 5
|
|
Posted: Sun Mar 15, 2009 5:26 pm |
|
|
I used this sensor in normal mode, I used all the 3 wires and I used a 10K pull up resistor; that's all I've made. |
|
|
pyu
Joined: 04 Feb 2009 Posts: 51
|
|
Posted: Mon Mar 16, 2009 2:01 am |
|
|
if you use DS18S20P, you shouldn't use all 3 pins. |
|
|
Alioshag
Joined: 23 Feb 2009 Posts: 5
|
|
Posted: Mon Mar 16, 2009 9:24 am |
|
|
I saw many people on internet having problem with this DS18S20P sensor, and they all didn't succeed to solve their problem.
The DS18S20P sensor is not compatible with the DS1820 or DS18B20. That's all what I found about this difficult to use sensor.
Is there anyone who managed to use this sensor (DS18S20P)?
If it's so, pls post some schematics or code, or both. .
Thanks a lot.
Last edited by Alioshag on Mon Mar 16, 2009 10:01 am; edited 1 time in total |
|
|
|