標題:
ATmega128 time1溢出中斷。定時器1在該模式下用法和51的一樣
[打印本頁]
作者:
liuqq
時間:
2015-5-21 23:45
標題:
ATmega128 time1溢出中斷。定時器1在該模式下用法和51的一樣
#include<iom128v.h>
#define uchar unsigned char
#define uint unsigned int
#pragma interrupt_handler timer1:15/*定時器溢出中斷向量標號*/
uchar t=0;
void timer1()
{
TCNT1H=(65536-50000)/256;
TCNT1L=(65536-50000)%256;
t++;
if(t==20)
{
t=0;
PORTA=~PORTA;
PORTA|=0xfe;
}
}
void IO_init()
{
DDRA=0xff;
PORTA=0xff;
}
void T1_init()
{
TCNT1H=(65536-50000)/256;//50ms溢出中斷
TCNT1L=(65536-50000)%256;
TCCR1B=0x02;//8分頻,8MHz晶振,1us
TIMSK=0x04;
SREG=0x80;
}
main()
{
IO_init();
T1_init();
while(1)
{
;
}
}
復制代碼
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1