BASIC4MCU | 질문게시판 | 답변 : Atmega 128 타이머 질문있습니다
페이지 정보
작성자 master 작성일2024-12-11 20:41 조회117회 댓글0건본문
#include <avr/io.h>
#define F_CPU 16000000L
#include <avr/interrupt.h>
#include "tools.h"
//
unsigned char fnd[3],num[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x27,0x7f,0x67};
unsigned char buz_flag=0;
volatile int time_100ms=100,comp_cc=0;
//
ISR(TIMER0_COMP_vect){
static unsigned char comp_count=0,digit=0;
if(++comp_count>=100){ comp_count=0;
if(--time_100ms>=100)time_100ms=99;
fnd[0]=time_100ms/10;
fnd[1]=time_100ms%10;
}
//
digit^=1;
PORTC=num[fnd[digit]]; if(digit)PORTC|=0x80;
PORTG=1<<digit;
//
comp_cc++;
if (comp_cc<10000){ PORTA=0x82; }
else if(comp_cc<13000){ PORTA=0x44; buz_flag=1; }
else if(comp_cc<23000){ PORTA=0x81; }
else {comp_cc=0; }
}
//
int main(void){
PORTA=0x81; DDRA=0xff; DDRB=0xff; DDRC=0xff; DDRG=0x07;
TCCR0=0x0C; OCR0=249; TIMSK=2; //16000000/64/(1+249),1ms
sei();
while(1){
if(buz_flag){ buz_flag=0; buzzer(523,130); }
}
}
댓글 0
조회수 117등록된 댓글이 없습니다.