Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #define F_CPU 1000000UL
  2. #include <avr/io.h>
  3. #include <avr/interrupt.h>
  4.  
  5. int delayTime;
  6. int cur;
  7. int dest;
  8.  
  9. ISR(TIMER1_OVF_vect) {
  10. cur++;
  11. if(cur < dest) {
  12. TCNT1 = delayTime;
  13. }
  14. }
  15.  
  16. void startTimer(int destValue, int delay) {
  17. cur = 0;
  18. dest = destValue;
  19. delayTime = 256 - delay;
  20. TCNT1 = delayTime;
  21. }
  22.  
  23. void sendBit(int bitValue) {
  24. if(bitValue == 1) {
  25. //560 high, 1680 low
  26. PORTB |= (1 << 4);
  27. startTimer(1, 140);
  28.  
  29. PORTB &= ~(1 << 4);
  30. startTimer(2, 210);
  31. } else {
  32. //560 high, 560 low
  33.  
  34. PORTB |= (1 << 4);
  35. startTimer(1, 140);
  36.  
  37. PORTB &= ~(1 << 4);
  38. startTimer(1, 140);
  39. }
  40.  
  41.  
  42. }
  43. void sendCommand(char state) {
  44.  
  45. PORTB |= (1 << 4);
  46. startTimer(50, 45);
  47.  
  48. PORTB &= ~(1 << 4);
  49. startTimer(5, 225);
  50.  
  51. int pos = 0;
  52. while(pos < 8) {
  53. sendBit((state >> pos) & 1);
  54. pos++;
  55. }
  56.  
  57. PORTB |= (1 << 4);
  58. startTimer(1, 140);
  59.  
  60. PORTB &= ~(1 << 4);
  61. }
  62.  
  63. int main(void)
  64. {
  65. DDRB = 0;
  66. PORTB = 0;
  67. DDRB |= (1 << 4);
  68. //PORTB |= (1 << 4);
  69.  
  70. TCCR1 |= (1 << CS11) | (1 << CS10);
  71. TIMSK = 0b00000010;
  72.  
  73. sendBit(0);
  74. /*
  75. char enable = 0xFA;
  76. char white = 0x2F;
  77. sendCommand(enable);
  78. sendCommand(white);
  79. */
  80. while (1)
  81. {
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement