我用南京沁恒电子公司在网上的提供的程序测试过,硬件没问题.但用我的程序的时候出现一个奇怪的问题,就是显示的时候,会出现要显示的值和0交替显示.程序如下,请大虾看看. #include #include #define uchar unsigned char #define uint unsigned int #define CH451_SYSON2 0x0403 //开显示、键盘 #define CH451_SYSON3 0x0407 //开显示、键盘、看门狗功能 #define CH451_DSP 0x0500 //设置默认显示方式 #define CH451_BCD 0x0580 //设置BCD译码方式 #define CH451_TWINKLE 0x0600 //设置闪烁控制 #define CH451_DIG0 0x0800 //数码管位0显示 #define CH451_DIG1 0x0900 //数码管位1显示 #define CH451_DIG2 0x0a00 //数码管位2显示 #define CH451_DIG3 0x0b00 //数码管位3显示 #define CH451_DIG4 0x0c00 //数码管位4显示 #define CH451_DIG5 0x0d00 //数码管位5显示 #define CH451_DIG6 0x0e00 //数码管位6显示 #define CH451_DIG7 0x0f00 //数码管位7显示 sbit ch451_dclk=P0^3; //串行数据时钟上升延激活 sbit ch451_din=P0^5; // 串行数据输出,接CH451的数据输入 sbit ch451_load=P0^7; //串行命令加载,上升延激活 sbit ch451_load0=P0^0; sbit ch451_dout=P0^1; sbit sclk=P1^4; sbit cs=P1^5; sbit din=P3^3; sbit dout=P1^2; sbit sstrb=P2^0; sbit vari1=P2^1; sbit vari0=P2^3; uchar key; int mv; unsigned char ms=0; void timer0_inint(void) { TMOD=0x01; TL0=0x00; TH0=0x00; EA=1; ET0=1; TR0=1; } void timer0_max186() interrupt 1 {TR0=0; TL0=0x00; TH0=0x00; ms++; TR0=1; } void ch451_write0(unsigned int command) //写指令 { unsigned char i; ch451_load0=0; //命令开始 for(i=0;i<12;i++) { //送入12位数据,低位在前 ch451_din=command&0x01; ch451_dclk=0; command>>=1; ch451_dclk=1; //上升沿有效
} ch451_load0=1; //加载数据
} void ch451_init0() { ch451_din=0; //先低后高,选择4线输入 ch451_din=1; ch451_write0(0x580); ch451_write0(0x401); } void main (void) {uchar temp; ch451_init0(); timer0_inint(); while(1) { if(ms>10) { ms=0; mv=324; } temp=mv/100; if(temp==0) ch451_write0(CH451_DIG1|0x10); else ch451_write0(CH451_DIG1|temp); temp=mv%100/10; if(temp==0) { mv=abs(mv); if(mv<100) ch451_write0(CH451_DIG2|0x10); else ch451_write0(CH451_DIG2|0x00); } else ch451_write0(CH451_DIG2|temp); temp=mv%100%10; ch451_write0(CH451_DIG3|temp); ch451_write0(CH451_DIG4|0x10); ch451_write0(CH451_DIG5|0x10); ch451_write0(CH451_DIG6|0x10); } }
在运行过程中就一下显示324,一下显示0,不知为何.