User`s manual
mikroBASIC
- Basic Compiler for Microchip PIC microcontrollers
program onewire
dim i as byte
dim j1 as byte
dim j2 as byte
dim por1 as byte
dim por2 as byte
dim text as char[14]
main:
text = "Temperature:"
portb = 0
' initialize portd to 0
PORTC = 255
' initialize portc to 255
trisb = 0
' designate portd as output
trisc = 255
' designate portc as input
Lcd_Init(PORTB)
Lcd_Cmd(PORTB, LCD_CURSOR_OFF)
LCD_Out(PORTB, 1, 1, text)
do
ow_reset(portc,2)
' 1-wire reset signal
ow_write(portc,2,$CC)
' issue command to DS1820
ow_write(portc,2,$44)
' issue command to DS1820
delay_ms(120)
i = ow_reset(portc,2)
ow_write(portc,2,$CC)
' issue command to DS1820
ow_write(portc,2,$BE)
' issue command to DS1820
delay_ms(1000)
j1 = ow_read(portc,2)
' get result
j2 = ow_read(portc,2)
' get result
j1 = j1 >> 1
' assuming the temp. >= 0C
ByteToStr(j1, text)
' convert j1 to text
Lcd_Out(PORTB, 2, 8, text)
' print text
Lcd_Chr(PORTB, 2, 10, 223)
' degree character (°)
Lcd_Chr(PORTB, 2, 11,"C")
Delay_ms(500)
loop until false
' endless loop
end.
MikroElektronika:
Development
tools
-
Books
-
Compilers
mikroBASIC
making it simple...
109
page