Last active
October 8, 2019 07:14
-
-
Save edp1096/029e3cf6bd3d5d8a3f6b476ec2746af4 to your computer and use it in GitHub Desktop.
atmega128 타이머 인터럽트 확인용
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #define F_CPU 16000000UL | |
| #define USART_BAUDRATE 9600 // baud rate | |
| #define UBRR_VALUE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1) // Clock, bps to UBRR | |
| #include <avr/io.h> | |
| #include <stdio.h> | |
| #include <util/delay.h> | |
| #include <avr/interrupt.h> | |
| volatile unsigned int count=0, num=0; | |
| int cnt = 0; | |
| void sendByte(uint8_t data) { | |
| while(!(UCSR1A & (1 << UDRE1))){}; // Wait for sending | |
| UDR1 = data; | |
| } | |
| void sendString(const char str[]) { | |
| uint8_t i = 0; | |
| while (str[i]) { | |
| sendByte(str[i]); | |
| i++; | |
| } | |
| } | |
| ISR(TIMER0_OVF_vect) | |
| { | |
| PORTA = 0xFF; | |
| if (cnt > 1000) { | |
| char ch[10]; | |
| sprintf(ch, "^_^ %d", cnt); | |
| sendString(ch); | |
| cnt = 0; | |
| } else { | |
| cnt++; | |
| } | |
| PORTA = 0xFE; | |
| } | |
| void initUART() | |
| { | |
| // 16bit UBRRn - Split by each 8bit | |
| UBRR1H = (uint8_t)(UBRR_VALUE>>8); | |
| UBRR1L = (uint8_t) UBRR_VALUE; | |
| UCSR1C |= (1 << UCSZ10) | (1 << UCSZ11); // Data bit - 8bit | |
| UCSR1C &= ~((1 << UPM11) | (1 << UPM10)); // Parity bit - none | |
| UCSR1C &= ~(1 << USBS1); // stop bit - 1bit | |
| UCSR1B=(1 << RXEN1) | (1 << TXEN1); // Enable send, receive | |
| } | |
| int main(void) | |
| { | |
| DDRA = 0xFF; | |
| PORTA = 0xFF; | |
| initUART(); | |
| TCCR0 = (0<<WGM01)|(0<<WGM01)|(0<<CS02)|(1<<CS01)|(1<<CS00); | |
| TCNT0 = 6; | |
| TIMSK = (0<<OCIE0)|(1<<TOIE0); | |
| sei(); | |
| unsigned int k = 20; | |
| while(k != 0) | |
| { | |
| _delay_ms (250); | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment