Fan174
Member level 2
I want to blink Led when I press switch button
PIC16F877A
Compiler MPLABX
This is my code
Output report
But when I press switch button my Led doesn't blink it stay only ON. Please someone help me
PIC16F877A
Compiler MPLABX
This is my code
Code:
// PIC16F877A Configuration Bit Settings
// 'C' source line config statements
// CONFIG
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = ON // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#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.
#define _XTAL_FREQ 16000000
#include <xc.h>
int main()
{
TRISB0 = 0; //RB0 as Output PIN
TRISD7 = 1; //RD7 as Input PIN
RB0 = 0; //LED Off
while(1)
{
if(RD7 == 0) //If Switch Pressed
{
RB0 = 1; //LED ON
__delay_ms(3000); //3 Second Delay
RB0 = 0; //LED OFF
}
}
return 0;
}
Output report
BUILD SUCCESSFUL (total time: 5s)
Loading code from E:/shyam/1. Embedded System/Project/PIC/Switch/Switch1/Switch1.X/dist/default/production/Switch1.X.production.hex...
Loading completed
But when I press switch button my Led doesn't blink it stay only ON. Please someone help me