BASIC4MCU | 질문게시판 | interupt 인터럽트 질문 드려요~!!!!!
페이지 정보
작성자 이이잉 작성일2021-06-06 02:28 조회2,445회 댓글1건본문
#include <avr/io.h> //컴파일러 헤더 파일
#define F_CPU 16000000 //발진기 16MHz
#include "ATmega128_v20.h" //사용자 정의 헤더파일
#include <avr/interrupt.h>
int ad_conversion(char ch) // 가변저항값 변환 함수
{
ADMUX = (ch & 0x1F) | 0x40; //기준전압=AVCC,오른쪽정렬,6번채널사용
ADCSRA = 0xD5; //1,1,0,1,0,101
// ADC Enable, ADC Start,ADC Free Running ,ADC Interrupt Flag ,ADC Prescaler(32)
while((ADCSRA & 0x10) != 0x10); //ADIF가 0일때 동안 반복
return(ADC); //ADC 반환
}
ISR(TIMER0_OVF_vect) // 인터럽트
{
//static int count=0;
TCNT0=50;
int adc7 =0; //adc7 변수선언,초기화
adc7 = ad_conversion(7);
if(adc7 > 100)
{
LCD_string(0x80," ");
LCD_string(0xc0," ");
LCD_string(0x80," NO ");
PORTG |= _BV(3);// buzzer on
Delay_ms(500);
}
else
{
LCD_string(0x80," ");
LCD_string(0xc0," ");
LCD_string(0x80," OK ");
PORTG &= ~_BV(3);// buzzer off
Delay_ms(500);
}
}int main(void)
{
MCU_initialize(); //MCU 초기화
Delay_ms(50); //딜레이 50ms
LCD_initialize(); //LCD 초기화
int adc6 =0; //adc6 변수선언, 초기화
int adc7 =0; //adc7
static int h_count =0;
LCD_string(0x80,"SYSTEM on");
인터럽트를 활용해서 가변저항 adc7 > 100 가 되면 LCD에 "NO" 를 띄우고 부저가 울리며
그외에는 LCD에 "OK"를 띄우고 부저를 끄는 기능을 하고 싶습니다ㅠㅠㅠ
어떻게 수정해야 할까요?????
댓글 1
조회수 2,445master님의 댓글
master 작성일
#include <avr/io.h>
#define F_CPU 16000000
#include "ATmega128_v20.h"
#include <avr/interrupt.h>
//
volatile int adc6=0,adc7=0;
//
ISR(TIMER0_OVF_vect){ // 1ms 인터럽트
TCNT0=6;
if(ADMUX==0x46){ adc6=ADCW; ADMUX=0x47; }
else { adc7=ADCW; ADMUX=0x46; }
}
//
int main(void){
MCU_initialize();
Delay_ms(50);
LCD_initialize();
LCD_string(0x80,"SYSTEM on ");
LCD_string(0xc0," ");
ADCSRA=0xE7; ADMUX=0x46;
TCCR0=4; TCNT0=6; TIMSK=1; //16000000/64/(256-6)=1000Hz=1ms
SREG=0x80;
while(1){
if(adc7>100){
LCD_string(0x80," NO ");
PORTG|=_BV(3); // buzzer on
}
else{
LCD_string(0x80," OK ");
PORTG &= ~_BV(3); // buzzer off
}
Delay_ms(500);
}
}