Advertisement
joric

lcd_lph7906.h

Jun 3rd, 2016
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 14.69 KB | None | 0 0
  1. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. /*
  3. Graphic LCD Siemens A50 (LPH7906)  
  4. With Windows-1215 codepage (Russian) (hardware spi mode)
  5. */
  6. // ex:
  7. //
  8. // ...
  9. // lph_init();
  10. // ...
  11. // lph_gotoxy(0,0);
  12. // printf(lph_printchar,"Hello, World!");
  13. // ...
  14. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  15.  
  16. //#define lph_sclk  PIN_C3
  17. //#define lph_sda   PIN_C5
  18.  
  19. #define lph_dc    PIN_C2
  20. #define lph_cs    PIN_C1
  21. #define lph_res   PIN_C6
  22. #define lph_vdd   PIN_C0
  23.  
  24. char char_row,charsel,charpos,chardata;       // for lph_7906 lcd
  25. int16 ddram;
  26.  
  27. #use delay ( clock=8000000 )
  28.  
  29. BYTE const TABLE5[240]=            {0x00,0x00,0x00,0x00,0x00,   // 20 space          ASCII table for NOKIA LCD: 96 rows * 5 bytes= 480 bytes
  30.   0x00,0x00,0x5f,0x00,0x00,   // 21 !
  31.   0x00,0x07,0x00,0x07,0x00,   // 22 "
  32.   0x14,0x7f,0x14,0x7f,0x14,   // 23 #
  33.   0x24,0x2a,0x7f,0x2a,0x12,   // 24 $
  34.   0x23,0x13,0x08,0x64,0x62,   // 25 %
  35.   0x36,0x49,0x55,0x22,0x50,   // 26 &
  36.   0x00,0x05,0x03,0x00,0x00,   // 27 '
  37.   0x00,0x1c,0x22,0x41,0x00,   // 28 (
  38.   0x00,0x41,0x22,0x1c,0x00,   // 29 )
  39.   0x14,0x08,0x3e,0x08,0x14,   // 2a *
  40.   0x08,0x08,0x3e,0x08,0x08,   // 2b +
  41.   0x00,0x50,0x30,0x00,0x00,   // 2c ,
  42.   0x08,0x08,0x08,0x08,0x08,   // 2d -
  43.   0x00,0x60,0x60,0x00,0x00,   // 2e .
  44.   0x20,0x10,0x08,0x04,0x02,   // 2f /
  45.   0x3e,0x51,0x49,0x45,0x3e,   // 30 0
  46.   0x00,0x42,0x7f,0x40,0x00,   // 31 1
  47.   0x42,0x61,0x51,0x49,0x46,   // 32 2
  48.   0x21,0x41,0x45,0x4b,0x31,   // 33 3
  49.   0x18,0x14,0x12,0x7f,0x10,   // 34 4
  50.   0x27,0x45,0x45,0x45,0x39,   // 35 5
  51.   0x3c,0x4a,0x49,0x49,0x30,   // 36 6
  52.   0x01,0x71,0x09,0x05,0x03,   // 37 7
  53.   0x36,0x49,0x49,0x49,0x36,   // 38 8
  54.   0x06,0x49,0x49,0x29,0x1e,   // 39 9
  55.   0x00,0x36,0x36,0x00,0x00,   // 3a :
  56.   0x00,0x56,0x36,0x00,0x00,   // 3b ;
  57.   0x08,0x14,0x22,0x41,0x00,   // 3c <
  58.   0x14,0x14,0x14,0x14,0x14,   // 3d =
  59.   0x00,0x41,0x22,0x14,0x08,   // 3e >
  60.   0x02,0x01,0x51,0x09,0x06,   // 3f ?
  61.   0x32,0x49,0x79,0x41,0x3e,   // 40 @
  62.   0x7e,0x11,0x11,0x11,0x7e,   // 41 A
  63.   0x7f,0x49,0x49,0x49,0x36,   // 42 B
  64.   0x3e,0x41,0x41,0x41,0x22,   // 43 C
  65.   0x7f,0x41,0x41,0x22,0x1c,   // 44 D
  66.   0x7f,0x49,0x49,0x49,0x41,   // 45 E
  67.   0x7f,0x09,0x09,0x09,0x01,   // 46 F
  68.   0x3e,0x41,0x49,0x49,0x7a,   // 47 G
  69.   0x7f,0x08,0x08,0x08,0x7f,   // 48 H
  70.   0x00,0x41,0x7f,0x41,0x00,   // 49 I
  71.   0x20,0x40,0x41,0x3f,0x01,   // 4a J
  72.   0x7f,0x08,0x14,0x22,0x41,   // 4b K
  73.   0x7f,0x40,0x40,0x40,0x40,   // 4c L
  74.   0x7f,0x02,0x0c,0x02,0x7f,   // 4d M
  75.   0x7f,0x04,0x08,0x10,0x7f,   // 4e N
  76.   0x3e,0x41,0x41,0x41,0x3e    // 4f O
  77. };    
  78.  
  79.  
  80. BYTE const TABLE6[240]=            {0x7f,0x09,0x09,0x09,0x06,   // 50 P
  81.   0x3e,0x41,0x51,0x21,0x5e,   // 51 Q
  82.   0x7f,0x09,0x19,0x29,0x46,   // 52 R
  83.   0x46,0x49,0x49,0x49,0x31,   // 53 S
  84.   0x01,0x01,0x7f,0x01,0x01,   // 54 T
  85.   0x3f,0x40,0x40,0x40,0x3f,   // 55 U
  86.   0x1f,0x20,0x40,0x20,0x1f,   // 56 V
  87.   0x3f,0x40,0x38,0x40,0x3f,   // 57 W
  88.   0x63,0x14,0x08,0x14,0x63,   // 58 X
  89.   0x07,0x08,0x70,0x08,0x07,   // 59 Y
  90.   0x61,0x51,0x49,0x45,0x43,   // 5a Z
  91.   0x00,0x7f,0x41,0x41,0x00,   // 5b [
  92.   0x02,0x04,0x08,0x10,0x20,   // 5c
  93.   0x00,0x41,0x41,0x7f,0x00,   // 5d
  94.   0x04,0x02,0x01,0x02,0x04,   // 5e
  95.   0x40,0x40,0x40,0x40,0x40,   // 5f
  96.   0x00,0x01,0x02,0x04,0x00,   // 60
  97.   0x20,0x54,0x54,0x54,0x78,   // 61 a
  98.   0x7f,0x48,0x44,0x44,0x38,   // 62 b
  99.   0x38,0x44,0x44,0x44,0x20,   // 63 c
  100.   0x38,0x44,0x44,0x48,0x7f,   // 64 d
  101.   0x38,0x54,0x54,0x54,0x18,   // 65 e
  102.   0x08,0x7e,0x09,0x01,0x02,   // 66 f
  103.   0x0c,0x52,0x52,0x52,0x3e,   // 67 g
  104.   0x7f,0x08,0x04,0x04,0x78,   // 68 h
  105.   0x00,0x44,0x7d,0x40,0x00,   // 69 i
  106.   0x20,0x40,0x44,0x3d,0x00,   // 6a j
  107.   0x7f,0x10,0x28,0x44,0x00,   // 6b k
  108.   0x00,0x41,0x7f,0x40,0x00,   // 6c l
  109.   0x7c,0x04,0x18,0x04,0x78,   // 6d m
  110.   0x7c,0x08,0x04,0x04,0x78,   // 6e n
  111.   0x38,0x44,0x44,0x44,0x38,   // 6f o
  112.   0x7c,0x14,0x14,0x14,0x08,   // 70 p
  113.   0x08,0x14,0x14,0x18,0x7c,   // 71 q
  114.   0x7c,0x08,0x04,0x04,0x08,   // 72 r
  115.   0x48,0x54,0x54,0x54,0x20,   // 73 s
  116.   0x04,0x3f,0x44,0x40,0x20,   // 74 t
  117.   0x3c,0x40,0x40,0x20,0x7c,   // 75 u
  118.   0x1c,0x20,0x40,0x20,0x1c,   // 76 v
  119.   0x3c,0x40,0x30,0x40,0x3c,   // 77 w
  120.   0x44,0x28,0x10,0x28,0x44,   // 78 x
  121.   0x0c,0x50,0x50,0x50,0x3c,   // 79 y
  122.   0x44,0x64,0x54,0x4c,0x44,   // 7a z
  123.   0x00,0x08,0x36,0x41,0x00,   // 7b
  124.   0x00,0x00,0x7f,0x00,0x00,   // 7c
  125.   0x00,0x41,0x36,0x08,0x00,   // 7d
  126.   0x10,0x08,0x08,0x10,0x08,   // 7e
  127.   0x78,0x46,0x41,0x46,0x78    // 7f
  128. };  
  129.  
  130. BYTE const TABLE7[240]=            
  131.  {
  132.  0x7E, 0x11, 0x11, 0x11, 0x7E,//c0 A  0x80
  133.  0x7F, 0x49, 0x49, 0x49, 0x30,//c1 Á
  134.  0x7F, 0x49, 0x49, 0x49, 0x36,//c2 B
  135.  0x7F, 0x01, 0x01, 0x01, 0x01,//c3 Ã
  136.  0x60, 0x3E, 0x21, 0x3F, 0x60,//c4 Ä
  137.  0x7F, 0x49, 0x49, 0x49, 0x41,//c5 Å
  138.  0x67, 0x18, 0x7F, 0x18, 0x67,//c6 Æ
  139.  0x22, 0x41, 0x49, 0x49, 0x36,//c7 Ç
  140.  0x7F, 0x10, 0x08, 0x04, 0x7F,//c8 È
  141.  0x7F, 0x10, 0x09, 0x04, 0x7F,//c9 É
  142.  0x7F, 0x08, 0x14, 0x22, 0x41,//ca Ê
  143.  0x40, 0x3E, 0x01, 0x01, 0x7E,//cb Ë
  144.  0x7F, 0x02, 0x04, 0x02, 0x7F,//cc Ì
  145.  0x7F, 0x08, 0x08, 0x08, 0x7F,//cd Í
  146.  0x3E, 0x41, 0x41, 0x41, 0x3E,//ce Î
  147.  0x7F, 0x01, 0x01, 0x01, 0x7F,//cf Ï
  148.  0x7F, 0x09, 0x09, 0x09, 0x06,//d0 Ð
  149.  0x3E, 0x41, 0x41, 0x41, 0x22,//d1 Ñ
  150.  0x01, 0x01, 0x7F, 0x01, 0x01,//d2 Ò
  151.  0x27, 0x48, 0x48, 0x48, 0x3F,//d3 Ó
  152.  0x1E, 0x21, 0x7F, 0x21, 0x1E,//d4 Ô
  153.  0x63, 0x14, 0x08, 0x14, 0x63,//d5 Õ
  154.  0x3F, 0x20, 0x20, 0x3F, 0x40,//d6 Ö
  155.  0x1F, 0x10, 0x10, 0x10, 0x7F,//d7 ×
  156.  0x7F, 0x40, 0x7F, 0x40, 0x7F,//d8 Ø
  157.  0x3F, 0x20, 0x3F, 0x20, 0x7F,//d9 Ù
  158.  0x01, 0x7F, 0x44, 0x44, 0x38,//da Ú
  159.  0x7F, 0x44, 0x7C, 0x00, 0x7F,//db Û
  160.  0x7F, 0x44, 0x44, 0x44, 0x38,//dc Ü
  161.  0x22, 0x41, 0x49, 0x49, 0x3E,//dd Ý
  162.  0x7F, 0x08, 0x7F, 0x41, 0x7F,//de Þ
  163.  0x46, 0x29, 0x19, 0x09, 0x7F,//df ß
  164.  0x20, 0x54, 0x54, 0x54, 0x78,//e0 à
  165.  0x3C, 0x4A, 0x4A, 0x4B, 0x30,//e1 á
  166.  0x7C, 0x54, 0x54, 0x58, 0x20,//e2 â
  167.  0x7C, 0x04, 0x04, 0x04, 0x04,//e3 ã
  168.  0x60, 0x38, 0x24, 0x3C, 0x60,//e4 ä
  169.  0x38, 0x54, 0x54, 0x54, 0x18,//e5 å
  170.  0x74, 0x08, 0x7C, 0x08, 0x74,//e6 æ
  171.  0x28, 0x44, 0x54, 0x54, 0x28,//e7 ç
  172.  0x7C, 0x20, 0x10, 0x08, 0x7C,//e8 è
  173.  0x7C, 0x21, 0x12, 0x09, 0x7C,//e9 é
  174.  0x7C, 0x10, 0x10, 0x28, 0x44,//ea ê
  175.  0x40, 0x78, 0x04, 0x04, 0x7C,//eb ë
  176.  0x7C, 0x08, 0x10, 0x08, 0x7C,//ec ì
  177.  0x7C, 0x10, 0x10, 0x10, 0x7C,//ed í
  178.  0x38, 0x44, 0x44, 0x44, 0x38,//ee î
  179.  0x7C, 0x04, 0x04, 0x04, 0x7C//ef ï
  180. };  
  181. BYTE const TABLE8[80]=            
  182.  {
  183.  0x7C, 0x14, 0x14, 0x14, 0x08,//f0 ð
  184.  0x38, 0x44, 0x44, 0x44, 0x28,//f1 ñ
  185.  0x04, 0x04, 0x7C, 0x04, 0x04,//f2 ò
  186.  0x0C, 0x50, 0x50, 0x50, 0x3C,//f3 ó
  187.  0x18, 0x24, 0x7C, 0x24, 0x18,//f4 ô
  188.  0x44, 0x28, 0x10, 0x28, 0x44,//f5 õ
  189.  0x3C, 0x20, 0x20, 0x3C, 0x40,//f6 ö
  190.  0x1C, 0x20, 0x20, 0x20, 0x7C,//f7 ÷
  191.  0x7C, 0x40, 0x7C, 0x40, 0x7C,//f8 ø
  192.  0x3C, 0x20, 0x3C, 0x20, 0x7C,//f9 ù
  193.  0x04, 0x7C, 0x48, 0x48, 0x30,//fa ú
  194.  0x7C, 0x48, 0x48, 0x30, 0x7C,//fb û
  195.  0x7C, 0x48, 0x48, 0x48, 0x30,//fc ü
  196.  0x28, 0x44, 0x54, 0x54, 0x38,//fd ý
  197.  0x7C, 0x38, 0x44, 0x44, 0x38,//fe þ
  198.  0x48, 0x34, 0x14, 0x14, 0x7C,//ff ÿ
  199.  
  200. };  
  201.  
  202.  
  203. void    lph_init(void);
  204. void    lph_write_command(char byteforlph_command);
  205. void    lph_write_data(char byteforlph_data);
  206. void    lph_write_dorc(char byteforlph);
  207. void    lph_gotoxy(int8 xlph, int8 ylph);
  208. void    lph_erase_y(int8 ylph);
  209. void    lph_erase_x(int8 xlph);
  210. void    lph_printchar(int8 cvar);
  211. void    lph_clean_ddram(void);
  212. void    table_to_lphlcd(void);
  213. //void    lph_plot(int8 xlph,int8 plot_value8);
  214. void    lph_write_data_inv(char byteforlph_data_inv);
  215. void    lph_clear_screen(void);
  216. void    lph_clear_xy(int8 xlph, int8 ylph);
  217.  
  218. void    lph_print_uparrow(void);
  219. void    lph_print_downarrow(void);
  220. void    lph_print_leftarrow(void);
  221. void    lph_print_rightarrow(void);
  222. void    lph_print_degree(void);
  223. void    lph_print_lowbatdegree(void);
  224.  
  225. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  226. void lph_init(void)
  227. {
  228.   setup_spi(SPI_MASTER|SPI_H_TO_L|SPI_CLK_DIV_4);
  229.   output_high(lph_dc);            // bytes are stored in the display data ram, address counter, incremented automatically
  230.   output_high(lph_cs);            // chip disabled
  231.   delay_ms(50);
  232.   output_low(lph_res);            // reset chip during 250ms
  233.   delay_ms(50);         // works with less.....
  234.   output_high(lph_vdd);
  235.   output_high(lph_res);
  236.   delay_ms(250);
  237.  
  238.   lph_write_command(0x21);   // set extins extended instruction set
  239.   lph_write_command(0x09);
  240.   lph_write_command(0xd0);  // Vop     ********************************************************************************************************************
  241.   lph_write_command(0x16);   // bias
  242.   lph_write_command(0x06);
  243.   lph_write_command(0x20);   // horizontal mode from left to right, X axe are incremented automatically , 0x22 for vertical addressing ,back on normal instruction set too
  244.   lph_write_command(0x0c);   // all on
  245.  
  246.   lph_clean_ddram();      // reset DDRAM, otherwise the lcd is blurred with random pixels
  247.  
  248.   lph_write_command(0x08);   // mod control blank change (all off)
  249.  
  250.   lph_write_command(0x0c);   // mod control normal change
  251.  
  252. }
  253.  
  254. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  255. void lph_clean_ddram(void)
  256. {
  257.   lph_gotoxy(0,0);         // 102*8=816      clear LCD
  258.   for (ddram=816;ddram>0;ddram--){lph_write_data(0x00);}
  259.  
  260. }
  261. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  262.  
  263. void lph_write_command(char byteforlph_command)
  264. {
  265.  
  266.   output_low(lph_dc);   // byte is a command it is read with the eight SCLK pulse
  267.   output_low(lph_cs);   // chip enabled
  268.   spi_write(byteforlph_command);
  269. //  lph_write_dorc(byteforlph_command);
  270.   output_high(lph_cs);   // chip disabled
  271.  
  272. }
  273. /////////////////////////////////////////////////////////////////////////////////
  274. void lph_write_data(char byteforlph_data)
  275. {
  276.  
  277.   output_high(lph_dc);
  278.   output_low(lph_cs);   // chip enabled
  279.   spi_write(byteforlph_data);
  280. //  lph_write_dorc(byteforlph_data);
  281.   output_high(lph_cs);   // chip disabled
  282.  
  283. }
  284. //////////////////////////////////////////////////////////////////////////////////
  285. /*
  286. void lph_write_dorc(char byteforlph)         // serial write data or command subroutine
  287. {
  288.   char caa;
  289.   for (caa=8;caa>0;caa--) {
  290.     output_low(lph_sclk);
  291.     // delay_us(2);
  292.     if ((byteforlph&0x80)==0){output_low(lph_sda);}
  293.     else {output_high(lph_sda);}
  294.     output_high(lph_sclk);
  295.     byteforlph=byteforlph<<1;
  296.   }
  297. }
  298. */
  299. //////////////////////////////////////////////////////////////////////////////////
  300. void lph_gotoxy(int8 xlph, int8 ylph)      // Siemens LCD A50 Position cursor
  301. {
  302.   lph_write_command(0x40|(ylph&0x07));   // Y axe initialisation: 0100 0yyy
  303.  
  304.   lph_write_command(0x80|(xlph&0x7f));   // X axe initialisation: 1xxx xxxx
  305. }
  306. //////////////////////////////////////////////////////////////////////////////////
  307. void lph_erase_y(int8 ylph)
  308. {
  309.   lph_gotoxy(0,ylph);
  310.   printf(lph_printchar,"                 ");
  311. }
  312. //////////////////////////////////////////////////////////////////////////////////
  313. void lph_erase_x(int8 xlph)
  314. {
  315.  
  316.  char column;
  317.  
  318.   for (column=0;column!=8;column++){
  319.     lph_gotoxy(xlph,column);
  320.     lph_write_data(0x00);
  321.     lph_write_data(0x00);
  322.     lph_write_data(0x00);
  323.     lph_write_data(0x00);
  324.     lph_write_data(0x00);
  325.     lph_write_data(0x00);
  326.  
  327.   }
  328. }
  329. //////////////////////////////////////////////////////////////////////////////////
  330.  
  331. void lph_printchar(int8 cvar)               // Write 1 character to LCD
  332. {
  333.   charsel=cvar;
  334.   table_to_lphlcd();
  335. }
  336. //////////////////////////////////////////////////////////////////////////////////
  337. void table_to_lphlcd(void)   // extract ascii from tables & write to LCD
  338. {
  339.   if (charsel<0x20)return;
  340.   if ((charsel<0xc0)&(charsel>0x7f))return;
  341.  
  342.   for (char_row=0;char_row<5;char_row++) {      // 5 bytes
  343.  
  344.     if (charsel<0x50){charpos=(((charsel&0xff)-0x20)*5);chardata=TABLE5[(charpos+char_row)];}            // use TABLE5
  345.     else if (charsel<0x80){charpos=(((charsel&0xff)-0x50)*5);chardata=TABLE6[(charpos+char_row)];}            // use TABLE6
  346.     else if (charsel<0xf0){charpos=(((charsel&0xff)-0xc0)*5);chardata=TABLE7[(charpos+char_row)];}            // use TABLE6
  347.     else /*if (charsel<=0xff)*/{charpos=(((charsel&0xff)-0xf0)*5);chardata=TABLE8[(charpos+char_row)];}            // use TABLE6
  348.  
  349.  
  350.     lph_write_data(chardata);      // send data to lph
  351.   }
  352.  
  353.   lph_write_data(0x00);      //    1 byte (always blank)
  354.  
  355. }
  356. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  357.  
  358.  
  359. void lph_clear_screen(void)
  360. {
  361.   lph_erase_y(0);
  362.   lph_erase_y(1);
  363.   lph_erase_y(2);
  364.   lph_erase_y(3);
  365.   lph_erase_y(4);
  366.   lph_erase_y(5);
  367.   lph_erase_y(6);
  368.   lph_erase_y(7);
  369. }
  370.  
  371. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  372.  
  373.  
  374. void lph_clear_xy(int8 xlph, int8 ylph)
  375. {
  376.  
  377.   lph_gotoxy(xlph,ylph);
  378.   lph_printchar(" ");
  379.  
  380.  
  381. }
  382. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  383. void lph_print_uparrow(void)
  384. {
  385.   lph_write_data(0x04);
  386.   lph_write_data(0x02);
  387.   lph_write_data(0x7f);
  388.   lph_write_data(0x02);
  389.   lph_write_data(0x04);
  390.   lph_write_data(0x00);
  391. }
  392. //
  393. void lph_print_downarrow(void)
  394. {
  395.   lph_write_data(0x10);
  396.   lph_write_data(0x20);
  397.   lph_write_data(0x7f);
  398.   lph_write_data(0x20);
  399.   lph_write_data(0x10);
  400.   lph_write_data(0x00);
  401. }
  402. //
  403. void lph_print_leftarrow(void)
  404. {
  405.   lph_write_data(0x08);
  406.   lph_write_data(0x1c);
  407.   lph_write_data(0x2a);
  408.   lph_write_data(0x08);
  409.   lph_write_data(0x08);
  410.   lph_write_data(0xf8);
  411. }
  412. //
  413. void lph_print_rightarrow(void)
  414. {
  415.   lph_write_data(0x08);
  416.   lph_write_data(0x08);
  417.   lph_write_data(0x2a);
  418.   lph_write_data(0x1c);
  419.   lph_write_data(0x08);
  420.   lph_write_data(0x00);
  421. }
  422. //
  423. void lph_print_degree(void)
  424. {
  425.   lph_write_data(0x00);
  426.   lph_write_data(0x06);
  427.   lph_write_data(0x09);
  428.   lph_write_data(0x09);
  429.   lph_write_data(0x06);
  430.   lph_write_data(0x00);
  431.  
  432.  
  433. }
  434. //
  435. void lph_print_lowbatdegree(void)
  436. {
  437.   lph_write_data(0x00);
  438.   lph_write_data(0x06);
  439.   lph_write_data(0x0f);
  440.   lph_write_data(0x0f);
  441.   lph_write_data(0x06);
  442.   lph_write_data(0x00);
  443.  
  444. }
  445. //////////////////////////////////////////////////////////////////////////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement