Advertisement
ivosexa

transmiter

Feb 3rd, 2015
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #define F_CPU 1000000UL
  2. #include <avr/io.h>
  3. #include <avr/interrupt.h>
  4.  
  5. int main(void)
  6. {
  7. DDRB&= ~(1<<PINB0);
  8. PORTB|= (1<<PINB0);
  9. DDRB|= (1<<PINB6);
  10. int pressed=0;
  11. int pressed_conf=0;
  12. int released_conf=0;
  13.  
  14. int UBRR_val=25;
  15.  
  16. UBRR0H = (unsigned char) (UBRR_val >> 8);
  17. UBRR0L = (unsigned char) UBRR_val;
  18. UCSR0B = (1 << RXEN0) | (1 << TXEN0);
  19. UCSR0C |= (1 << USBS0) | (3 << UCSZ00);
  20.  
  21.  
  22. while(1)
  23. {
  24.  
  25. if( bit_is_clear(PINB, 0) )
  26.  
  27. {
  28. pressed_conf++;
  29. released_conf=0;
  30. if(pressed_conf >100)
  31. {
  32. if(pressed==0)
  33. {
  34. pressed=1;
  35. PORTB ^= (1<<PINB6);
  36. while ( !(UCSR0A &(1 <<UDRE0)) )
  37. {
  38. UDR0 = 0b11111111;
  39. }
  40. }
  41. pressed_conf=0;
  42. }
  43. }
  44.  
  45. else
  46. {
  47. released_conf++;
  48. pressed_conf=0;
  49. if(released_conf >100)
  50. {
  51. pressed=0;
  52. released_conf=0;
  53. }
  54. }
  55. }
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement