📄 7segment.bas
字号:
'--------------------------------------------------------------
' (c) 1997-2000 MCS Electronics
'--------------------------------------------------------------
' file: 7SEGMENT.BAS
' demo: how to use a 7 segment display mutiplexed using TIMER0
' *TIMER1 is used for RS-232 baudrate generator
' The 7 segment displays are connected as following
' 7 SEGMENT PORT PIN value
' a P1.0 1
' b P1.1 2
' c P1.2 4
' d P1.3 8
' e P1.4 16
' f P1.5 32
' g P1.7 128
'number 0 will be : a+b+c+d+e+f=1+2+4+8+16+32=63
'1 = b+c=2+4=6
'2=a+b+g+e+d=1+2+8+16+128=155
'3=a+b+c+d+g=1+2+4+8+128=143
'well the rest I leave up to you !
' The common can be common cathode or common anode
'This example uses common cathode so making one of the displays common 0V, will
'show the segments when the signals on P1 are positive
' Common 1 P3.0 MSB
' Common 2 P3.1
' Common 3 P3.2
' common 4 P3.3 LSB
'--------------------------------------------------------------
Dim Gt As Byte , L As Byte , Char As Byte , Disp As Byte , S As String * 5 , Z As String * 5
Config Timer0 = Timer , Gate = Internal , Mode = 2
'Timer0 = counter : timer0 operates as a counter
'Gate = Internal : no external gate control
'Mode = 2 : 8-bit auto reload (default)
On Timer0 Timer_0_int
Load Timer0 , 100 '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 'start the timer
Do
Gt = Gt + 1
Wait 1
Loop 'loop until users enters 1
End
Rem The Interrupt Handler For The Timer0 Interrupt
Timer_0_int:
'we will display the valueof gt on the 7 segment displays
P3 = P3 Or 15 'all displays off
Disp = Disp + 1 'which display are we doing?
If Disp > 4 Then Disp = 1
S = Str(gt) 'for example 123
L = Len(s) 'get the length of the string
L = 4 - l
Z = String(l , 48)
Z = Z + S 'add leading zeros
mov r0,#{z} ; address of string
mov a,{disp} ; value of disp
dec a ; adjust
add a,r0 ; add to a
mov r0,a ; address of character
mov a,@r0 ; get into acc
subb a,#48 ; strip ascii
P1 = Lookup(acc , 7seg)
If Disp = 1 Then
Reset P3.0
Elseif Disp = 2 Then
Reset P3.1
Elseif Disp = 3 Then
Reset P3.2
Elseif Disp = 4 Then
Reset P3.3
End If
Return
'here we store the values that will be assigned to P1 to show a number
'dont forget to add the other digit values!
7seg:
Data 63 , 6 , 155 , 143
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -