1.用AT89S52驱动1602液晶,单片机的P0.0-0.7分别连液晶的DB7-DB0,原定义为 #define databus P0 ,改为 #define databus ~P0 这样可以吗,如果不行,是否要把程序里的每处P0 都改为~P0呢?
2.如果MCU连接1602的8位数据线不连续,比如P0.1 P0.3 P0.8 P0.9 P1.5 ...分别连DB0-DB7,用什么指令能解决?
刚开始学51,菜鸟一个,望大家支持,谢谢
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
solution 1:
- unsigned char brev0(unsigned char x) {
- x = (((x & 0xaa) >> 1) | ((x & 0x55) << 1));
- x = (((x & 0xcc) >> 2) | ((x & 0x33) << 2));
- x = (((x & 0xf0) >> 4) | ((x & 0x0f) << 4));
- return x;
- }
复制代码solution 2:- //map 4 bits
- const unsigned char code b2b[]={
- 0x00, //0x00
- 0x08, //0x01
- 0x04, //0x02
- 0x0c, //0x03
- 0x02, //0x04
- 0x0a, //0x05
- 0x06, //0x06
- 0x0e, //0x07
- 0x01, //0x08
- 0x09, //0x09
- 0x05, //0x0a
- 0x0d, //0x0b
- 0x03, //0x0c
- 0x0b, //0x0d
- 0x07, //0x0e
- 0x0f //0x0f
- };
- unsigned char brev1(unsigned char x) {
- return b2b[x>>4] | (b2b[x&0x0f]<<4);
- }
复制代码so rather than "Pn=dat;", you say "Pn=brevx[dat];" to bit reverse the data.if you need speed, you can inline brev1().
一周热门 更多>