Datasheet

' extract temp_whole
temp_whole = word(temp2write >> RES_SHIFT)
' convert temp_whole to characters
if ( temp_whole div 100 ) then
text[0] = temp_whole div 100 + 48
else
text[0] = "0"
end if
text[1] = (temp_whole div 10)mod 10 + 48 ' Extract tens digit
text[2] = temp_whole mod 10 + 48 ' Extract ones digit
' extract temp_fraction and convert it to unsigned int
temp_fraction = word(temp2write << (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 sub
main:
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,178) ' 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
286
MIKROELEKTRONIKA - SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroBasic PRO for AVR
CHAPTER 6