Advertisement
Guest User

Untitled

a guest
Feb 13th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include <avr/io.h>
  2. //#include <avr/delay.h>
  3.  
  4. void delay(void);
  5.  
  6. void delay_long(void);
  7.  
  8. int main(void) {
  9.  
  10. DDRB = 0xFF; // port B is configured as output DDRB : 0b11111111
  11. DDRB &= ~(1<<PB1); // pin 1 of port B is configured as input DDRB : 0b11111101
  12. PORTB = 0x00; // pins of port B are low (output) and with no pull-up resistor (input)
  13. PORTB |= (1<<PB0)|(1<<PB1); // pin 0 is high (output) and pin 1 is pulled high (input) PORTB : 0b00000011
  14.  
  15. while(1) {
  16. PORTB &= ~(1<<PB0);
  17. delay();
  18. PORTB |= 1<<PB0;
  19. delay();
  20. PORTB = ~(1<<PB0);
  21. delay_long();
  22. PORTB = 1<<PB0;
  23. delay_long();
  24. }
  25.  
  26. return 1;
  27.  
  28. }
  29.  
  30. void delay(void) {
  31. TCNT0 = 0x00;
  32. TCCR0B = 0x05;
  33. while ( (TIFR0 & TOV0) == 0 )
  34. ;
  35. TCCR0B = 0x00;
  36. TIFR0 |= 1<<TOV0;
  37. }
  38.  
  39. void delay_long(void) {
  40. TCNT0 = 0x00;
  41. TCCR0B = 0x05;
  42. while ( (TIFR0 & TOV0) == 0 )
  43. ;
  44. TCCR0B = 0x00;
  45. TIFR0 |= 1<<TOV0;
  46. TCCR0B = 0x05;
  47. while ( (TIFR0 & TOV0) == 0 )
  48. ;
  49. TCCR0B = 0x00;
  50. TIFR0 |= 1<<TOV0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement