|
哪位大虾帮忙看看,为什么定时器中断不能进入
#define F_CPU 4000000UL
#include<avr/io.h>
#include<util/delay.h>
#include<avr/interrupt.h>
#define uchar unsigned char
#define uint unsigned int
#define s1 !(PIND& _BV(PD0))
#define s2 !(PIND& _BV(PD1))
#define s3 !(PIND& _BV(PD2))
#define s4 !(PIND& _BV(PD0))
uchar temp=0;
void write_com(uchar com)
{
PORTA=0x3f;
PORTC=com;
PORTA=0x40;
_delay_ms(5);
PORTA=0xdf;
}
void write_dat(uchar dat)
{
PORTA=0xbf;
PORTC=dat;
PORTA=0x40;
_delay_ms(5);
PORTA=0xdf;
}
void show()
{
uint bai,shi,ge;
bai=temp/100;
shi=temp/10%10;
ge=temp%10;
write_com(0x80+3);
write_dat(0x30+bai);
write_dat(0x30+shi);
write_dat(0x30+ge);
}
void init()
{
TCCR0=0x05;
TCNT0=256-F_CPU/1024.0*0.05;
TIMSK=0x01;
SREG=0x80;
DDRA=0xff;
PORTA=0x40;
DDRC=0xff;
DDRD=0x00;
PORTD=0xff;
// MCUCR=0x02;
// GICR=0x40;
write_com(0x38);
_delay_ms(5);
write_com(0x01);
_delay_ms(5);
write_com(0x0c);
_delay_ms(5);
write_com(0x06);
}
void keyscan()
{
if(s1)
{
_delay_ms(1);
if(s1)
{
while(s1);
if(TIMSK==0x01)
{
TIMSK=0;
}
if(TIMSK==0)
{
TIMSK=0x01;
}
}
}
if(s2)
{
_delay_ms(1);
if(s2)
{
while(s2);
if(TIMSK==0)
{
temp=0;
}
}
}
}
int main()
{
init();
while(1)
{
keyscan();
show();
}
}
ISR (TIMER0_OVF_vect)
{
uint aa=0;
TCNT0=256-F_CPU/1024.0*0.05;
aa++;
if(aa>=20)
{
aa=0;
temp++;
if(temp==100);
{
temp=0;
}
}
}
|
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|