Articles Posted by the Author:

  • volatile

    volatile

    volatile 是 C 语言内定的关键字之一,它用在宣告变数的资料型态之前,让编译器还有后续的程式码改变对它的操作方式。 宣告一个变数为 volatile 可以引导编译器的行为。编译器是能将 C/C++ 语言程式码转换成机器码的软体,转换后的机器码则由 86Duino CPU 去执行。 volatile 的特别之处在于,它引导编译器从 RAM 中载入变数而不是从暂存器(暂存器是程式暂时储存与调出变数的空间)。在某些情况下将变数数值存到暂存器可能会不准确。 如果变数可能会被其他同时处理的执行绪修改时,应该宣告成 volatile (例如:中断副程式和使用者程式共用的全域变数)。在 86Duino 中只有控制中断 (interrupt) 的中断副程式 (interrupt service routine) 有关的地方可能会发生这种情况。 范例 See also - attachInterrupt() 语法参考主页面 本页由热血青年 LBU 译自英文版。 The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative […]


  • Static

    Static

    函式中用 static 宣告的变数只能在该函式中被使用,但它不像一般区域变数,每当函式被呼叫时,就会被重新创建然后随着函式执行完毕后就会被释放,静态变数的存在不受函式的呼叫与否影响,变数的值在每次呼叫完函式之后继续被保留。 变数只能在第一次呼叫函式时被宣告为静态变数并给定型别、初值。 范例 语法参考主页面 本页由热血青年 LBU 译自英文版。 The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.


  • 变数作用范围

    变数作用范围

    在 86Duino 中使用的 C 语言变数,可依照其作用域的不同来加以区分,这点与所有变数皆为全域变数的早期程式语言 BASIC 有所不同。 全域变数是可以被程式中的所有函式使用的,而区域变数则只能被宣告它的函式使用;在 86Duino 的环境中,所有被宣告在函式之外的变数 (例:setup()、loop()、等等…) 为全域变数。. 当程式码变得更大更复杂之后,区域变数可以确保各函式内的变数只会被自身函式存取,这能预防程式的错误,让一个函式不会不小心去存取到其他函式在使用的变数。 在 for 回圈内也可以宣告一个变数并给定初值,这样可以让这个变数只能在该 for 回圈中存取。 范例 语法参考主页面 本页由热血青年 LBU 译自英文版。 The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the […]


  • float()

    float()

    描述 將一個值轉換成 float 的資料型別。 語法 float(x) 參數 x: 任何型別的值 回傳 float 注意 在 float 這篇文章中,介紹了 float 浮點數在 86Duino 上的特性,敘述使用時的精度及數值範圍,在運用 float 浮點數時可以參考。 See also - float 語法參考主頁面 The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are […]


  • long()

    long()

    描述 将一个数值转换成 long 资料型别。 语法 long(x) 参数 x: 一个任意型别的数值 回传 long See also - long 语法参考主页面 本页由热血青年 LBU 译自英文版。 The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.


  • word()

    word()

    描述 将一个数值转换成 word 资料型别或将 2 bytes 合并为 1 个 word。 语法 word(x) word(h, l) 参数 x: 一个任意型别的数值 h: word 中的高位元组 l: word 中的低位元组 回传 word See also - word 语法参考主页面 本页由热血青年 LBU 译自英文版。 The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 […]


  • int()

    int()

    描述 将一个值转换成 int 的资料型别。 语法 int(x) 参数 x: 任何型别的值 回传 int See also - int 语法参考主页面 本页由热血青年 LBU 译自英文版。 The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.


  • byte()

    byte()

    描述 将一个值转换成 byte 的资料型别。 语法 byte(x) 参数 x: 任何型别的值 回传 byte See also - byte 语法参考主页面 本页由热血青年 LBU 译自英文版。 The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.


  • char()

    char()

    描述 将一个数值转换成 char 资料型态。 语法 char(x) 参数 x: 一个任意型别的值 回传 char See also - char 语法参考主页面 本页由热血青年 LBU 译自英文版。 The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.


  • 数组

    数组

    数组是一群变数的集合,每个变数可以利用特定的索引值来存取。86Duino 的数组与 C 语言相同,数组的使用可以很复杂也可以很简单。 宣告数组 以下是有效宣告数组的方法。 你可以宣告一个数组而不初始化,例如 myInts。 第 2 行在宣告 myPins 数组时不给明确的大小,但编译器将会自动计算元素数量并且创建一个适当大小的数组。 你也可以同时初始化数组内容以及数组大小,像是 mySensVals;注意宣告 char 数组时,需要初始化一个值给数组让它存放空字元。 存取数组 数组索引从 0 开始,第一个元素的索引值是0: mySensVals[0] == 2, mySensVals[1] == 4, 直到第四个。 它也代表一个数组中若有十个元素,最后一个元素的索引将是 9。因此: int myArray[10]={9,3,2,4,3,2,7,8,9,11}; // myArray[9] 的内容是 11 // myArray[10] 10 是未宣告的位置,内容是不可预期的。 有上面的案例提醒我们必须小心地存取数组,存取超出宣告范围 (使用大于宣告大小减 1 的索引值) 的元素时,会读到用于其他用途的记忆体位址。读取到这些位置很可能会产生不预期的结果。而撰写一个随机记忆体位置存取是很不明智的行为,可能会造成整个程式崩溃或故障,而且非常难除错。 不像 Basic 或者 Java,C 的编译器在使用数组时不会去检查索引值是否合法。 指派数值给数组元素: mySensVals[0] = 10; 从数组元素中取回数值: […]