Mikroelektronika MIKROE-724 データシート
410
mikoBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
Library Example
This example reads the temperature using DS18x20 connected to pin RF6. After reset, MCU obtains temperature from
the sensor and prints it on the Lcd. Be sure to set Fosc appropriately in your project, to pull-up RF6 line and to turn off
the PORTF leds.
Copy Code To Clipboard
program OneWire
‘ LCD module connections
dim LCD_RS as sbit at LATB4_bit
dim LCD_EN as sbit at LATB6_bit
dim LCD_D4 as sbit at LATD4_bit
dim LCD_D5 as sbit at LATD5_bit
dim LCD_D6 as sbit at LATD6_bit
dim LCD_D7 as sbit at LATD7_bit
dim LCD_RS_Direction as sbit at TRISB4_bit
dim LCD_EN_Direction as sbit at TRISB6_bit
dim LCD_D4_Direction as sbit at TRISD4_bit
dim LCD_D5_Direction as sbit at TRISD5_bit
dim LCD_D6_Direction as sbit at TRISD6_bit
dim LCD_D7_Direction as sbit at TRISD7_bit
‘ End LCD module connections
‘ Set TEMP_RESOLUTION to the corresponding resolution of used DS18x20 sensor:
‘ 18S20: 9 (default settingcan be 9,10,11,or 12)
‘ 18B20: 12
const TEMP_RESOLUTION as byte = 9
dim text as char[9]
temp as word
sub procedure Display_Temperature( dim temp2write as word )
const RES_SHIFT = TEMP_RESOLUTION - 8
dim temp_whole as byte
temp_fraction as word
text = “000.0000”
‘ Check if temperature is negative
if (temp2write and 0x8000) then
text[0] = “-”
temp2write = not temp2write + 1
end if
‘ 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