UPS25 30
RTD Embedded Technologies, Inc
Clearing and setting bits in an I/O port
When you clear or set bits in an I/O port you must be careful not to alter the
status of other bits. You can preserve the status of all the bits you do not wish to
change by proper use of the bitwise AND- and OR- operators. Using and /or
operators, single or multiple bits can easily be set or cleared in a one-line
operation.
1.
To clear a single bit in a port, AND the current value of the port with the
value "B", where B = 255-2(exp) bit.
2.
To set a single bit in a port, OR the current value of the port with the value
"B", where B = 2(exp) bit.
Bits are numbered from 0-7 for the low byte of a word and from 8-15 for
the high byte of a word. Setting and clearing of multiple bits in a bye or
word is more complex.
3.
To clear multiple bits in a port, AND the current value of the port with the
value "B", where B = 255 - (the sum of the values of the bits to be
cleared). Note that the bits do not have to be consecutive.
4.
To set multiple bits in a port, OR the current value of the port with the
value "B", where B = (sum of the individual bits to be set).
INTERRUPTS
What is an interrupt?
An interrupt is an event that causes the processor in your computer to temporarily
halt its current process and execute another routine. Upon completion of the new
routine, control is returned to the original routine at the point where its execution
was interrupted.
Interrupts are a very flexible way of dealing with asynchronous events. Keyboard
activity is a good example; your computer cannot predict when you might press a
key and it would be a waste of processor time to do nothing whilst waiting for a
keystroke to occur. Thus the interrupt scheme is used and the processor proceeds
with other tasks. When a keystroke finally occurs, the keyboard then 'interrupts'
the processor so that it can get the keyboard data .It then places it into the
memory, and then returns to what it was doing before the interrupt occurred. Other
common devices that use interrupts are A/D boards, network boards, serial ports
etc.
Your UPS25 can interrupt the main processor when the main power supply fails or
falls below 10V if interrupts are enabled on the UPS25 board. By using interrupts
you can write powerful code to interface to your UPS25.