-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAtmega16 + L298.bas
More file actions
172 lines (133 loc) · 2.51 KB
/
Copy pathAtmega16 + L298.bas
File metadata and controls
172 lines (133 loc) · 2.51 KB
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
'======================================================================='
' Title: DC Motor Driver * PWM
' Last Updated : 01.2022
' Author : A.Hossein.Khalilian
' Program code : BASCOM-AVR 2.0.8.5
' Hardware req. : Atmega16 + L298
'======================================================================='
$regfile = "m16def.dat"
$crystal = 1000000
Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Down , Prescale = 1024
Config Porta = Output
Config Portb = &B00000111
Config Portd.0 = Output
Config Portd.1 = Output
Config Portd.5 = Output
Config Portc.0 = Output
Config Portc.1 = Output
Enable Interrupts
Dim A As Word
Dim B As Bit
Dim P As Bit
Declare Sub Leds(n As Word)
A = 100
B = 0
P = 0
'-----------------------------------------------------------
Do
If Pinb.4 = 1 Then
B = 1
Set Portd.0
Reset Portd.1
Reset Portc.0
Set Portc.1
Bitwait Pinb.4 , Reset
End If
If Pinb.5 = 1 Then
B = 0
Reset Portd.0
Set Portd.1
Set Portc.0
Reset Portc.1
Bitwait Pinb.5 , Reset
End If
If Pinb.3 = 1 Then
P = Not P
If P = 0 Then
If B = 0 Then
Reset Portd.0
Set Portd.1
Set Portc.0
Reset Portc.1
End If
End If
If P = 0 Then
If B = 1 Then
Set Portd.0
Reset Portd.1
Reset Portc.0
Set Portc.1
End If
End If
If P = 1 Then
Reset Portd.0
Reset Portd.1
End If
Bitwait Pinb.3 , Reset
End If
If Pinb.6 = 1 Then
If A < 250 Then A = A + 10
Bitwait Pinb.6 , Reset
End If
If Pinb.7 = 1 Then
If A > 10 Then A = A - 10
Bitwait Pinb.7 , Reset
End If
Pwm1a = A
Call Leds(a)
Loop
End
'-----------------------------------------------------------
Sub Leds(n As Word)
If N < 25 Then
Portb.1 = 1
Portb.0 = 0
Porta = 0
End If
If N < 50 And N >= 25 Then
Portb.1 = 1
Portb.0 = 1
Porta = 0
End If
If N < 75 And N >= 50 Then
Portb.1 = 1
Portb.0 = 1
Porta = &B10000000
End If
If N < 100 And N >= 75 Then
Portb.1 = 1
Portb.0 = 1
Porta = &B11000000
End If
If N < 125 And N >= 100 Then
Portb.1 = 1
Portb.0 = 1
Porta = &B11100000
End If
If N < 150 And N >= 125 Then
Portb.1 = 1
Portb.0 = 1
Porta = &B11110000
End If
If N < 175 And N >= 150 Then
Portb.1 = 1
Portb.0 = 1
Porta = &B11111000
End If
If N < 200 And N >= 175 Then
Portb.1 = 1
Portb.0 = 1
Porta = &B11111100
End If
If N < 225 And N >= 200 Then
Portb.1 = 1
Portb.0 = 1
Porta = &B11111110
End If
If N < 255 And N >= 225 Then
Portb.1 = 1
Portb.0 = 1
Porta = &B11111111
End If
End Sub
'-----------------------------------------------------------