empero
Newbie level 1
- Joined
- May 12, 2013
- Messages
- 1
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,296
hey guys, I have a C# program which will send "A"or "B" (C# code \\serialPort1.write("A")\\) to RS232.
RS232 will go to microcontroller(PIC18f4520).
Microcontroller will do some editing and final output is "1" or "0"
my coding doesn't work and there is no build error. So please help me to check the code and help me to correct it.
thanks a lot.
#include <p18f4520.h>
#include <usart.h>
#include "xlcd.h"
#include <delays.h>
#pragma config OSC = XT
#pragma config PWRT = OFF
#pragma config BOREN = OFF
#pragma config WDT = OFF
#pragma config MCLRE = ON
#pragma config PBADEN = OFF
#pragma config LVP = OFF
#pragma config FCMEN = OFF
void rx_isr (void);
#pragma interrupt rx_isr
#pragma code high_vector = 0x08
void high_vector (void)
{
_asm goto rx_isr _endasm
}
#pragma code
void rx_isr(void)
{
char inputtext ;
inputtext = getcUSART();
if (inputtext == 'A')
{
PORTBbits.RB0 = ~PORTBbits.RB0;
}
else if (inputtext == 'B')
{
PORTBbits.RB0 = 0;
PORTBbits.RB1 = 0;
PORTBbits.RB2 = 0;
PORTBbits.RB3 = 0;
}
PIR1bits.RCIF = 0;
}
void main(void)
{
TRISCbits.TRISC7 = 1;
TRISBbits.TRISB0 = 0;
TRISBbits.TRISB1 = 0;
TRISBbits.TRISB2 = 0;
TRISBbits.TRISB3 = 0;
PORTBbits.RB0 = 0;
PORTBbits.RB1 = 0;
PORTBbits.RB2 = 0;
PORTBbits.RB3 = 0;
RCONbits.IPEN = 1;
INTCONbits.GIEH = 1;
PIR1bits.RCIF = 0;
PIE1bits.RCIE = 1;
IPR1bits.RCIP = 1;
RCSTAbits.SPEN = 1;
OpenUSART( USART_TX_INT_OFF &
USART_RX_INT_ON &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_HIGH,25)
//9600bps
while(1)
{
}
CloseUSART();
}
RS232 will go to microcontroller(PIC18f4520).
Microcontroller will do some editing and final output is "1" or "0"
my coding doesn't work and there is no build error. So please help me to check the code and help me to correct it.
thanks a lot.
#include <p18f4520.h>
#include <usart.h>
#include "xlcd.h"
#include <delays.h>
#pragma config OSC = XT
#pragma config PWRT = OFF
#pragma config BOREN = OFF
#pragma config WDT = OFF
#pragma config MCLRE = ON
#pragma config PBADEN = OFF
#pragma config LVP = OFF
#pragma config FCMEN = OFF
void rx_isr (void);
#pragma interrupt rx_isr
#pragma code high_vector = 0x08
void high_vector (void)
{
_asm goto rx_isr _endasm
}
#pragma code
void rx_isr(void)
{
char inputtext ;
inputtext = getcUSART();
if (inputtext == 'A')
{
PORTBbits.RB0 = ~PORTBbits.RB0;
}
else if (inputtext == 'B')
{
PORTBbits.RB0 = 0;
PORTBbits.RB1 = 0;
PORTBbits.RB2 = 0;
PORTBbits.RB3 = 0;
}
PIR1bits.RCIF = 0;
}
void main(void)
{
TRISCbits.TRISC7 = 1;
TRISBbits.TRISB0 = 0;
TRISBbits.TRISB1 = 0;
TRISBbits.TRISB2 = 0;
TRISBbits.TRISB3 = 0;
PORTBbits.RB0 = 0;
PORTBbits.RB1 = 0;
PORTBbits.RB2 = 0;
PORTBbits.RB3 = 0;
RCONbits.IPEN = 1;
INTCONbits.GIEH = 1;
PIR1bits.RCIF = 0;
PIE1bits.RCIE = 1;
IPR1bits.RCIP = 1;
RCSTAbits.SPEN = 1;
OpenUSART( USART_TX_INT_OFF &
USART_RX_INT_ON &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_HIGH,25)
//9600bps
while(1)
{
}
CloseUSART();
}