找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 849|回復(fù): 4
打印 上一主題 下一主題
收起左側(cè)

PIC單片機(jī)串口傳輸數(shù)據(jù)錯(cuò)誤,是什么原因

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:80213 發(fā)表于 2022-7-21 16:47 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
為什么我串口傳輸?shù)臄?shù)據(jù)在電腦打印輸出不是'S',但是如果我使用#define定義KS 為'S'時(shí)就能正常打印輸出‘S’?這兩者有什么區(qū)別嗎?

單片機(jī)代碼如下:
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);
    }
}





分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:883242 發(fā)表于 2022-7-21 16:58 | 只看該作者
這是個(gè)高難的問(wèn)題,只能看生成的匯編代碼有什么區(qū)別了。
回復(fù)

使用道具 舉報(bào)

板凳
ID:401564 發(fā)表于 2022-7-21 18:35 | 只看該作者
變量這樣定義試一下
unsigned char KS;
回復(fù)

使用道具 舉報(bào)

地板
ID:883242 發(fā)表于 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);

人家就是有符號(hào)的好不好?
回復(fù)

使用道具 舉報(bào)

5#
ID:80213 發(fā)表于 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;
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表