Data Sheet

Page 12
Page 13
Time has come to do some coding. mikroBasic
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 congure each PORT and
enable pins that you need, without worrying
about complex procedure that this operation
requires. To demonstrate this, we will write
our rst line of code:
Once we have enabled PORTA to act as digital
output, we can now initialize PORTA with
logic zeros on every PORT pin:
Finally, in a while() loop we will toggle the
PORTA value, and put a 1000 ms delay, so the
blinking is not too fast.
program LedBlinking
‘ Declarations section
main:
‘ Main program
‘ Set PORTA as digital output
GPIO_Digital_Output(@GPIO_PORTA,
_GPIO_PINMASK_ALL)
‘ Set PORTA initial value to zero
GPIO_PORTA_DATA = 0
while TRUE
‘ Toggle PORTA
GPIO_PORTA_DATA = NOT GPIO_PORTA_DATA
‘ Delay 1000 ms
Delay_ms(1000)
wend
end.
‘ 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
19
20
21
22
LedBlinking.mbas - source code
4. Code Example
Figure 4-1: Complete source code of the PORTA LED blinking