mikroC

making it simple...

Library Example

mikroC - C Compiler for Microchip PIC microcontrollers

unsigned temp; unsigned short j;

void Display_Temperature(unsigned int temp) { //...

}

void main() {

 

ADCON1 = 0xFF;

// Configure RA5 pin as digital I/O

PORTA

= 0xFF;

 

TRISA

= 0x0F;

// PORTA is input

PORTB

= 0;

 

TRISB

= 0;

// PORTB is output

// Initialize LCD on PORTB

and prepare for output

do {

OW_Reset(&PORTA,5);

OW_Write(&PORTA,5,0xCC);

OW_Write(&PORTA,5,0x44);

Delay_us(120);

OW_Reset(&PORTA,5);

OW_Write(&PORTA,5,0xCC);

OW_Write(&PORTA,5,0xBE);

Delay_ms(400);

j = OW_Read(&PORTA,5); temp = OW_Read(&PORTA,5); temp <<= 8; temp += j; Display_Temperature(temp); Delay_ms(500);

//Onewire reset signal

//Issue command SKIP_ROM

//Issue command CONVERT_T

//Issue command SKIP_ROM

//Issue command READ_SCRATCHPAD

//Get temperature LSB

//Get temperature MSB

//Form the result

//Format and display result on LCD

}while (1);

}//~!

 

 

page

 

MikroElektronika: Development tools - Books - Compilers

235