本帖最后由 liu_qing532 于 2016-3-12 15:55 编辑 ![]() ![]() ![]() #include<reg51.h> #define uchar unsigned char #define uint unsigned int sbit MBI_SDIG=P3^4; sbit MBI_SDIR=P3^2; sbit MBI_CLK=P3^5; sbit MBI_LE=P3^7; uint code Tab[]= { 0xd680, // 0 0x5000, // 1 0xc620, // 2 0xd420, // 3 0x50a0, // 4 0x94a0, // 5 0x96a0, // 6 0xd000, // 7 0xd6a0, // 8 0xd4a0 // 9 }; void delay(uint xms) { uint i,j; for(i=xms;i>0;i--) for(j=100;j>0;j--); } void mbi5026(uint dat) { uint k; for(k=0;k<16;k++) { MBI_SDIR=(dat &0x8000)?1:0; MBI_CLK=1; dat<<=1; MBI_CLK=0; } MBI_LE = 1; delay(1000); MBI_LE = 0; } void main() { uchar q; MBI_CLK=0; MBI_SDIR=0; MBI_SDIG=0; for(q=0;q<10;q++) { mbi5026(Tab[q]); delay(1000); } } 只能显示零星的字段,不能显示完整数字,求大神告知是哪错了???数组编码应该不会错,对了好几遍了。 |
nsj21n 发表于 2016-3-1 15:03 #include<reg51.h> #define uchar unsigned char #define uint unsigned int sbit MBI_SDIG=P3^4; sbit MBI_SDIR=P3^2; sbit MBI_CLK=P3^5; sbit MBI_LE=P3^7; //显示段码表 uchar code Tab[]= { 0xdfc0, // 0 0x03c0, // 1 0xc620, // 2 0x86a0, // 3 0x12a0, // 4 0x94a0, // 5 0xd4a0, // 6 0x0680, // 7 0xd6a0, // 8 0x96a0, // 9 }; void delay(uint xms) { uint i,j; for(i=xms;i>0;i--) for(j=100;j>0;j--); } void mbi5026(uchar dat) { uchar k; for(k=0;k<16;k++) { MBI_SDIR=(dat &0x8000)?1:0; MBI_CLK=1; dat<<=1; MBI_CLK=0; } MBI_LE = 1; delay(100); MBI_LE = 0; } void main() { uchar q; MBI_CLK=0; MBI_SDIR=0; MBI_SDIG=0; for(q=0;q<10;q++) { mbi5026(Tab[q]); delay(1000); } } 求教,大神!! |
MBI是16位串行数据,你这样确定能把数据送出去?给你个参考发送16位数据,其它依照时序图补上:for(i=0;i<16;i++) { MBI_SDI=(dat & 0x8000)?1:0; //串口移位的数据 MBI_CLK=1; dat<<=1; delay(10); MBI_CLK=0; // delay(500); } |
nsj21n 发表于 2016-3-1 09:11 #include<reg51.h> #define uchar unsigned char #define uint unsigned int sbit MBI_SDI=P3^4; sbit MBI_CLK=P3^5; sbit MBI_LE=P3^7; uchar num; //显示段码表 uchar code Tab[]= { 0xdfc0, // 0 0x03c0, // 1 0xc620, // 2 0x86a0, // 3 0x12a0, // 4 0x94a0, // 5 0xd4a0, // 6 0x0680, // 7 0xd6a0, // 8 0x96a0, // 9 }; void delayms(uint xms) { uint i,j; for(i=xms;i>0;i--) for(j=100;j>0;j--); } void main() { MBI_CLK = 0; MBI_SDI = 0; while(1) { for(num=9;num>0;num--) { MBI_SDI=Tab[num]; MBI_CLK=1; MBI_CLK=0; MBI_LE=1; delayms(1000); MBI_LE=0; } } } 初学,哪里错?? |
程序写出来了么?先参考时序图写写贴出来大家给你参考 |