Shafaq Gul
Junior Member level 1
- Joined
- Dec 24, 2013
- Messages
- 18
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 122
Hello!
I am using mplab and proteus...my c code transmits the data but don't receive it.Am really worried.
I am using mplab and proteus...my c code transmits the data but don't receive it.Am really worried.
Code:
#define CRYSTAL_FREQUENCY 10000000 /* 10 MHz */
#define FCY CRYSTAL_FREQUENCY/2UL /* Cylce frequency 5 MHz*/
#include <p24F16KA102.h>
#include <libpic30.h>
#include <stddef.h>
/******************************************************************************/
/* *** Configuration Bits Setting *** */
//_FGS(GWRP_OFF & GCP_OFF)
//_FOSCSEL(FNOSC_PRI & IESO_OFF)
//_FOSC(POSCMOD_HS & OSCIOFNC_ON & POSCFREQ_HS & FCKSM_CSDCMD)
//_FWDT(WINDIS_OFF & FWDTEN_OFF)
//_FPOR(BOREN_BOR2 & PWRTEN_OFF & MCLRE_ON)
//_FDS(DSBOREN_OFF & DSWDTEN_OFF)
_FOSCSEL(FNOSC_FRC); // Use internal oscillator (FOSC ~ 8 Mhz)
_FOSC(FCKSM_CSECMD & OSCIOFNC_ON & POSCMOD_NONE); // RA3 pin is output FCKSM_CSECMD Only clock switching enabled;OSCIOFNC_ON Digital I/O; POSCMD_NONE Primary disabled
_FWDT(FWDTEN_OFF); // Watchdog timer is disabled
_FICD(BKBUG_OFF);
/******************************************************************************/
/*
*
*/
int i;
unsigned char c;
int main(void)
{
U2MODE = 0; // Clear UART1 mode register
U2STA = 0; // Clear UART1 status register
U2MODEbits.BRGH=0;
U2BRG = 25;
IPC7bits.U2RXIP = 7; //set recieve interrupt priority to 4
IPC7bits.U2TXIP=7;
// IEC1bits.U2RXIE = 1; //recieve interrupt enable
// IEC1bits.U2TXIE=1;
// _U2RXIF=0; // Clear UART RX Interrupt Flag
// _U2TXIF=0;
U2STAbits.URXISEL = 0; //interrupt when any character is recieved
U2MODEbits.UARTEN = 1; // Enable UART2 module
U2STAbits.UTXEN = 1; // Enable UART2 transmit
TRISBbits.TRISB1=1;
U2STAbits.UTXEN=1;
c='m';
while(U2STAbits.UTXBF);
U2STAbits.UTXBF=1;
U2TXREG=c;
while(!U2STAbits.URXDA);
c=U2RXREG;
U2STAbits.URXDA=1;
while(U2STAbits.UTXBF);
U2STAbits.UTXBF=1;
U2TXREG=c;
while(1);
return 0;
}