User manual

mikroBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
411
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:
ADPCFG = 0 ‘ Congure AN pins as digital I/O
text = “000.0000”
Lcd_Init() ‘ Initialize LCD
Lcd_Cmd(_LCD_CLEAR) ‘ Clear LCD
Lcd_Cmd(_LCD_CURSOR_OFF) ‘ Turn cursor off
Lcd_Out(1, 1, “ Temperature: “)
Lcd_Chr(2,13,178) ‘ Print degree character, “C” for Centigrades
‘ Different LCD displays have different char code for degree
Lcd_Chr(2,14,”C”) ‘ If you see greek alpha letter try typing 178 instead of 223
‘--- Main loop
while TRUE
‘--- Perform temperature reading
Ow_Reset(PORTF, 6) ‘ Onewire reset signal
Ow_Write(PORTF, 6, 0xCC) ‘ Issue command SKIP_ROM
Ow_Write(PORTF, 6, 0x44) ‘ Issue command CONVERT_T
Delay_us(120)
Ow_Reset(PORTF, 6)
Ow_Write(PORTF, 6, 0xCC) ‘ Issue command SKIP_ROM
Ow_Write(PORTF, 6, 0xBE) ‘ Issue command READ_SCRATCHPAD
temp = Ow_Read(PORTF, 6)
temp = (Ow_Read(PORTF, 6) << 8) + temp
‘--- Format and display result on Lcd
Display_Temperature(temp)
Delay_ms(520)
wend
end.