BASIC4MCU | 질문게시판 | Atmega 128 타이머 질문있습니다
페이지 정보
작성자 ednda 작성일2024-12-11 17:53 조회157회 댓글1건본문
#include <avr/io.h>
#define F_CPU 16000000L
#include <avr/interrupt.h>
#include "tools.h"
#define INTERVAL1_1ms 125
volatile int comp_count =0;
volatile int time_100ms=100;
volatile int comp_cc =0;
volatile int digit =0;
volatile int digit_change =0;
unsigned char num[] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x27, 0x7f, 0x67};
unsigned char fnd[3];
ISR(TIMER0_COMP_vect){
TCNT0 = 0;
digit_change++;
comp_count ++;
comp_cc++;
if( comp_count>= 100){
comp_count =0;
time_100ms--;
if(time_100ms == 0) time_100ms =100;
}
}
int main(void)
{
DDRB = 0xff;
DDRA = 0xff;
PORTA = 0b10000001;
DDRC = 0xff;
DDRG = 0x07;
TCNT0 =0;
TCCR0 |= (1<<CS02) | (1<<CS00);
OCR0 = INTERVAL1_1ms;
TIMSK |=(1<<OCIE0) ;
sei();
/* Replace with your application code */
while (1)
{
if(comp_cc >=10000){
PORTA =0b10000010;
}
if (comp_cc ==13000)
{
PORTA = 0b01000100;
buzzer(523,130);
if(digit_change ==1){ <---------------------------------------------------------------이 코드가 실행이 안됩니다.
fnd[1] = (time_100ms /100)%10;
fnd[0] = (time_100ms/ 10)%10;
PORTG = 1<<digit;
PORTC = num[fnd[digit]];
if (digit == 1)
{
PORTC = num[fnd[digit]] | 0x80;
}
if(++digit>=2) digit =0;
}
}
if(comp_cc >=23000){
comp_cc=0;
PORTA = 0b10000001;
}
}
}
고수님들 도와주세요.
댓글 1
조회수 157master님의 댓글
master 작성일
digit_change++;
1ms마다 증가하면 순식간에 1을 넘게되는데요
buzzer(523,130);
if(digit_change==1){ // <---------------------------이 코드가 실행이 안됩니다.
buzzer() 함수에서 1ms 이상 지연 되면 1번도 실행되지 못합니다.