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....

Only one enumerated  constant  RELAY  is used in this example.  It is assigned  a value when
declared.

All the  constants,  following  those  with  assigned  values  (RELAY  = 3 and  MOTOR  = 6),  are automatically  assigned  values incremented  by 1 relative  to the previous  constant  value. In this  example,  constants  HEATER  and  PUMP  will  be  assigned  values  4 and  7,  respectively (HEATER = 4 and PUMP = 7).

0 komentar: