Datasheet
Page 14
Time has come to do some coding. mikroC
PRO for ARM
®
has the unique libraries that
enable you to do complicated tasks in a
single line of code. Built-in GPIO library
enables you to set congure each PORT
and enable pins that you need, without
worrying about complex procedure that
this operation requires. To demonstrate
this,wewillwriteourrstlineofcode:
Once we have enabled PORTA to act as
digital output, we can now initialize PORTA
withlogiczerosoneveryPORTpin:
Finally, in a while() loop we will toggle the
PORTA value, and put a 1000 ms delay, so
the blinking is not too fast.
void main() {
// Set PORTA as digital output
GPIO_Digital_Output(&GPIO_PORTA,
_GPIO_PINMASK_ALL);
// Set PORTA initial value to zero
GPIO_PORTA_DATA = 0;
while(1) {
// Toggle PORTA
GPIO_PORTA_DATA = ~GPIO_PORTA_DATA;
// Delay 1000 ms
Delay_ms(1000);
}
}
// Set PORTA as digital output
GPIO_Digital_Output(
&GPIO_PORTA,
_GPIO_PINMASK_ALL);
// Set PORTA initial value to 0
GPIO_PORTA_DATA = 0;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
LedBlinking.c - source code
4. Code example
Figure 4-1: Complete source code of the PORTA LED blinking