cs16-2.c

来自「《手把手教你学单片机的C程序设计》及实验程序」· C语言 代码 · 共 43 行

C
43
字号
#include <REG51.H>		
#define uint unsigned int	
#define uchar unsigned char	
uchar code SEG7[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar code ACT[4]={0xfe,0xfd,0xfb,0xf7};
uint counter;
/****************************/
void initial(void)			
{					
TMOD=0x50;			
TH1=0x00;			
TL1=0x00;			
IE=0x00;				
TR1=1;				
}
/******************************/
void delay(uint k)				
{							
uint data i,j;						
for(i=0;i<k;i++)					
{for(j=0;j<121;j++)					
{;}}							
}							
/**********************************/
void display(void)
{
P0=SEG7[counter%10];P2= ACT[0];delay(1);
P0=SEG7[(counter%100)/10];P2= ACT[1];delay(1);
P0=SEG7[(counter/100)%10];P2= ACT[2];delay(1);
P0=SEG7[counter/1000];P2= ACT[3];delay(1);
}
/*********************************/
void main(void)		
{	uint temp1,temp2;				
	initial();						
	  for(;;)						
	  {
	   display();
	   temp1=TL1;temp2=TH1;						
	   counter=(temp2<<8)+temp1;		
	  }					
}					

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?