Difference between revisions of "Relay with PIC16F877A Starter Board"
(Created page with "Category:Starter PIC16F877 =Demo= File:Pic16f877a relay.gif<br><br>") |
|||
Line 1: | Line 1: | ||
[[Category:Starter PIC16F877]] | [[Category:Starter PIC16F877]] | ||
+ | |||
+ | Code= | ||
+ | <html> | ||
+ | <script src="https://gist.github.com/sharanago/20cf284b93c9ccbcd9f129efef53e1fe.js"></script> | ||
+ | </html> | ||
=Demo= | =Demo= | ||
[[File:Pic16f877a relay.gif]]<br><br> | [[File:Pic16f877a relay.gif]]<br><br> |
Revision as of 19:37, 27 April 2016
Code=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "gpio.h" | |
#define Relay PD_0 // Relay is connected to PORTD.0 | |
#define SW1 PD_2 // Switch is connected to PORTD.2 | |
/* start the main program */ | |
void main() | |
{ | |
uint8_t value; | |
GPIO_PinDirection(SW1,INPUT); // Configure the switch pin as Input | |
GPIO_PinDirection(Relay,OUTPUT); // Configure the Relay pin as OUTPUT | |
while(1) | |
{ | |
value = GPIO_PinRead(SW1); // Read the switch status | |
GPIO_PinWrite(Relay,!value); // ON/OFF the Relay as per switch status | |
} | |
} |