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

Показать описание
Example 3
TMR0 as a counter, declaring new variables, enumerated constants, using relay ...
Referring to the previous examples, the microcontroller executes the program without being affected in any way by its surrounding. Practically, devices operating in this manner are very rare (for example, simple neon sign controller). Input pins are also used in this example. There is a schematic in figure below, while the program is on the next page. It’s still very simple. Timer TMR0 is used as a counter. The counter input is connected to a push button so that any button press causes timer TMR0 to count one pulse. When the number of pulses matches the number stored in the TEST register, a logic one (5V) appears on the pin PORTD.3. This voltage activates an electromechanical relay, and this bit is called ‘RELAY’ in the program, therefore. In this example, the TEST register stores number 5. Of course, it can be any number obtained either by computing or defined as a constant. Besides, the microcontroller can activate some other device instead of relay, while the sensor can be used instead of the push button. This example illustrates one of the most common applications of the microcontroller in the industry; when something is performed as many times as needed, then something else should be turned on or off....
TMR0 as a counter, declaring new variables, enumerated constants, using relay ...
Referring to the previous examples, the microcontroller executes the program without being affected in any way by its surrounding. Practically, devices operating in this manner are very rare (for example, simple neon sign controller). Input pins are also used in this example. There is a schematic in figure below, while the program is on the next page. It’s still very simple. Timer TMR0 is used as a counter. The counter input is connected to a push button so that any button press causes timer TMR0 to count one pulse. When the number of pulses matches the number stored in the TEST register, a logic one (5V) appears on the pin PORTD.3. This voltage activates an electromechanical relay, and this bit is called ‘RELAY’ in the program, therefore. In this example, the TEST register stores number 5. Of course, it can be any number obtained either by computing or defined as a constant. Besides, the microcontroller can activate some other device instead of relay, while the sensor can be used instead of the push button. This example illustrates one of the most common applications of the microcontroller in the industry; when something is performed as many times as needed, then something else should be turned on or off....