1s定时器

 #include<reg52.h>

#define DataPort P0 
sbit LATCH1=P2^2;
sbit LATCH2=P2^3;
//unsigned char code dofly[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//共阳
unsigned char code dofly_DuanMa[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};// 共阴显示段码值0~9
unsigned char code dofly_WeiMa[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//分别对应相应的数码管点亮,即位码
void Display(unsigned char FirstBit,unsigned char Num);
unsigned char TempData[8]; 

void delay();

void main(void)
{
	unsigned char i;

	TMOD = 0X01;
	TH0 = 0X3C;
	TL0 = 0XB0;
	TR0 = 1;

	
	while(1)
	{
		i++;	
		if(i == 10)
			i = 0;
		TempData[0] = dofly_DuanMa[i];
		Display(7,1);			
	}

}
void delay()
{
	unsigned char i;
	for(i = 0; i < 20; i++)
	{
		while(!TF0);
		TF0 = 0;
		TH0 = 0X3C;
		TL0 = 0XB0;
	}	
}
void Display(unsigned char FirstBit,unsigned char Num)
{
      unsigned char i;
	  
	  for(i=0;i<Num;i++)
	  { 
	   DataPort=0; 
       LATCH1=1;    
       LATCH1=0;

       DataPort=dofly_WeiMa[i+FirstBit];
       LATCH2=1;    
       LATCH2=0;

       DataPort = TempData[i]; 
       LATCH1=1;    
       LATCH1=0;
       
	   delay(); 
       }
}

STM32的1S #include "stm32f10x_it.h" /** @addtogroup STM32F10x_StdPeriph_Template * @{ */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ extern u32 SystickCounter; extern u8 KeySwitch_Press; extern u8 KeyAdjust_Press; #define TRUE 1 #define FALSE 0 /* Private function prototypes -----------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ /******************************************************************************/ /* Cortex-M3 Processor Exceptions Handlers */ /******************************************************************************/ /** * @brief This function handles NMI exception. * @param None * @retval None */ void NMI_Handler(void) { } /** * @brief This function handles Hard Fault exception. * @param None * @retval None */ void HardFault_Handler(void) { /* Go to infinite loop when Hard Fault exception occurs */ while (1) { } } /** * @brief This function handles Memory Manage exception. * @param None * @retval None */ void MemManage_Handler(void) { /* Go to infinite loop when Memory Manage exception occurs */ while (1) { } } /** * @brief This function handles Bus Fault exception. * @param None * @retval None */ void BusFault_Handler(void) { /* Go to infinite loop when Bus Fault exception occurs */ while (1) { } } /** * @brief This function handles Usage Fault exception. * @param None * @retval None */ void UsageFault_Handler(void) { /* Go to infinite loop when Usage Fault exception occurs */ while (1) { } } /** * @brief This function handles SVCall exception. * @param None * @ret
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值