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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2424|回復: 0
收起左側

BASCOM-8051寫的1602顯示18B20溫度和時間程序+仿真

[復制鏈接]
ID:732506 發(fā)表于 2020-4-23 05:53 | 顯示全部樓層 |閱讀模式
BASCOM是basic語言的開發(fā)工具,比C容易入門,雖然很多功能受限,但常用庫已經(jīng)集成在內(nèi),很適合初學者。本例中有些測試用代碼未刪除,但不影響功能。8051在1602液晶和串口輸出時間,到秒為0時讀取18B20溫度,顯示在液晶屏,并通過串口打印18B20的寄存器值,同時將分鐘和溫度值寫入24C04。仿真時如暫停可用鼠標右鍵查看24C04內(nèi)存儲器的值,一小時循環(huán)一次,覆蓋上一小時的記錄。本想加上讀取24C04和數(shù)碼管顯示的語句,但還是覺得留一點給有興趣的人自己做吧。

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

單片機源程序如下:
  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.png
所有資料51hei提供下載:
89C52LCD DS1820 24c04.zip (26.37 KB, 下載次數(shù): 10)


回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 欧美在线观看一区 | 99久久久久久99国产精品免 | 国内精品伊人久久久久网站 | 亚洲精品在线91 | 精品一区二区久久久久久久网站 | 伊人二区 | 欧美日韩久 | 91久久久久久久 | 国产高清在线精品一区二区三区 | 一级毛片免费视频观看 | 久久国产精品视频 | 伊人婷婷| 午夜一区 | 一级a性色生活片久久毛片 一级特黄a大片 | 久久久久久国产精品久久 | 国产精品成人一区二区 | 99免费视频| 精品无码久久久久久国产 | 日本亚洲欧美 | 久久久久久色 | 国产亚洲二区 | 精品国产欧美日韩不卡在线观看 | 国产女人叫床高潮大片免费 | 天天曰夜夜操 | 婷婷福利| 国产精品久久在线观看 | 日本不卡一区二区三区在线观看 | 亚洲精品99 | 午夜天堂精品久久久久 | 亚洲欧洲一区二区 | 久久久久久综合 | 国产日韩免费观看 | 国产免费高清 | 福利视频亚洲 | 欧美精品一区二区蜜桃 | 天天色天天射天天干 | 羞羞视频在线观看网站 | 欧美www在线 | 国产精品久久国产精品 | h视频在线观看免费 | 久久国产一区 |