This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] CCS/MSP430F5529:使用 UART 和 PuTTY 执行简单的命令

Guru**** 2946650 points
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/952848/ccs-msp430f5529-using-uart-and-putty-for-simple-commands

器件型号:MSP430F5529

工具/软件:Code Composer Studio

我有一个程序通过终端请求用户名和密码(我正在使用 PuTTY)、然后将其与预存储的值进行比较。  它过早打印"正确答案"陈述、我不确定它是否正确存储了用户名和密码输入。

//说明:在 PuTTY //
端口中设置以下参数: COM4
//波特率:115200
//数据位:8//
奇偶校验: 无
//停止位:1
//流控制:无

#include 
#include 
#include 
#include 
#include 

//输出和输入
字符的值 firstquestion[28]="请输入用户名:";
const char username[9];
char usernameinput[9];
secondchar question[21]="输入密码:";
const char password[9]="密码";
char passwordinput[9];char
certswer ="325"欢迎使用!
char incorrectanswer[34]="用户名或密码不正确!!!";


//循环计数器
unsigned int i=0;

//新行和回车
符返回 void newline (void)
{
while (!(UCA0IFG&UCTXIFG));//等待字符
UCA0TXBUF='\n'; //将字符设置为新行
while (!(UCA0IFG&UCTXIFG));//等待字符
UCA0TXBUF='\r\n'; //set character to carriage return
}
//提示用户名
void userdata (void)
{
对于(i=0;i "enter="" key"="" will="" break="" from="" receiving="" break;="" transmit="" buffer="" equal="" receive="" echo="" print="" what="" types="" usernameinput[i]="UCA0RXBUF;" uca0rxbuf="0;" clears="" adds="" null="" end="" array="" void="" passdata(void)="" i'*'="" bonus="" passwordinput[i]="UCA0RXBUF;" correct(void)="" i

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    char firstquestion[28]="请输入用户名:";

    该字符串具有28个字符、因此  firstquestion[28]数组不包含用于存储终止空字符的空间。

    因此 、strlen (firstquestion)将在  firstquestion[28]数组的末尾运行、直到在内存中找到下一个空。

    即、以下内容将显示 "请输入用户名:"、然后在存储器中显示以下字符、直至找到空字符:

    对于(i=0;i 
    

    为避免必须保持常量字符串的数组大小、建议不要使用数组来声明常量字符串的指针。 例如:

    const char firstquestion * const ="请输入用户名:";