標(biāo)題: PIC單片機串口傳輸數(shù)據(jù)錯誤,是什么原因 [打印本頁]

作者: xwr121    時間: 2022-7-21 16:47
標(biāo)題: PIC單片機串口傳輸數(shù)據(jù)錯誤,是什么原因
為什么我串口傳輸?shù)臄?shù)據(jù)在電腦打印輸出不是'S',但是如果我使用#define定義KS 為'S'時就能正常打印輸出‘S’?這兩者有什么區(qū)別嗎?

單片機代碼如下:
void main(void)
{
    // initialize the device
    SYSTEM_Initialize();

    // When using interrupts, you need to set the Global and Peripheral Interrupt Enable bits
    // Use the following macros to:

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

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

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

    // Disable the Peripheral Interrupts
    //INTERRUPT_PeripheralInterruptDisable();
    char KS;
    KS= 'S';
    while (1)
    {
        // Add your application code
        putch(KS);
    }
}






作者: Hephaestus    時間: 2022-7-21 16:58
這是個高難的問題,只能看生成的匯編代碼有什么區(qū)別了。
作者: Y_G_G    時間: 2022-7-21 18:35
變量這樣定義試一下
unsigned char KS;
作者: Hephaestus    時間: 2022-7-21 20:28
Y_G_G 發(fā)表于 2022-7-21 18:35
變量這樣定義試一下
unsigned char KS;

\microchip\xc8\v2.36\pic\include\c90\conio.h
extern void        putch(char);

人家就是有符號的好不好?
作者: xwr121    時間: 2022-7-22 15:28
Hephaestus 發(fā)表于 2022-7-21 20:28
\microchip\xc8\v2.36\pic\include\c90\conio.h
extern void        putch(char);

我有這樣定義,但結(jié)果還是一樣的
unsigned char KS;




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1