A sample program to blink an LED by using MPLBX - C Compilers in PIC16F877A as our previous post PIC Microcontroller Tutorial gives the basic Details of PIC16f877A.
In MPLABX at first we need to configure the bit first. That means ,
For more learn from Here.
In MPLABX at first we need to configure the bit first. That means ,
- How or what type Oscillator will use ?
- Is there needed Watch Dog timer ?
- Program Memory Code Protection bit ie, no one can be read the HEX code from the Controller.
For more learn from Here.
#include<xc.h>// 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 = OFF // Brown-out Reset Enable bit (BOR disabled) #pragma config LVP = ON // 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) #define _XTAL_FREQ 8000000 // taking as crystal frequency as 8Mhz #define LED_Port PORTD // defining PORTD as LED_Port int main() { TRISD = 0x00; // Making PORTD as output while(1) { LED_Port =0Xff; // giving High values to Port to lightup LED __delay_ms(500); // giving a half second delay LED_Port = 0x00; // Giving a low to port to turn off the LEDs __delay_ms(500); } }