Datasheet
Page 15
It’s time to do some coding. First thing we
need to do is to put PORT0 LEDs into initial
state. For example, let’s ll it with logic zeros
on every pin:
Finally, in a while() loop we will toggle the
PORT0 value, and put a 1000 ms delay, so
the blinking is not too fast.
// Turn OFF all LEDs on PORT0
P0 = 0;
while(1) {
// Toggle LEDs on PORT0
P0 = ~P0;
// Delay 1000 ms
Delay_ms(1000);
}
4. Code example
void main() {
// Turn OFF LEDs on PORT0
P0 = 0;
while(1) {
// Toggle LEDs on PORT0
P0 = ~P0;
// Delay 1000 ms
Delay_ms(1000);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
LedBlinking.c - source code
Figure 4-1: Complete source code of the PORT0 LED blinking