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

 找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 2500|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

BASCOM-8051寫(xiě)的1602顯示18B20溫度和時(shí)間程序+仿真

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
BASCOM是basic語(yǔ)言的開(kāi)發(fā)工具,比C容易入門(mén),雖然很多功能受限,但常用庫(kù)已經(jīng)集成在內(nèi),很適合初學(xué)者。本例中有些測(cè)試用代碼未刪除,但不影響功能。8051在1602液晶和串口輸出時(shí)間,到秒為0時(shí)讀取18B20溫度,顯示在液晶屏,并通過(guò)串口打印18B20的寄存器值,同時(shí)將分鐘和溫度值寫(xiě)入24C04。仿真時(shí)如暫?捎檬髽(biāo)右鍵查看24C04內(nèi)存儲(chǔ)器的值,一小時(shí)循環(huán)一次,覆蓋上一小時(shí)的記錄。本想加上讀取24C04和數(shù)碼管顯示的語(yǔ)句,但還是覺(jué)得留一點(diǎn)給有興趣的人自己做吧。

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


單片機(jī)源程序如下:
  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
復(fù)制代碼

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


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

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

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 国产欧美精品一区二区色综合朱莉 | 台湾a级理论片在线观看 | 欧美激情啪啪 | 欧美日韩大片 | 拍真实国产伦偷精品 | 国产精品视频偷伦精品视频 | 碰碰视频| 欧美中文字幕一区二区 | 五月婷婷中文 | 精品一区二区三区在线观看国产 | 黑人一级黄色大片 | 激情婷婷成人 | 伊人伊人 | 黄色网一级片 | 国产精品一区二区久久精品爱微奶 | 久热免费 | 亚洲精品久久久 | 日韩视频一区二区三区 | 日韩在线免费 | 国产美女福利在线观看 | 青青草国产在线观看 | 久久久久91 | 成人在线精品视频 | 91精品久久久久久久久久 | 伊人一区 | av一级久久 | 日韩2020狼一二三 | 久久国产精品色av免费观看 | 免费激情网站 | 亚洲精品久久久一区二区三区 | 午夜一区二区三区在线观看 | 欧美视频一区二区三区 | 精国产品一区二区三区 | 亚洲精品国产第一综合99久久 | 天天射天天干 | 亚洲最大福利网 | 欧美日韩高清一区 | 欧美日韩精品久久久免费观看 | 国产日韩免费观看 | 日本xx视频免费观看 | 免费在线成人 |