In the previous post, we have discussed about using the digital input/Output of PORTA. Now let move to a typical example of turn on a relay on and off. This job is easily done by inverting the output bit of PORTA register.
Schematic Diagram |
Each time the switch connects to RA0 is pressed, the CPU toggle the output relay.
#define RLY PORTA.F1 #define SW PORTA.F0 void main() { PORTA=0x00; // CLEAR PORTA TRISA=0x01; // RA0 IS INPUT ANSEL=0x00; // Disable all analog function while(1) { if(SW==0) { while(SW==0) ; // wait for switch release RLY=RLY^1; // toggle relay on/off } } }
No comments:
Post a Comment