GPIO Registers
PORT | Direction Register | Number of Pins | Alternative Function |
PORTA | TRISA | 6 (PA0-PA5) | ADC |
PORTB | TRISB | 8 (PB0-PB7) | Interrupts |
PORTC | TRISC | 8 (PC0-PC7) | UART,I2C,PWM |
PORTD | TRISD | 8 (PD0-PD7) | Parallel Slave Port |
PORTE | TRISE | 3 (PE0-PB2) | ADC |
Hardware Connection:
LED On Off Control with Pushbutton using PIC16f877a |
Program:
/** File: 2_LedOnOffWithPushButton.c
* Author: Udaya
* LedOnOffWithPushButton
*
* Circuit connection
* RD6- Connected to LED as OUTPUT
* RC0- Connected to Pushbutton/SPDT switch to on/off control
*
* Created on June 3, 2019, 2:23 PM
*/
#define _XTAL_FREQ 8000000
#pragma config FOSC = HS // Oscillator Selection bits (RC oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = OFF // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3/PGM pin has PGM function; low-voltage programming enabled)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
#include <xc.h>
void delay(k)
{ //delay function
unsigned int i,j;
for(i=0;i<k;i++)
{
for(j=0;j<100;j++);
}
}
int main()
{
TRISD6 = 0;
TRISC0 = 1;
while(1)
{
if(RC0 = 1)
{
RD6 =1;
delay(100);
}
else
{
RD6 = 0;
delay(100);
}
}
}