PicBasic Interfacing 18F PIC with Temperature Sensor Maxim DS18B20


/ Published in: PicBasic
Save to your folder(s)

Displays temperature from DS18B20 in Celsius on hardware serial port


Copy this code and paste it in your HTML
  1. '****************************************************************
  2. '* Name : DS18B20 Temperature sensor reading *
  3. '* Author : Daniel Bowen [email protected] *
  4. '* Notice : Copyright (c) 2007 UTARC www.utarc.org *
  5. '* : All Rights Reserved *
  6. '* Date : 2/20/2007 *
  7. '* Version : 1.0 *
  8. '* Notes : Displays temperature from DS18B20 in Celsius on hardware serial port
  9. '* : Microcontroller used: PicMicro 18F4620
  10. '* : *
  11. '****************************************************************
  12.  
  13. INCLUDE "MODEDEFS.BAS"
  14. DEFINE OSC 20
  15. DEFINE LOADER_USED 1
  16. DEFINE HSER_BAUD 2400
  17. DEFINE ADC_CLOCK 1
  18. DEFINE ADC_BITS 10
  19. DEFINE ADC_SAMPLEUS 50
  20. SYMBOL LF=$0A
  21. CMCON=$07
  22. ADCON1=%00001100
  23. TRISA=%00110111
  24. TRISB=%01111101
  25. TRISC=%10010100
  26. TRISD=%10010100
  27. TRISE=%00000000
  28.  
  29. '*** Pin assignments
  30. TempIn VAR PORTA.4
  31.  
  32. '*** Temp Read Variables ***
  33. char VAR BYTE
  34. TTData VAR BYTE
  35. TSign VAR BIT
  36. TempData VAR WORD
  37. Sign VAR TEMPDATA.15
  38.  
  39.  
  40.  
  41.  
  42.  
  43. START:
  44.  
  45. GOSUB TEMPINREAD
  46. LOOKUP TSIGN, ["+","-"], CHAR
  47. HSEROUT [char,DEC3 TEMPDATA, "C" CR,LF] ' and display it 0=positive, 1=negative
  48.  
  49. GOTO START
  50.  
  51.  
  52. TEMPINREAD:
  53. OWOUT TEMPIN,1,[$CC,$44]
  54. HIGH TEMPIN
  55. PAUSE 10
  56. OWOUT TEMPIN,1,[$CC,$BE]
  57. OWIN TEMPIN,0,[TEMPDATA.LowByte,TEMPDATA.HighByte,SKIP 7]
  58. tSign = SIGN ' save sign bin
  59. IF TSIGN=1 THEN
  60. TEMPDATA = $FFFF-TEMPDATA
  61. TEMPDATA = TEMPDATA + 1
  62. ENDIF
  63. TEMPDATA = TEMPDATA/16
  64. RETURN

URL: http://www.utarc.org/wiki/index.php?title=Source_Code

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.