Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr/io.h>
- //#include <avr/delay.h>
- void delay(void);
- void delay_long(void);
- int main(void) {
- DDRB = 0xFF; // port B is configured as output DDRB : 0b11111111
- DDRB &= ~(1<<PB1); // pin 1 of port B is configured as input DDRB : 0b11111101
- PORTB = 0x00; // pins of port B are low (output) and with no pull-up resistor (input)
- PORTB |= (1<<PB0)|(1<<PB1); // pin 0 is high (output) and pin 1 is pulled high (input) PORTB : 0b00000011
- while(1) {
- PORTB &= ~(1<<PB0);
- delay();
- PORTB |= 1<<PB0;
- delay();
- PORTB = ~(1<<PB0);
- delay_long();
- PORTB = 1<<PB0;
- delay_long();
- }
- return 1;
- }
- void delay(void) {
- TCNT0 = 0x00;
- TCCR0B = 0x05;
- while ( (TIFR0 & TOV0) == 0 )
- ;
- TCCR0B = 0x00;
- TIFR0 |= 1<<TOV0;
- }
- void delay_long(void) {
- TCNT0 = 0x00;
- TCCR0B = 0x05;
- while ( (TIFR0 & TOV0) == 0 )
- ;
- TCCR0B = 0x00;
- TIFR0 |= 1<<TOV0;
- TCCR0B = 0x05;
- while ( (TIFR0 & TOV0) == 0 )
- ;
- TCCR0B = 0x00;
- TIFR0 |= 1<<TOV0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement