
#include <iom16.h>
#include<intrinsics.h>
#define xtal 8
#define uchar unsigned char
#define uint unsigned int
uint vss_ctr=0,tach_ctr=0;
/***************************************/
void port_init(void)
{
PORTA = 0x00;
DDRA = 0xFF;
PORTB = 0x00;
DDRB = 0xFF;
PORTC = 0x04;
DDRC = 0xFF;
PORTD = 0x00;
DDRD = 0xFF;
}
/***************************************/
void timer0_init(void)
{
TCNT0 = 0xE7;
TCCR0 = 0x02;
}
/***************************************/
#pragma vector=TIMER0_OVF_vect
__interrupt void timer0_ovf_isr(void)
{
TCNT0=0xFD;
vss_ctr++;
tach_ctr++;
if(vss_ctr>=150)
{PORTA^=1<<1;vss_ctr=0;}
if(tach_ctr>=90)
{PORTA^=1<<0;tach_ctr=0;}
}
/***************************************/
void init_devices(void)
{
timer0_init();
port_init();
TIMSK=0x01; //开启timer0
SREG=0x80; //开启总中断
}
/***************************************/
void Delay_1ms(void)
{
uint i;
for(i=1;i<(uint)(xtal*143-2);i++);
}
/***************************************/
void Delay_nms(uint n)
{
uint i=0;
while(i<n)
{
Delay_1ms();
i++;
}
}
/***************************************/
void main(void)
{
Delay_nms(1000);
init_devices();
while(1)
{ ;
}
}