日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

type c pin定义_在C中定义宏以设置和清除PIN的位

發布時間:2025/3/11 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 type c pin定义_在C中定义宏以设置和清除PIN的位 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

type c pin定義

Given a PIN (value in HEX) and bit number, we have to SET and then CLEAR given bit of the PIN (val) by using Macros.

給定一個PIN(十六進制值)和位數,我們必須使用宏將SET(設置),然后清除給定的PIN(值)位(值)。

Macros definitions:

宏定義:

#define SET(PIN,N) (PIN |= (1<<N))#define CLR(PIN,N) (PIN &= ~(1<<N))

Here,

這里,

  • SET and CLR are the Macro names

    SET和CLR是宏名稱

  • PIN is the value whose bit to set or/and clear

    PIN是要設置或清除的位的值

  • N is the bit number to set or/and clear

    N是要設置或清除的位數

Example:

例:

#include <stdio.h>#define SET(PIN,N) (PIN |= (1<<N)) #define CLR(PIN,N) (PIN &= ~(1<<N))int main(){unsigned char val = 0x11;unsigned char bit = 2;printf("val = %X\n",val);//set bit 2 of valSET(val,bit);printf("Aftre setting bit %d, val = %X\n", bit, val);//clear bit 2 of valCLR(val,bit);printf("Aftre clearing bit %d, val = %X\n", bit, val); return 0; }

Output

輸出量

val = 11Aftre setting bit 2, val = 15Aftre clearing bit 2, val = 11

Explanation:

說明:

  • Initially val is 0x11, its binary value is "0001 0001".

    最初val為0x11 ,其二進制值為“ 0001 0001” 。

  • In the example, we are setting and clear bit 2 (please note start counting bits from 0 i.e. first bit is 0, second bit is 1 and third bit is 2).

    在該示例中,我們正在設置并清除位2(請注意從0開始計數位,即第一位為0,第二位為1,第三位為2)。

  • After calling Macro SET(val,bit), the bit number 2 (i.e. third bit) will be set/hight and the value of val will be "0001 0101" that will be 0x15 in Hexadecimal.

    調用Macro SET(val,bit)后 ,將設置2位(即第三位)/高,并且val的值將為“ 0001 0101” ,十六進制為0x15 。

  • And then, we are calling CLR(val,bit), after calling this Macro, the bit number 2 (i.e. third bit) will be cleared and the value of val will be "0001 0001" again, that is 0x11 in Hexadecimal.

    然后,我們調用CLR(val,bit) ,在調用此宏后,將清除位數2(即第三位),并且val的值將再次為“ 0001 0001” ,即十六進制為0x11 。

翻譯自: https://www.includehelp.com/c-programs/define-macros-to-set-and-clear-bit-of-a-pin-in-c.aspx

type c pin定義

總結

以上是生活随笔為你收集整理的type c pin定义_在C中定义宏以设置和清除PIN的位的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。