Difference between revisions of "Buzzer with PIC16F877A Starter Board"
Line 4: | Line 4: | ||
=Steps= | =Steps= | ||
− | #Configure the PORT D0 as output . | + | #Configure the PORT D0 as output to control the buzzer. |
− | #Configure the PORT D2 as input. | + | #Configure the PORT D2 as input to read the switch status.. |
#Read the switch status. | #Read the switch status. | ||
#ON/OFF the Buzzer as per switch status. | #ON/OFF the Buzzer as per switch status. |
Revision as of 18:25, 2 May 2016
In this tutorial we will see how to interface a switch and buzzer with Pic16f877a starter board.
The switch will be used to control the buzzer.
Steps
- Configure the PORT D0 as output to control the buzzer.
- Configure the PORT D2 as input to read the switch status..
- Read the switch status.
- ON/OFF the Buzzer as per switch status.
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 LED PD_0 // Led 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(LED,OUTPUT); // Configure the Led pin as OUTPUT | |
while(1) | |
{ | |
value = GPIO_PinRead(SW1); // Read the switch status | |
GPIO_PinWrite(LED,value); // ON/OFF the led as per switch status | |
} | |
} |