Advertisement
Guest User

GLEDIATOR NO BUFFER - Not tested

a guest
Feb 23rd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.65 KB | None | 0 0
  1.  
  2. //Arduino Mega Sketch to drive strands and matrices of WS2801 pixels with Glediator.
  3. //(c)2012 by R. Heller
  4. //wwww.solderlab.de
  5.  
  6. //Set Baudrate in Glediator to 1MBit !!!
  7.  
  8. //Change this to YOUR matrix size!!
  9. #define Num_Pixels 16
  10.  
  11. //Serial Data Output (Arduino-Mega Pin 6)
  12. #define SDO_Port          PORTH
  13. #define SDO_DDR           DDRH
  14. #define SDO_Pin           3
  15.  
  16. //Serial Data Clock (Arduino-Mega Pin 7)
  17. #define CLK_Port          PORTH
  18. #define CLK_DDR           DDRH
  19. #define CLK_Pin           4
  20.  
  21. //############################################################################################################################################################
  22. // Don't change anything upon here!                                                                                                                          #
  23. //############################################################################################################################################################
  24.  
  25. #define Set_CLK_Low       CLK_Port     &=     ~(1 << CLK_Pin)
  26. #define Set_CLK_High      CLK_Port     |=      (1 << CLK_Pin)
  27. #define Set_CLK_Output    CLK_DDR      |=      (1 << CLK_Pin)
  28.  
  29. #define Set_SDO_Low       SDO_Port     &=     ~(1 << SDO_Pin)
  30. #define Set_SDO_High      SDO_Port     |=      (1 << SDO_Pin)
  31. #define Set_SDO_Output    SDO_DDR      |=      (1 << SDO_Pin)
  32.  
  33. #define CMD_NEW_DATA 1
  34.  
  35. volatile unsigned char go = 0;
  36.  
  37. void setup()
  38. {
  39.   Set_SDO_Output;
  40.   Set_CLK_Output;
  41.  
  42.   //Disable global interrupts
  43.   cli();
  44.  
  45.   //UART Initialisation
  46.   UCSR0A |= (1<<U2X0);                                
  47.   UCSR0B |= (1<<RXEN0)  | (1<<TXEN0) | (1<<RXCIE0);  
  48.   UCSR0C |= (1<<UCSZ01) | (1<<UCSZ00)             ;
  49.   UBRR0H = 0;
  50.   UBRR0L = 1; //Baud Rate 1 MBit
  51.  
  52.   ptr=display_buffer;
  53.    
  54.   //Enable global interrupts
  55.   sei();
  56. }
  57.  
  58. void loop()
  59. {
  60.   if (go==1) {shift_out_data(); go=0;}
  61. }
  62.  
  63. //############################################################################################################################################################
  64. // USART-Interrupt-Prozedur (called every time one byte is compeltely received)                                                                               #
  65. //############################################################################################################################################################
  66.  
  67. ISR(USART0_RX_vect)
  68. {
  69.   unsigned char b;
  70.  
  71.   b=UDR0;
  72.  
  73.   if (b == CMD_NEW_DATA)  {
  74.         Set_CLK_Low;
  75.         delayMicroseconds(800); //Latch Data
  76.     } else {
  77.         shift_out_data(b);
  78.     }
  79. }
  80.  
  81.  
  82. //############################################################################################################################################################
  83. // Shift out Data                                                                                                                                            #
  84. //############################################################################################################################################################
  85.  
  86. void shift_out_data(char b)
  87. {
  88.   for (byte j=0; j<8; j++) {
  89.     Set_CLK_Low;
  90.     if (b & (1<<(7-j))) {Set_SDO_High;} else {Set_SDO_Low;}    
  91.     Set_CLK_High;
  92.   }
  93. }
  94.  
  95. //############################################################################################################################################################
  96. //############################################################################################################################################################
  97. //############################################################################################################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement