ABL electronic PIC16 Personal Computer User Manual


 
MikroElektronika:
Development
tools
-
Books
-
Compilers
23 5
page
mikroC
- C Compiler for Microchip PIC microcontrollers
mikroC
making it simple...
Library Example
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);
// Onewire reset signal
OW_Write(&PORTA,5,0xCC);
// Issue command SKIP_ROM
OW_Write(&PORTA,5,0x44);
// Issue command CONVERT_T
Delay_us(120);
OW_Reset(&PORTA,5);
OW_Write(&PORTA,5,0xCC);
// Issue command SKIP_ROM
OW_Write(&PORTA,5,0xBE);
// Issue command READ_SCRATCHPAD
Delay_ms(400);
j = OW_Read(&PORTA,5);
// Get temperature LSB
temp = OW_Read(&PORTA,5);
// Get temperature MSB
temp <<= 8; temp += j;
// Form the result
Display_Temperature(temp);
// Format and display result on LCD
Delay_ms(500);
} while (1);
}//~!