filmov
tv
PIC Microcontrollers Programming in C - Example 1 with MikroC Pro for PIC and Protheus

Показать описание
Example 1-1
The only purpose of this program is to turn on a few LED diodes on port B.
When switching on, every other LED diode on the port B emits light, which indicates that the microcontroller is properly connected and operates normally.
Example 1-2
To make this example more interesting, we will enable LEDs connected to the port B to blink. There are several ways to do it:
As soon as the microcontroller is turned on, all LEDs will emit light for a second. The Delay function is in charge of it in the program. It’s only needed to set delay expressed in milliseconds.
After one second, the program enters the for loop and remains there as long as the variable k is less than 20. The variable is incremented by 1 after each iteration. Within the for loop, the switch operation monitors port B logic state. If PORTB=0xFF, its state is inverted into 0x00 and vice versa. Any change of these logic states causes all LEDs to blink. Duty Cycle is 5:1 (500mS:100mS).
When the program exits the for loop, the port B logic state changes (0xb 01010101) and the program enters the endless while loop and remains there as long as 1=1. The port B logic state is inverted each 200mS.
The only purpose of this program is to turn on a few LED diodes on port B.
When switching on, every other LED diode on the port B emits light, which indicates that the microcontroller is properly connected and operates normally.
Example 1-2
To make this example more interesting, we will enable LEDs connected to the port B to blink. There are several ways to do it:
As soon as the microcontroller is turned on, all LEDs will emit light for a second. The Delay function is in charge of it in the program. It’s only needed to set delay expressed in milliseconds.
After one second, the program enters the for loop and remains there as long as the variable k is less than 20. The variable is incremented by 1 after each iteration. Within the for loop, the switch operation monitors port B logic state. If PORTB=0xFF, its state is inverted into 0x00 and vice versa. Any change of these logic states causes all LEDs to blink. Duty Cycle is 5:1 (500mS:100mS).
When the program exits the for loop, the port B logic state changes (0xb 01010101) and the program enters the endless while loop and remains there as long as 1=1. The port B logic state is inverted each 200mS.