sed1335.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. #ifdef SED1335_DISABLE_INT
  72. cli();
  73. #endif
  74. SED1335_DATA_PORT = dataToWrite;
  75. #ifdef SED1335_CS
  76. SED1335_CONTROL_PORT &= ~SED1335_CS;
  77. #endif
  78. SED1335_CONTROL_PORT &= ~SED1335_WR;
  79. asm("nop");
  80. SED1335_CONTROL_PORT |= SED1335_WR;
  81. #ifdef SED1335_CS
  82. SED1335_CONTROL_PORT |= SED1335_CS;
  83. #endif
  84. #ifdef SED1335_DISABLE_INT
  85. sei();
  86. #endif
  87. }
  88. void GLCD_WriteCommand(unsigned char commandToWrite){
  89. SED1335_CONTROL_PORT |= SED1335_A0;
  90. #ifdef SED1335_DISABLE_INT
  91. cli();
  92. #endif
  93. SED1335_DATA_PORT = commandToWrite;
  94. #ifdef SED1335_CS
  95. SED1335_CONTROL_PORT &= ~SED1335_CS;
  96. #endif
  97. SED1335_CONTROL_PORT &= ~SED1335_WR;
  98. asm("nop");
  99. SED1335_CONTROL_PORT |= SED1335_WR;
  100. #ifdef SED1335_CS
  101. SED1335_CONTROL_PORT |= SED1335_CS;
  102. #endif
  103. #ifdef SED1335_DISABLE_INT
  104. sei();
  105. #endif
  106. SED1335_CONTROL_PORT &= ~SED1335_A0;
  107. }
  108. /*unsigned char GLCD_ReadData(void){
  109. unsigned char tmp;
  110. #ifdef SED1335_CS
  111. SED1335_CONTROL_PORT &= ~SED1335_CS;
  112. #endif
  113. SED1335_CONTROL_PORT |= SED1335_A0;
  114. #ifdef SED1335_DISABLE_INT
  115. cli();
  116. #endif
  117. SED1335_DATA_DIR = 0x00;
  118. SED1335_CONTROL_PORT &= ~SED1335_RD;
  119. asm("nop");
  120. tmp = SED1335_DATA_PIN;
  121. SED1335_CONTROL_PORT |= SED1335_RD;
  122. #ifdef SED1335_CS
  123. SED1335_CONTROL_PORT |= SED1335_CS;
  124. #endif
  125. #ifdef SED1335_DISABLE_INT
  126. sei();
  127. #endif
  128. SED1335_CONTROL_PORT &= ~SED1335_A0;
  129. return tmp;
  130. }*/
  131. void GLCD_HardReset(void){
  132. wdt_reset();
  133. _delay_ms(150);
  134. wdt_reset();
  135. SED1335_RST_PORT &= ~(SED1335_RES);
  136. _delay_ms(20);
  137. SED1335_RST_PORT |= (SED1335_RES);
  138. _delay_ms(20);
  139. wdt_reset();
  140. }
  141. //external LCD access functions
  142. /*void GLCD_Clear(void){ //używam swojej w gtext.c
  143. GLCD_ClearText();
  144. GLCD_ClearGraphic();
  145. }*/
  146. /*void GLCD_SetPixel(unsigned int x,unsigned int y, int color){ //nietestowane!
  147. unsigned char tmp = 0;
  148. unsigned int address = SED1335_GRAPHICSTART + (40 * y) + (x/8);
  149. GLCD_SetCursorAddress(address);
  150. GLCD_WriteCommand(SED1335_MREAD);
  151. tmp = GLCD_ReadData();
  152. if(color)
  153. tmp |= (1 << (SED1335_FX - (x % 8)));
  154. else
  155. tmp &= ~(1 << (SED1335_FX - (x % 8)));
  156. GLCD_SetCursorAddress(address);
  157. GLCD_WriteCommand(SED1335_MWRITE);
  158. GLCD_WriteData(tmp);
  159. }*/
  160. // funkcje do trybu tekstowego - nie używam
  161. /*void GLCD_WriteText(char * tekst){
  162. GLCD_WriteCommand(SED1335_MWRITE);
  163. while(*tekst)
  164. GLCD_WriteData(*tekst++);
  165. }*/
  166. /*void GLCD_WriteTextP(char * tekst){
  167. GLCD_WriteCommand(SED1335_MWRITE);
  168. while(pgm_read_byte(tekst))
  169. GLCD_WriteData(GLCD_ReadByteFromROMMemory(tekst++));
  170. }*/
  171. /*void GLCD_TextGoTo(unsigned char x, unsigned char y){
  172. GLCD_SetCursorAddress((y * 40) + x);
  173. }*/
  174. /*void GLCD_ClearText(void){
  175. int i;
  176. GLCD_TextGoTo(0,0);
  177. GLCD_WriteCommand(SED1335_MWRITE);
  178. for(i = 0; i < 1200; i++)
  179. GLCD_WriteData(' ');
  180. }*/
  181. void GLCD_SetCursorAddress(unsigned int address){
  182. GLCD_WriteCommand(SED1335_CSRW);
  183. GLCD_WriteData((unsigned char)(address & 0xFF));
  184. GLCD_WriteData((unsigned char)(address >> 8));
  185. }
  186. // funkcje do trybu graficznego - używam własnych w gtext.c
  187. /*void GLCD_GraphicGoTo(unsigned int x, unsigned int y){
  188. GLCD_SetCursorAddress(SED1335_GRAPHICSTART + (y * 80) + x*2);
  189. }*/
  190. /*void GLCD_ClearGraphic(void){
  191. unsigned int i;
  192. GLCD_SetCursorAddress(SED1335_GRAPHICSTART);
  193. GLCD_WriteCommand(SED1335_MWRITE);
  194. for(i = 0; i < SED1335_GRAPHICSIZE; i++) //zweryfikuj przed użyciem, czy dobra strona!!!
  195. GLCD_WriteData(0x00);
  196. clearbg();
  197. }*/
  198. /*void GLCD_Bitmap(char * bmp, int x, int y, int width, int height){ //nietestowane
  199. unsigned int i, j;
  200. for(i = 0; i < height ; i++){
  201. GLCD_GraphicGoTo(x, y+i);
  202. GLCD_WriteCommand(SED1335_MWRITE);
  203. for(j = 0; j < width/8; j++)
  204. GLCD_WriteData(pgm_read_byte(bmp+j+(40*i)));
  205. }
  206. }*/