九鼎创展论坛中文版English
登录 | 立即注册 设为首页收藏本站 切换到宽版
查看: 5300|回复: 0
打印 上一主题 下一主题

arduino ibox项目实战26-ASCIITable实验

[复制链接]
跳转到指定楼层
楼主
发表于 2014-10-28 14:32:40 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
硬件平台:PC机一台,ibox卡片电脑一只,arduino扩展板一个
软件平台:WIN7操作系统,android4.0android4.4系统
实验目标:通过串口打印函数将ascii码值在调试窗口打印出来。
打开arduino的IDE开发工具,依次点击文件->示例->04.Communication->ASCIITable,ASCIITable的示例程序将会被打开,其源码如下:
  1. void setup() {
  2.   //Initialize serial and wait for port to open:
  3.   Serial.begin(9600);
  4.   while (!Serial) {
  5.     ; // wait for serial port to connect. Needed for Leonardo only
  6.   }

  7.   // prints title with ending line break
  8.   Serial.println("ASCII Table ~ Character Map");
  9. }

  10. // first visible ASCIIcharacter '!' is number 33:
  11. int thisByte = 33;
  12. // you can also write ASCII characters in single quotes.
  13. // for example. '!' is the same as 33, so you could also use this:
  14. //int thisByte = '!';

  15. void loop() {
  16.   // prints value unaltered, i.e. the raw binary version of the
  17.   // byte. The serial monitor interprets all bytes as
  18.   // ASCII, so 33, the first number,  will show up as '!'
  19.   Serial.write(thisByte);

  20.   Serial.print(", dec: ");
  21.   // prints value as string as an ASCII-encoded decimal (base 10).
  22.   // Decimal is the  default format for Serial.print() and Serial.println(),
  23.   // so no modifier is needed:
  24.   Serial.print(thisByte);
  25.   // But you can declare the modifier for decimal if you want to.
  26.   //this also works if you uncomment it:

  27.   // Serial.print(thisByte, DEC);


  28.   Serial.print(", hex: ");
  29.   // prints value as string in hexadecimal (base 16):
  30.   Serial.print(thisByte, HEX);

  31.   Serial.print(", oct: ");
  32.   // prints value as string in octal (base 8);
  33.   Serial.print(thisByte, OCT);

  34.   Serial.print(", bin: ");
  35.   // prints value as string in binary (base 2)
  36.   // also prints ending line break:
  37.   Serial.println(thisByte, BIN);

  38.   // if printed last visible character '~' or 126, stop:
  39.   if (thisByte == 126) {    // you could also use if (thisByte == '~') {
  40.     // This loop loops forever and does nothing
  41.     while (true) {
  42.       continue;
  43.     }
  44.   }
  45.   // go on to the next character
  46.   thisByte++;
  47. }
复制代码
运行程序,观察调试窗口上的打印信息。

回复

使用道具 举报

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

本版积分规则

QQ|手机版|小黑屋|深圳市九鼎创展科技官方论坛 ( 粤ICP备11028681号-2  

GMT+8, 2024-11-23 13:43 , Processed in 0.018723 second(s), 20 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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