I followed this Tutorial and changed the code for my Micro-controller 16f1827. I also changed the function of the code. It should turn on a LED if the ADC Value is more than half of max. ADC Value and turn off a LED if less than half.
// CONFIG
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#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 = 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)
#include <xc.h>
#include <pic16f1827.h>
#define _XTAL_FREQ 8000000
void ADC_Init()
{
ADCON0 = 0x81; //Turn ON ADC and Clock Selection
ADCON1 = 0x00; //All pins as Analog Input and setting Reference Voltages
}
unsigned int ADC_Read(unsigned char channel)
{
if(channel > 7) //Channel range is 0 ~ 7
return 0;
ADCON0 &= 0xC5; //Clearing channel selection bits
ADCON0 |= channel<<3; //Setting channel selection bits
__delay_ms(2); //Acquisition time to charge hold capacitor
GO_nDONE = 1; //Initializes A/D conversion
while(GO_nDONE); //Waiting for conversion to complete
return ((ADRESH<<8)+ADRESL); //Return result
}
void main()
{
unsigned int a;
TRISA = 0xFF; //Analog pins as Input
TRISB = 0x00; //Port B as Output
//TRISC = 0x00; //Port C as Output
ADC_Init(); //Initialize ADC
do
{
a = ADC_Read(0); //Read Analog Channel 0
//PORTB = a; //Write Lower bits to PORTB
//PORTC = a>>8; //Write Higher 2 bits to PORTC
if(a > 512){
PORTBbits.RB7 = 1;
}else{
PORTBbits.RB7 = 0;
}
__delay_ms(100); //Delay
}while(1); //Infinite Loop
}
The Code compiles without error in XC8. The problem is the PIC detects the ADC changes too slow. If I take the Input pin and connect it to the positive reference Value it turns on the LED with a Delay of maybe 2 Seconds. The same happens when I change the ADC Input to 0v. All changes are detected very slow. Why is the ADC working so slow?
The tutorial that you link to uses a PIC16F877A with an 8MHz crystal oscillator whereas you appear to be trying to use a PIC16F1827 with its internal oscillator instead of an external oscillator. It is not sufficient to just change the PIC header file as you have done. You must also set the required oscillator mode and take care of any other configuration options that differ between the two parts. I'm not certain, but I think that the default internal oscillator frequency for the 16F1827 is 1MHz, not 8MHz. This may go some way to explaining the problems that you are experiencing.
BTW: Don't be tempted to fudge your code. Make sure that you configure your microcontrollers correctly otherwise they will bite you on the bum sooner or later.
Related
Using a PIC18F47J53, MPLAB x, XC8 (v2.31), I am trying to use the internal RTCC, but I cannot see it counting (the seconds). The register RTCVALL, is not changing after waiting a few seconds.
I would like to use the 8MHz internal oscillator for the main clock, and the internal INTRC for the RTCC. Maybe first someone can confirm is it possible to use those 2?
The code is fairly simple, just setting a "seconds" value in RTCVALL, wait a bit, read the same register and hoping to find it has changed.. but it hasn't.
I am posting the main part of the code.
Other question, what is the RTCC pin is supposed to output? I have chosen the "seconds" as output, but if it is supposed to toggle high/low every seconds, where can I see in the datasheet the duty cycle? in my case the LED on RTCC pin stays solid high.
'''
// CONFIG1L
#pragma config WDTEN = OFF // Watchdog Timer (Disabled - Controlled by SWDTEN bit)
#pragma config PLLDIV = 1 // PLL Prescaler Selection (No prescale (4 MHz oscillator input drives PLL directly))
#pragma config CFGPLLEN = OFF // PLL Enable Configuration Bit (PLL Disabled)
#pragma config STVREN = ON // Stack Overflow/Underflow Reset (Enabled)
#pragma config XINST = OFF // Extended Instruction Set (Disabled)
// CONFIG1H
#pragma config CPUDIV = OSC1 // CPU System Clock Postscaler (No CPU system clock divide)
#pragma config CP0 = OFF // Code Protect (Program memory is not code-protected)
// CONFIG2L
#pragma config OSC = INTOSC // Oscillator (INTOSC)
#pragma config SOSCSEL = HIGH // T1OSC/SOSC Power Selection Bits (High Power T1OSC/SOSC circuit selected)
#pragma config CLKOEC = ON // EC Clock Out Enable Bit (CLKO output enabled on the RA6 pin)
#pragma config FCMEN = ON // Fail-Safe Clock Monitor (Enabled)
#pragma config IESO = ON // Internal External Oscillator Switch Over Mode (Enabled)
// CONFIG2H
#pragma config WDTPS = 32768 // Watchdog Postscaler (1:32768)
// CONFIG3L
#pragma config DSWDTOSC = INTOSCREF// DSWDT Clock Select (DSWDT uses INTRC)
#pragma config RTCOSC = INTOSCREF // RTCC Clock Select (INTRC)
#pragma config DSBOREN = ON // Deep Sleep BOR (Enabled)
#pragma config DSWDTEN = ON // Deep Sleep Watchdog Timer (Enabled)
#pragma config DSWDTPS = G2 // Deep Sleep Watchdog Postscaler (1:2,147,483,648 (25.7 days))
// CONFIG3H
#pragma config IOL1WAY = ON // IOLOCK One-Way Set Enable bit (The IOLOCK bit (PPSCON<0>) can be set once)
#pragma config ADCSEL = BIT10 // ADC 10 or 12 Bit Select (10 - Bit ADC Enabled)
#pragma config MSSP7B_EN = MSK7 // MSSP address masking (7 Bit address masking mode)
// CONFIG4L
#pragma config WPFP = PAGE_127 // Write/Erase Protect Page Start/End Location (Write Protect Program Flash Page 127)
#pragma config WPCFG = OFF // Write/Erase Protect Configuration Region (Configuration Words page not erase/write-protected)
// CONFIG4H
#pragma config WPDIS = OFF // Write Protect Disable bit (WPFP<6:0>/WPEND region ignored)
#pragma config WPEND = PAGE_WPFP// Write/Erase Protect Region Select bit (valid when WPDIS = 0) (Pages WPFP<6:0> through Configuration Words erase/write protected)
#pragma config LS48MHZ = SYS48X8// Low Speed USB mode with 48 MHz system clock bit (System clock at 48 MHz USB CLKEN divide-by is set to 8)
#define UINT_TO_BCD_ONES(x) ((x) % 10)
#define UINT_TO_BCD_TENS(x) (((x) % 100) / 10)
#define BCD_TO_UINT_TENS(x) ((x) >> 4)
#define BCD_TO_UINT_ONES(x) ((x) & 0x0F)
void main(void)
{
// set to 8MHz internal oscillator
OSCCON = 0x70;
// not sure that is necessary but either 0 or 1 don't work
OSCTUNEbits.INTSRC = 1;
pic_uart1_init(UART_BDS_9600);
__delay_ms(1000);
uint8_t seconds = 0;
// seconds RTCC output pin
PADCFG1bits.RTSECSEL1 = 0;
PADCFG1bits.RTSECSEL0 = 1;
pic_rtc_set_alarm_output(ON);
pic_rtc_enable(ON);
pic_rtc_wr_enable(ON);
pic_rtc_set_seconds(45);
pic_rtc_wr_enable(OFF);
// wait some time
for (int i = 0; i < 12; i++){
__delay_ms(1000);
printf("-> RTCVALL = %d\n", RTCVALL);
printf("-> RTCVALH = %d\n", RTCVALH);
}
pic_rtc_read_seconds(&seconds);
pic_rtc_enable(OFF);
printf("seconds = %d\n", seconds);
}
pic_status_t pic_rtc_enable(feature_status_t set_status)
{
pic_rtc_wr_enable(ON);
RTCCFGbits.RTCEN = set_status;
pic_rtc_wr_enable(OFF);
return PIC_SUCCESS;
}
pic_status_t pic_rtc_set_alarm_output(feature_status_t set_status)
{
RTCCFGbits.RTCOE = set_status;
return PIC_SUCCESS;
}
pic_status_t pic_rtc_wr_enable(feature_status_t set_status)
{
INTCONbits.GIE = 0;
EECON2 = 0x55;
EECON2 = 0xAA;
RTCCFGbits.RTCWREN = set_status;
INTCONbits.GIE = 1;
return PIC_SUCCESS;
}
pic_status_t pic_rtc_read_seconds(uint8_t *seconds)
{
// point to minutes
RTCCFGbits.RTCPTR1 = 0;
RTCCFGbits.RTCPTR0 = 0;
printf("RTCCFGbits.RTCPTR1 = %d\n", RTCCFGbits.RTCPTR1);
printf("RTCCFGbits.RTCPTR0 = %d\n", RTCCFGbits.RTCPTR0);
printf("RTCCFGbits.RTCWREN = %d\n", RTCCFGbits.RTCWREN);
uint8_t buffer_rd_sec = RTCVALL;
printf("buffer_rd_sec (BCD) = 0x%02x\n", buffer_rd_sec);
*seconds = (uint8_t)((BCD_TO_UINT_TENS(buffer_rd_sec) * 10) + (BCD_TO_UINT_ONES(buffer_rd_sec)));
return PIC_SUCCESS;
}
pic_status_t pic_rtc_set_seconds(uint8_t seconds)
{
if (seconds > 59)
return PIC_FAIL;
// point to seconds
RTCCFGbits.RTCPTR1 = 0;
RTCCFGbits.RTCPTR0 = 0;
printf("RTCCFGbits.RTCPTR1 = %d\n", RTCCFGbits.RTCPTR1);
printf("RTCCFGbits.RTCPTR0 = %d\n", RTCCFGbits.RTCPTR0);
printf("RTCCFGbits.RTCWREN = %d\n", RTCCFGbits.RTCWREN);
uint8_t buf_ones = UINT_TO_BCD_ONES(seconds);
printf("buf_ones = 0x%02x\n", buf_ones);
uint8_t buf_tens = UINT_TO_BCD_TENS(seconds);
printf("buf_tens = 0x%02x\n", buf_tens);
uint8_t buffer = buf_tens << 4 | buf_ones;
printf("buffer = 0x%02x\n", buffer);
RTCVALL = buffer;
return PIC_SUCCESS;
}
'''
Thanks for having a look and help
I got it working, looks like it wasn't the understanding of the PIC the problem, but the XC8 compiler instead..
I thought the RTCWREN bit had to be checked before enable the RTCEN
pic_status_t pic_rtc_enable(feature_status_t set_status)
{
while(!RTCCFGbits.RTCWREN); // wait for the bit to be set
RTCCFGbits.RTCEN = set_status;
return PIC_SUCCESS;
}
and found that the bit wasn't set at all, resulting the rest of the code been ignored.
so I looked into my pic_rtc_wr_enable function and I am very puzzled why the parameter set_status is making the block!
it is an enum,
typedef enum {
OFF = 0,
ON = 1,
} feature_status_t;
but if you replace the code with
pic_status_t pic_rtc_wr_enable(feature_status_t set_status)
{
if (set_status == 1) {
INTCONbits.GIE = 0;
EECON2 = 0x55;
EECON2 = 0xAA;
RTCCFGbits.RTCWREN = 1;
INTCONbits.GIE = 1;
}
return PIC_SUCCESS;
}
then it works perfectly fine.
So why XC8 doesn't substitute my enum ON with its int value of 1 for the bit assignment? despite it works in the check?
Any ideas?
For the RTCC pin, got it working too now, and it looks like the pin out is pulsing every seconds (in my case), and duty cycle is 50%.
I'm using PIC10F322 and timer0 with interrupt, trying to blink an LED, on for 1s and then off for another 1s. I had tried coded the timer called for interrupt, and it work good. But the counting for time isn't correct. The counting was On for about 2s and then Off for another 2s, which is isn't correct. I wonder is there something wrong with the calculation? The chip is 16MHZ, timer0 is 8 bits and set prescaler to 256. My attempt is to trigger interrupt every 1ms, then do a 999 loop count to hit 1 second.
My calculation is:
256 - [(Delay * Fosc) / (prescaler*4)] = 256 - [(1ms * 16000000)/(256*4)] = 240
#define _XTAL_FREQ 16000000
#include <xc.h>
#pragma config FOSC = INTOSC // Oscillator Selection bits (INTOSC oscillator: CLKIN function disabled)
#pragma config BOREN = OFF // Brown-out Reset Enable (Brown-out Reset disabled)
#pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = OFF // MCLR Pin Function Select bit (MCLR pin function is MCLR)
#pragma config CP = OFF // Code Protection bit (Program memory code protection is disabled)
#pragma config LVP = OFF // Low-Voltage Programming Enable (High-voltage on MCLR/VPP must be used for programming)
#pragma config LPBOR = ON // Brown-out Reset Selection bits (BOR disabled)
#pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off)
int z = 0,count=0;
void main(void) {
ANSELA = 0x00;
TRISA = 0b0100;
TRISAbits.TRISA2 = 1;
LATAbits.LATA0 = 0;
INTCONbits.GIE=1; /* Enable Global Interrupt*/
INTCONbits.PEIE = 1; /* Enable peripheral Interrupt */
OPTION_REGbits.T0CS = 0;
OPTION_REGbits.PSA = 0;
OPTION_REGbits.PS0 = 1; /* set prescaler to 256 */
OPTION_REGbits.PS1 = 1;
OPTION_REGbits.PS2 = 1;
OPTION_REGbits.INTEDG = 0;
TMR0 = 240;
INTCONbits.TMR0IF = 0;
INTCONbits.TMR0IE = 1;
while(1){
}
return;
}
void __interrupt(high_priority) tcInt(void)
{
if (TMR0IE && TMR0IF)
{
TMR0 = 240;
TMR0IF = 0;
if (count == 999)
{
z = 0;
LATAbits.LATA0 = ~LATAbits.LATA0;
count =0;
}
count++;
}
return;
}
You timer calculation is fine but I guess your microcontroller is running at 8 MHz which is the default value after reset if you are working with the internal oscillator (#pragma config FOSC = INTOSC). If you like 16 MHz, you had to do the selection in the OSCCON register.
OSCCON = 0b01110000;
I am trying to make a proximity sensor using ATmega328P. I am using the onboard ADC to convert the voltage value and if it is higher than the ambient, an LED is lit.
The voltage that is being sensed is according to this circuit:
In the circuit, the VOUT is going to ADC channel 3 and should be sensed (think of the led on the right as the IR Sensor).
When the program starts, it senses 30 readings and takes their average to be used as the ambient setting. If any subsequent measurement is higher than this value, the LED should be lit.
But the LED does not light even if I place my hand above the sensor.
I have tested with just the LED to see if the IR sensor is ok. It is ok by the way.
The code for the microcontroller is as follows:
/*
* Proximity Sensor IR.c
*
* Created: 6/3/2017 2:35:33 PM
* Author : Rishav
*/
#include <avr/io.h>
#include <stdio.h>
#define F_CPU 16000000UL
#include <util/delay.h>
int calibration()
{
unsigned int sum = 0;
for (int i=0; i<30; i++)
{
ADCSRA |= (1<<ADSC);
while(!(ADCSRA & (1<<ADIF)));
ADCSRA |= (1<<ADIF);
sum += (ADCH<<8)|ADCL;
}
return (sum/30);
}
int main(void)
{
unsigned int val = 0;
ADMUX |= (0<<REFS1)|(1<<REFS0)|(0<<MUX3)|(0<<MUX2)|(1<<MUX1)|(1<<MUX0); //setting the multiplexer to ADC3
ADCSRA |= (1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);
DDRB = 0b00000010;
DDRD |= (1<<PCINT22);
PORTD |= (1<<PCINT22);
int calib_value = calibration();
while (1)
{
ADCSRA |= (1<<ADSC);
while(!(ADCSRA & (1<<ADIF)));
val = (ADCH<<8)|ADCL;
ADCSRA |= (1<<ADIF);
if (val > calib_value)
PORTB = 0b00000010;
}
}
I think there is some problem in the code. Please help.
Some things that come to mind when looking at your code:
You are really not completely initializing the ADMUX and ADCSRA registers - everything you put in there is just 'ORed'-in. (ADLAR in ADMUX is not in a defined state, for example, ADCSRA has even more undefined bits).
After setting the reference voltage source in the ADMUX register, you are supposed to wait for the chip to switch, but don't. Most probably, your first measurement in calibration will be way off. The simplest way to address this is to do one first measurement whose result you simply ignore. (or wait some ms after you have set up ADC).
You are supposed to always read ADCL before ADCH (the AVR locks the ADC for writing further results to the result register when ADCL is read until ADCH is read as well). Your current code has an undefined read order of those 2 registers.
You have to enable the ADC first and select channel and reference voltage afterwards. It is easy to skip this fact in the datasheet.
The ADC is enabled by setting the ADC Enable bit, ADEN in ADCSRA.
Voltage reference and input channel selections will not go into effect
until ADEN is set. Datasheet page 238.
I did not check all of your settings but I am pretty sure that this must be your issue.
Example order:
void init_adc()
{
ADCSRA |= (1<<ADEN); // enable ADC
ADMUX |= (1<<MUX1) | (1<<MUX0); // channel selection ADC3 - PB3
ADMUX &= ~(1<<REFS0); // VCC as reference
ADCSRA |= (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0); // setting prescaler to 128
}
As mentioned a you should read ADCL first to:
ADCL must be read first, then ADCH, to ensure that the content of the
Data Registers belongs to the same conversion
I suggest to move this part into a separate function like:
uint16_t read_adc()
{
ADCSRA |= (1<<ADSC);
while(!(ADCSRA & (1<<ADIF)));
uint8_t adcl = ADCL;
uint8_t adch = ADCH;
ADCSRA |= (1<<ADIF);
return (adch<<8) | adcl;
}
An external interrupt vector should occur when a 5v input is supplied to int0.
The interrupt should change a volatile integer flag to allow a LED to illuminate that is connected to a pin on PORTB. Compiles with no errors in Atmel studio. The problem is no change occurs when a 5v supply is sent to the int0 pin. Is this that the interrupt is not triggering?
#include <avr/io.h>
#include <stdio.h>
#define F_CPU 16000000UL
#include <util/delay.h>
#include <avr/interrupt.h>
volatile int pwm_flag=0;
int main(void)
{
DDRD &= ~(1 << DDD2); // Clear the PD2 pin
// PD2 (PCINT0 pin) is now an input
PORTD |= (1 << PORTD2); // turn On the Pull-up
// PD2 is now an input with pull-up enabled
EICRA |= (1 << ISC00)|(1 << ISC10); // set INT0 to trigger on Rising edge
EIMSK |= (1 << INT0); // Turns on INT0
sei(); // turn on interrupts
DDRB = 0xFF;
PORTB = 0x00;
while(1)
{
if(pwm_flag==1)//if flag is raised
{
PORTB = 0xFF;//turn on all pins of portb
pwm_flag=0;//reset flag to 0
}
}
}
ISR (INT0_vect)
{
/* interrupt code here */
pwm_flag =1;//raise flag
}
The problem is no change occurs when a 5v supply is sent to the int0 pin.
How do you send 5V to the INT0 pin? Your code is setting INT0 pin as an input with pullup so unless you short it to the ground it is at 5V.
Also, what do you mean by no change occurs? Is the LED on or off?
Another thing is that the line:
EICRA |= (1 << ISC00)|(1 << ISC10);
sets both INT0 and INT1 to occur on any logical change on appropriate pin. Bits with name ISC0x control INT0, bits called ISC1x are used to configure INT1. In your code you are mixing both and you end up with the following configuration:
ISC01 | ISC00 | meaning
-------------------------------------------------------------------------
0 | 1 | any logical change on INT0 generates an interrupt request
ISC11 | ISC10 | meaning
-------------------------------------------------------------------------
0 | 1 | any logical change on INT1 generates an interrupt request
If you are trying to supply 5v from a pin on PORTB to an LED then perhaps that is your problem. Most micro-controller pins can sink more current than they can give. Perhaps your LED is just not getting the current it needs?
Your wiring should be as follows:
Connect the positive leg of the LED to 5V. Connect the negative leg to a small resistor 100-500 Ohms. Connect the other leg of the resistor to the pin on PORTB.
Now you can write PORTB to 0x00 to turn on the LED or 0xFF to turn it off.
To test that the LED is working test the LED in your main loop by writing PORTB low and high with a noticeable delay in between.
If that works. Then test your ISR. If the ISR doesn't work a this point then the ISR is the problem.
Bear in mind that in your current configuration of EICRA you are triggering an interrupt on a rising edge. So if the pin is already high not interrupt will occur.
I have changed your code below so LOW is ON and HIGH is OFF.
int main(void){
DDRD &= ~(1 << DDD2); // set PD2 DDR as input
PORTD |= (1 << PORTD2); // set PD2 as input pull-up
EICRA |= (1 << ISC00)|(1 << ISC10); // set INT0 to trigger on rising edge
EIMSK |= (1 << INT0); // Turns on INT0
DDRB = 0xFF; // set PORTB as all outputs
PORTB = 0xFF; // set PORTB high
sei(); // turn on interrupts
while(1){
if(pwm_flag!=0){ // check flag
PORTB = 0x00; // set PORTB low
pwm_flag=0; // reset flag
}
}
ISR (INT0_vect){
pwm_flag = 1; // raise flag
}
I have covered lately adc and lcd in microcontroller and gone into USART and as usual my first code I make is not working and I need some help with discovering the problem, here's the code:
Transmitter code:
main.c:
#include "config.h"
void main(){
TRISCbits.TRISC6 = 1;
TRISCbits.TRISC7 = 1;
TRISDbits.TRISD0 = 1;
SPBRG = 25;
TXSTAbits.TX9 = 0;
TXSTAbits.SYNC = 0;
TXSTAbits.BRGH = 1;
TXSTAbits.TXEN = 1;
RCSTAbits.SPEN = 1;
RCSTAbits.RX9 = 0;
RCSTAbits.CREN = 0;
while(1){
while(TRMT == 0);
if(PORTDbits.RD0 == 1){
TXREG = 0xFF;
}else{
TXREG = 0;
}
}
}
Receiver code:
main.c:
#include "config.h"
char recieve;
void main(){
TRISCbits.TRISC6 = 1;
TRISCbits.TRISC7 = 1;
TRISDbits.TRISD0 = 0;
PORTDbits.RD0 = 0;
SPBRG = 25;
TXSTAbits.TX9 = 0;
TXSTAbits.SYNC = 0;
TXSTAbits.BRGH = 1;
TXSTAbits.TXEN = 1;
RCSTAbits.SPEN = 1;
RCSTAbits.RX9 = 0;
RCSTAbits.CREN = 0;
while(1){
RCREG = recieve;
if(recieve == 0xFF){
PORTDbits.RD0 = 1;
}else{
PORTDbits.RD0 = 0;
}
}
}
and for both transmitter and receiver projects config.h is a header file where I set the frequency of crystal oscillator and configuration bits so it is the same file/code for both projects
config.h:
/*
* File: config.h
* Author: Fady
*
* Created on August 25, 2014, 1:53 PM
*/
// PIC16F877A Configuration Bit Settings
// 'C' source line config statements
#include <xc.h>
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
// CONFIG
#pragma config FOSC = XT // Oscillator Selection bits (XT oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#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 = 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 4000000
EDIT
I am trying to communicate 2 pic microcontrollers in which if I press the button on D0 in transmitter it sends a 0xFF data and then the receiver checks for if the received data == 0xFF if yes it turns on the LED on D0 in receiver but when I connect it on isis the TX pin of receiver keeps blinking high and low (red and blue) each half a second but when I press the button the high (red) signal keeps for a bit longer but keeps flashing with high and low and I suppose this is for start bit but the receiver doesn't turn on the led that's the error part I don't know what's wrong here
Its just a very stupid silly c programming mistake I wrote:
RCREG = recieve;
which will take the value of receive and assign it to RCREG instead it should be
receive = RCREG;
which will assign the value of RCREG to receive and worked after building...