Datasheet
Page 15
Time has come to do some coding. First
thing we need to do is to put PORT0 LEDs
intoinitialstate.Forexample,let’sllitwith
logiczerosoneverypin:
Finally, in a while loop we will toggle the
PORT0 value, and put a 1000 ms delay, so
the blinking is not too fast.
program LedBlinking;
begin
// Turn OFF LEDs on PORT0
P0 := 0;
while TRUE do
begin
// Toggle LEDs on PORT0
P0 := not P0;
// Delay 1000 ms
Delay_ms(1000);
end; // Endless loop
end.
// Turn OFF all LEDs on PORT0
P0 := 0;
while TRUE do
begin
// Toggle LEDs on PORT0
P0 := not P0;
// Delay 1000 ms
Delay_ms(1000);
end;
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 PORT0 LED blinking