samir82show

Slave mode(GSM, Manual/Auto)

Feb 15th, 2014
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. #include <mega32a.h>
  2. #include <delay.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <spi.h>
  6. #define MAX 10
  7. #define MAXANGLE 1999
  8. #define MINANGLE 999
  9. #define MOTOR_PLUS 0x01
  10. #define MOTOR_MINUS 0x02
  11. #define REMOTE_MOTOR 0x03
  12. unsigned int dump_mode1 = 1; //this dump variable is to keep synchronization with master
  13. unsigned int dump_mode2 = 1; //this dump variable is to keep synchronization with master
  14. unsigned int dump_mode3 = 1; //this dump variable is to keep synchronization with master
  15. unsigned int dump_mode4 = 1; //this dump variable is to keep synchronization with master
  16. // SPI interrupt service routine
  17. interrupt [SPI_STC] void spi_isr(void)
  18. {
  19. unsigned char data;
  20. data = SPDR;
  21. if(data == MOTOR_PLUS) // condition used for Auto/Manual mode
  22. {
  23. if(OCR1A <= MAXANGLE)
  24. {
  25. OCR1A++;
  26. PORTD ^= 1 << PIND7;
  27. }
  28. }
  29. else if(data == MOTOR_MINUS) // condition used for Auto/Manual mode
  30. {
  31. if(OCR1A >= MINANGLE)
  32. {
  33. OCR1A--;
  34. PORTD ^= 1 << PIND7;
  35. }
  36. }
  37. else
  38. {
  39. OCR1A = data * 10; //returning the value back to the PWM range values then assign it to OCR1A
  40. PORTD ^= 1 << PIND7;
  41. }
  42. }
  43.  
  44. // Declare your global variables here
  45. void init()
  46. {
  47. PORTA=0x00;
  48. DDRA=0x00;
  49. PORTB=0x00;
  50. DDRB=0x40;
  51. PORTC=0x00;
  52. DDRC=0x00;
  53. PORTD=0x00;
  54. DDRD=0xA0;
  55.  
  56. TCCR1A=0b10000010;
  57. TCCR1B=0b00011001;
  58. ICR1H=0x4E;
  59. ICR1L=0x1F;
  60. OCR1A = 1499;
  61.  
  62. TIMSK=0x00;
  63.  
  64. ACSR=0x80;
  65. SFIOR=0x00;
  66.  
  67. SPCR=0xC0;
  68. SPSR=0x00;
  69. }
  70. void main(void)
  71. {
  72. // Clear the SPI interrupt flag
  73. #asm
  74. in r30,spsr
  75. in r30,spdr
  76. #endasm
  77. // Global enable interrupts
  78. #asm("sei")
  79. init();
  80. while (1)
  81. {
  82. // Place your code here
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment