Learn   /   Peripheral Tutorials   /   PIC16F877A

One wire bus (DS1820) Control For Basic PRO Compiler

Effortlessly manage DS1820 on One Wire Bus using Basic PRO Compiler: Your gateway to streamlined Arduino control and monitoring!

Published
Updated

At a glance

CategoryPeripheral Tutorials
PIC modelPIC16F877A
IncludesCode
Reading time~1 min
C source
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
Beginner Tutorials · PIC16F877A

PIC16F877 Driving LCD in 4-Bit Mode using PIC16F877 with Proteus Simulation

Introduction This microcontroller project shows how a PIC16F877 can drive an LCD display using 4-bit mode inside a Proteus simulation.The project demonstrates...

Programmers & ICSP · PIC16F877A

EPE PIC/LCD Demo using PIC16F877 with Proteus Simulation

IntroductionThe EPE PIC/LCD Demo is a classic microcontroller project that demonstrates how a PIC16F877 can fully control a PG12864F graphical LCD.Designed as...

Motors & Robotics · PIC16F877A

Efficient Sun-Following Robot: A Solar Tracker with Microcontroller Control

Abstract The impending global challenge of dwindling non-renewable fuel resources underscores the urgency of transitioning towards renewable energy alternatives like solar power....

Peripheral Tutorials · PIC18F4550

PICDEM FS USB Mass Storage Device using PIC18F4550 with Proteus Simulation

Introduction This microcontroller project demonstrates how to simulate a USB Mass Storage Device (MSD) using the PIC18F4550 in a Proteus simulation environment....

Peripheral Tutorials

Hands-On Digital I/O Lab with PIC18F46K22 Microcontroller

PIC18F46K22 Microcontroller Digital I/O specifically explores the design of simple combinational circuits using the digital I/O capabilities of the PIC18F46K22 microcontroller. Moving...

Peripheral Tutorials

Design for manufacturing and assembly: DFA&DFM

Product developers understand the challenges involved in creating a market-ready product. Even experienced designers often go through multiple prototype iterations before reaching...

Ibrar Ayyub

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough...