- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用带有 Atmega 微 Controller 的 AVR C。我正在使用串行通信,我想将一个字符“A”传输到屏幕,然后将其删除并显示“B”。我在清除屏幕时遇到了麻烦。
我读到 ESC ASCII 可以工作,所以我尝试了。
#define F_CPU 16000000UL
void initUART(unsigned int baud);
void transmitByte(unsigned char data);
unsigned char receiveByte(void);
int getNumOfDigits(int num);
void printDec(int num);
int main(void) {
DDRB = 0b00000011;
PORTB = 0b00011000;
initUART(9600);
while(1) {
//s1 pressed
if ((PINB & 0b00001000) == 0) {
transmitByte('A');
transmitByte((char) 27);
transmitByte('B');
_delay_ms(1000);
}
}
return 0;
}
void initUART(unsigned int baud) {
/*
Initialize settings for uart functions.
Must be done once at the beginning of the program.
*/
//Normal mode UBRR formula
unsigned int ubrr = F_CPU/16/baud-1;
//shift MSB and store in UBRR0H
UBRR0H = (unsigned char) (ubrr >> 8);
//store LSB in UBRR0L
UBRR0L = (unsigned char) ubrr;
//Enable transmitter/receiver
UCSR0B = (1 << RXEN0) | (1 << TXEN0);
//8-Bit Characters, 0 Stop bits, No parity
UCSR0C = (1 << UCSZ00) | (1 << UCSZ01);
}
void transmitByte(unsigned char data) {
/*
Write byte to UART
*/
//Wait for empty transmit buffer
while(!(UCSR0A & (1 << UDRE0)));
//Start transmission by writing to UDR0
UDR0 = data;
}
unsigned char receiveByte(void){
/*
Read byte from UART
*/
//Wait for incoming byte
while(!(UCSR0A & (1 << RXC0)));
//Return the byte
return UDR0;
}
但它不起作用,我对微 Controller 还很陌生,它只是打印
AAAA..
如何清除屏幕然后在串行通信屏幕上打印一个新字符,我正在使用腻子。
更新
transmitByte('A');
transmitByte(27); // this is the escape
transmitByte('[');
transmitByte('2');
transmitByte('J'); // uppercase J
transmitByte('^');
transmitByte('[');
transmitByte('H');
transmitByte('B');
输出
如何让光标回到原来的位置?
最终工作
transmitByte('A');
transmitByte(27); // this is the escape
transmitByte('[');
transmitByte('2');
transmitByte('J'); // uppercase J
transmitByte(27);
transmitByte('[');
transmitByte('H');
transmitByte('B');
以上代码有效,删除并将光标移回。
最佳答案
我不太确定你想要传输一个“A”然后清除屏幕,但是......如果你想清除屏幕你必须发送你的终端模拟器理解的转义序列 .通常,ESC[2J
会执行此操作,并且许多终端仿真器都可以理解它。所以你可以这样写:
transmitByte(27); // this is the escape
transmitByte('[');
transmitByte('2');
transmitByte('J'); // uppercase J
查看 putty 的“终端仿真”特性(它有几个选项),一般来说,“转义序列”。还要考虑 ^[[2J
(^[ 表示 Escape)清除屏幕,但不应将光标发送到主页。为此,您需要 ^[[H
。
基本信息的一些链接:http://www.isthe.com/chongo/tech/comp/ansi_escapes.html
还有:http://ascii-table.com/ansi-escape-sequences.php
也就是说,打印退格键返回行中的一个位置(十进制字符 8)或回车返回到当前行的开头(十进制字符 13)也可能很有趣,并且最后打印一些东西,然后使用 ESC[K
清除该行的其余部分。
关于c - AVR C : Serial Communication Clear Screen,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42639909/
我有兴趣了解有关 Microsoft Office Communicator 的更多信息IM 客户端,以及它如何确定您的存在(即您是在计算机旁还是不在)。任何人都可以向我指出解释这一点的教程或 API
我正在使用 python。我正在尝试运行一个进程并使用 subprocess.popen 获取输出。阅读周围后,我看到人们使用 communicate()[0] 但那不在文档中,它用于示例。我想知道是
我正在使用 python。我正在尝试运行一个进程并使用 subprocess.popen 获取输出。阅读周围后,我看到人们使用 communicate()[0] 但那不在文档中,它用于示例。我想知道是
我有一些设置和拆卸脚本,它们使用 csrun.exe 为一些自动化测试准备本地计算模拟器。 C:\Program Files\Microsoft SDKs\Azure\Emulator\csrun.e
我想知道对这句名言最接地气的解释是什么: Don't communicate by sharing memory; share memory by communicating. (R. Pike) 在
(所以 this question has been asked before ,但在一般意义上,大多数响应都是在与多个服务器/客户端/等的一般网络通信的上下文中) 在简单的点对点通信协议(proto
我正在尽力将 C++ 模块链接到 python 绑定(bind)。我正在努力实现 boost mpi 通信。我正在将 boost.mpi.world 对象发送到 C++,它需要一个 boost::mp
情况是这样的: 我有一个正在运行的命令: import subprocess foo = subprocess.Popen('ls /', shell=True, stdout=subprocess.
关闭。这个问题是opinion-based .它目前不接受答案。 想改善这个问题吗?更新问题,以便可以通过 editing this post 用事实和引文回答问题. 7年前关闭。 Improve t
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题? Update the question所以它是on-topic对于堆栈溢出。 10年前关闭。 Improve this qu
关闭。这个问题是opinion-based .它目前不接受答案。 想改善这个问题吗?更新问题,以便可以通过 editing this post 用事实和引文回答问题. 2年前关闭。 Improve t
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎与 help center 中定义的范围内的编程无关。 . 关闭 5 年前。 Improve
我曾与那些与同龄人在线聊天的人一起工作,他们不断地围绕想法进行讨论。我也曾与那些坚决拒绝并认为这是浪费时间的人一起工作。 在线实时聊天论坛对您特别有用吗?为什么或者为什么不? 在您的公司内部,还是在外
我在一个分为两组的 IT 部门工作。一组开发和管理应用程序,另一组管理公司的基础设施和服务器。我们面临的问题之一是沟通中断。我为应用程序组工作,我遇到的问题之一是当基础设施关闭服务器或刷新数据库时没有
我的团队与 IM 进行了很多交流。我们有时甚至会使用 IM 向在下一个立方体中的人提问。这样做的原因是我们都发现接听 IM 的干扰比说话要少得多。 尽管如此,我发现当我低头编码时,闪烁的消息窗口可能会
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 4年前关闭。 Improve thi
关闭。这个问题是opinion-based .它目前不接受答案。 想改善这个问题吗?更新问题,以便可以通过 editing this post 用事实和引文回答问题. 3年前关闭。 Improve t
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题? Update the question所以它是on-topic对于堆栈溢出。 10年前关闭。 Improve this qu
传输数据时,汉明码显然允许您重新创建已通过线路损坏的数据(纠错码)。 这是如何工作的,它的局限性是什么(如果有的话)? 有没有更好的纠错解决方案(相对于重传)?是否存在重传更好的情况? 最佳答案 让我
我是一名优秀的程序员,十分优秀!