Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define F_CPU 128000UL
- #include <avr/io.h>
- #include <avr/interrupt.h>
- #include <util/delay.h>
- #define MOSIPIN PB5
- #define REGPIN PB4
- #define CLK_PIN PB7
- volatile int sekunde = 0;
- volatile int intteruptCount = 0;
- volatile int i=0;
- void startUP() {
- cli(); //Disable Interrupts
- TIMSK |= (1<<OCIE0A) | (1<<TOIE0); //Enable OCIE0A: Timer/Counter0 Output Compare Match A Interrupt Enable
- DDRB = 0xFF;
- PORTB = 0x00;
- DDRD = 0xFF;
- PORTD = 0x00;
- DDRB |= (1<<PB5);
- DDRB &= ~(1<<PB6);
- CLKPR = 0x80; //Ukljuci prescale originalnog takta
- TCCR0A |= (1 << WGM01); // Configure Timer 0 for CTC mode
- TCCR0B |= (1 << CS02) | (1 << CS00); //Prescaling the timer (1024)
- OCR0A = 0xF9; // Set CTC compare value to 1Hz AVR clock, with pre-scaler of 1024
- TCNT0 = 0x06; //Podesi brojac odakle da pocne da broji
- sei(); //Enable Interrupts
- }
- unsigned char SPI_SR(unsigned char data)
- {
- USIDR = data;
- USISR = (1<<USIOIF); // clear IRQ
- while ((USISR & (1<<USIOIF)) == 0)// send 8 bits
- {
- // Positive edge SCK clock strobe
- USICR = (1<<USIWM0)|(1<<USICS1)|(1<<USICLK)|(1<<USITC);
- }
- return USIDR;
- }
- void RegisterCLK() {
- PORTB &= ~(1<<REGPIN);
- _delay_ms(10);
- PORTB |= (1<<REGPIN);
- _delay_ms(10);
- PORTB &= ~(1<<REGPIN);
- _delay_ms(10);
- }
- //Timer0 Interrupt funkcija
- ISR(TIMER0_COMPA_vect)
- {
- //PORTD ^= 0xFF;
- //PORTB ^= 0xFF;
- }
- int main(void)
- {
- startUP();
- RegisterCLK();
- while(1)
- {
- PORTB &= ~(1<<MOSIPIN);
- _delay_ms(10);
- for(i=0; i<8; i++) {
- PORTB &= ~(1<<CLK_PIN);
- _delay_ms(10);
- PORTB |= (1<<CLK_PIN);
- _delay_ms(10);
- }
- RegisterCLK();
- _delay_ms(1000);
- PORTB |= (1<<MOSIPIN);
- _delay_ms(10);
- for(i=0; i<8; i++) {
- PORTB &= ~(1<<CLK_PIN);
- _delay_ms(10);
- PORTB |= (1<<CLK_PIN);
- _delay_ms(10);
- }
- RegisterCLK();
- _delay_ms(1000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement