养生 装修 购物 美食 感冒 便秘 营销 加盟 小吃 火锅 管理 创业 搭配 减肥 培训 旅游

在KEIL C8051中直接输入二进制

时间:2024-11-07 10:46:02

懂C8051单片机的朋友一定用过KEI雉搽妤粲L吧?KEIL中,用C语言编程支持十六进制、八进制、十进制数据,不支持二进制。用二进制可以更直观的设置IO口的状态,聍铝遒灰有没有办法可以让KEIL支持二进制呢?下面就介绍我一直在用的方法,就是用宏定义

工具/原料

记事本

KEIL

方法1

1、先打开记事本

在KEIL C8051中直接输入二进制

在KEIL C8051中直接输入二进制

2、把以下代码粘贴到记事本里#ifndefBIN#def坡纠课柩ineBIN#defineB0000_00000x00#颊俄岿髭defineB0000_00010x01#defineB0000_00100x02#defineB0000_00110x03#defineB0000_01000x04#defineB0000_01010x05#defineB0000_01100x06#defineB0000_01110x07#defineB0000_10000x08#defineB0000_10010x09#defineB0000_10100x0A#defineB0000_10110x0B#defineB0000_11000x0C#defineB0000_11010x0D#defineB0000_11100x0E#defineB0000_11110x0F#defineB0001_00000x10#defineB0001_00010x11#defineB0001_00100x12#defineB0001_00110x13#defineB0001_01000x14#defineB0001_01010x15#defineB0001_01100x16#defineB0001_01110x17#defineB0001_10000x18#defineB0001_10010x19#defineB0001_10100x1A#defineB0001_10110x1B#defineB0001_11000x1C#defineB0001_11010x1D#defineB0001_11100x1E#defineB0001_11110x1F#defineB0010_00000x20#defineB0010_00010x21#defineB0010_00100x22#defineB0010_00110x23#defineB0010_01000x24#defineB0010_01010x25#defineB0010_01100x26#defineB0010_01110x27#defineB0010_10000x28#defineB0010_10010x29#defineB0010_10100x2A#defineB0010_10110x2B#defineB0010_11000x2C#defineB0010_11010x2D#defineB0010_11100x2E#defineB0010_11110x2F#defineB0011_00000x30#defineB0011_00010x31#defineB0011_00100x32#defineB0011_00110x33#defineB0011_01000x34#defineB0011_01010x35#defineB0011_01100x36#defineB0011_01110x37#defineB0011_10000x38#defineB0011_10010x39#defineB0011_10100x3A#defineB0011_10110x3B#defineB0011_11000x3C#defineB0011_11010x3D#defineB0011_11100x3E#defineB0011_11110x3F#defineB0100_00000x40#defineB0100_00010x41#defineB0100_00100x42#defineB0100_00110x43#defineB0100_01000x44#defineB0100_01010x45#defineB0100_01100x46#defineB0100_01110x47#defineB0100_10000x48#defineB0100_10010x49#defineB0100_10100x4A#defineB0100_10110x4B#defineB0100_11000x4C#defineB0100_11010x4D#defineB0100_11100x4E#defineB0100_11110x4F#defineB0101_00000x50#defineB0101_00010x51#defineB0101_00100x52#defineB0101_00110x53#defineB0101_01000x54#defineB0101_01010x55#defineB0101_01100x56#defineB0101_01110x57#defineB0101_10000x58#defineB0101_10010x59#defineB0101_10100x5A#defineB0101_10110x5B#defineB0101_11000x5C#defineB0101_11010x5D#defineB0101_11100x5E#defineB0101_11110x5F#defineB0110_00000x60#defineB0110_00010x61#defineB0110_00100x62#defineB0110_00110x63#defineB0110_01000x64#defineB0110_01010x65#defineB0110_01100x66#defineB0110_01110x67#defineB0110_10000x68#defineB0110_10010x69#defineB0110_10100x6A#defineB0110_10110x6B#defineB0110_11000x6C#defineB0110_11010x6D#defineB0110_11100x6E#defineB0110_11110x6F#defineB0111_00000x70#defineB0111_00010x71#defineB0111_00100x72#defineB0111_00110x73#defineB0111_01000x74#defineB0111_01010x75#defineB0111_01100x76#defineB0111_01110x77#defineB0111_10000x78#defineB0111_10010x79#defineB0111_10100x7A#defineB0111_10110x7B#defineB0111_11000x7C#defineB0111_11010x7D#defineB0111_11100x7E#defineB0111_11110x7F#defineB1000_00000x80#defineB1000_00010x81#defineB1000_00100x82#defineB1000_00110x83#defineB1000_01000x84#defineB1000_01010x85#defineB1000_01100x86#defineB1000_01110x87#defineB1000_10000x88#defineB1000_10010x89#defineB1000_10100x8A#defineB1000_10110x8B#defineB1000_11000x8C#defineB1000_11010x8D#defineB1000_11100x8E#defineB1000_11110x8F#defineB1001_00000x90#defineB1001_00010x91#defineB1001_00100x92#defineB1001_00110x93#defineB1001_01000x94#defineB1001_01010x95#defineB1001_01100x96#defineB1001_01110x97#defineB1001_10000x98#defineB1001_10010x99#defineB1001_10100x9A#defineB1001_10110x9B#defineB1001_11000x9C#defineB1001_11010x9D#defineB1001_11100x9E#defineB1001_11110x9F#defineB1010_00000xA0#defineB1010_00010xA1#defineB1010_00100xA2#defineB1010_00110xA3#defineB1010_01000xA4#defineB1010_01010xA5#defineB1010_01100xA6#defineB1010_01110xA7#defineB1010_10000xA8#defineB1010_10010xA9#defineB1010_10100xAA#defineB1010_10110xAB#defineB1010_11000xAC#defineB1010_11010xAD#defineB1010_11100xAE#defineB1010_11110xAF#defineB1011_00000xB0#defineB1011_00010xB1#defineB1011_00100xB2#defineB1011_00110xB3#defineB1011_01000xB4#defineB1011_01010xB5#defineB1011_01100xB6#defineB1011_01110xB7#defineB1011_10000xB8#defineB1011_10010xB9#defineB1011_10100xBA#defineB1011_10110xBB#defineB1011_11000xBC#defineB1011_11010xBD#defineB1011_11100xBE#defineB1011_11110xBF#defineB1100_00000xC0#defineB1100_00010xC1#defineB1100_00100xC2#defineB1100_00110xC3#defineB1100_01000xC4#defineB1100_01010xC5#defineB1100_01100xC6#defineB1100_01110xC7#defineB1100_10000xC8#defineB1100_10010xC9#defineB1100_10100xCA#defineB1100_10110xCB#defineB1100_11000xCC#defineB1100_11010xCD#defineB1100_11100xCE#defineB1100_11110xCF#defineB1101_00000xD0#defineB1101_00010xD1#defineB1101_00100xD2#defineB1101_00110xD3#defineB1101_01000xD4#defineB1101_01010xD5#defineB1101_01100xD6#defineB1101_01110xD7#defineB1101_10000xD8#defineB1101_10010xD9#defineB1101_10100xDA#defineB1101_10110xDB#defineB1101_11000xDC#defineB1101_11010xDD#defineB1101_11100xDE#defineB1101_11110xDF#defineB1110_00000xE0#defineB1110_00010xE1#defineB1110_00100xE2#defineB1110_00110xE3#defineB1110_01000xE4#defineB1110_01010xE5#defineB1110_01100xE6#defineB1110_01110xE7#defineB1110_10000xE8#defineB1110_10010xE9#defineB1110_10100xEA#defineB1110_10110xEB#defineB1110_11000xEC#defineB1110_11010xED#defineB1110_11100xEE#defineB1110_11110xEF#defineB1111_00000xF0#defineB1111_00010xF1#defineB1111_00100xF2#defineB1111_00110xF3#defineB1111_01000xF4#defineB1111_01010xF5#defineB1111_01100xF6#defineB1111_01110xF7#defineB1111_10000xF8#defineB1111_10010xF9#defineB1111_10100xFA#defineB1111_10110xFB#defineB1111_11000xFC#defineB1111_11010xFD#defineB1111_11100xFE#defineB1111_11110xFF#endif

在KEIL C8051中直接输入二进制

3、在记事本中选择“文件,保存”

在KEIL C8051中直接输入二进制

4、在保存对话框中输入名字“bin.c”,不包括引号。这个名字要记好,以后要用。点保存,这个文件就会生成。

在KEIL C8051中直接输入二进制

5、这个文件要放到“KEIL安装目录\C51\INC”目录下,可以在第四步保存对话框中选好路径直接保存,否则就要复制过去

在KEIL C8051中直接输入二进制

6、这时可以在程序中使用踮碚牢邗了,在开头用代码“#include<bin.c>”引入就可以直接使用二进制,就像下图一样。

在KEIL C8051中直接输入二进制

7、仿真的结果跟数据是一样的,很直观

在KEIL C8051中直接输入二进制

8、你也可以修改“bin.c”文件,把下划线去掉,但是前面的“B”不能删除,因为C语言命名规则不能以数字开头。

© 一点知识