蓝桥杯省赛准备,CT107D开发板数码管显示自动移位显示,检测不到异常显示的字形码的值

@蓝桥杯省赛准备过程中遇到问题,关于数码管的移位显示

#第一次用在这里提问,请多包涵 ,希望前辈帮忙解答一下,谢谢!

想实现的功能:
用定时器和中断实现矩阵按键控制数码管显示0-20的循环计时,在七八位上显示,仅此。

遇到的问题:
七八位正常显示,但是第八位和第一位连着循环继续显示第七位和第八位一样的数字,第八位显示有重叠显示的现象,第一位显示的值和第八位重叠显示的值比第七位、第八位偏暗,但是显示同步。

自己测试第一位的值是多少,是11(什么都不显示)和2-6位一样,LED灯亮检测到其在程序中的理论值还是对的 ,还是11,但是肉眼可见其联合第八位一起显示本来应该在第七位第八位显示的字形码。

希望解决:
第八位和第一位显示的暗的字形码小消失,七八位正常显示。

如发现不好的编程习惯,也欢迎批评指正。
谢谢!

#include"stc15F2k60s2.h"

#define uchar unsigned char
	#define uint unsigned int
		
uchar ss,s7,s6,s5,s4,ss,one,two,three,four,five,six,seven,eight;
uint nu,num,count;
uchar code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf,0xff};
void delayms(int ms);
//void keyscan(void);
void keyscan16(void);
void nixie_tube1(uchar one,uchar two);
void nixie_tube2(uchar three,uchar four);
void nixie_tube3(uchar five,uchar six);
void nixie_tube4(uchar seven,uchar eight);
void initial(void);
void Timer0Init(void);
void main()
{
	initial();
	one=two=three=four=five=six=seven=eight=11;
	Timer0Init();
	EA=1;ET0=1;
 while(1)
 {
    nixie_tube1(one,two);
		nixie_tube2(three,four);
		nixie_tube3(five,six);
		nixie_tube4(seven,eight);
	  keyscan16();
	  
	  
 }
}
//void keyscan(void)
//{
//  if(P30==0)//S7
//	{
//		delayms(5);
//			if(P30==0)
//		{
//			s7=1;
//		}
//		while(P30!=0);
//	}
//	
//	
//	if(P31==0)//S6
//	{
//		delayms(5);
//			if(P31==0)
//		{
//			s6=1;
//		}
//		while(P31!=0);
//	}
//	
//	
//	if(P32==0)//S5
//	{
//		delayms(5);
//			if(P32==0)
//		{
//			s5=1;
//		}while(P32!=0);
//	}
//	//S4
//	
//	if(P33==0)
//	{
//		delayms(5);
//			if(P33==0)
//		{
//			s4=1;
//		}while(P33!=0);
//	}
//	
//		
//}
void keyscan16(void)
{
	uchar temp;
	
	P3=0X7F;P42=1;P44=0;//0
	temp=P3;
	temp=temp&0x0f;
	if(temp!=0x0f)
	{
	   delayms(5);
		 temp=P3;
	   temp=temp&0x0f;
     if	(temp!=0x0f)
		 {
		    temp=P3;
				switch(temp)
				{
				  case 0x7e:num=0;break;
					case 0x7d:num=1;break;
					case 0x7b:num=2;break;
					case 0x77:num=3;break;
				}
				while(temp!=0x0f)
				{
				  temp=P3;
					temp&=0x0f;
				}
		 }			 
	}
	
	P3=0XbF;P42=0;P44=1;//1
	temp=P3;
	temp&=0x0f;
	if(temp!=0x0f)
	{
	   delayms(5);
		 temp=P3;
	   temp&=0x0f;
     if	(temp!=0x0f)
		 {
		   temp=P3;
				switch(temp)
				{
				  case 0xbe:num=4;break;
					case 0xbd:num=5;break;
					case 0xbb:num=6;break;
					case 0xb7:num=7;break;
				}
				while(temp!=0x0f)
				{
				  temp=P3;
					temp&=0x0f;
				}
		 }			 
	}
	
	P3=0XdF;P42=1;P44=1;//2
	temp=P3;
	temp&=0x0f;
	if(temp!=0x0f)
	{
	  delayms(5);
		temp=P3;
	  temp&=0x0f;
     if	(temp!=0x0f)
		 {
		   temp=P3;
				switch(temp)
				{
				  case 0xde:num=8;break;
					case 0xdd:num=9;break;
					case 0xdb:num=10;break;
					case 0xd7:num=11;break;
				}
				while(temp!=0x0f)
				{
				  temp=P3;
					temp&=0x0f;
				}
		 }			 
	}
	
	P3=0XeF;P42=1;P44=1;//3
	temp=P3;
	temp&=0x0f;
	if(temp!=0x0f)
	{
	   delayms(5);
		 temp=P3;
	   temp&=0x0f;
     if	(temp!=0x0f)
		 {
		   temp=P3;
				switch(temp)
				{
				  case 0xee:num=12;break;
					case 0xed:num=13;break;
					case 0xeb:num=14;break;
					case 0xe7:num=15;break;
				}
				while(temp!=0x0f)
				{
				  temp=P3;
					temp&=0x0f;
				}
		 }			 
	}
	
}
void nixie_tube1(uchar one,uchar two)
{
	P0=0X01;P2=P2&0X1F|0XC0;P2&=0X1F;//OTSEGB
	P0=tab[one];P2=P2&0X1F|0XE0;P2&=0X1F;//OTSEGS
	delayms(5);
	
	P0=0X02;P2=P2&0X1F|0XC0;P2&=0X1F;//OTSEGB
	P0=tab[two];P2=P2&0X1F|0XE0;P2&=0X1F;//OTSEGS
	delayms(5);
}
	
void nixie_tube2(uchar three,uchar four)
{
	P0=0X04;P2=P2&0X1F|0XC0;P2&=0X1F;//OTSEGB
	P0=tab[three];P2=P2&0X1F|0XE0;P2&=0X1F;//OTSEGS
	delayms(5);
	
	P0=0X08;P2=P2&0X1F|0XC0;P2&=0X1F;//OTSEGB
	P0=tab[four];P2=P2&0X1F|0XE0;P2&=0X1F;//OTSEGS
	delayms(5);
}

void nixie_tube3(uchar five,uchar six)
{
		P0=0X10;P2=P2&0X1F|0XC0;P2&=0X1F;//OTSEGB
	P0=tab[five];P2=P2&0X1F|0XE0;P2&=0X1F;//OTSEGS
	delayms(5);
	
	P0=0X20;P2=P2&0X1F|0XC0;P2&=0X1F;//OTSEGB
	P0=tab[six];P2=P2&0X1F|0XE0;P2&=0X1F;//OTSEGS
	delayms(5);
}

void nixie_tube4(uchar seven,uchar eight)
{
	P0=0X40;P2=P2&0X1F|0XC0;P2&=0X1F;//OTSEGB
	P0=tab[seven];P2=P2&0X1F|0XE0;P2&=0X1F;//OTSEGS
	delayms(5);
	
	P0=0X80;P2=P2&0X1F|0XC0;P2&=0X1F;//OTSEGB
	P0=tab[eight];P2=P2&0X1F|0XE0;P2&=0X1F;//OTSEGS
	delayms(5);
}
void initial(void)
{
	P0=0X00;P2=P2&0X1F|0XA0;P2&=0X1F;//CTB
	P0=0XFF;P2=P2&0X1F|0X80;P2&=0X1F;//CTLED
	P0=0XFF;P2=P2&0X1F|0XC0;P2&=0X1F;//CTSEGB
	P0=0XFF;P2=P2&0X1F|0XE0;P2&=0X1F;//CTSEGS
}
	
	
void delayms(int ms)
{
  int i,j;
	for(i<ms;i>0;i--)
	for(j=845;j>0;j--);
}

void Timer0Init(void)		//5毫秒@11.0592MHz
{
	AUXR |= 0x80;		//定时器时钟1T模式
	TMOD &= 0xF0;		//设置定时器模式
	TL0 = 0x00;		//设置定时初值
	TH0 = 0x28;		//设置定时初值
	TF0 = 0;		//清除TF0标志
	TR0 = 1;		//定时器0开始计时
}

void time0() interrupt 1
{
   ss++;
	if(ss==200)
	{
	   ss=0;
		if(num==15)
		{
			 nu++;
			one=two=three=four=five=11;
			seven=nu/10;
			one=11;
			eight=nu%10;
			if(nu>=20)
				nu=0;
			one=11;
			if(one==11)//这里确定了 one显示的值一直是11,板子上LED灯一直亮
			{
			 P2=0XA0;P0=0X00;P2=0X80;P0=0XFF;
			 P0=0X66;//点亮LED测试
			 P2=0XC0;P0=0XC0;P2=0XFF;P0=0XFF;
			}
			if(one!=11)
			{
			 P2=0XA0;P0=0X00;P2=0X80;P0=0XFF;
			 P2=0XC0;P0=0Xc0;P2=0XFF;P0=0XFF;
			}
				
		}
	}
}






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值