One wire bus (DS1820) Control For Basic PRO Compiler




Include "modedefs.bas" 
@ Device PIC16F877,XT_OSC,WDT_off,PWRT_off,PROTECT_off ,BOD_Off
define  adc_bits 8
define  osc 4
DEFINE  LCD_DREG PORTD
DEFINE  LCD_DBIT 4
DEFINE  LCD_RSREG PORTD
DEFINE  LCD_RSBIT 1
DEFINE  LCD_EREG PORTD
DEFINE  LCD_EBIT 0
low     portD.2 
trisa  = $ff
trisb  = $00
TRISD  = $00
adcon1 = 7
temperature   VAR WORD  
count_remain  VAR BYTE  
count_per_c   VAR BYTE  
sV            var byte
PV            var byte
mode          var porta.0
up            var porta.1
down          var porta.2
DQ            VAR PORTA.3 ' One-wire data pin
heater        VAR PORTB.0
High heater
sV =  25 
LCDOut $fe, 1,"  TEMPS  SENSOR  "
LCDOut $fe, $c0,"DS1820 1WIRE BUS" 
pause 2000
main: 
gosub read_pv
gosub calculate
gosub display
read 0,sv
if mode = 0 then pause 200 : gosub set_temp
pause 10
GoTo main  
End
read_pv:   
OWOut DQ, 1,[$CC, $44]  
loop: 
OWIn DQ, 4, [count_remain]  
IF count_remain = 0 Then loop 
OWOut DQ, 1, [$CC, $BE]  
OWIn DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE, Skip 4, count_remain, count_per_c]
temperature = (((temperature >> 1) * 100) - 25) + (((count_per_c - count_remain) * 100) / count_per_c)
LCDOut $fe, 1, DEC (temperature / 100), ".", DEC2 temperature, " C"
PV =  (temperature / 100)
return
calculate: 
If (PV >= (SV - 1/2))  then   
gosub display
write 0,sv 
high heater 'off heater 
Pause 100
endif  
If (PV < sV ) then    
gosub display
write 0,sv    
low heater 'on  heater 
Pause 100
endif
return     
display:
LCDOut $fe, 1,"PV=", DEC (temperature / 100)+1,"C"
LCDOut $fe, $c0,"SV=" ,dec SV,"C" 
pause 10
return 
set_temp:
LCDOut $fe, 1,"settemp "
pause 2000
LCDOut $fe, 1 
pause 1000
loop2:
if mode = 1 then  
IF (Up=0)THEN
PAUSE 100
SV = SV+1
IF (SV>=100)THEN SV = 100
write 0,sv  
ENDIF
IF(DOWn=0)THEN
PAUSE 100
SV = Sv-1
IF(SV<=0)THEN SV = 0
write 0,sv 
ENDIF
pause 100
LCDOut $fe, 1,"setpoint temp "
LCDOut $fe, $c0,"SV=", dec SV,"C" 
goto loop2
endif
pause 100
goto main
RETURN

JLCPCB – Prototype 10 PCBs for $2 + 2 days Lead Time
China’s Largest PCB Prototype Enterprise, 300,000+ Customers & 10,000+ Online Orders Per Day
Inside a huge PCB factory: https://www.youtube.com/watch?v=_XCznQFV-Mw

READ  Output bit For Basic PRO Compiler




Current Project / Post can also be found using:

  • 1wire picbasic pro
  • interfacing ds1302 pic-microcontroller com

Leave a Comment

*
= 3 + 3

Read previous post:
PIC12F
PIC12F microcontroller project board

The 12F series of PIC microcontrollers are handy little 8-pin devices designed for small embedded applications that do not require...

Close
Scroll to top