AVR单片机定时0

2019-03-24 20:38发布

//ICC-AVR application builder : 2013-7-18 下午 08:03:54
// Target : M128
// Crystal: 16.000Mhz
#include <iom128v.h>
#include <macros.h>
typedef unsigned char uchar;
uchar i;
void port_init(void)
{
PORTA = 0xff;
DDRA  = 0xff;
PORTE = 0xff;
DDRE  = 0xff;
}
//TIMER0 initialize - prescale:1024
// WGM: Normal
// desired value: 10mSec
// actual value:  9.984mSec (0.2%)
void timer0_init(void)
{
TCCR0 = 0x00; //stop
ASSR  = 0x00; //set async mode
TCNT0 = 0x01; //set count
OCR0  = 0x4f;
TCCR0 = 0x07; //start timer
}
#pragma interrupt_handler timer0_ovf_isr:17
void timer0_ovf_isr(void)
{
i++;
if (i == 100)
{i=0;
  PORTA= PORTA + 1;}
  TCNT0 = 0x01;
//reload counter value
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
timer0_init();
TIMSK= 0x01; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
void main(void)
{
init_devices();
while(1);
}




大家帮忙看看程序有没有问题,下载到板子,不工作! 此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
1条回答
gh131413
2019-03-25 03:07
我总看到别人的程序头就有点晕,不知道怎么回事

一周热门 更多>