Datasheet
temp_fraction := word(temp2write shl (4-RES_SHIFT));
temp_fraction := temp_fraction and 0x000F;
temp_fraction := temp_fraction * 625;
// convert temp_fraction to characters
text[4] := word(temp_fraction div 1000) + 48; //
Extract thousands digit
text[5] := word((temp_fraction div 100)mod 10 + 48); //
Extract hundreds digit
text[6] := word((temp_fraction div 10)mod 10 + 48); //
Extract tens digit
text[7] := word(temp_fraction mod 10) + 48; //
Extract ones digit
// print temperature on Lcd
Lcd_Out(2, 5, text);
end;
begin
text := '000.0000';
UART1_Init(9600);
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
while (TRUE) do
begin
//--- perform temperature reading
Ow_Reset(); // Onewire reset signal
Ow_Write(0xCC); // Issue command SKIP_ROM
Ow_Write(0x44); // Issue command CONVERT_T
Delay_us(120);
Ow_Reset();
Ow_Write(0xCC); // Issue command SKIP_ROM
Ow_Write(0xBE); // Issue command READ_SCRATCHPAD
temp := Ow_Read();
temp := (Ow_Read() shl 8) + temp;
//--- Format and display result on Lcd
300
MIKROELEKTRONIKA - SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroPASCAL PRO for AVR
CHAPTER 6