标题:
BASCOM-8051写的单片机开发板4位led时钟仿真附带串口输出程序
[打印本页]
作者:
hotpet
时间:
2020-4-22 23:55
标题:
BASCOM-8051写的单片机开发板4位led时钟仿真附带串口输出程序
用BASCOM-8051写的4位led时钟,带串口输出。附源码,hex文件,protues仿真文件。
代码较粗燥,只是为了验证软硬件功能。
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
LEDx4-8051.JPG
(312.73 KB, 下载次数: 40)
下载附件
2020-4-22 23:45 上传
单片机源程序如下:
$crystal = 11059000
$baud = 9600
Dim Ct As Byte
Dim H As Byte
Dim H1 As Byte
Dim H2 As Byte
Dim M As Byte
Dim M1 As Byte
Dim M2 As Byte
Dim S As Byte
Dim S1 As Byte
Dim S2 As Byte
Dim Led0 As Bit 'LED is a Bit variable since it will turn on and
Dim Led1 As Bit
Dim Point As Byte
Dim K As Byte
Dim A(10) As Byte
A(1) = Not &H06
A(2) = Not &H5B
A(3) = Not &H4F
A(4) = Not &H66
A(5) = Not &H6D
A(6) = Not &H7D
A(7) = Not &H07
A(8) = Not &H7F
A(9) = Not &H6F
A(10) = Not &H3F
Config Timer0 = Timer , Gate = Internal , Mode = 1
'Timer0 = counter : timer0 operates as a counter
'Gate = Internal : no external gate control
'Mode = 2 : 8-bit auto reload (default)
'Mode = 1 : 16-bit reload
On Timer0 Timer_0_int
Load Timer0 , 0 'when the timer reaches 100 an interrupt will occur
Enable Interrupts 'enable the use of interrupts
Enable Timer0 'enable the timer
Rem Setting Of Priority
Priority Set Timer0 'highest priority
Start Timer0
Led0 = 1
Led1 = 0
P2 = &HFF
Do
K = Inkey()
If K = 48 Then
M = M + 1
If M = 60 Then
M = 0
End If
Elseif K = 49 Then
M = M - 1
If M = 255 Then
M = 59
End If
End If
P2.0 = 0
P0 = A(m1)
Waitms 2
P2.0 = 1
Waitms 3
P2.1 = 0
If Point = 1 Then
P0 = A(m2) + &H80
Else
P0 = A(m2)
End If
Waitms 2
P2.1 = 1
Waitms 3
P2.2 = 0
P0 = A(s1)
Waitms 2
P2.2 = 1
Waitms 3
P2.3 = 0
P0 = A(s2)
Waitms 2
P2.3 = 1
Waitms 3
Loop
End
Rem The Interrupt Handler For The Timer0 Interrupt
Timer_0_int:
If Ct = 13 Then
Ct = 0
P1.1 = Led1
P1.0 = Led0
Led0 = Not Led0
Led1 = Not Led1 'invert LED value
H1 = H / 10
H2 = H Mod 10
M1 = M / 10
M2 = M Mod 10
S1 = S / 10
S2 = S Mod 10
Point = S Mod 2
Print "Time is:" ; H1 ; H2 ; ":" ; M1 ; M2 ; ":" ; S1 ; S2 '; (Second / 10) ;
If M1 = 0 Then
M1 = 10
End If
If M2 = 0 Then
M2 = 10
End If
If S1 = 0 Then
S1 = 10
End If
If S2 = 0 Then
S2 = 10
End If
S = S + 1
If S = 60 Then
S = 0
M = M + 1
If M = 60 Then
M = 0
H = H + 1
If H = 24 Then
H = 0
End If
End If
End If
Else
Incr Ct
End If
Return
复制代码
所有资料51hei提供下载:
QXmini51.zip
(612.65 KB, 下载次数: 8)
2020-4-22 23:39 上传
点击文件名下载附件
下载积分: 黑币 -5
作者:
富贵竹
时间:
2020-7-22 22:52
hotpet 你好,看到你发的BASCOM 贴我很高兴,希望能加你 QQ
作者:
富贵竹
时间:
2020-7-22 22:52
hotpet 你好,看到你发的 BASCOM 贴很想和你联系一下 请加我QQ 976086284
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1