找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2218|回复: 2
收起左侧

BASCOM-8051写的单片机开发板4位led时钟仿真附带串口输出程序

[复制链接]
ID:732506 发表于 2020-4-22 23:55 | 显示全部楼层 |阅读模式
用BASCOM-8051写的4位led时钟,带串口输出。附源码,hex文件,protues仿真文件。
代码较粗燥,只是为了验证软硬件功能。
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
LEDx4-8051.JPG

单片机源程序如下:
  1. $crystal = 11059000
  2. $baud = 9600

  3. Dim Ct As Byte
  4. Dim H As Byte
  5. Dim H1 As Byte
  6. Dim H2 As Byte
  7. Dim M As Byte

  8. Dim M1 As Byte
  9. Dim M2 As Byte

  10. Dim S As Byte

  11. Dim S1 As Byte
  12. Dim S2 As Byte
  13. Dim Led0 As Bit                                               'LED is a Bit variable since it will turn on and
  14. Dim Led1 As Bit
  15. Dim Point As Byte
  16. Dim K As Byte


  17. Dim A(10) As Byte
  18. A(1) = Not &H06
  19. A(2) = Not &H5B
  20. A(3) = Not &H4F
  21. A(4) = Not &H66
  22. A(5) = Not &H6D
  23. A(6) = Not &H7D
  24. A(7) = Not &H07
  25. A(8) = Not &H7F
  26. A(9) = Not &H6F
  27. A(10) = Not &H3F


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


  37. Rem Setting Of Priority
  38. Priority Set Timer0                                           'highest priority
  39. Start Timer0



  40. Led0 = 1
  41. Led1 = 0

  42. P2 = &HFF


  43. Do


  44. K = Inkey()
  45. If K = 48 Then
  46.    M = M + 1
  47.    If M = 60 Then
  48.       M = 0
  49.    End If
  50. Elseif K = 49 Then
  51.    M = M - 1
  52.    If M = 255 Then
  53.       M = 59
  54.    End If
  55. End If

  56. P2.0 = 0
  57. P0 = A(m1)
  58. Waitms 2
  59. P2.0 = 1
  60. Waitms 3

  61. P2.1 = 0
  62. If Point = 1 Then
  63.    P0 = A(m2) + &H80
  64. Else
  65.    P0 = A(m2)
  66. End If
  67. Waitms 2
  68. P2.1 = 1
  69. Waitms 3

  70. P2.2 = 0
  71. P0 = A(s1)
  72. Waitms 2
  73. P2.2 = 1
  74. Waitms 3

  75. P2.3 = 0
  76. P0 = A(s2)
  77. Waitms 2
  78. P2.3 = 1
  79. Waitms 3


  80. Loop
  81. End


  82.   Rem The Interrupt Handler For The Timer0 Interrupt
  83. Timer_0_int:
  84. If Ct = 13 Then
  85.      Ct = 0

  86.      P1.1 = Led1
  87.      P1.0 = Led0

  88.      Led0 = Not Led0
  89.      Led1 = Not Led1                                          'invert LED value


  90.      H1 = H / 10
  91.      H2 = H Mod 10
  92.      M1 = M / 10

  93.      M2 = M Mod 10

  94.      S1 = S / 10

  95.      S2 = S Mod 10
  96.      Point = S Mod 2

  97.      Print "Time is:" ; H1 ; H2 ; ":" ; M1 ; M2 ; ":" ; S1 ; S2       '; (Second / 10) ;
  98.      If M1 = 0 Then
  99.       M1 = 10
  100.      End If
  101.      If M2 = 0 Then
  102.       M2 = 10
  103.      End If
  104.      If S1 = 0 Then
  105.       S1 = 10
  106.      End If
  107.      If S2 = 0 Then
  108.       S2 = 10
  109.      End If
  110.      S = S + 1
  111.      If S = 60 Then
  112.            S = 0
  113.            M = M + 1

  114.            If M = 60 Then
  115.               M = 0
  116.               H = H + 1
  117.               If H = 24 Then
  118.                  H = 0
  119.               End If
  120.            End If
  121.      End If
  122. Else
  123.    Incr Ct
  124. End If
  125. Return
复制代码

所有资料51hei提供下载:
QXmini51.zip (612.65 KB, 下载次数: 8)

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

ID:806933 发表于 2020-7-22 22:52 | 显示全部楼层
hotpet 你好,看到你发的BASCOM 贴我很高兴,希望能加你 QQ
回复

使用道具 举报

ID:806933 发表于 2020-7-22 22:52 | 显示全部楼层
hotpet 你好,看到你发的 BASCOM 贴很想和你联系一下 请加我QQ 976086284
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表