AVR无功能秒表

 
#include <iom8v.h>
#include 
<macros.h>


/**********************
* PC0~3 -------   G1~4 *
* PB0~7 -------    h~a *
*********************
*/


#define LED_BITE_SELECT PORTC    //当前选择的显示的7位数码管
#define LED_BITE_DATA PORTD       //当前数码管的数据

#pragma interrupt_handler timer0_ovf_isr:iv_TIM0_OVF

UINT16 g_Time_Count;
//建立数组,存储各个数字对应的数码管显示段位对应的二进制
UINT16 LED_TEXT[24= {0xFC0x600xDA0xF20x660xB60xBE0xE0,
                        
0xFE0xF60xEE0x3E0x9C0x7A0x9E0x8E,
                        
0xCE0x1C0x6E0x7C0x0A0x100x020x00}
;


void Port_Init(void)
{
    DDRD 
= 0xFF;
    DDRC 
= 0xFF;
    PORTD 
= 0x00;
    PORTC 
= 0xFF;
}


void Device_Init(void)
{
    Port_Init();


 
//stop errant interrupts until set up
 CLI(); //disable all interrupts
 timer0_init();

 MCUCR 
= 0x00;
 GICR  
= 0x00;
 TIMSK 
= 0x01//timer interrupt sources
 SEI(); //re-enable interrupts
 
//all peripherals are now initialized

}


void timer0_init(void)
{    
 TCCR0 
= 0x00//stop
 TCNT0 = 0x83//set count
 TCCR0 = 0x03//start timer
}



void Show_Led(UINT16 wNum)    //将数字显示在数码管上
{
    UINT8 chBit;
    
for(chBit = 0x08; chBit > 0; chBit >>= 1)
    
{
        LED_BITE_DATA 
= ~LED_TEXT[wNum % 10];
        LED_BITE_SELECT 
= chBit;
        wNum 
/= 10;
        
if(wNum == 0)
        
{
            
return;
        }

    }

}


void Count_Increase(void)    //将统计次数增加
{
    g_Time_Count
++;
    
if(g_Time_Count > 9999)
    
{
        g_Time_Count 
= 0;
    }

}


void timer0_ovf_isr(void)    //中断程序,在达到1s时将统计次数加一
{
    
static UINT16 wCount = 0;
    TCNT0 
= 0x83//reload counter value
    if(wCount >= 1000
    
{
        wCount 
= 0;
        Count_Increase();
    }

    wCount
++;
}


void main()
{
    g_Time_Count 
= 0;
    Device_Init();
    
while(1)
    
{
        Show_Led(g_Time_Count);
    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值