65|2

2

帖子

0

TA的资源

一粒金砂(中级)

楼主
 

使用串口调试助手不能回显数据,但是能控制灯的状态 [复制链接]

使用的是MSP430F2618的芯片和MSP-TS430PM64的开发板,写了一个使串口能够控制LED灯并且对输入的数字进行回显,使用串口调试助手输入0和1能正常控制灯,就是不能接收到数字,求助求助大神啊来帮帮,搞了好几天都没解决,已经要崩溃了。

下面是代码:

#include <msp430.h>

void main(void)
{
    WDTCTL = WDTPW + WDTHOLD;          // 停止看门狗定时器

    // 初始化 DCO 为 1 MHz
    BCSCTL1 = CALBC1_1MHZ;
    DCOCTL = CALDCO_1MHZ;

    // 配置 LED
    P1DIR |= BIT0;                      // 设置 P1.0 为输出模式
    P1OUT &= ~BIT0;                     // 初始化 LED 为关闭状态

    // 配置串口
    P3SEL |= 0x30;                      // 设置 P3.4 和 P3.5 为 USCI_A0 的 TX 和 RX 引脚
    UCA0CTL1 |= UCSSEL_2;               // 使用 SMCLK 作为时钟源
    UCA0BR0 = 104;                      // 设置波特率为 9600,SMCLK = 1 MHz
    UCA0BR1 = 0;
    UCA0MCTL = UCBRS0;                  // 设置调制
    UCA0CTL1 &= ~UCSWRST;               // 初始化 USCI 状态机
    IFG2 &= ~UCA0RXIFG;                 // 清除 RX 中断标志位
    IE2 |= UCA0RXIE;                    // 启用 RX 中断

    __delay_cycles(1000000);            // 等待系统稳定(1 秒)
    __bis_SR_register(CPUOFF + GIE);    // 进入低功耗模式,启用中断

    while (1);                          // 无限循环,保持程序运行
}

// USCI_A0 RX 中断服务例程
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
    unsigned char receivedChar = UCA0RXBUF;  // 获取接收到的字符

    if (receivedChar == '1') {
        P1OUT |= BIT0;  // 点亮 LED
    } else if (receivedChar == '0') {
        P1OUT &= ~BIT0; // 关闭 LED
    }

    while (!(IFG2 & UCA0TXIFG));        // 等待 TX 缓冲区准备好
    UCA0TXBUF = receivedChar;           // 回显接收到的字符
}
 

最新回复

https://weibo.com/ttarticle/p/show?id=2309405104386635595889 https://weibo.com/ttarticle/p/show?id=2309405104974349861062 https://weibo.com/ttarticle/p/show?id=2309405104975016755414 https://weibo.com/ttarticle/p/show?id=2309405105430165848555 https://weibo.com/ttarticle/p/show?id=2309405105430287483272 https://weibo.com/ttarticle/p/show?id=2309405105432413995174 https://weibo.com/ttarticle/p/show?id=2309405105434192380056 https://weibo.com/ttarticle/p/show?id=2309405105434389512347 https://weibo.com/ttarticle/p/show?id=2309405105434557284736 https://weibo.com/ttarticle/p/show?id=2309405105434942898217 https://weibo.com/ttarticle/p/show?id=2309405105435106476179 https://weibo.com/ttarticle/p/show?id=2309405105435962376622 https://weibo.com/ttarticle/p/show?id=2309405105436348252361 https://weibo.com/ttarticle/p/show?id=2309405105437404954660 https://weibo.com/ttarticle/p/show?id=2309405105437568794729 https://weibo.com/ttarticle/p/show?id=2309405105438172774704 https://weibo.com/ttarticle/p/show?id=2309405105430455255712 https://weibo.com/ttarticle/p/show?id=2309405105431260299440 https://weibo.com/ttarticle/p/show?id=2309405105431478403211 https://weibo.com/ttarticle/p/show?id=2309405105431751295168 https://weibo.com/ttarticle/p/show?id=2309405105431969399031 https://weibo.com/ttarticle/p/show?id=2309405105433265439274 https://weibo.com/ttarticle/p/show?id=2309405105433642926716 https://weibo.com/ttarticle/p/show?id=2309405105434016219317 https://weibo.com/ttarticle/p/show?id=2309405105435282636917 https://weibo.com/ttarticle/p/show?id=2309405105435517780650 https://weibo.com/ttarticle/p/show?id=2309405105435773370524 https://weibo.com/ttarticle/p/show?id=2309405105436146663518 https://weibo.com/ttarticle/p/show?id=2309405105436532802027 https://weibo.com/ttarticle/p/show?id=2309405105436759294041 https://weibo.com/ttarticle/p/show?id=2309405105437212279218 https://weibo.com/ttarticle/p/show?id=2309405105437740499065 https://weibo.com/ttarticle/p/show?id=2309405105437954670809   详情 回复 发表于 1 小时前
 
点赞 关注(1)

回复
举报

2

帖子

0

TA的资源

一粒金砂(中级)

沙发
 

 

 
 

回复

7

帖子

0

TA的资源

一粒金砂(中级)

板凳
 
https://weibo.com/ttarticle/p/show?id=2309405104386635595889
https://weibo.com/ttarticle/p/show?id=2309405104974349861062
https://weibo.com/ttarticle/p/show?id=2309405104975016755414
https://weibo.com/ttarticle/p/show?id=2309405105430165848555
https://weibo.com/ttarticle/p/show?id=2309405105430287483272
https://weibo.com/ttarticle/p/show?id=2309405105432413995174
https://weibo.com/ttarticle/p/show?id=2309405105434192380056
https://weibo.com/ttarticle/p/show?id=2309405105434389512347
https://weibo.com/ttarticle/p/show?id=2309405105434557284736
https://weibo.com/ttarticle/p/show?id=2309405105434942898217
https://weibo.com/ttarticle/p/show?id=2309405105435106476179
https://weibo.com/ttarticle/p/show?id=2309405105435962376622
https://weibo.com/ttarticle/p/show?id=2309405105436348252361
https://weibo.com/ttarticle/p/show?id=2309405105437404954660
https://weibo.com/ttarticle/p/show?id=2309405105437568794729
https://weibo.com/ttarticle/p/show?id=2309405105438172774704
https://weibo.com/ttarticle/p/show?id=2309405105430455255712
https://weibo.com/ttarticle/p/show?id=2309405105431260299440
https://weibo.com/ttarticle/p/show?id=2309405105431478403211
https://weibo.com/ttarticle/p/show?id=2309405105431751295168
https://weibo.com/ttarticle/p/show?id=2309405105431969399031
https://weibo.com/ttarticle/p/show?id=2309405105433265439274
https://weibo.com/ttarticle/p/show?id=2309405105433642926716
https://weibo.com/ttarticle/p/show?id=2309405105434016219317
https://weibo.com/ttarticle/p/show?id=2309405105435282636917
https://weibo.com/ttarticle/p/show?id=2309405105435517780650
https://weibo.com/ttarticle/p/show?id=2309405105435773370524
https://weibo.com/ttarticle/p/show?id=2309405105436146663518
https://weibo.com/ttarticle/p/show?id=2309405105436532802027
https://weibo.com/ttarticle/p/show?id=2309405105436759294041
https://weibo.com/ttarticle/p/show?id=2309405105437212279218
https://weibo.com/ttarticle/p/show?id=2309405105437740499065
https://weibo.com/ttarticle/p/show?id=2309405105437954670809
 
 
 

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

查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/10 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表