sed1335.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. #include <util/delay.h>
  2. #include <avr/io.h>
  3. #include <avr/pgmspace.h>
  4. #include <util/delay.h>
  5. #include <avr/interrupt.h>
  6. #include <avr/wdt.h>
  7. #include "sed1335.h"
  8. //config data is set in sed1335.h
  9. void GLCD_Initialize(void){
  10. GLCD_InitializePorts();
  11. GLCD_HardReset();
  12. GLCD_WriteCommand(SED1335_SYSTEM_SET);
  13. _delay_ms(10);
  14. GLCD_WriteData(SED1335_SYS_P1);
  15. GLCD_WriteData(SED1335_SYS_P2);
  16. GLCD_WriteData(SED1335_FY);
  17. GLCD_WriteData(SED1335_CR);
  18. GLCD_WriteData(SED1335_TCR);
  19. GLCD_WriteData(SED1335_LF);
  20. GLCD_WriteData(SED1335_AP & 0xff);
  21. GLCD_WriteData(SED1335_AP >> 8);
  22. GLCD_WriteCommand(SED1335_SCROLL);
  23. GLCD_WriteData(SED1335_SAD1 & 0xff);
  24. GLCD_WriteData(SED1335_SAD1 >> 8);
  25. GLCD_WriteData(SED1335_SL1);
  26. GLCD_WriteData(SED1335_SAD2 & 0xff);
  27. GLCD_WriteData(SED1335_SAD2 >> 8);
  28. GLCD_WriteData(SED1335_SL2);
  29. GLCD_WriteData(SED1335_SAD3 & 0xff);
  30. GLCD_WriteData(SED1335_SAD3 >> 8);
  31. GLCD_WriteData(SED1335_SAD4 & 0xff);
  32. GLCD_WriteData(SED1335_SAD4 >> 8);
  33. GLCD_WriteCommand(SED1335_CSRFORM);
  34. GLCD_WriteData(SED1335_CRX);
  35. GLCD_WriteData(SED1335_CSRF_P2);
  36. GLCD_WriteCommand(SED1335_CGRAM_ADR);
  37. GLCD_WriteData(SED1335_SAG & 0xff);
  38. GLCD_WriteData(SED1335_SAG >> 8);
  39. GLCD_WriteCommand(SED1335_CSRDIR_R);
  40. GLCD_WriteCommand(SED1335_HDOT_SCR);
  41. GLCD_WriteData(SED1335_SCRD);
  42. GLCD_WriteCommand(SED1335_OVLAY);
  43. GLCD_WriteData(SED1335_OVLAY_P1);
  44. GLCD_WriteCommand(SED1335_GRAYSCALE);
  45. GLCD_WriteData(SED1335_BPP);
  46. GLCD_WriteCommand(SED1335_DISP_ON);
  47. GLCD_WriteData(SED1335_FLASH);
  48. GLCD_Clear();
  49. }
  50. //internal functions
  51. void GLCD_InitializePorts(void){
  52. SED1335_DATA_DIR = 0xFF;
  53. #ifdef SED1335_CS
  54. SED1335_CONTROL_PORT |= SED1335_CS;
  55. SED1335_CONTROL_DIR |= SED1335_CS;
  56. #endif
  57. SED1335_CONTROL_PORT |= (SED1335_WR
  58. #ifdef SED1335_RD
  59. | SED1335_RD
  60. #endif
  61. | SED1335_RES);
  62. SED1335_CONTROL_DIR |= (SED1335_A0 | SED1335_WR
  63. #ifdef SED1335_RD
  64. | SED1335_RD
  65. #endif
  66. | SED1335_RES);
  67. SED1335_RST_PORT |= SED1335_RES;
  68. SED1335_RST_DIR |= SED1335_RES;
  69. }
  70. void GLCD_WriteData(unsigned char dataToWrite){
  71. cli();
  72. SED1335_DATA_PORT = dataToWrite;
  73. #ifdef SED1335_CS
  74. SED1335_CONTROL_PORT &= ~SED1335_CS;
  75. #endif
  76. SED1335_CONTROL_PORT &= ~SED1335_WR;
  77. asm("nop");
  78. SED1335_CONTROL_PORT |= SED1335_WR;
  79. #ifdef SED1335_CS
  80. SED1335_CONTROL_PORT |= SED1335_CS;
  81. #endif
  82. sei();
  83. }
  84. void GLCD_WriteCommand(unsigned char commandToWrite){
  85. SED1335_CONTROL_PORT |= SED1335_A0;
  86. cli();
  87. SED1335_DATA_PORT = commandToWrite;
  88. #ifdef SED1335_CS
  89. SED1335_CONTROL_PORT &= ~SED1335_CS;
  90. #endif
  91. SED1335_CONTROL_PORT &= ~SED1335_WR;
  92. asm("nop");
  93. SED1335_CONTROL_PORT |= SED1335_WR;
  94. #ifdef SED1335_CS
  95. SED1335_CONTROL_PORT |= SED1335_CS;
  96. #endif
  97. sei();
  98. SED1335_CONTROL_PORT &= ~SED1335_A0;
  99. }
  100. /*unsigned char GLCD_ReadData(void){
  101. unsigned char tmp;
  102. #ifdef SED1335_CS
  103. SED1335_CONTROL_PORT &= ~SED1335_CS;
  104. #endif
  105. SED1335_CONTROL_PORT |= SED1335_A0;
  106. cli();
  107. SED1335_DATA_DIR = 0x00;
  108. SED1335_CONTROL_PORT &= ~SED1335_RD;
  109. asm("nop");
  110. tmp = SED1335_DATA_PIN;
  111. SED1335_CONTROL_PORT |= SED1335_RD;
  112. #ifdef SED1335_CS
  113. SED1335_CONTROL_PORT |= SED1335_CS;
  114. #endif
  115. sei();
  116. SED1335_CONTROL_PORT &= ~SED1335_A0;
  117. return tmp;
  118. }*/
  119. void GLCD_HardReset(void){
  120. wdt_reset();
  121. _delay_ms(150);
  122. wdt_reset();
  123. SED1335_RST_PORT &= ~(SED1335_RES);
  124. _delay_ms(20);
  125. SED1335_RST_PORT |= (SED1335_RES);
  126. _delay_ms(20);
  127. wdt_reset();
  128. }
  129. //external LCD access functions
  130. /*void GLCD_Clear(void){ //używam swojej w gtext.c
  131. GLCD_ClearText();
  132. GLCD_ClearGraphic();
  133. }*/
  134. /*void GLCD_SetPixel(unsigned int x,unsigned int y, int color){ //nietestowane!
  135. unsigned char tmp = 0;
  136. unsigned int address = SED1335_GRAPHICSTART + (40 * y) + (x/8);
  137. GLCD_SetCursorAddress(address);
  138. GLCD_WriteCommand(SED1335_MREAD);
  139. tmp = GLCD_ReadData();
  140. if(color)
  141. tmp |= (1 << (SED1335_FX - (x % 8)));
  142. else
  143. tmp &= ~(1 << (SED1335_FX - (x % 8)));
  144. GLCD_SetCursorAddress(address);
  145. GLCD_WriteCommand(SED1335_MWRITE);
  146. GLCD_WriteData(tmp);
  147. }*/
  148. // funkcje do trybu tekstowego - nie używam
  149. /*void GLCD_WriteText(char * tekst){
  150. GLCD_WriteCommand(SED1335_MWRITE);
  151. while(*tekst)
  152. GLCD_WriteData(*tekst++);
  153. }*/
  154. /*void GLCD_WriteTextP(char * tekst){
  155. GLCD_WriteCommand(SED1335_MWRITE);
  156. while(pgm_read_byte(tekst))
  157. GLCD_WriteData(GLCD_ReadByteFromROMMemory(tekst++));
  158. }*/
  159. /*void GLCD_TextGoTo(unsigned char x, unsigned char y){
  160. GLCD_SetCursorAddress((y * 40) + x);
  161. }*/
  162. /*void GLCD_ClearText(void){
  163. int i;
  164. GLCD_TextGoTo(0,0);
  165. GLCD_WriteCommand(SED1335_MWRITE);
  166. for(i = 0; i < 1200; i++)
  167. GLCD_WriteData(' ');
  168. }*/
  169. void GLCD_SetCursorAddress(unsigned int address){
  170. GLCD_WriteCommand(SED1335_CSRW);
  171. GLCD_WriteData((unsigned char)(address & 0xFF));
  172. GLCD_WriteData((unsigned char)(address >> 8));
  173. }
  174. // funkcje do trybu graficznego - używam własnych w gtext.c
  175. /*void GLCD_GraphicGoTo(unsigned int x, unsigned int y){
  176. GLCD_SetCursorAddress(SED1335_GRAPHICSTART + (y * 80) + x*2);
  177. }*/
  178. /*void GLCD_ClearGraphic(void){
  179. unsigned int i;
  180. GLCD_SetCursorAddress(SED1335_GRAPHICSTART);
  181. GLCD_WriteCommand(SED1335_MWRITE);
  182. for(i = 0; i < SED1335_GRAPHICSIZE; i++) //zweryfikuj przed użyciem, czy dobra strona!!!
  183. GLCD_WriteData(0x00);
  184. clearbg();
  185. }*/
  186. /*void GLCD_Bitmap(char * bmp, int x, int y, int width, int height){ //nietestowane
  187. unsigned int i, j;
  188. for(i = 0; i < height ; i++){
  189. GLCD_GraphicGoTo(x, y+i);
  190. GLCD_WriteCommand(SED1335_MWRITE);
  191. for(j = 0; j < width/8; j++)
  192. GLCD_WriteData(pgm_read_byte(bmp+j+(40*i)));
  193. }
  194. }*/