久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

標題: BASCOM-8051寫的1602顯示18B20溫度和時間程序+仿真 [打印本頁]

作者: hotpet    時間: 2020-4-23 05:53
標題: BASCOM-8051寫的1602顯示18B20溫度和時間程序+仿真
BASCOM是basic語言的開發工具,比C容易入門,雖然很多功能受限,但常用庫已經集成在內,很適合初學者。本例中有些測試用代碼未刪除,但不影響功能。8051在1602液晶和串口輸出時間,到秒為0時讀取18B20溫度,顯示在液晶屏,并通過串口打印18B20的寄存器值,同時將分鐘和溫度值寫入24C04。仿真時如暫停可用鼠標右鍵查看24C04內存儲器的值,一小時循環一次,覆蓋上一小時的記錄。本想加上讀取24C04和數碼管顯示的語句,但還是覺得留一點給有興趣的人自己做吧。

仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)


單片機源程序如下:
  1. ' Program Led1.bas

  2. $crystal = 11059000
  3. $baud = 9600

  4. '$crystal = 12000000
  5. '$baud = 4800


  6. Config 1wire = P1.7                                           'use this pin
  7. Dim Ar(8) As Byte , A As Byte , I As Byte




  8. Declare Sub Write_eeprom(adres As Byte , Value As Byte)
  9. Declare Sub Read_eeprom(adres As Byte , Value As Byte)
  10. Config I2cdelay = 1                                           'default so not needed
  11. 'declare constants
  12. Const Addressw = 160
  13. Const Addressr = 161



  14. Dim B1 As Byte , Adres As Byte , Value As Byte                'dim byte


  15. Dim T As Byte
  16. Dim T1 As Byte
  17. Dim T2 As Byte
  18. Dim Ct As Byte
  19. Dim H As Byte
  20. Dim H1 As Byte
  21. Dim H2 As Byte
  22. Dim M As Byte
  23. Dim M1 As Byte
  24. Dim M2 As Byte
  25. Dim S As Byte
  26. Dim S1 As Byte
  27. Dim S2 As Byte
  28. Dim Led As Bit                                                'LED is a Bit variable since it will turn on and
  29. Dim Led1 As Bit

  30. Config Lcd = 16 * 2
  31. 'P1.0 = 0
  32. Initlcd
  33. Cls



  34. Config Timer0 = Timer , Gate = Internal , Mode = 1
  35. 'Timer0 = counter : timer0 operates as a counter
  36. 'Gate = Internal  : no external gate control
  37. 'Mode = 2         : 8-bit auto reload (default)
  38. 'Mode = 1         : 16-bit reload
  39. On Timer0 Timer_0_int
  40. Load Timer0 , 0                                               'when the timer reaches 100 an interrupt will occur
  41. Enable Interrupts                                             'enable the use of interrupts
  42. Enable Timer0                                                 'enable the timer


  43. Rem Setting Of Priority
  44. Priority Set Timer0                                           'highest priority
  45. Start Timer0                                                  'start the timer

  46. Call Write_eeprom(0 , 48)
  47. Call Write_eeprom(1 , 49)                                     'write value of three to address 1 of EEPROM

  48. Print Value
  49. Call Read_eeprom(0 , Value) : Print Value                     'read it back
  50. Call Read_eeprom(5 , Value) : Print Value                     'again for address 5

  51. Led1 = 1                                                      'initial value
  52. Led = 0                                                       'Do is a start of a Do-Loop loop

  53. Do



  54. Loop                                                          'end of Do-Loop loop

  55. End

  56. Rem The Interrupt Handler For The Timer0 Interrupt
  57. Timer_0_int:
  58. If Ct = 13 Then
  59.      Ct = 0

  60.      P0.1 = Led1
  61.      P0.0 = Led
  62.      Led = Not Led
  63.      Led1 = Not Led1                                          'invert LED value
  64.      H1 = H / 10
  65.      H2 = H Mod 10
  66.      M1 = M / 10
  67.      M2 = M Mod 10
  68.      S1 = S / 10
  69.      S2 = S Mod 10
  70.      Print "Time is:" ; H1 ; H2 ; ":" ; M1 ; M2 ; ":" ; S1 ; S2       '; (Second / 10) ; (Second%10)       ' test serial com


  71.      Lowerline
  72.      Lcd "Time is:" ; H1 ; H2 ; ":" ; M1 ; M2 ; ":" ; S1 ; S2

  73.      S = S + 1
  74.      If S = 60 Then
  75.            S = 0
  76.            M = M + 1

  77.            1wreset                                            'reset the device
  78.            Print Err                                          'print error 1 if error

  79.            1wwrite &HCC
  80.            1wwrite &H44                                       'read ROM command

  81.             Waitms 255
  82.             Waitms 255
  83.             Waitms 240
  84.            1wreset
  85.            1wwrite &HCC
  86.            1wwrite &HBE

  87.             For I = 1 To 8
  88.               Ar(i) = 1wread()                                'place into array
  89.             Next
  90.             For I = 1 To 8
  91.                Printhex Ar(i);                                'print output
  92.             Next
  93.             Print
  94.             T1 = Ar(1) / 16                                 'linefeed
  95.             T2 = Ar(2) * 16
  96.             T = T1 + T2

  97.             Upperline
  98.             Lcd "Temp is:" ; T

  99.             Call Write_eeprom(m , T)


  100.            If M = 60 Then
  101.               M = 0
  102.               H = H + 1
  103.               If H = 24 Then
  104.                  H = 0
  105.               End If
  106.            End If
  107.      End If
  108. Else
  109.    Incr Ct
  110. End If
  111. Return

  112.   'sample of writing a byte to EEPROM AT2404
  113. Sub Write_eeprom(adres As Byte , Value As Byte)
  114.     I2cstart                                                  'start condition
  115.     I2cwbyte Addressw                                         'slave address
  116.     I2cwbyte Adres                                            'asdress of EEPROM
  117.     I2cwbyte Value                                            'value to write
  118.     I2cstop                                                   'stop condition
  119.     Waitms 10                                                 'wait for 10 milliseconds
  120. End Sub


  121. 'sample of reading a byte from EEPROM AT2404
  122. Sub Read_eeprom(adres As Byte , Value As Byte)
  123.    I2cstart                                                   'generate start
  124.    I2cwbyte Addressw                                          'slave adsress
  125.    I2cwbyte Adres                                             'address of EEPROM
  126.     Waitms 10
  127.    I2cstart                                                   'repeated start
  128.    I2cwbyte Addressr                                          'slave address (read)
  129.    I2crbyte Value , 9                                         'read byte
  130.    I2cstop                                                    'generate stop
  131. End Sub
復制代碼

所有資料51hei提供下載:
89C52LCD DS1820 24c04.zip (26.37 KB, 下載次數: 10)







歡迎光臨 (http://www.zg4o1577.cn/bbs/) Powered by Discuz! X3.1
主站蜘蛛池模板: 久久久精品网站 | 激情 一区 | 在线一区| 日韩高清中文字幕 | 一级视频在线免费观看 | 日本中文字幕一区 | 手机在线一区二区三区 | 99精品观看 | 天堂成人国产精品一区 | 亚洲电影一区二区三区 | 亚洲视频免费在线播放 | 国产在线小视频 | 亚洲人在线 | 久久精品视频在线播放 | 欧美精品在线一区二区三区 | 国产精品成人国产乱一区 | 日韩中文字幕在线视频 | 欧美黄色网 | 蜜桃视频在线观看免费视频网站www | 91精品国产91久久综合桃花 | 亚洲视频一区二区三区 | 成人久草| 玖玖免费| 亚洲电影一级片 | 精品国产一区二区三区日日嗨 | 国产激情在线看 | 91亚洲精品国偷拍自产在线观看 | 日韩无 | 91免费高清 | 国产婷婷在线视频 | 久久这里只有精品首页 | 国产精品精品视频 | 全部免费毛片在线播放网站 | 国产高清精品在线 | 婷婷桃色网 | 一级毛片免费完整视频 | 99精品一区 | 中文字幕在线视频一区二区三区 | 日本成人二区 | 日韩视频免费看 | 中国大陆高清aⅴ毛片 |