FRMD KL25Z <=i2c=> NXP PCF8563 (RTC) FRMD KL25Z SPI=> MCP23S17 => (GLCD) T6963C FRMD KL25Z Tsi => 3 button : <--> <enter> <++> FRMD KL25Z => Bip()
Fork of RTC8564NB_Clock by
GLCD_spi.h
00001 #ifndef GLCDSPI_H 00002 #define GLCDSPI_H 00003 00004 /*** GLCD_spi.h*** 00005 * Új változat char* int_string(int) 00006 * MCP23S17 - Microchip MCP23S17 16-bit Port Extender using SPI 00007 * Copyright (c) 2010 Gert van der Knokke 00008 */ 00009 #include "mbed.h" 00010 00011 // for 21 characters on a row (6x8 font) 00012 #define LCDFONTSEL 0xFF 00013 // for 16 characters on a row (8x8 font) 00014 // #define LCDFONTSEL 0xDF 00015 00016 #define IODIRA 0x00 00017 #define IODIRB 0x01 00018 #define IPOLA 0x02 00019 #define IPOLB 0x03 00020 #define GPINTENA 0x04 00021 #define GPINTENB 0x05 00022 #define DEFVALA 0x06 00023 #define DEFVALB 0x07 00024 #define INTCONA 0x08 00025 #define INTCONB 0x09 00026 #define IOCONA 0x0A 00027 #define IOCONB 0x0B 00028 #define GPPUA 0x0C 00029 #define GPPUB 0x0D 00030 #define INTFA 0x0E 00031 #define INTFB 0x0F 00032 #define INTCAPA 0x10 00033 #define INTCAPB 0x11 00034 #define GPIOA 0x12 00035 #define GPIOB 0x13 00036 #define OLATA 0x14 00037 #define OLATB 0x15 00038 00039 // LCD pin connections/bit numbers 00040 #define LCD_HALT 0x80 00041 #define LCD_FS 0x20 00042 #define LCD_RST 0x10 00043 #define LCD_CD 0x08 00044 #define LCD_CE 0x04 00045 #define LCD_RD 0x02 00046 #define LCD_WR 0x01 00047 00048 // T6963C OPCODES 00049 #define TXHOME 0x40 // SET TXT HOME ADDRESS 00050 #define TXAREA 0x41 // SET TXT AREA 00051 #define GRHOME 0x42 // SET GRAPHIC HOME ADDRESS 00052 #define GRAREA 0x43 // SET GRAPHIC AREA 00053 #define OFFSET 0x22 // SET OFFSET ADDRESS 00054 #define ADPSET 0x24 // SET ADDRESS POINTER 00055 #define AWRON 0xB0 // SET AUTO WRITE MODE 00056 #define AWROFF 0xB2 // RESET AUTO WRITE MODE 00057 00058 00059 /* This file contains definitions for all of the commands in a t6963. */ 00060 /********************************************************************/ 00061 /* Register set */ 00062 #define CPS 0x21 //Cursor pointer set 00063 #define ORS 0x22 //Offset register set 00064 #define APS 0x24 //Address pointer set 00065 #define THAS 0x40 //Text home address set 00066 #define TAS 0x41 //Text area set 00067 #define GHAS 0x42 //Graphic home address set 00068 #define GAS 0x43 //Graphic area set 00069 #define OM 0x80 //OR mode 00070 #define EM 0x81 //EXOR mode 00071 #define AM 0x83 //AND mode 00072 #define TAM 0x84 //TEXT ATTRIBUTE mode 00073 #define DOF 0x90 //Display OFF 00074 #define CONBOF 0x92 //Cursor ON, Blink OFF 00075 #define CONBON 0x93 //Cursor ON, Blink ON 00076 #define TONGOF 0x94 //Text ON, Graphic OFF 00077 #define TOFGON 0x98 //Text OFF, Graphic ON 00078 #define TONGON 0x9C //Text ON, Graphic ON 00079 #define LC1 0xA0 //1 Line cursor 00080 #define LC2 0xA1 //2 Line cursor 00081 #define LC3 0xA2 //3 Line cursor 00082 #define LC4 0xA3 //4 Line cursor 00083 #define LC5 0xA4 //5 Line cursor 00084 #define LC6 0xA5 //6 Line cursor 00085 #define LC7 0xA6 //7 Line cursor 00086 #define LC8 0xA7 //8 Line cursor 00087 #define DAWS 0xB0 //Data auto write set 00088 #define DARS 0xB1 //Data auto read set 00089 #define AR 0xB2 //Auto reset 00090 #define DWAAI 0xC0 //Data write and ADP increment 00091 #define DRAAI 0xC1 //Data read and ADP increment 00092 #define DWAAD 0xC2 //Data write and ADP decrement 00093 #define DRAAD 0xC3 //Data read and ADP decrement 00094 #define DWAAN 0xC4 //Data write and ADP nonvariable 00095 #define DRAAN 0xC5 //Data read and ADP nonvariable 00096 #define SP 0xE0 //Screen PEEK 00097 #define SC 0xE8 //Screen COPY 00098 #define BR 0xF0 //Bit RESET 00099 #define BS 0xF8 //Bit SET 00100 //add 3 bit data to these 00101 //commands to select bit 00102 00103 // for 21 characters on a row (6x8 font) 00104 #define LCDFONTSEL 0xFF 00105 // for 16 characters on a row (8x8 font) 00106 // #define LCDFONTSEL 0xDF 00107 00108 // lcd dimensions in pixels 00109 #define LCD_XWIDTH 128 00110 #define LCD_YHEIGHT 64 00111 00112 #if LCDFONTSEL == 0xFF 00113 // lcd dimensions in characters 00114 #define LCD_WIDTH 22 00115 #define LCD_HEIGHT 16 00116 #define PIXELWIDTH 6 00117 #else 00118 #define LCD_WIDTH 16 00119 #define LCD_HEIGHT 16 00120 #define PIXELWIDTH 8 00121 #endif 00122 00123 #define TEXT_STARTADDRESS 0x0000 00124 #define GRAPHIC_STARTADDRESS 0x1000 00125 00126 00127 #define CENTERX 50 00128 #define CENTERY 32 00129 #define INNER_RADIUS 20 00130 #define OUTER_RADIUS 25 00131 #define CENTER_CIRCLE 5 00132 00133 extern char d[14]={0}; // inttochar() visszaadott érték string-je 00134 00135 //DigitalOut K_LED(LED1), P_LED(LED3), Z_LED(LED2); 00136 SPI spi(PTC6, PTC7, PTC5); // mosi, miso, sclk 00137 DigitalOut cs2(PTC10); //CS1=PTC11; CS2=PTC10; CS3=PTC4 Hardware CS a panelon 00138 //---------------------------------------------------- 00139 void SPI_init() 00140 { 00141 // set SPI to full speed (10 MHz mode) 00142 spi.format(8,0); 00143 spi.frequency(10000000); 00144 //spi.frequency(10000); 00145 } 00146 //---------------------------------------------------- 00147 00148 void lcd_data(unsigned char d) // write 8 bits lcd data 00149 { 00150 cs2=0; 00151 spi.write(0x40); 00152 spi.write(GPIOB); // select GPIOB 00153 spi.write(d); // set data byte 00154 cs2=1; 00155 00156 cs2=0; 00157 spi.write(0x40); 00158 spi.write(GPIOA); // select GPIOA 00159 spi.write(LCDFONTSEL-LCD_CE-LCD_CD); 00160 cs2=1; 00161 00162 cs2=0; 00163 spi.write(0x40); 00164 spi.write(GPIOA); // select GPIOA 00165 spi.write(LCDFONTSEL - LCD_WR - LCD_CE - LCD_CD); 00166 cs2=1; 00167 00168 cs2=0; 00169 spi.write(0x40); 00170 spi.write(GPIOA); // select GPIOA 00171 spi.write(LCDFONTSEL - LCD_CD); 00172 cs2=1; 00173 00174 } 00175 //---------------------------------------------------- 00176 00177 void lcd_command(unsigned char c) // write 8 bits lcd command 00178 { 00179 cs2=0; 00180 spi.write(0x40); 00181 spi.write(GPIOB); // select GPIOB 00182 spi.write(c); // set data byte 00183 cs2=1; 00184 00185 cs2=0; 00186 spi.write(0x40); 00187 spi.write(GPIOA); // select GPIOA 00188 spi.write(LCDFONTSEL-LCD_CE); 00189 cs2=1; 00190 00191 cs2=0; 00192 spi.write(0x40); 00193 spi.write(GPIOA); // select GPIOA 00194 spi.write(LCDFONTSEL - LCD_WR - LCD_CE); 00195 cs2=1; 00196 00197 cs2=0; 00198 spi.write(0x40); 00199 spi.write(GPIOA); // select GPIOA 00200 spi.write(LCDFONTSEL); 00201 cs2=1; 00202 } 00203 //---------------------------------------------------- 00204 void lcd_init() //Grafikus LCD initializálása 00205 { 00206 cs2=0; 00207 spi.write(0x40); 00208 spi.write(IODIRA); // select IODIRA at start 00209 spi.write(0x00); // IODIRA all outputs 00210 spi.write(0x00); // IODIRB all outputs 00211 cs2=1; 00212 wait(0.1); 00213 00214 cs2=0; 00215 spi.write(0x40); 00216 spi.write(GPIOA); // select GPIOA at start 00217 spi.write(LCDFONTSEL-LCD_RST); // activate reset 00218 spi.write(0x00); // all B outputs 0 00219 cs2=1; 00220 wait(0.1); 00221 00222 cs2=0; 00223 spi.write(0x40); 00224 spi.write(GPIOA); // select GPIOA at start 00225 spi.write(LCDFONTSEL); // deactivate reset 00226 cs2=1; 00227 wait(0.1); 00228 00229 // set text home address at 0x0000 00230 lcd_data(TEXT_STARTADDRESS%0x100); 00231 lcd_data(TEXT_STARTADDRESS/0x100); 00232 lcd_command(TXHOME); 00233 00234 // set graphic home address at 0x1000 00235 lcd_data(GRAPHIC_STARTADDRESS%0x100); 00236 lcd_data(GRAPHIC_STARTADDRESS/0x100); 00237 lcd_command(GRHOME); 00238 00239 // set text area 00240 lcd_data(LCD_WIDTH); 00241 lcd_data(0x00); 00242 lcd_command(TXAREA); 00243 00244 // set graphic area 00245 lcd_data(LCD_WIDTH); 00246 lcd_data(0x00); 00247 lcd_command(GRAREA); 00248 00249 // mode set (internal character generation mode) 00250 lcd_command(0x80); 00251 00252 // set offset register 00253 lcd_data(0x02); 00254 lcd_data(0x00); 00255 lcd_command(OFFSET); 00256 00257 // display mode (text on graphics on cursor off) 00258 lcd_command(0x90+0x08+0x04); 00259 00260 } 00261 //------------------------------------------------- 00262 00263 //------------------------------------------------------ 00264 char* int_string(double da){ // elő nullák nélküli kiíratás 00265 00266 int b,c,dx,i; //b=adott helyiértéken a számjegy, c=0 akkor elő nulla; dx= az elő nullák nélküli helyiérték száma 00267 char* f; // egy karakter tipusú változó pointere 00268 c=0; 00269 dx=0; 00270 for(i=0;i<15;i++){d[i]=char(0x00);} 00271 //teszt adat: 00272 //da=123456; 00273 b=int(da/100000000); // 9. helyiérték 00274 if(b>0){c=1;d[dx]=0x30 | char(b);dx++;} 00275 da = da - b*100000000; // 8. helyiérték 00276 b=int(da/10000000); 00277 if(b>0 | c>0){c=1;d[dx]=0x30 | char(b);dx++;} 00278 da = da - b*10000000; // 7. helyiérték 00279 b=int(da/1000000); 00280 if(b>0 | c>0){c=1;d[dx]=0x30 | char(b);dx++;} 00281 da = da - b*1000000; // 6. helyiérték 00282 b=int(da/100000); 00283 if(b>0 | c>0){c=1;d[dx]=0x30 | char(b);dx++;} 00284 da = da - b*100000; // 5. helyiérték 00285 b=int(da/10000); 00286 if(b>0 | c>0){c=1;d[dx]=0x30 | char(b);dx++;} 00287 da = da - b*10000; // 4. helyiérték 00288 b=int(da/1000); 00289 if(b>0 | c>0){c=1;d[dx]=0x30 | char(b);dx++;} 00290 da = da - b*1000; // 3. helyiérték 00291 b=int(da/100); 00292 if(b>0 | c>0){c=1;d[dx]=0x30 | char(b);dx++;} 00293 da = da - b*100; // 2. helyiérték 00294 b=int(da/10); 00295 if(b>0 | c>0){c=1;d[dx]=0x30 | char(b);dx++;} 00296 da = da - b*10; // 1. helyiérték 00297 b=int(da); 00298 if(b>0 | c>0){c=1;d[dx]=0x30 | char(b);dx++;} 00299 // visszatérési érték: d[] string 00300 f = d; // f tartalmazza a d char tömb pointerét 00301 return f; 00302 } 00303 00304 00305 00306 //------------------------------------------------------ 00307 void lcd_string(char y,char x,char *s) // put a text string at position x,y (character row,column) 00308 { 00309 int adr; 00310 adr=TEXT_STARTADDRESS+x+y*LCD_WIDTH; // 0x0000 + x + y + 22 00311 lcd_data(adr%0x100); // % maradék képzés jele 00312 lcd_data(adr/0x100); 00313 lcd_command(ADPSET); 00314 lcd_command(AWRON); 00315 while (s[0]){ 00316 // convert from ascii to t6963 00317 lcd_data(s[0]-32); 00318 s++; 00319 } 00320 lcd_command(AWROFF); 00321 } 00322 //---------------------------------------------------- 00323 void lcd_cls() // clear lcd display memory (8k) 00324 { 00325 int a; 00326 lcd_data(0x00); 00327 lcd_data(0x00); 00328 lcd_command(ADPSET); 00329 lcd_command(AWRON); 00330 for (a=0; a<8192; a++) lcd_data(0); 00331 lcd_command(AWROFF); 00332 } 00333 //---------------------------------------------------- 00334 void lcd_plot(char x,char y,char color) // set or reset a pixel on the display on position x,y with color 0 or 1 00335 { 00336 int adr; 00337 adr = GRAPHIC_STARTADDRESS + ((LCD_WIDTH) * y) + (x/PIXELWIDTH); // calculate offset 00338 lcd_data(adr%0x100); // set low byte 00339 lcd_data(adr/0x100); // set high byte 00340 lcd_command(ADPSET); // set address pointer 00341 if (color) lcd_command(BS + ((PIXELWIDTH-1)-(x%PIXELWIDTH))); // use bit set mode 00342 else lcd_command(BR + ((PIXELWIDTH-1)-(x%PIXELWIDTH))); // use bit reset mode 00343 } 00344 //---------------------------------------------------- 00345 00346 void lcd_line(int x0, int y0, int x1, int y1,char color) // Bresenham line routine 0-128 x 0-64 color= char(1) 00347 { // color 1, 0 00348 char steep=1; 00349 int i,dx,dy,e; 00350 signed char sx,sy; 00351 00352 dx = abs(x1-x0); 00353 sx = ((x1 - x0) >0) ? 1 : -1; 00354 dy=abs(y1-y0); 00355 sy = ((y1 - y0) >0) ? 1 : -1; 00356 00357 if (dy > dx) 00358 { 00359 steep=0; 00360 // swap X0 and Y0 00361 x0=x0 ^ y0; 00362 y0=x0 ^ y0; 00363 x0=x0 ^ y0; 00364 00365 // swap DX and DY 00366 dx=dx ^ dy; 00367 dy=dx ^ dy; 00368 dx=dx ^ dy; 00369 00370 // swap SX and SY 00371 sx=sx ^ sy; 00372 sy=sx ^ sy; 00373 sx=sx ^ sy; 00374 } 00375 00376 e = (dy << 1) - dx; 00377 00378 for (i=0; i<=dx; i++) 00379 { 00380 if (steep) 00381 { 00382 lcd_plot(x0,y0,color); 00383 } 00384 else 00385 { 00386 lcd_plot(y0,x0,color); 00387 } 00388 while (e >= 0) 00389 { 00390 y0 += sy; 00391 e -= (dx << 1); 00392 } 00393 x0 += sx; 00394 e += (dy << 1); 00395 } 00396 } 00397 //---------------------------------------------------- 00398 00399 // kör kirajzolása 00400 void lcd_circle(int x0,int y0, int radius, char color) // Bresenham circle routine 00401 { 00402 int i; 00403 float cx =1.3; // kör rajzolás LCD torzítás kompenzálása 00404 i=0; 00405 //char sa[3]; 00406 int f = 1 - radius; 00407 int dx = 1; 00408 int dy = -2 * radius; 00409 int x = 0; 00410 int y = radius; 00411 //float cx =1.3; 00412 lcd_plot(x0 * cx, y0 + radius,color); 00413 lcd_plot(x0 * cx, y0 - radius,color); 00414 lcd_plot((x0 + radius) * cx, y0,color); 00415 lcd_plot((x0 - radius) * cx, y0,color); 00416 00417 while(x < y){ 00418 i++; 00419 if(f >= 0) 00420 { 00421 y--; 00422 dy += 2; 00423 f += dy; 00424 } 00425 x++; 00426 dx += 2; 00427 f += dx; 00428 lcd_plot((x0 + x) * cx, y0 + y,color); 00429 //a=(x0+x)*cx; 00430 //glcd_inttochar(a); 00431 //lcd_string(0,0,d); 00432 //a= y0 + y; 00433 //glcd_inttochar(a); 00434 //lcd_string(12,0,d); 00435 lcd_plot((x0 - x) * cx, y0 + y,color); 00436 lcd_plot((x0 + x) * cx, y0 - y,color); 00437 lcd_plot((x0 - x) * cx, y0 - y,color); 00438 lcd_plot((x0 + y) * cx, y0 + x,color); 00439 lcd_plot((x0 - y) * cx, y0 + x,color); 00440 lcd_plot((x0 + y) * cx, y0 - x,color); 00441 lcd_plot((x0 - y) * cx, y0 - x,color); 00442 //wait(.2); 00443 } 00444 } 00445 00446 #endif
Generated on Mon Jul 18 2022 01:34:26 by 1.7.2