Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Can't read data using PIC18F2550 & DS18B20

Status
Not open for further replies.

AdyMareshal

Newbie level 1
Joined
Nov 10, 2010
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,286
I am using 18F2550 connected to a DS18B20 using PORTC.RC1, compiled with MikroC for PIC and virtual terminal in proteus. The terminal is working, but the rest doesn't

Here's the code I am using
Code:
char t;
int temp;

void ds1820_read()
{
      Ow_Reset(&PORTC, 1);       //                    'Reset
      Ow_Write(&PORTC, 1, 0xCC);//                   'Skip ROM
      Ow_Write(&PORTC, 1, 0x4E);//                   'Write to scratchpad
      Ow_Write(&PORTC, 1, 0x55);//                   'TH register value  (85 degrees C)
      Ow_Write(&PORTC, 1, 0x19);//                   'TL register value  (25 degrees C)
      Ow_Write(&PORTC, 1, 0x7F);//                   'Config register value (12bit)

                            // 'Do temp conversion

     Ow_Reset(&PORTC, 1);//                            ' Reset
     Ow_Write(&PORTC, 1, 0xCC);//                    'SKIP_ROM
     Ow_Write(&PORTC, 1, 0x44);//                    ' Issue command CONVERT_T
     Delay_us(120);

//                            'Read Temp

     Ow_Reset(&PORTC, 1);
     Ow_Write(&PORTC, 1, 0xCC);//                    'SKIP_ROM
     Ow_Write(&PORTC, 1, 0xBE);//                    'READ_SCRATCHPAD

     temp =  Ow_Read(&PORTC, 1);
     temp = (Ow_Read(&PORTC, 1) << 8) + temp;

}

void main() {
     UART1_Init(9600);
     Delay_ms(100);
     UART1_Write_Text("DS18B20: ");
     
     TRISC = 0b00000010;
     
     while(1)
     {
      ds1820_read();
      UART1_Write_Text(temp);
      UART1_Write('\r\n');
      Delay_ms(300);
     }
}

Anyone can give me a working code in 18F2550, or make this code work? I've tried the mikroC example code, but didn't succeded.

Thanks a lot
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top