-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathATmega8 + 4-Digit 7Segment.bas
158 lines (117 loc) · 2.37 KB
/
ATmega8 + 4-Digit 7Segment.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
'======================================================================='
' Title: 4-Digit 7Seg LED Clock
' Last Updated : 04.2022
' Author : A.Hossein.Khalilian
' Program code : BASCOM-AVR 2.0.8.5
' Hardware req. : ATmega8 + 4-Digit 7Segment
'======================================================================='
$regfile = "m8def.dat"
$crystal = 1000000
Config Portb = Output
Config Portc = Output
Config Portd = Input
Config Portd.6 = Output
Config Clock = Soft , Gosub = Sectic
Enable Interrupts
Time$ = "12:10:01"
Dp Alias Portd.6
Comm Alias Portc
Datport Alias Portb
Seet Alias Pind.4
Ad Alias Pind.0
De Alias Pind.7
Dim Dat As Byte
Dim V As Byte
Dim L As Byte
Dim A1 As Bit
Dim A2 As Bit
Dim A3 As Bit
Dim A4 As Bit
Declare Sub A
Declare Sub B
Declare Sub Refresh
Declare Sub F
A1 = 1
A2 = 1
A3 = 1
A4 = 1
V = 0
'-----------------------------------------------------------
Do
Call A
Call B
Loop
End
'-----------------------------------------------------------
Sub A
If Seet = 0 Then
Incr V
If V = 2 Then
A1 = 0
Else
A1 = 1
End If
If V = 1 Then
A4 = 0
Else
A4 = 1
End If
Call F
If V > 2 Then V = 0
End If
If V = 1 Then
If Ad = 0 Then
Incr _hour
If _hour > 23 Then _hour = 0
Call F
End If
If De = 0 Then
Decr _hour
If _hour < 1 Then _hour = 23
Call F
End If
End If
''''''''''''''''''''''''''''''
If V = 2 Then
If Ad = 0 Then
Incr _min
If _min > 59 Then _min = 0
Call F
End If
If De = 0 Then
Decr _min
If _min < 1 Then _min = 59
Call F
End If
End If
End Sub
''''''''''''''''''''''''''''''
Sub B
Comm = &B1000 : Dp = A1 : Dat = _min Mod 10 : Call Refresh
Comm = &B0100 : Dp = A2 : Dat = _min / 10 : Call Refresh
Comm = &B0010 : Dp = A3 : Dat = _hour Mod 10 : Call Refresh
Comm = &B0001 : Dp = A4 : Dat = _hour / 10 : Call Refresh
End Sub
''''''''''''''''''''''''''''''
Sub F
For L = 0 To 25
Call B
Next L
End Sub
''''''''''''''''''''''''''''''
Sub Refresh
Datport = Lookup(dat , Seg)
Waitms 5
End Sub
''''''''''''''''''''''''''''''
Seg:
Data &B11000000 , &B11111001 , &B10100100 , &B10110000
Data &B10011001 , &B10010010 , &B10000010 , &B11111000
Data &B10000000 , &B10010000
''''''''''''''''''''''''''''''
Sectic:
If V = 0 Then
Toggle A3
End If
Return
'-----------------------------------------------------------