piyushpandey
Member level 4
Hello guys
I am using pic16f688 with the MPLAB X IDE and using the Hitech compiler version 9.83 .
I have made a simple program for the receiver section of the pic micrcontroller and want to blink the LEDs connected at the PORTC pins 2 and 3.
Here is my code:
But I am not able to blink the LEDS on the pins 2 and 3 when I send the characters g and a .
Please guys tell me what is the problem I am facing am I missing something.
Thanks
I am using pic16f688 with the MPLAB X IDE and using the Hitech compiler version 9.83 .
I have made a simple program for the receiver section of the pic micrcontroller and want to blink the LEDs connected at the PORTC pins 2 and 3.
Here is my code:
Code:
#include <pic.h>
//#define OSCILLATOR (OSCCON = 0x71)
#define _XTAL_FREQ 8000000
__CONFIG(WDTE_OFF & FOSC_INTOSCCLK & MCLRE_ON);
void EUSART_init(void)
{
// Set the baud rate
SPBRG = 12; // 9600 baud rate at 8.0 Mhz
TXSTAbits.SYNC = 0; // asynchronous mode
TXSTAbits.BRGH = 0; // low baud rate
BAUDCTLbits.BRG16 = 0; // 8 bit baud rate generator
// Disable all interrupts
INTCONbits.GIE = 0;
INTCONbits.PEIE = 0;
// Only 8-bit mode for the receiver
RCSTAbits.RX9 = 0;
// Enable the transmitter and receiver
TXSTAbits.TXEN = 1;
RCSTAbits.CREN = 1;
// Enable the Serial communication
RCSTAbits.SPEN = 1;
}
void EUSART_transmit_data(unsigned char data)
{
while(!TXIF)
continue;
NOP();
_nop();
_nop();
TXREG = data;
return;
}
unsigned char EUSART_recieve_data(void)
{
unsigned char data;
// RCREG = data;
/* if(FERR==1)
{
RCSTAbits.SPEN = 0;
EUSART_receiver_init();
}*/
while(!RCIF)
continue;
data = RCREG;
// return RCREG;
return data ;
}
void main(void) {
unsigned int x;
OSCCON = 0x71;
// Initialise the portc bits
//#define ports
//#ifdef ports
TRISCbits.TRISC2 = 0;
TRISCbits.TRISC3 = 0;
//#endif
// Disable the analog inputs
ANSEL = 0x00;
// Disable the comparator
CMCON0 = 0x07;
// EUSART_transmitter_enable();
EUSART_init();
while(1)
// for (unsigned int j = 0;j<=20;j++)
{
// EUSART_transmit_data(0x41);
x = EUSART_recieve_data();
// EUSART_transmit_data(x);
// __delay_ms(100);
// to blink the LEDs
switch (x)
{
case 'a':
case 'A':
case 1:
PORTCbits.RC3 = 1;
break ;
case 'g':
case 'G':
case 2:
PORTCbits.RC2 = 1;
break ;
case 'p':
case 'P':
case 3:
PORTCbits.RC3 = 0;
break ;
case 'r':
case 'R':
case 4:
PORTCbits.RC2 = 0;
break ;
default:
PORTCbits.RC2 = 0;
PORTCbits.RC3 = 0;
}
}
}
But I am not able to blink the LEDS on the pins 2 and 3 when I send the characters g and a .
Please guys tell me what is the problem I am facing am I missing something.
Thanks