Advertisement
Guest User

the gLCD control code

a guest
Sep 7th, 2012
3
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. #include <avr/interrupt.h>
  2. #include <glcd.h>
  3. //----------------------------------------------------------------------
  4. // GLCD Function - Implementation
  5. //----------------------------------------------------------------------
  6. // to initialise the LCD
  7. void GlcdInit( void )
  8. {
  9. // This function must be provided by the user.
  10. GlcdInitPort();
  11. // send different controlcommand to the LCD (datasheet for details)
  12. // internal Reset
  13. GlcdSendCmd( 0xE2 );
  14. // ADC select
  15. GlcdSendCmd( 0xA0 ) ;
  16. // COM output scan direction = revers
  17. GlcdSendCmd( 0xC8 );
  18. // LCD drive voltage bias ratio
  19. GlcdSendCmd( 0xA2 );
  20. // no idea
  21. GlcdSendCmd( 0x2F );
  22. // no idea
  23. GlcdSendCmd( 0x26 );
  24. // select booster ratio
  25. GlcdSendCmd( 0xF8 );
  26. // no idea
  27. GlcdSendCmd( 0x00 );
  28. // set output voltage
  29. GlcdSendCmd( 0x81 );
  30. // no idea
  31. GlcdSendCmd( 0x09 );
  32. // read-modify-write
  33. GlcdSendCmd( 0xE0 );
  34. // display on
  35. GlcdSendCmd( 0xAF );
  36. return;
  37. }
  38. //--------------------
  39. // Set the position for the next output, for text e. g.
  40. // the y-value is round down to a 8like value (0,8,16,24...56)
  41. // parameter: x = x-coordinate 0...127; y = y-coordinate 0...63
  42. void GlcdSetPos( uint8_t x, uint8_t y )
  43. {
  44. // x-coordinate
  45. GlcdSendCmd( 0x10 | ( ( x >> 4 ) & 0x0F ) );
  46. GlcdSendCmd( 0x00 | ( ( x & 0x0F ) ) );
  47. // y-coordinate
  48. GlcdSendCmd( 0b10110000 | ( ( y >> 3 ) & 0x0F ) );
  49. return;
  50. }
  51. //--------------------
  52. // move to the inputline to the actual line on the LCD (srcolleffect)
  53. // parameter: Line = number of the line to goto
  54. void GlcdGotoLine( uint8_t line )
  55. {
  56. // initial display line
  57. GlcdSendCmd( 0x40 | ( line & 0x3F ) );
  58. return;
  59. }
  60. //--------------------
  61. // clears all data on the LCD
  62. void GlcdClear( void )
  63. {
  64. uint8_t y;
  65. uint8_t x;
  66. // the Display consists of 128 * 8 Bytes, which are placed vertical
  67. // in each byte are bit0 up and bit7 down
  68. // y-loop (vertical); 8 times, 64 pixels are 8 bytes * 8 bits
  69. for( y = 0; y < 8; y++ )
  70. {
  71. // goto linebegin
  72. GlcdSetPos( 0, y * 8 );
  73. // x-Schleife (waagerecht); 128 Pixel sind 128
  74. for( x = 0; x < 128; x++ )
  75. {
  76. // set byte to 0
  77. GlcdSendData( 0 );
  78. }
  79. }
  80. // set actual position to leftupper corner ( 0, 0 )
  81. GlcdSetPos( 0, 0 );
  82. return;
  83. }
  84. //--------------------
  85. // inverse display (dark at bright backround/ bright at dark backround)
  86. // parameter: on = off/on 0/1; 0 = normal (dark at blight backround); 1 = inverse (blight at dark backround)
  87. void GlcdSendCmdReverse( uint8_t bit0 )
  88. {
  89. // display normal/reverse
  90. GlcdSendCmd( 0b10100110 + ( bit0 & 0x01 ) );
  91. return;
  92. }
  93. //--------------------
  94. // turn the display on/off
  95. // parameter: on = on/off 0/1; 0 = display on; 1 = display off (complete dark)
  96. void GlcdSendCmdOn( uint8_t bit0 )
  97. {
  98. // all pixels on /off
  99. GlcdSendCmd( 0b10100100 + ( bit0 & 0x01 ) );
  100. return;
  101. }
  102. //--------------------
  103. // set a Pixel on position x,y at the LCD
  104. // parameter: x = x-coordinate 0...127; y = y-coordinate 0...63
  105. void GlcdSetPixel( uint8_t x, uint8_t y )
  106. {
  107. uint8_t data;
  108. // goto position
  109. GlcdSetPos( x, y );
  110. // bitmask for the bit (pixel) in the byte
  111. data = 1 << ( y & 0b00000111 );
  112. // read the byte, set the bit, write the byte
  113. GlcdSendData( GlcdReadData() | data );
  114. return;
  115. }
  116. //--------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement