Rev Author Line No. Line
1213 mija 1 //************************************************************************
2 // lcd /define nSCLK, nSDIN, nDC, nSC, nRESET /
3  
4 //uint8_t init_n5110[9]={0x21,0xc5,0x13,0x20,0x09,0x08,0xc,0x40,0x80};
5  
6 #include <avr/io.h>
7 #include <avr/pgmspace.h>
8 #include <util/delay.h>
9 #include <stdint.h>
10 #include <stdio.h>
11 #include "lcd.h"
12 #include "ascii_table.h"
13  
14 void delay_ms1(uint16_t time)
15 {
16 while(time--) _delay_ms(1);
17 }
18  
19 void N5110_send(uint8_t data)
20 {
21 uint8_t a;
22  
23 for (a=0;a<8;a++)
24 {
25 nSCLK_L;
26 if (data & 0x80) nSDIN_H;
27 else nSDIN_L;
28 data <<= 1;
29 nSCLK_H;
30 }
31 }
32  
33 void N5110_send_data(uint8_t data)
34 {
35 nDC_H;
36 nCS_L;
37 N5110_send(data);
38 nCS_H;
39 }
40  
41 void N5110_send_command(uint8_t data)
42 {
43 nDC_L;
44 nCS_L;
45 N5110_send(data);
46 nCS_H;
47 }
48  
49 void LCD_N5110_INIT(void)
50 {
51 //uint8_t a;
52  
53 nDC_H;
54 nSCLK_H;
55 nCS_H;
56 nRESET_L;
57 delay_ms1(20);
58 nRESET_H;
59  
60 //mise lcd
61 //for (a=0;a<9;a++) N5110_send_command(init_n5110[a]);
62 N5110_send_command(EXTENDED_SET);
63 N5110_send_command(VOP|0x45); //default 0x45
64 N5110_send_command(BIAS_1);
65 N5110_send_command(H_ADDR);
66 N5110_send_command(DISPLAY_ALL_ON);
67 //clear_lcd();
68 //delay_ms1(1000);
69 N5110_send_command(DISPLAY_BLANK);
70 //delay_ms1(1000);
71 N5110_send_command(DISPLAY_NORMAL);
72  
73 /* //mija lcd
74 //for (a=0;a<9;a++) N5110_send_command(init_n5110[a]);
75 //N5110_send_command(EXTENDED_SET);
76 //N5110_send_command(VOP|69); //default 0x45
77 //N5110_send_command(BIAS_3);
78 N5110_send_command(H_ADDR);
79 //N5110_send_command(DISPLAY_ALL_ON);
80 //clear_lcd();
81 //delay_ms(1000);
82 //N5110_send_command(DISPLAY_BLANK);
83 //delay_ms(1000);
84 N5110_send_command(DISPLAY_NORMAL);
85 */
86 }
87  
88 //************************************************************************
89 // buffer lcd
90  
91 uint8_t video_buf[504];
92 uint8_t *offset_text;
93  
94 int lcd_put(char c, FILE *stream)
95 {
96 uint8_t a;
97 uint16_t pos;
98  
99 pos = (c - 0x20) * 5;
100 for(a=0; a<5;a++)
101 {
102 *(offset_text++) = pgm_read_byte(&ASCII_TABLE1[pos+a]);
103 }
104 *(offset_text++) = 0;
105 return 0;
106 }
107  
108 int lcd_put2(char c, FILE *stream)
109 {
110 uint8_t a;
111 uint8_t b;
112 uint16_t pos;
113 uint8_t pom;
114 uint8_t l_text;
115 uint8_t h_text;
116  
117 pos = (c - 0x20) * 5;
118 for(a=0; a<5;a++)
119 {
120 h_text=0;
121 l_text=0;
122 pom = pgm_read_byte(&ASCII_TABLE1[pos+a]);
123 for (b=0;b<4;b++)
124 {
125 if (pom & 0x01) l_text |= 3<<(2*b);
126 if (pom & 0x10) h_text |= 3<<(2*b);
127 pom>>=1;
128 }
129 *(offset_text+84) = h_text;
130 *(offset_text++) = l_text;
131 }
132 *(offset_text+84) = 0;
133 *(offset_text++) = 0;
134 return 0;
135 }
136  
137  
138 void gotoxy(uint8_t x,uint8_t y)
139 {
140 offset_text= video_buf + (y-1)*84 + 6*(x-1);
141 }
142  
143 void lcd_refresh(void)
144 {
145 uint16_t a;
146 uint8_t *point;
147  
148 N5110_send_command(0x40);
149 N5110_send_command(0x80);
150 point = video_buf;
151 for (a=0;a<504;a++) N5110_send_data(*(point++));
152  
153 }
154  
155 void buffer_clr(void)
156 {
157 uint16_t a;
158  
159 for (a=0;a<504;a++) video_buf[a]=0;
160 offset_text = video_buf;
161 }
162  
163 //************************************************************************
164 // graphics
165  
166 void lcd_plot(uint8_t x, uint8_t y)
167 {
168 uint8_t *point;
169  
170 if (x>(LCD_WIDTH-1) || y>(LCD_HEIGHT-1)) return;
171 point = video_buf + LCD_WIDTH*((LCD_HEIGHT-y-1)/8)+x;
172 *point |= 1<<(7-(y%8));
173 }
174  
175 void lcd_line(uint8_t x1,uint8_t y1,uint8_t x2, uint8_t y2)
176 {
177 uint8_t a;
178 uint8_t savex,savey;
179  
180 if (x1>x2) {savex=x1;savey=y1;x1=x2;y1=y2;x2=savex;y2=savey;}
181 if (y1>y2)
182 {
183 if ((x2-x1)>(y1-y2))for (a=x1;a<=x2;a++)lcd_plot(a,y1-((y1-y2)*(a-x1)/(x2-x1)));
184 else for (a=y2;a<=y1;a++)lcd_plot(x2-((x2-x1)*(a-y2)/(y1-y2)),a);
185 return;
186 }
187 if ((x2-x1)>(y2-y1))for (a=x1;a<=x2;a++)lcd_plot(a,y1+((y2-y1)*(a-x1)/(x2-x1)));
188 else for (a=y1;a<=y2;a++)lcd_plot(x1+((x2-x1)*(a-y1)/(y2-y1)),a);
189 }
190