標(biāo)題: 有誰熟悉ATtiny45單片機(jī)編程嗎?定時器1問題請教 [打印本頁]

作者: daiya    時間: 2018-12-21 16:53
標(biāo)題: 有誰熟悉ATtiny45單片機(jī)編程嗎?定時器1問題請教
我為了使用ATtiny45定時器1作每秒1000HZ的定時中斷,編了以下程序,可是運行不了,想了好久也想不出解決的方法。請各位高手指導(dǎo),看看問題出在哪里?
#include <tiny45.h>

#define uchar unsigned char
#define uint unsigned int

#define led PORTB.0
#define LED_ON 0
#define LED_OFF 1

uint mark = 0;

// Timer1 overflow interrupt service routine
interrupt [TIM1_OVF] void timer1_ovf_isr(void)
{
// Reinitialize Timer1 value
TCNT1=0x64;
// Place your code here
mark++;
}


void main(void)
{
PORTB=0x03;
DDRB=0x01;

// Timer/Counter 1 initialization
PLLCSR=0x00;

TCCR1=0x01;
GTCCR=0x00;
TCNT1=0x64;
OCR1A=0x00;
OCR1B=0x00;
OCR1C=0x00;

// Interrupt(s) initialization
TIMSK=0x04;

while(1)
    {
        if(mark==500)     
            led = LED_ON;
        if(mark==1000)     
            led = LED_OFF;
        mark = 0;
    }
}

作者: angmall    時間: 2018-12-22 10:05
你的程序有缺陷,給你改了一下,你試試。
TIMER1_OVF_vect


// Timer1 overflow interrupt service routine
interrupt [TIMER1_OVF_vect] void timer1_ovf_isr(void)
{
// Reinitialize Timer1 value
TCNT1=0x64;
// Place your code here
mark++;
}




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1