4个数码管就是想显示个0到9 然后显示一个9986 9986延时加1 一直加到9999 清0 但是显示0~9是正常的,9986只显示段选a的那一横 就不动了
#include "reg52.h"
typedef unsigned int u16; //对数据类型进行声明定义
typedef unsigned char u8;
sbit C1=P2^7;
sbit C2=P2^6;
sbit C3=P2^5;
sbit C4=P2^4;
sbit W0=P1^3;
sbit W1=P1^2;
sbit W2=P0^2;
sbit W3=P0^3;
sbit W4=P0^4;
sbit W5=P0^5;
sbit W6=P0^6;
sbit W7=P0^7;
unsigned char SMGDUAN_CA[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//共阳极0 1 2 3~9
unsigned int count=9986;
void dis(unsigned char i);
void delaySMG(unsigned int n)
{
while(n--);
}
void dis(unsigned char i) //写入8位数据
{
W0=i&0x01;i>>=1;
W1=i&0x01;i>>=1;
W2=i&0x01;i>>=1;
W3=i&0x01;i>>=1;
W4=i&0x01;i>>=1;
W5=i&0x01;i>>=1;
W6=i&0x01;i>>=1;
W7=i&0x01;
}
void displaySMG_Bit(unsigned char pos,unsigned char dat) //显示的哪一位,在什么位置
{
//P0=0xff;
dis(0xff);
switch(pos)//选择数码管位置
{
case 1:
C1=1; C2=0; C3=0; C4=0;
break;
case 2:
C1=0; C2=1; C3=0; C4=0;
break;
case 3:
C1=0; C2=0; C3=1; C4=0;
break;
case 4:
C1=0; C2=0; C3=0; C4=1;
break;
}
dis(dat);//这边到底怎么调用哈,感觉总不对
delaySMG(100);
}
void displaySMG_4Bit(unsigned int dat)
{
displaySMG_Bit(1,SMGDUAN_CA[dat/1000]);
delaySMG(100);
displaySMG_Bit(2,SMGDUAN_CA[dat%1000/100]);
delaySMG(100);
displaySMG_Bit(3,SMGDUAN_CA[dat%100/10]);
delaySMG(100);
displaySMG_Bit(4,SMGDUAN_CA[dat%10]);
delaySMG(100);
}
void displaySMG_zeronine()
{
char S;
C1=1;
C2=1;
C3=1;
C4=1;
for(S=0;S<10;S++)
{
dis(SMGDUAN_CA[S]);
delaySMG(40000);
}
}
void delay(unsigned int t)
{
while(t--)
{
displaySMG_4Bit(count);
}
}
void main()
{ displaySMG_zeronine();
while(1)
{
displaySMG_4Bit(count);
delay(200);
count++;
if(count==10000)
{
count=0;
}
}
}
|