Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define F_CPU 9216000UL
- #include <util/delay.h>
- #include <avr/io.h>
- #include <avr/interrupt.h>
- #include <stdlib.h>
- void USART_init(void);
- void InitTimer0(void);
- void StartTimer0(void);
- void USART_init(void){
- UCSR0A = (1<<U2X0);
- UBRR0H = (uint8_t)(4>>8);
- UBRR0L = (uint8_t)(4);
- UCSR0B = (1<<RXEN0)|(1<<TXEN0);
- UCSR0C = (3<<UCSZ00);
- }
- void InitTimer0(void)
- {
- OCR0A=(119); //119 //9k6Hz
- TCCR0A |= (1<<WGM01); //Set CTC mode
- }
- void StartTimer0(void)
- {
- TCCR0B |=(1<<CS01); //Set Prescaler 64 and start timer //|(1<<CS00)
- }
- int main(void)
- {
- DDRB|=(1<<DDB0);
- USART_init();
- InitTimer0();
- sei();
- StartTimer0();
- TIMSK0 |= (1<<OCIE0A);
- while (1)
- {
- }
- }
- ISR (TIMER0_COMPA_vect)
- {
- static uint8_t cnt; //unser "i"
- PORTB =(1<<PB0);
- cnt++;
- UDR0=(cnt);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement