Anda di halaman 1dari 4

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

#include
#include
#include
#include
#include
#include
#include
#include
#include

"xhw_types.h"
"xhw_sysctl.h"
"xhw_memmap.h"
"xhw_ints.h"
"xhw_nvic.h"
"xcore.h"
"xsysctl.h"
"xgpio.h"
"xwdt.h"

volatile long Tim;


unsigned long* p;
int State = 0, mPWM=50000;int b;
void Lcd_wrn(unsigned char value, unsigned char mode);
void Lcd_init(void);
void Lcd_cmd_wrb(unsigned char value);
unsigned char Lcd_cmd_rdb(void);
void Lcd_data_wrb(unsigned char value);
unsigned char Lcd_rdn(unsigned char mode);
unsigned char Lcd_data_rdb(void);
void LCD_display_string(char *string_ptr);
SysTickIntHandler()
{
Tim++;

// When SysTick is thrown, this code is performed

}
int main(void)
{
int val=5;
int a=0;
b=6;
int c=0;// ABCD are used for testing
int d=0;
WDTimerDisable();

// When WatchDog is enabled, it will restart in cca 1s

xSysCtlClockSet(48000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_8MHZ); //Setting up max freq


xSysTickPeriodSet(480);
xSysTickIntEnable();
xSysTickEnable();

//SysTick will throw int by 10us (value freq/1000 = 48000 will do 1ms)
// End of SysTick init

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);// Enabling clock for port B
xGPIOSPinTypeGPIOOutput(PB18); //Red Led for signalizing reset
Tim = 0;
while (Tim<1000)
// 10ms blink
{}
xGPIOPinWrite( xGPIO_PORTB_BASE, xGPIO_PIN_18, 1 );
// Turn off red led
xGPIOSPinTypeGPIOOutput(PB19); //Green PWM Led
xGPIOSPinTypeGPIOOutput(PB0);//Probe for Osciloscope or Logic analyzator
xGPIOSPinTypeGPIOInput(PB1);
xGPIOSPinTypeGPIOInput(PE20);// connections to keypad
xGPIOSPinTypeGPIOInput(PE21);
xGPIOSPinTypeGPIOInput(PE22);
xGPIOSPinTypeGPIOOutput(PE23);
xGPIOSPinTypeGPIOOutput(PE29);
xGPIOSPinTypeGPIOOutput(PE30);

67
68
Lcd_init(); //LCD initialization
69
70
Lcd_cmd_wrb(0x80);
71
LCD_display_string("WELCOME");
72
73
Lcd_cmd_wrb(0xC0);
74
LCD_display_string("SELECT SPEED LEVEL");
75
76
restart:
77
78
for(b=0;b<1000;b++)
79
for(c=0;c<1000;c++);
80
81
while(1) //keypad driver codes
82
{
83
xGPIOPinWrite( xGPIO_PORTE_BASE, xGPIO_PIN_23,1);
84
xGPIOPinWrite( xGPIO_PORTE_BASE, xGPIO_PIN_29,0);
85
xGPIOPinWrite( xGPIO_PORTE_BASE, xGPIO_PIN_30,0);
86
87
88
for(b=0;b<1000;b++)
89
for(c=0;c<1000;c++);
90
91
if(xGPIOPinRead( xGPIO_PORTE_BASE, xGPIO_PIN_20)!=0)// These code finds out which key is pressed
and stores value as "val".
92
{
93
for(b=0;b<1000;b++)
94
for(c=0;c<1000;c++);
95
if(xGPIOPinRead( xGPIO_PORTE_BASE, xGPIO_PIN_20)!=0)
96
{
97
val=1;
98
break;
99
}
100
}
101
102
else if(xGPIOPinRead( xGPIO_PORTE_BASE, xGPIO_PIN_21)!=0)
103
{
104
for(b=0;b<1000;b++)
105
for(c=0;c<1000;c++);
106
107
if(xGPIOPinRead( xGPIO_PORTE_BASE, xGPIO_PIN_21)!=0)
108
{
109
val=2;
110
break;
111
}
112
}
113
114
else if(xGPIOPinRead(xGPIO_PORTE_BASE, xGPIO_PIN_22)!=0)
115
{
116
for(b=0;b<1000;b++)
117
for(c=0;c<1000;c++);
118
119
if(xGPIOPinRead( xGPIO_PORTE_BASE, xGPIO_PIN_22)!=0)
120
{
121
val=3;
122
break;
123
}
124
}
125
126
xGPIOPinWrite( xGPIO_PORTE_BASE, xGPIO_PIN_23,0);
127
xGPIOPinWrite( xGPIO_PORTE_BASE, xGPIO_PIN_29,1);
128
xGPIOPinWrite( xGPIO_PORTE_BASE, xGPIO_PIN_30,0);
129
130
131
for(b=0;b<1000;b++)

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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197

for(c=0;c<1000;c++);

if(xGPIOPinRead( xGPIO_PORTE_BASE, xGPIO_PIN_20)!=0)


{
for(b=0;b<1000;b++)
for(c=0;c<1000;c++);
if(xGPIOPinRead( xGPIO_PORTE_BASE, xGPIO_PIN_20)!=0)
{
val=4;
break;
}
}

else if(xGPIOPinRead( xGPIO_PORTE_BASE, xGPIO_PIN_21)!=0)


{
for(b=0;b<1000;b++)
for(c=0;c<1000;c++);
if(xGPIOPinRead( xGPIO_PORTE_BASE, xGPIO_PIN_21)!=0)
{
val=5;
break;
}
}
else if(xGPIOPinRead(xGPIO_PORTE_BASE, xGPIO_PIN_22)!=0)
{
for(b=0;b<1000;b++)
for(c=0;c<1000;c++);
if(xGPIOPinRead( xGPIO_PORTE_BASE, xGPIO_PIN_22)!=0)
{
val=6;
break;
}
}
xGPIOPinWrite( xGPIO_PORTE_BASE, xGPIO_PIN_23,0);
xGPIOPinWrite( xGPIO_PORTE_BASE, xGPIO_PIN_29,0);
xGPIOPinWrite( xGPIO_PORTE_BASE, xGPIO_PIN_30,1);
for(b=0;b<1000;b++)
for(c=0;c<1000;c++);
if(xGPIOPinRead( xGPIO_PORTE_BASE, xGPIO_PIN_20)!=0)
{
for(b=0;b<1000;b++)
for(c=0;c<1000;c++);
if(xGPIOPinRead( xGPIO_PORTE_BASE, xGPIO_PIN_20)!=0)
{
val=7;
break;
}
}
else if(xGPIOPinRead( xGPIO_PORTE_BASE, xGPIO_PIN_21)!=0)
{
for(b=0;b<1000;b++)
for(c=0;c<1000;c++);
if(xGPIOPinRead( xGPIO_PORTE_BASE, xGPIO_PIN_21)!=0)
{

198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254

val=8;
break;
}
}
else if(xGPIOPinRead(xGPIO_PORTE_BASE, xGPIO_PIN_22)!=0)
{
for(b=0;b<1000;b++)
for(c=0;c<1000;c++);
if(xGPIOPinRead( xGPIO_PORTE_BASE, xGPIO_PIN_22)!=0)
{
val=9;
break;
}
}
xGPIOPinWrite( xGPIO_PORTB_BASE, xGPIO_PIN_18, 0);
if(a>100000)
{
xGPIOPinWrite( xGPIO_PORTB_BASE, xGPIO_PIN_18, 1);
}
a++;
}
start: //PWM section starts here
mPWM=val*10000; //adjusts the duty cycle curresponding to the number input
xGPIOPinWrite( xGPIO_PORTE_BASE, xGPIO_PIN_23,1);
xGPIOPinWrite( xGPIO_PORTE_BASE, xGPIO_PIN_29,0);
xGPIOPinWrite( xGPIO_PORTE_BASE, xGPIO_PIN_30,0);
for(b=0;b<1000;b++)
for(c=0;c<1000;c++);
while(1) //generation of pwm.
{
Tim=0;
while (Tim<mPWM)
{}
xGPIOPinWrite( xGPIO_PORTB_BASE,
xGPIOPinWrite( xGPIO_PORTB_BASE,
Tim=0;
while (Tim<(100000-mPWM))
{}
xGPIOPinWrite( xGPIO_PORTB_BASE,
xGPIOPinWrite( xGPIO_PORTB_BASE,
}
}

xGPIO_PIN_19, 1 ); // Turn off green led


xGPIO_PIN_0, 1 ); // Probe off

xGPIO_PIN_19, 0 ); // Turn on green led


xGPIO_PIN_0, 0 ); // Probe on

Anda mungkin juga menyukai