SHARE
TWEET

Driver hd44780

a guest Oct 3rd, 2016 43 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * main.c
  3.  *
  4.  *  Created on: 28.09.2016
  5.  *      Author: levi
  6.  */
  7.  
  8. #include <avr/io.h>
  9. #include <util/delay.h>
  10. #include <hd44780.c>
  11. #include <hd44780.h>
  12. #include <stdlib.h>
  13.  
  14. typedef _Bool bool;
  15. typedef unsigned char byte;
  16.  
  17. typedef struct buffer  {
  18.     byte  Xpos;
  19.     byte  Ypos;
  20.     byte  Xsize;
  21.     byte  Ysize;
  22. } layer;
  23.  
  24. enum LCD_PINS {
  25.     RS,RW,R,D1,D2,D3,D4,D5,D6,D7
  26. };
  27.  
  28. enum formating {nowrap, wrap};
  29.  
  30. void LCD_animate(layer * buffer);
  31. void LCD_Draw (layer * buffer, char text[], enum formating format);
  32. void LCD_initSurface (layer * buffer);
  33.  
  34. int main (void) {
  35.  
  36.     layer base = {
  37.         .Xpos=3,
  38.         .Ypos=4,
  39.         .Xsize=6,
  40.         .Ysize=1,
  41.     };
  42.  
  43.     LCD_Initalize();
  44.     LCD_Clear();
  45.  
  46.     LCD_initSurface(&base);
  47.     LCD_Draw(&base, "123456", nowrap);
  48.  
  49.     while(1) {
  50.     //
  51.     }
  52. }
  53.  
  54. //====================================================
  55. void LCD_animate(layer * buffer) {
  56.     buffer->Xpos++;
  57. }
  58. //----------------------------------------------------
  59. void LCD_Draw (layer * buffer, char text[], enum formating format) {
  60.     LCD_GoTo (buffer->Xpos, buffer->Ypos);
  61.  
  62.     byte framesize = (buffer->Xsize * buffer->Ysize)-1;
  63.     byte i;
  64.     byte trackx = 0;
  65.  
  66.     for (i=0; i <= framesize; i++) {
  67.         trackx++;
  68.  
  69.         if (format==wrap && trackx >= buffer->Xsize+1 && buffer->Ysize >=2) {
  70.  
  71.             LCD_GoTo (buffer->Xpos, buffer->Ypos+1);
  72.             LCD_WriteData(text[i]);
  73.             trackx =0;
  74.         }
  75.         else {
  76.             LCD_WriteData(text[i]);
  77.         }
  78.     }
  79. }
  80. //----------------------------------------------------
  81.  
  82. void LCD_initSurface (layer * buffer) {
  83.     buffer->Xpos--;
  84.     buffer->Ypos--;
  85. }
  86. //----------------------------------------------------
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top