smart1
Newbie level 4
Dear all.... I am trying to executing the UART module of dspic33fj16gs504. But its not working... The code is as bellow...Please revert back.
Thanks in advance.
================================================================================
================================================================================
Thanks in advance.
================================================================================
Code:
#include "p33FJ16GS504.h"
// Configuration Bit Settings
_FOSCSEL(FNOSC_FRCPLL)
_FOSC(OSCIOFNC_OFF & POSCMD_NONE)
#define CLOCK_FREQ 40000000 // Assuming 5.00MHz and X8 PLL
#define BAUD 19200
void U1_Putch(unsigned char Data)
{
while (U1STAbits.UTXBF);
while(1)
U1TXREG = Data;
}
void setup_uart(void)
{
U1MODE = 0x0000;
U1STA = 0x0000;
U1BRG = ((CLOCK_FREQ/16)/BAUD) - 1; // set baudrate to BAUD rate
IEC0bits.U1RXIE = 1;
U1MODEbits.UARTEN=1; // UART1 is enabled
U1STAbits.UTXEN = 1; // Initiate transmission
}
void main()
{
TRISBbits.TRISB1=1; // Used for Rx as input
TRISBbits.TRISB2=0; // Used for Tx as output
// Remmappable INPUT PIN configuration for UART1
RPINR18bits.U1RXR=1; // PORT PIN NO. 32, This pin is for Rx
// Remmappable OUTPUT PIN configuration for UART1
RPOR1bits.RP2R=0x000011; // PORT PIN NO. 33, This pin is for Tx
setup_uart();
U1_Putch('A');
while(1);
}
void __attribute__((__interrupt__)) _U1TXInterrupt(void)
{
IFS0bits.U1TXIF = 0; // clear interrupt flag
}
void __attribute__((__interrupt__)) _U1RXInterrupt(void)
{
IFS0bits.U1RXIF = 0; // clear interrupt flag
}
================================================================================
Last edited by a moderator: