Comencé a trabajar en el microcontrolador PIC24FJ128GA202. Pruebas de programas como el parpadeo y el interruptor de LED, el controlador funciona bien con la codificación, luego comencé a trabajar en UART configuré todos los parámetros según las normas de la hoja de datos. Pero mi PIC no funciona con mi código. He conectado mi controlador a la PC para comprobar los caracteres transferidos. He publicado mi código a continuación. No recibo ningún carácter en hiperterminal ... Algunas veces recibí valores de basura.
#include "p24FJ128GA202.h" // Pic24FJ128GA202 header file
#define led PORTAbits.RA2
void init_processor(void);
void init_processor(void)
{
/* oscillator configuration is pending*/
OSCCON = 0x0000;
CLKDIV = 0x0000; //do not divide
OSCTUN = 0;
RPINR18bits.U1RXR = 7; //UART1 receive set to RB7
RPOR4bits.RP8R = 3; //UART1 transmit set to RB8
__builtin_write_OSCCONL(OSCCON & 0xbf); //clear the bit 6 of OSCCONL to
//unlock Pin Re-map
RPOR4bits.RP8R = 3;
//__builtin_write_OSCCONL(OSCCON | 0x40); //set the bit 6 of OSCCONL to
//lock Pin Re-map
// configure digital pins
ANSA = 0x0000;
ANSB = 0x0000;
// assign IO values for ports
PORTA = 0x0000;
TRISA = 0x0000;
PORTB = 0x0000;
TRISB = 0x0000; // 7 as receive and 8 as transmitter
// Init UART1
U1MODE = 0x0000;
U1STA = 0x0400; //Enable Transmission, Clear all flags
U1BRG = 25;
U1MODEbits.UARTEN = 1; // And turn the peripheral on
}
void uart1tx(char in_c)
{
while(U1STAbits.UTXBF != 0);
U1TXREG = in_c;
}
void uart1str(char *s)
{
while(*s!='#include "p24FJ128GA202.h" // Pic24FJ128GA202 header file
#define led PORTAbits.RA2
void init_processor(void);
void init_processor(void)
{
/* oscillator configuration is pending*/
OSCCON = 0x0000;
CLKDIV = 0x0000; //do not divide
OSCTUN = 0;
RPINR18bits.U1RXR = 7; //UART1 receive set to RB7
RPOR4bits.RP8R = 3; //UART1 transmit set to RB8
__builtin_write_OSCCONL(OSCCON & 0xbf); //clear the bit 6 of OSCCONL to
//unlock Pin Re-map
RPOR4bits.RP8R = 3;
//__builtin_write_OSCCONL(OSCCON | 0x40); //set the bit 6 of OSCCONL to
//lock Pin Re-map
// configure digital pins
ANSA = 0x0000;
ANSB = 0x0000;
// assign IO values for ports
PORTA = 0x0000;
TRISA = 0x0000;
PORTB = 0x0000;
TRISB = 0x0000; // 7 as receive and 8 as transmitter
// Init UART1
U1MODE = 0x0000;
U1STA = 0x0400; //Enable Transmission, Clear all flags
U1BRG = 25;
U1MODEbits.UARTEN = 1; // And turn the peripheral on
}
void uart1tx(char in_c)
{
while(U1STAbits.UTXBF != 0);
U1TXREG = in_c;
}
void uart1str(char *s)
{
while(*s!='%pre%')
{
uart1tx(*s);
s++;
}
}
char uart1rx()
{
char c;
while(U1STAbits.URXDA == 0);
c = U1RXREG;
return c;
}
int main()
{
int i,j;
led = 1;
init_processor();
while(1)
{
uart1tx('A');
led = ~led;
for(j=0;j<250;j++)
{
for(i=0;i<1275;i++);
}
}
return 0;
}
')
{
uart1tx(*s);
s++;
}
}
char uart1rx()
{
char c;
while(U1STAbits.URXDA == 0);
c = U1RXREG;
return c;
}
int main()
{
int i,j;
led = 1;
init_processor();
while(1)
{
uart1tx('A');
led = ~led;
for(j=0;j<250;j++)
{
for(i=0;i<1275;i++);
}
}
return 0;
}