BASIC4MCU | 질문게시판 | avr atmega128 코드 수정 질문
페이지 정보
작성자 master 작성일2018-12-14 16:11 조회7,662회 댓글0건
https://www.basic4mcu.com/bbs/board.php?bo_table=gac&wr_id=6875
본문
#include "test.h" // 기본 위치에 두도록#include "lcd.h" //#define TIMER8_INTERVAL 125 // for 1msec at 8MHz , 0.5 msec at 16MHz#include <avr/io.h>#include <avr/interrupt.h>#include <avr/signal.h>#include <util/delay.h>volatile unsigned char interrupt_count;int s = 0;SIGNAL(SIG_INTERRUPT0) /* EXTERNAL interrupt 0*/{PORTB = 0b00000000;}SIGNAL(SIG_INTERRUPT1) /* EXTERNAL interrupt 0*/{OCR0 = 70;PORTB = 0b10010000;}SIGNAL(SIG_INTERRUPT2) /* EXTERNAL interrupt 0*/{OCR0 = 1;PORTB = 0b10010000;}SIGNAL(SIG_OUTPUT_COMPARE2) /* OC0 interrupt function */{interrupt_count--;if(interrupt_count == 0) // 250th interrupt ?{ interrupt_count = 250; // if yes, toggle LED3s-=1;}}int main(void){DDRB = 0xFF;DDRD = 0b1000;PORTB = 0x00;DDRC = 0xFF;char time[12];MCU_initialize();Delay_ms(50);lcd_init();DDRA = 0xF0;PORTA = 0x0F;TCCR0 = 0x77;TCCR2 = 0x0E;OCR2 = 124;TCNT2 = 0x00;ASSR = 0x00;EIMSK = 0b00000111;EICRA = 0b00111111; //rising edgePORTB = 0b00000000;sei();interrupt_count = 250;while(1){sprintf(time,"%d",s);lcd_putstring(0,0, time);Delay_ms(100);if (!bit_is_set(PINA, 0))s += 10;}}여기서 변수 s의 값을 타이머카운터2를 이용하여 1초당 -1씩 감소하게끔 lcd에 띄우고 싶습니다. 그리고 타이머카운터2의 인터럽트를 PC0에 스위치를 연결하여 인터럽트할려고 하는데 어떻게 해야되는지 제발 좀 가르쳐주세요 ㅠㅠ//
// MCU BASIC: https://www.basic4mcu.com// DateTime : 2018-12-14 오후 4:15:57// by Ok-Hyun Park//#include "test.h"#include "lcd.h"//#include <avr/io.h>#include <avr/interrupt.h>#include <avr/signal.h>#include <util/delay.h>//volatile unsigned char interrupt_count=0,run=0;volatile int s=0;//SIGNAL(SIG_INTERRUPT0){ PORTB=0b00000000; }SIGNAL(SIG_INTERRUPT1){ OCR0=70; PORTB=0b10010000; }SIGNAL(SIG_INTERRUPT2){ OCR0= 1; PORTB=0b10010000; }//SIGNAL(SIG_OUTPUT_COMPARE2){if(run){if(--interrupt_count==0){ interrupt_count=125; s--; }}}//int main(void){char time[12],flag=0;PORTA=0x0F; DDRA=0xF0; DDRB=0xFF; DDRD=0x08; DDRC=0xFF;MCU_initialize();Delay_ms(50);lcd_init();TCCR0=0x77;TCCR2=0x0E; OCR2=124; TIMSK=0x80; //16000000/1024/(1+124),8msEICRA=0xFF; EIMSK=0x07; //rising edgesei();interrupt_count=250;while(1){sprintf(time,"%d",s); lcd_putstring(0,0,time); Delay_ms(100);//---------------------if((PINA&1)==1)s+=10;//---------------------if((PINC&1)==1){if(flag==0){ flag=1; run^=1; } // 누를 때마다 토글(반전)}else{ flag=0; }}}
댓글 0
조회수 7,662등록된 댓글이 없습니다.