internetuser2k12
Banned
- Joined
- Jul 25, 2012
- Messages
- 1,192
- Helped
- 171
- Reputation
- 342
- Reaction score
- 162
- Trophy points
- 1,343
- Activity points
- 0
I am using PIC16F877A and Hi Tech C. I want to store the received characters from uart to a
string like myString[4] and then compare if for some string and do action depending upon it.
The code is like this
My UART receive interrupt routine is like this
My initializations are like this
Is this method right? For me it is not working.
OK. I changed the method to
but still it is not working.
string like myString[4] and then compare if for some string and do action depending upon it.
The code is like this
Code:
if(uart_receive_flag == 1) {
uart_receive_flag = 0;
myString[count] = RCREG;
count++;
if(count == 3) {
count = 0;
}
}
myString[3] = '\0';
My UART receive interrupt routine is like this
Code:
void interrupt ISR(void)
{
if(RCIF) //If UART Rx Interrupt
{
if(OERR) //if over run error, then reset the receiver
{
CREN = 0;
CREN = 1;
}
RCIF = 0;
uart_receive_flag = 1;
}
}
My initializations are like this
Code:
unsigned int count, uart_receive_flag;
unsigned char myString[4];
TRISA=0x00; //One side of Motor
TRISB=0x00; //LCD and Buzzer
TRISD=0x00; //LCD display
TRISE=0x00; //One side of Motor
PORTA=0; //Switch
PORTB=0;
PORTD=0;
PORTE=0;
TRISC=0xFF; //Switch
PORTC=0; //Switch
ADCON1 = 0b10000111;
CMCON = 0b00000111;
CVROE = 0;
//Configure UART
SPBRG=129; //set baud rate as 9600 baud
BRGH=1; //baud rate high speed option
TXEN=0; //disable transmission
TX9 =0; //8-bit transmission
RX9 =0; //8-bit reception
CREN=1; //enable reception
SPEN=1; //enable serial port
SYNC = 0;
SPEN = 1;
RX9 = 0;
//SREN = 0;
CREN = 1;
ADDEN = 0;
FERR = 0;
OERR = 0;
TXIE = 0;
RCIE = 1;
TXEN = 1;
//Include these settings
GIE = 1; //Enable global interrupts
PEIE = 1; //Enable Peripheral Interrupts
void main() {
while(1) {
if(myString == "LU") {
PORTBbits.RB4 = 1;
}
}
}
Is this method right? For me it is not working.
OK. I changed the method to
Code:
if((myString[0] == 'L') && (myString[1] == 'U'))
Last edited: