我正在使用带有 HEW(高性能嵌入式工作台)编译器的 Renesas 16 bt MCU。
系统接收格式如下的 ACSII 数据:
<data><cc>
其中<cc>包含两个 ASCII 十六进制数字,对应于所有前面字符的 8 位按位异或。包含的字符串的最大长度<cc>为 14。
这是我的尝试:
#pragma INTERRUPT Interrupt_Rx0
void Interrupt_Rx0 (void)
{
    unsigned char   rx_byte, rx_status_byte,hex;
    char buffer[15],test[5];
    int r,k[15];
    char * pEnd;
    unsigned char dat,arr[14],P3;
    unsigned int i,P1[10];
    rx_byte = u0rbl;    //get rx data
    rx_status_byte = u0rbh;
    if ((rx_status_byte & 0x80) == 0x00)        //if no error
    {
        if ((bf_rx0_start == 0) && (rx_byte == '?') && (bf_rx0_ready == 0))
        {
            byte_rx0_buffer[0]=rx_byte;
            bf_rx0_start = 1;                                    
            byte_rx0_ptr = 1;       
        }
        else
        {
            if (rx_byte == '?')
            {
                bf_rx0_start = 1;
                byte_rx0_ptr = 0;
            }
            if(bf_rx0_start == 1)
            {
                byte_rx0_buffer[byte_rx0_ptr++] = rx_byte;          
                sprintf(buffer,"%X",rx_byte); //ASCII CONVERSION
                dat=strtol(buffer,&pEnd,16);
                //  P1=(int)dat;
                //  sprintf(P1,"%s",dat);
                delay_ms(2000);
                k[byte_rx0_ptr++]=dat;  
            }                       
            if ((byte_rx0_ptr == 14))               
                bf_rx0_start = 0;//end further rx until detect new STX
        }
    }
}