Leyendo el valor hexadecimal en uart

0

Estoy usando Mplab x Ide con v3.61 en el compilador Xc8, PIC18F24K40. Usé el código UART generado por MCC para enviar y recibir datos.

Tengo funciones de Euart como a continuación

#define LED_RX RC7 // Pin assigned RX LED
#define LED_TX RC6 // Pin assigned TX LED
#define LED RC2 // Pin assigned for LED 

unsigned int count=0;
char data;
char data1[10];


/* Send Data Serially */
void send_string(const char *x)
{
     while(*x)
     {
        EUSART_Write(*x++); 
     }
}



char receive_text()
{
unsigned char text[10]; /*character arrya to store the string*/
unsigned char i=0; /*array index variable */
/*character is received until end of the string received */
do
{ 
while(1==PIR3bits.RCIF);
*(text+i)=RC1REG;
i++;
}while(*(text+i));

return text; /* return the base address of received string */



}







 char UART_Read()
{

     while(1==PIR3bits.RCIF);

  return RC1REG;
}

/* Timer Interrupt Service Routine Program*/
void Blink_Count()
{
   if(PIR0bits.TMR0IF == 1)
   { 
       PIR0bits.TMR0IF =0;
       count=count+1;
       if(count>=15)
       {
          // LED=!LED;
           count=0;

       }

   }

}







void main(void)
{
    // Initialize the device
    SYSTEM_Initialize();

    // If using interrupts in PIC18 High/Low Priority Mode you need to enable the Global High and Low Interrupts
    // If using interrupts in PIC Mid-Range Compatibility Mode you need to enable the Global and Peripheral Interrupts
    // Use the following macros to:

    // Enable high priority global interrupts
    //INTERRUPT_GlobalInterruptHighEnable();

    // Enable low priority global interrupts.
    //INTERRUPT_GlobalInterruptLowEnable();

    // Disable high priority global interrupts
    //INTERRUPT_GlobalInterruptHighDisable();

    // Disable low priority global interrupts.
    //INTERRUPT_GlobalInterruptLowDisable();

    // Enable the Global Interrupts
    //INTERRUPT_GlobalInterruptEnable();

    // Enable the Peripheral Interrupts
    //INTERRUPT_PeripheralInterruptEnable();

    // Disable the Global Interrupts
    //INTERRUPT_GlobalInterruptDisable();

    // Disable the Peripheral Interrupts
    //INTERRUPT_PeripheralInterruptDisable();

    send_string("Serial CHECK CODE\r\n"); 

    while (1)
    {


     data= EUSART_Read();
     rxbuf[10]=data;
     printf("%s\n",&rxbuf[10]);
     __delay_ms(150);


    }


}

Y la comunicación serial probada. con este código podría imprimir la bienvenida en Serial Monitor. El problema al que me estoy enfrentando es. Cuando trato de enviar datos 0103000000Ac5CD en formato ASCii recibo como personaje, pero cuando intento enviar en formato hexadecimal no pude recibir nada. Si estoy imprimiendo datos como los que utilicé en el ejemplo de impresión de trabajo, recibí un valor de basura.

void main(void)
{
  EUSART_Initialize();
    while (1)
    {
     char array[20] = "Hello World";
     printf("%s\n",array);
      __delay_ms(150);

    }

}

    
pregunta AMPS

0 respuestas

Lea otras preguntas en las etiquetas