c - 在 PIC18f87k22 上使用 EUSART 模块时出现问题

标签 c declaration xc8

我正在尝试配置 arduino pro trinket 和我的 PIC18f87k22 之间的 UART 通信。 运行我的代码时出现以下错误:

error code

这是函数的原型(prototype):

char EUSART1_Read(void)
{

RCSTA1bits.SREN = 1;
 while(!PIR1bits.RC1IF)
 {
    ;
 }


if(1 == RCSTA1bits.OERR)
{
    // EUSART1 error - restart

    RCSTA1bits.CREN = 0; 
    RCSTA1bits.CREN = 1; 
}

return RCREG1;
}

这就是我使用它的方式(到目前为止唯一的用途):

int16_t get_courant()
{
   char courant1;
   char courant2;
   int16_t courant;

   if(EUSART1_is_tx_ready())
           {
               EUSART1_Write(0b00000001);
           }
   if(EUSART1_is_rx_ready())
           {
           courant1= EUSART1_Read(); 
           }

   if(EUSART1_is_tx_ready())
           {
               EUSART1_Write(0b00000010);
           }
   if(EUSART1_is_rx_ready())
           {
           courant2= EUSART1_Read(); 
           }
   if (CheckBit(courant1,8))
           {
           bit_clr(courant1,8);
           courant = (courant1 << 8) | courant2;
           courant = - courant;
           }
   else 
   {
       courant = (courant1 << 8) | courant2;
   }
   return courant;   
   }

我尝试用 unsigned char 或 uint8_t 替换 char 类型,但没有任何改变。 关于我的代码有什么问题的任何想法? 泰

最佳答案

放入一个文件:

// Prototype
char EUSART1_Read(void);
int16_t get_courant(void);

// function definition
char EUSART1_Read(void)
{
    RCSTA1bits.SREN = 1;
    while(!PIR1bits.RC1IF)
    {
        ;
    }
    if (1 == RCSTA1bits.OERR)
    {
        // EUSART1 error - restart
        RCSTA1bits.CREN = 0; 
        RCSTA1bits.CREN = 1; 
    }
    return RCREG1;
}


int16_t get_courant(void)
{
    char courant1;
    char courant2;
    int16_t courant;

    if(EUSART1_is_tx_ready())
    {
        EUSART1_Write(0b00000001);
    }
    if(EUSART1_is_rx_ready())
    {
        courant1= EUSART1_Read(); 
    }

    if(EUSART1_is_tx_ready())
    {
        EUSART1_Write(0b00000010);
    }
    if(EUSART1_is_rx_ready())
    {
        courant2= EUSART1_Read(); 
    }
    if (CheckBit(courant1,8))
    {
        bit_clr(courant1,8);
        courant = (courant1 << 8) | courant2;
        courant = - courant;
     }
     else 
     {
         courant = (courant1 << 8) | courant2;
     }
     return courant;   
}

关于c - 在 PIC18f87k22 上使用 EUSART 模块时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51138748/

相关文章:

c - Httperf 文件描述符限制

c - C sine(x) 近似误差

C (XC8) 使用三元运算符隐式有符号到无符号转换

c++ - .h 中的声明.cpp 中的定义。正确的?

c# - 如何声明 QueryFullProcessImageName() API C# (Windows 7 x64)

c - XC8编译器: program returning to beginning of main()

c - 简单中断程序陷阱/卡住cpu(USART/PIC18F/MICROCHIP/XC8)

c - 二维数组的邻接矩阵

c - 在 C 中释放一个结构数组

c++ - 没有在标题中声明的模板类成员特化