首页 > 学院 > 开发设计 > 正文

数码管

2019-11-08 18:31:32
字体:
来源:转载
供稿:网友
#include <reg52.h>#define DataPort P0 //定义数据端口sbit LATCH_Seg = P2^2;//定义锁存使能端口,段锁存sbit LATCH_Bit = P2^3;//                  位unsigned char DuanMa[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};unsigned char WeiMa[] ={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};unsigned char sec;//unsigned char i;void delay(unsigned int t);void ISR_T0(void);/*void Delay_1s()//50*20{    int t;    TMOD = 0x01;    for(t=0;t<20;t++)    {        TH0 = 0x3c;//高位        TL0 = 0xb0;//低位        TR0 = 1;//开关        while(!TF0);//标志位(溢出)        TF0 = 0;    }}*/void timer_init(){     TH0 = 0x3c;//高位     TL0 = 0xb0;//低位}void main(void){   int i;//	int num;	TMOD = 0x01;	Timer_init();        TR0 = 1;//开关        //while(!TF0);//标志位(溢出)        //TF0 = 0;//	num = 0;	EA = 1;//总开关	ET0 = 1;//外部中断开关	sec = 0;	while(1)	{	      // if(i<60)		 //  {	       //     num++;        while(1)    	{         //       if(sec == 10) sec = 0;		 	if(sec == 60)				{			        sec = 0;				    i++;				 }    	        DataPort = DuanMa[sec%10];    	        LATCH_Seg = 1;    	    	LATCH_Seg = 0;		        DataPort = WeiMa[7];    	    	LATCH_Bit = 1;	        	LATCH_Bit = 0; 				delay(200); 				DataPort = DuanMa[sec/10];    	        LATCH_Seg = 1;    	    	LATCH_Seg = 0;		        DataPort = WeiMa[6];    	    	LATCH_Bit = 1;	        	LATCH_Bit = 0; 				delay(200);		//	 Delay_1s();		     //   DataPort = DuanMa[num/10];    	    //    LATCH_Seg = 1;    	    //	LATCH_Seg = 0;    	   // 	DataPort = WeiMa[6];    	    //	LATCH_Bit = 1;	      //  	LATCH_Bit = 0;		  //      Delay_1s();			//	i++;		}		//	if(i>=60)		//	{			 //   num = 0;			//	i=0;		//	}	//    }	}}void delay(unsigned int t){   while(t--);}void ISR_T0(void) interrupt 1{    unsigned char i;	EA = 0;//关掉其他中断    timer_init();    i++;	if(i==20)	{	    sec++;		i = 0;	}//如果i=20时完成了1s	EA = 1;//结束后再打开中断}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表