problem with Dallas18b20 need help

misel0019pic

New Member
Hi,
I'm new in PIC. i usually use Atmel IC . but i need to do project on PIC.

so i started with PIC16F877A and compiler Mikroc.

I WORKED till lcd smoothly now i wanna work with Dallas ds18b20. but i got problem with that.

i use program

Code:
sbit LCD_RS at RD2_bit;
sbit LCD_EN at RD3_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;

sbit LCD_RS_Direction at TRISD2_bit;
sbit LCD_EN_Direction at TRISD3_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
// End LCD module connections

const unsigned short TEMP_RESOLUTION = 9;


unsigned int temp=0;
unsigned int a,b;

unsigned int i;

void disp_func(unsigned int adval)
{

//Lcd_Chr(3,5,i+48);

if(adval<100)
   {
   a=adval/10;
   b=adval-a*10;
   }

Lcd_Chr(2,1,a+48);
Lcd_Chr(2,2,b+48);

}



void main() {

  Lcd_Init();                                    // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR);                           // Clear LCD
  Lcd_Cmd(_LCD_CURSOR_OFF);                      // Turn cursor off
  Lcd_Out(1, 1, " Temperature:   ");
  // Print degree character, 'C' for Centigrades
  //Lcd_Chr(2,13,223);  // different LCD displays have different char code for degree
                      // if you see greek alpha letter try typing 178 instead of 223

 // Lcd_Chr(2,14,'C');

  //--- main loop
  do {
    //--- perform temperature reading
    Ow_Reset(&PORTB, 5);                         // Onewire reset signal
    Ow_Write(&PORTB, 5, 0xCC);                   // Issue command SKIP_ROM
    Ow_Write(&PORTB, 5, 0x44);                   // Issue command CONVERT_T
    Delay_us(120);

    Ow_Reset(&PORTB, 5);
    Ow_Write(&PORTB, 5, 0xCC);                   // Issue command SKIP_ROM
    Ow_Write(&PORTB, 5, 0xBE);                   // Issue command READ_SCRATCHPAD

    temp =  Ow_Read(&PORTB, 5);
    temp = (Ow_Read(&PORTB, 5) << 8) + temp;

    //--- Format and display result on Lcd
    Lcd_Out(1, 1, " Temperature:   ");

    //temp=39;
    disp_func(temp);
    
    Lcd_Chr(2,15,223);  // different LCD displays have different char code for degree
    Lcd_Out(2, 16, "C");                  // if you see greek alpha letter try typing 178 instead of 223

    i=5;
    
    Lcd_Chr(3,1,i+48);

    Delay_ms(500);
  } while (1);
}

and i got garbage value
can any one help me with that

Regards

misel0019PIC
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…