Guest User

Untitled

a guest
Oct 19th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. //INCLUDES
  2.  
  3. #include <avr/io.h>
  4. #include <avr/interrupt.h>
  5. #include <util/delay.h>
  6. #include "GPP.h"
  7.  
  8. //MAIN FUNCTION
  9. int main()
  10. {
  11.  
  12. GPP *gpp = new GPP();
  13.  
  14. //Turn on system power
  15. gpp->setPowerPin();
  16. gpp->screenOn();
  17.  
  18. //Perform initialisation code
  19. gpp->SPI_Init();
  20.  
  21. //Draw Logo on screen
  22. gpp->displayLogo();
  23.  
  24.  
  25.  
  26. for( int i=0; i < 5*5 /*5 loops for each second, 5 seconds*/; i++ )
  27. {
  28. _delay_ms(200);
  29. }
  30.  
  31.  
  32.  
  33. /* End Game Infinite Loop - Interrupts now run the show */
  34. while(1);
  35.  
  36. }
  37.  
  38. #ifndef GPOWERPACK_H
  39. #define GPOWERPACK_H
  40.  
  41.  
  42. //Defines...
  43.  
  44.  
  45. //Pins
  46. //#define RST_PIN 0b00000001
  47. #define BUSY_PIN 0b00000010
  48. #define DC_PIN 0b00001000
  49. #define CS_PIN 0b00010000
  50.  
  51.  
  52.  
  53. //Includes...
  54. #include <avr/io.h>
  55. #include <avr/interrupt.h>
  56. #include "ePaperLibrary/epdpaint.h"
  57. #include "ePaperLibrary/fonts.h"
  58. #include "BasicsLibrary/LinkedList.h"
  59. #include "BasicsLibrary/dataBits.h"
  60. #include "Waveshare.h"
  61.  
  62.  
  63.  
  64. class GPP
  65. {
  66. public:
  67.  
  68. GPP();
  69. //~GPP();
  70.  
  71. void setPowerPin();
  72. void screenOn();
  73. void SPI_Init();
  74.  
  75. void SPI_SendNext();
  76.  
  77. void displayLogo();
  78.  
  79.  
  80. private:
  81.  
  82. Waveshare screen;
  83.  
  84. };
  85.  
  86.  
  87. #endif
  88.  
  89. //INCLUDES
  90. #include "GPP.h"
  91.  
  92.  
  93. //GLOBALS: INTERRUPTS AND VARIABLES
  94. extern LinkedList<dataBits> SPI_DATA_BUFFER;
  95.  
  96.  
  97. // SPI interrupt -> micro controller specific global function
  98. ISR( SPIC_INT_vect )
  99. {
  100. dataBits package = SPI_DATA_BUFFER.removeHead();
  101. unsigned char data = package.data;
  102.  
  103. switch (package.context)
  104. {
  105. // SPI DC pin low --> Command
  106. case 0:
  107. PORTC.OUT &= ~DC_PIN;
  108. break;
  109.  
  110. // SPI DC pin high --> Data
  111. case 1:
  112. PORTC.OUT |= DC_PIN;
  113. break;
  114.  
  115. default:
  116. break;
  117. }
  118.  
  119.  
  120.  
  121.  
  122. }
  123.  
  124.  
  125.  
  126. //PUBLIC FUNCTIONS
  127.  
  128. GPP::GPP()
  129. {
  130. //Perform any setup here
  131. SPI_DATA_BUFFER = new LinkedList<dataBits>();
  132. Waveshare screen = new Waveshare( SPI_DATA_BUFFER, (unsigned char) RST_PIN, (unsigned char) DC_PIN, (unsigned char) CS_PIN, (unsigned char) BUSY_PIN );
  133. }
  134.  
  135.  
  136.  
  137. // Activate PD0: Connected to the gate of the MosFET
  138. // that controls battery power delivered to the circuit
  139. void GPP::setPowerPin()
  140. {
  141. PORTD.DIR |= 0b00000001; //Pin0 output
  142. PORTD.OUT |= 0b00000001; //Pin0 High
  143. }
  144.  
  145.  
  146. ...... and so on
Add Comment
Please, Sign In to add comment