找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 846|回复: 4
打印 上一主题 下一主题
收起左侧

PIC单片机串口传输数据错误,是什么原因

[复制链接]
跳转到指定楼层
楼主
ID:80213 发表于 2022-7-21 16:47 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
为什么我串口传输的数据在电脑打印输出不是'S',但是如果我使用#define定义KS 为'S'时就能正常打印输出‘S’?这两者有什么区别吗?

单片机代码如下:
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空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:883242 发表于 2022-7-21 16:58 | 只看该作者
这是个高难的问题,只能看生成的汇编代码有什么区别了。
回复

使用道具 举报

板凳
ID:401564 发表于 2022-7-21 18:35 | 只看该作者
变量这样定义试一下
unsigned char KS;
回复

使用道具 举报

地板
ID:883242 发表于 2022-7-21 20:28 | 只看该作者
Y_G_G 发表于 2022-7-21 18:35
变量这样定义试一下
unsigned char KS;

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

人家就是有符号的好不好?
回复

使用道具 举报

5#
ID:80213 发表于 2022-7-22 15:28 | 只看该作者
Hephaestus 发表于 2022-7-21 20:28
\microchip\xc8\v2.36\pic\include\c90\conio.h
extern void        putch(char);

我有这样定义,但结果还是一样的
unsigned char KS;
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表