rendered paste body#include <avr/io.h>#include <avr/interrupt.h>#include <stdint.h>#include <avr/sfr_defs.h>#include <util/delay.h>#define F_CPU 4000000#define F_OSC 4000000#define BAUD 9600#define MYUBRR F_OSC/16/BAUD-1#define STOP 0#define RUN 1#define OUTPUT 1#define INPUT 0volatile uint8_t state;volatile uint8_t ledCount = 0;volatile uint8_t switchPressed[10];/* Initialize UART */void USART_Init( unsigned int ubrr ){ /* Set the baud rate */ UBRRH = (unsigned char) (ubrr>>8); UBRRL = (unsigned char) ubrr; /* Enable UART receiver and transmitter */ UCSRB = ( ( 1 << RXEN ) | ( 1 << TXEN ) ); //atta databitar, tva stopbitar! UCSRC = (1<<URSEL)|(1<<USBS)|(3<<UCSZ0);}/* Read and write functions */unsigned char USART_Receive( void ){ /* Wait for incomming data */ while ( !(UCSRA & (1<<RXC)) ) return UDR;}void USART_Transmit( unsigned char data ){ /* Wait for empty transmit buffer */ while ( !(UCSRA & (1<<UDRE)) ) ; /* Start transmittion */ UDR = data;}void USART_printstring(unsigned char *data){ while(*data) { USART_Transmit(*data); data++; }}void enableAllStops(){ PORTB |=(1<<PB0)|(1<<PB1)|(1<<PB2)|(1<<PB3);}void disableAllStops(){ PORTB &=~(1<<PB0)&~(1<<PB1)&~(1<<PB2)&~(1<<PB3);}void enableRun(){ PORTD |=(1<<PD4);}void disableRun(){ PORTD &=~(1<<PD4);}void enableMCURunning(){ PORTD |=(1<<PD5);}SIGNAL(SIG_OVERFLOW0){ ledCount=1; //RESET if(bit_is_set(PINC,PC6) && state==STOP){ // if(switchPressed[0]==1) // switchPressed[0]==0; // else{ enableRun(); disableAllStops(); //PORTD |=(1<<PD4); state=RUN; switchPressed[0]=1; // } } //SW1 if(bit_is_set(PINC,PC5) && state==RUN){ PORTD &=~(1<<PD4); disableRun(); PORTB |=(1<<PB0); state=STOP; } //SW2 if(bit_is_set(PINA,PA2) && state==RUN){ disableRun(); PORTD |=(1<<PD4); state=STOP; }}void initTimer(){ TCNT0 = 0; TCCR0=0x14; TIFR = 1<<TOV0; TIMSK = 1<<TOIE0;}int main(void){ uint8_t i =0; for(i=0;i<10;i++) switchPressed[i]=0; state=STOP; GICR=0xC0; // MCUCR=0x03; initTimer(); sei(); DDRD |= (OUTPUT<<PD6)|(OUTPUT<<PD5)|(OUTPUT<<PD4)|(OUTPUT<<PD7); DDRB |= (OUTPUT<<PB0)|(OUTPUT<<PB1)|(OUTPUT<<PB2)|(OUTPUT<<PB3); DDRA = (INPUT << PA0 | INPUT << PA1 |INPUT << PA2 |INPUT << PA3 |INPUT << PA4 |INPUT << PA5 |INPUT << PA6 |INPUT << PA7); DDRC = 0x00; //PORTC == INPUT PORT // PORTD &=~(1 << PD2); PORTA = 0x00; //pullup 0 pa alla pinnar PORTC = 0x00; // USART_Init( MYUBRR ); //9600 @ 4Mhz // USART_Transmit(0x01); enableMCURunning(); enableAllStops(); disableRun(); while (1) { // USART_Transmit(0x01); // _delay_ms(100); } return 0;}