LCD

Dependencies:   LCDTFT TFT_fonts mbed

Fork of TFT_CJS_ssd01399_portver_prettyfont by Oxford CWM Team

Committer:
danlock10y
Date:
Wed Jun 08 15:21:02 2016 +0000
Revision:
4:deab14782e4d
Parent:
2:1bc1605bffae
LCD ; ;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cstevens 0:92feefa9d5ba 1 #include "mbed.h"
cstevens 1:b4ae6047d590 2 #include "LCDTFT.h"
cstevens 1:b4ae6047d590 3 #include "Arial12x12.h"
cstevens 1:b4ae6047d590 4 #include "Arial24x23.h"
cstevens 1:b4ae6047d590 5 #include "Arial28x28.h"
cstevens 2:1bc1605bffae 6 #include "Neu42x35.h"
cstevens 2:1bc1605bffae 7 #include "ComicSans21x25.h"
cstevens 0:92feefa9d5ba 8
cstevens 1:b4ae6047d590 9 //BusOut MyBus(PTA13,PTD5,PTD4,PTA12,PTA4,PTA5,PTC8,PTC9); // 8 bit bus on these dvices
cstevens 1:b4ae6047d590 10
cstevens 1:b4ae6047d590 11
cstevens 1:b4ae6047d590 12 PortOut MyPort(PortD ,0xFF); // define a port with only the lower 8 bits included - that'llbe PTD0-PTD7 making a single 8 bit port.
cstevens 1:b4ae6047d590 13 LCDTFT MyLCD(PTB0,PTB1,PTB2,PTB3,PTC2,&MyPort);//LCDTFT(PinName PIN_RD,PinName PIN_WR,PinName PIN_RS,PinName PIN_CS,PinName PIN_RESET, PortOut *PORTLCD);
cstevens 1:b4ae6047d590 14
cstevens 1:b4ae6047d590 15
cstevens 2:1bc1605bffae 16 // next two functions need moving to the library.....
cstevens 1:b4ae6047d590 17 // ok - a simple sub to put in a character from the fonts defined in TFT_fonts
cstevens 1:b4ae6047d590 18 // c= charactetr to put
cstevens 1:b4ae6047d590 19 // font = pointer to font to use
cstevens 1:b4ae6047d590 20 // x,y locatoin of bottom lh of character, bcol = background color, fcol = foreground color
cstevens 2:1bc1605bffae 21 //prettyputc("m",Arial12x12,50,50,ColorBlack,ColorWhite);
cstevens 1:b4ae6047d590 22 void prettyputc(char c, const unsigned char *font,short xpos,short ypos,short bcol, short fcol)
cstevens 1:b4ae6047d590 23 {
cstevens 1:b4ae6047d590 24 // Length,horz,vert,byte/vert
cstevens 1:b4ae6047d590 25 int length,hor,vert,bpver; // number of bytes per character, horizontal pixels, vertical pixels and bytes per column
cstevens 1:b4ae6047d590 26 //
cstevens 1:b4ae6047d590 27 int x,y,i,j,k,ptr;
cstevens 1:b4ae6047d590 28 short coltowrite;
cstevens 1:b4ae6047d590 29 char byte,point;
cstevens 1:b4ae6047d590 30 length=font[0];
cstevens 1:b4ae6047d590 31 hor=font[1];
cstevens 1:b4ae6047d590 32 vert=font[2];
cstevens 1:b4ae6047d590 33 bpver=font[3];
cstevens 1:b4ae6047d590 34 for(i=0; i<hor; i++) { // loop over columns
cstevens 1:b4ae6047d590 35 for(j=0; j<vert; j++) {
cstevens 1:b4ae6047d590 36 x=xpos+i;
cstevens 1:b4ae6047d590 37 y=ypos+j; // NB assumes colums stored from bottom to top.... ?
cstevens 2:1bc1605bffae 38 ptr=((c -32) * length+1) + 4+i*bpver+(j/8); // pointer in font array to start of the character we want +1 to avoid the first byte that holds the char width
cstevens 1:b4ae6047d590 39 byte=(char)font[ptr];
cstevens 1:b4ae6047d590 40 k=j%8; // number of the pixel in this byte
cstevens 1:b4ae6047d590 41 point=byte & (1<<k); // get the next bit
cstevens 1:b4ae6047d590 42 if(point>0) {
cstevens 1:b4ae6047d590 43 coltowrite=fcol;
cstevens 1:b4ae6047d590 44 } else {
cstevens 1:b4ae6047d590 45 coltowrite=bcol;
cstevens 1:b4ae6047d590 46 }
cstevens 0:92feefa9d5ba 47
cstevens 1:b4ae6047d590 48 MyLCD.vLCDTFTPoint(x,y,coltowrite);
cstevens 1:b4ae6047d590 49
cstevens 1:b4ae6047d590 50 }
cstevens 0:92feefa9d5ba 51 }
cstevens 0:92feefa9d5ba 52
cstevens 1:b4ae6047d590 53 }
cstevens 1:b4ae6047d590 54
cstevens 1:b4ae6047d590 55
cstevens 1:b4ae6047d590 56
cstevens 1:b4ae6047d590 57
cstevens 2:1bc1605bffae 58 // ok now a function to use pretty putc to write strings whose bottom left corner are at xpo,ypos
cstevens 2:1bc1605bffae 59 // general idea is that the string is first formatted byb sprintf and the PrettyPrint is called
cstevens 2:1bc1605bffae 60 // bcol and fcol are the backgroun adn foreground colors
cstevens 2:1bc1605bffae 61 //NB max message length = 64 characters
cstevens 2:1bc1605bffae 62 void PrettyPrint(char *message,const unsigned char *font,short xpos,short ypos,short bcol, short fcol)
cstevens 2:1bc1605bffae 63 {
cstevens 2:1bc1605bffae 64 short x,y,messlength,i,ptr;
cstevens 2:1bc1605bffae 65 messlength=strlen(message);
cstevens 2:1bc1605bffae 66 if (messlength >64) messlength=64; // avoid writing too large a string....
cstevens 2:1bc1605bffae 67 x=xpos;
cstevens 2:1bc1605bffae 68 for(i=0; i<messlength; i++) {
cstevens 2:1bc1605bffae 69 // x=xpos+i*(font[1]*8/10); // font[1]=char width 80% to avoid gaps
cstevens 2:1bc1605bffae 70 //pointer = &font[((c -32) * offset) + 4]; // start of char bitmap
cstevens 2:1bc1605bffae 71 // w = pointer[0]; // width of actual char
cstevens 2:1bc1605bffae 72 ptr=((message[i] -32) * font[0]) + 4;
cstevens 2:1bc1605bffae 73
cstevens 2:1bc1605bffae 74 y=ypos; // will have to add cod and more to deal with different screen orientations
cstevens 2:1bc1605bffae 75 //prettyputc(char c, const unsigned char *font,short xpos,short ypos,short bcol, short fcol)
cstevens 2:1bc1605bffae 76 prettyputc(message[i],font,x,y,bcol,fcol);
cstevens 2:1bc1605bffae 77 x=x+font[ptr]+2;
cstevens 2:1bc1605bffae 78 }
cstevens 2:1bc1605bffae 79
cstevens 2:1bc1605bffae 80 }
cstevens 2:1bc1605bffae 81
cstevens 2:1bc1605bffae 82 //function to make a simple vertical progress bar
cstevens 2:1bc1605bffae 83 //dir is direction of fill
cstevens 2:1bc1605bffae 84 //0=down,1=up,2=right to left,3=left to right
cstevens 2:1bc1605bffae 85 void waitbar(short x,short y,short width,short height,int wtime,short emptycol,short bordercol,short fillcol,short dir)
cstevens 2:1bc1605bffae 86 {
cstevens 2:1bc1605bffae 87
cstevens 2:1bc1605bffae 88 short i;
cstevens 2:1bc1605bffae 89 // MyLCD.vLCDTFTRectangle(x,y,x+width,y+height,1,emptycol); // outline empty
cstevens 2:1bc1605bffae 90 MyLCD.vLCDTFTRectangle(x,y,x+width,y+height,1,emptycol); // outline empty
cstevens 2:1bc1605bffae 91 MyLCD.vLCDTFTRectangle(x,y,x+width,y+height,0,bordercol); // outline empty
cstevens 2:1bc1605bffae 92 if(dir<2) {
cstevens 2:1bc1605bffae 93 for(i=1; i<height; i++) {
cstevens 2:1bc1605bffae 94 wait((float)wtime/(float)height);
cstevens 2:1bc1605bffae 95 //wait(0.1);
cstevens 2:1bc1605bffae 96 if(dir==0) MyLCD.vLCDTFTLine(x+1,y+i,x+width-1,y+i,fillcol);
cstevens 2:1bc1605bffae 97 if(dir==1) MyLCD.vLCDTFTLine(x+1,y+height-i,x+width-1,y+height-i,fillcol);
cstevens 2:1bc1605bffae 98
cstevens 2:1bc1605bffae 99 }
cstevens 2:1bc1605bffae 100 } else {
cstevens 2:1bc1605bffae 101 for(i=1; i<width; i++) {
cstevens 2:1bc1605bffae 102 wait((float)wtime/(float)height);
cstevens 2:1bc1605bffae 103 //wait(0.1);
cstevens 2:1bc1605bffae 104
cstevens 2:1bc1605bffae 105 if(dir==2) MyLCD.vLCDTFTLine(x+width-i,y+1,x+width-i,y+height-1,fillcol);
cstevens 2:1bc1605bffae 106 if(dir==3) MyLCD.vLCDTFTLine(x+i,y+1,x+i,y+height-1,fillcol);
cstevens 2:1bc1605bffae 107 }
cstevens 2:1bc1605bffae 108
cstevens 2:1bc1605bffae 109 }
cstevens 2:1bc1605bffae 110
cstevens 2:1bc1605bffae 111
cstevens 2:1bc1605bffae 112 }
cstevens 2:1bc1605bffae 113
cstevens 2:1bc1605bffae 114
cstevens 2:1bc1605bffae 115
cstevens 1:b4ae6047d590 116 int main()
cstevens 1:b4ae6047d590 117 {
danlock10y 4:deab14782e4d 118 // int i,j,cwid;
danlock10y 4:deab14782e4d 119 // char message[32];
danlock10y 4:deab14782e4d 120 // sprintf(message,"Dive-Computer");
danlock10y 4:deab14782e4d 121
danlock10y 4:deab14782e4d 122
danlock10y 4:deab14782e4d 123 MyLCD.vLCDTFTInit(1);
danlock10y 4:deab14782e4d 124 MyLCD.vLCDTFTFillScreen(ColorBlack);
cstevens 1:b4ae6047d590 125 while(1) {
cstevens 1:b4ae6047d590 126
danlock10y 4:deab14782e4d 127
danlock10y 4:deab14782e4d 128 MyLCD.vLCDTFTRectangle(24,24,29,29,1,ColorWhite);
danlock10y 4:deab14782e4d 129
danlock10y 4:deab14782e4d 130 /*MyLCD.vLCDTFTInit(1);
cstevens 2:1bc1605bffae 131 MyLCD.vLCDTFTFillScreen(ColorBlack);
cstevens 2:1bc1605bffae 132 for(i=97; i<123; i++) {
cstevens 2:1bc1605bffae 133 j=i-97;
cstevens 2:1bc1605bffae 134 cwid=Arial12x12[(i-32)*Arial12x12[0]+4];
cstevens 2:1bc1605bffae 135 prettyputc((char)i,Arial12x12,j*12,50,ColorBlack,ColorWhite);
cstevens 2:1bc1605bffae 136 MyLCD.vLCDTFTRectangle(j*12,50,j*12+12,62,0,ColorLime);
cstevens 2:1bc1605bffae 137
cstevens 2:1bc1605bffae 138 prettyputc((char)i,Arial12x12,j*12,80,ColorBlack,ColorWhite);
cstevens 2:1bc1605bffae 139 MyLCD.vLCDTFTRectangle(j*12,80,j*12+cwid,92,0,ColorOrange);
cstevens 2:1bc1605bffae 140 }
cstevens 2:1bc1605bffae 141
cstevens 2:1bc1605bffae 142 waitbar(290,120,20,100,2,ColorBlue,ColorWhite,ColorRed,0);
cstevens 2:1bc1605bffae 143 sprintf(message,"Dive-Computer");
cstevens 2:1bc1605bffae 144 MyLCD.vLCDTFTFillScreen(ColorBlack);
cstevens 2:1bc1605bffae 145 PrettyPrint(message,Arial28x28,10,50,ColorBlack,ColorLime);
cstevens 2:1bc1605bffae 146 PrettyPrint(message,Arial24x23,10,80,ColorBlack,ColorLime);
cstevens 2:1bc1605bffae 147 PrettyPrint("Message",Arial12x12,10,105,ColorBlack,ColorLime);
cstevens 2:1bc1605bffae 148
cstevens 2:1bc1605bffae 149 sprintf(message,"width m=%d",Arial12x12[(109-32)*Arial12x12[0]+4]);
cstevens 2:1bc1605bffae 150
cstevens 2:1bc1605bffae 151 PrettyPrint(message,Arial12x12,10,125,ColorBlack,ColorOrange);
cstevens 2:1bc1605bffae 152 PrettyPrint("CCR-Ray",Neu42x35,10,175,ColorBlack,ColorCyan);
cstevens 2:1bc1605bffae 153 PrettyPrint("CCR-Ray",ComicSans21x25,10,20,ColorBlack,ColorYellow);
cstevens 2:1bc1605bffae 154 waitbar(290,10,20,100,2,ColorBlue,ColorWhite,ColorRed,1);
cstevens 2:1bc1605bffae 155
cstevens 1:b4ae6047d590 156
cstevens 1:b4ae6047d590 157 MyLCD.vLCDTFTFillScreen(ColorWhite);
danlock10y 4:deab14782e4d 158 waitbar(10,230,60,20,1,ColorBlack,ColorBlue,ColorRed,2);*/
cstevens 1:b4ae6047d590 159
cstevens 1:b4ae6047d590 160 }// endwhile
cstevens 1:b4ae6047d590 161 } //endmain