Could you explain, what did you mean.Try hard-coding your output to be displayed to the LCD. Instead of reading the sensor, give the part of your code that formats your data for output something like 1234, that way, you can work on just getting your LCD formatting right.
Don't try reading the sensor. Try displaying a number you put into your code that won't change and work your logic out that way.Could you explain, what did you mean.
buffer[0] = '1';
buffer[1] = '2';
buffer[2] = '3';
buffer[3] = '4';
I'm assuming this is supposed to be in the past tenseI try this, show me 1234
itoa(buffer,12345,10);
lcd_puts(buffer);
__delay_ms(5000);
#include <htc.h>
#include <stdlib.h>
#ifndef _XTAL_FREQ
#define _XTAL_FREQ 8000000
#endif
#include "lcd.h"
#define Skip_ROM 0xCC
#define Convert_T 0x44
#define Read_scratchpad 0xBE
#define Port_18B20 RA0
#define Tx_18B20 TRISA0 = 0
#define Rx_18B20 TRISA0 = 1
unsigned char reset();
void write(char WRT);
unsigned char read();
int main(void)
{
unsigned temp;
unsigned short tempL, tempH, fraction;
int i=0 ;
unsigned char buffer [20];
lcd_init();
lcd_goto(0);
lcd_puts("DS18B20"); //LCD display for the starting part
while(1) // create an infinite loop
{
if(!reset())
{
write(Skip_ROM);
write(Convert_T);
__delay_ms(500);
write(Skip_ROM);
write(Read_scratchpad);
tempL = read(); //read low temp value
tempH = read(); //read high temp value
i=((unsigned int)tempH << 8 ) | (unsigned int)tempL; //put both value in one variable
lcd_goto(0x40);
itoa(buffer,i,10);
lcd_puts(buffer);
__delay_ms(5000);
}
}
while(1) continue;
}
unsigned char reset()
{
Tx_18B20; // Tris = 0 (output)
Port_18B20 = 0; // set pin# to low (0)
__delay_us(550); // 1 wire require time delay
Rx_18B20; // Tris = 1 (input)
__delay_us(60); // 1 wire require time delay
if (Port_18B20 == 0) // if there is a presence pluse
{
__delay_us(550);
return 0; // return 0 ( 1-wire is presence)
}
else
{
__delay_us(550);
return 1; // return 1 ( 1-wire is NOT presence)
}
}
void write(char WRT)
{
char i,Cmd;
Cmd=WRT;
Rx_18B20; // set pin# to input (1)
for(i = 0; i < 8; i++)
{
if((Cmd & (1<<i))!= 0)
{
// write 1
Tx_18B20; // set pin# to output (0)
Port_18B20 = 0; // set pin# to low (0)
__delay_us(10); // 1 wire require time delay
Rx_18B20; // set pin# to input (release the bus)
__delay_us(80); // 1 wire require time delay
}
else
{
//write 0
Tx_18B20; // set pin# to output (0)
Port_18B20 = 0; // set pin# to low (0)
__delay_us(80); // 1 wire require time delay
Rx_18B20; // set pin# to input (release the bus)
}
}
}
unsigned char read()
{
char i,result = 0;
Rx_18B20; // TRIS is input(1)
for(i = 0; i < 8; i++)
{
Tx_18B20; // TRIS is output(0)
Port_18B20 = 0; // genarate low pluse for 2us
__delay_us(10);
Rx_18B20; // TRIS is input(1) release the bus
if(Port_18B20 != 0)
result |= 1<<i;
__delay_us(80); // wait for recovery time
}
return result;
}
unsigned char read()
{
char i,result = 0;
Rx_18B20; // TRIS is input(1)
for(i = 0; i < 8; i++)
{
Tx_18B20; // TRIS is output(0)
Port_18B20 = 0; // genarate low pluse for 2us
__delay_us(10);
Rx_18B20; // TRIS is input(1) release the bus
if(Port_18B20 != 0)
result |= 1<<i;
__delay_us(80); // wait for recovery time
}
//return result;
return 12;
}
LCD shows me 3084try changing the read() to return a known value... your one-wire interface may be having issues... i.e.
that's what you should have gotten if it's working.LCD shows me 3084
This should be taken into account in the LCD_init(), but it is worth looking in to...I think your problems are a quite common error. After a reset a PIC will by default set pins as analog input. If such is an option. Check what the datasheet say about the the ANSEL and CMCON0 register. The ANSEL register should cleared but not sure then it comes to CMCON0. Confer with the datasheet
What are you programming the PIC with? Or do you only get the no device error when trying to debug?I have pickit3 on sure electronics, but when i try to connect to MPLAB can't find my device, so i can't use debuger
Reread post #31In LCD_init() I define
TRISB=0;
TRISA=0;
TRISC=0;
I use Pickit3 (beta). When I want to debug show me no device connect.What are you programming the PIC with? Or do you only get the no device error when trying to debug?
Do you have isolation resistors/diodes on the programming lines?I use Pickit3 (beta). When I want to debug show me no device connect.
I haven't.Do you have isolation resistors/diodes on the programming lines?
Look at FIGURE 16-11: on page 240 of the datasheet, this may be your problem...I haven't.