Vizitator ady_ady689 Postat August 1, 2008 Partajează Postat August 1, 2008 Am folosit softul de aici http://thomaspfeifer.net/ pentru a scrie un driver pentru lcd-ul de nokia 6100 cu driver philips, dar am intampinat niste probleme legate de programare, vreau sa afisez o imagina si niste carcatere dar nu reusesc -controlerul folosit = atemga32 pentru orice alta functie de ex, draw() , displaiul va function dar cu carcaterele si imaginea nu codul folosit: #include "PCF8833U8_lcd.h" #include #include #include "bmp.h" /////////////////////////////////// #define F_CPU 12000000UL // #define SPIPORT PORTA #define SPIDDR DDRA #define CS 4 #define CLK 3 #define SDA 2 #define RESET 1 //////////////////////////////////// // Font sizes #define SMALL 0 #define MEDIUM 1 #define LARGE 2 ////////////////////////////////////// // 12-bit color definitions #define WHITE 0xFFF #define BLACK 0x000 #define RED 0xF00 #define GREEN 0x0F0 #define BLUE 0x00F #define CYAN 0x0FF #define MAGENTA 0xF0F #define YELLOW 0xFF0 #define BROWN 0xB22 #define ORANGE 0xFA0 #define PINK 0xF6A /////////////////////////////////// #define USR UCSRA #define UCR UCSRB #define UBRR UBRRL #define BAUD_RATE 38400 //#define MODE565 //////////////////////////// #define cbi(reg, bit) (reg&=~(1< #define sbi(reg, bit) (reg|= (1< #define CS0 cbi(SPIPORT,CS); #define CS1 sbi(SPIPORT,CS); #define CLK0 cbi(SPIPORT,CLK); #define CLK1 sbi(SPIPORT,CLK); #define SDA0 cbi(SPIPORT,SDA); #define SDA1 sbi(SPIPORT,SDA); #define RESET0 cbi(SPIPORT,RESET); #define RESET1 sbi(SPIPORT,RESET); #define byte unsigned char byte n=0; byte s1,s2; byte r,g,b; /////////////////////////////////// void sendCMD(byte cmd); void sendData(byte cmd); void shiftBits(byte b); void setPixel(byte r,byte g,byte b); /////////////////////////// const unsigned char FONT6x8[97][8]; const unsigned char FONT8x8[97][8]; const unsigned char FONT8x16[97][16]; int main(void) { InitLCD(); //LCD_Circle(40,30,30,LightGreen); //LCD_Fill(0,0,132,132,0,255,0); //LCD_Fill(50,50,90,90,0,0,255); //LCD_Box(0,10,50,100,0,255,0); //LCD_Circle(40,30,30,0,255,0); //draw(); //ShowImage(0,0,bmp[6206]); LCDPutChar('Eeeeeeee', 20, 20, MEDIUM,0,255,0); //LCDSetCircle(50,50,100,0,255,0); } void InitLCD(void) { SPIDDR=(1< CS0 SDA0 CLK1 RESET1 RESET0 RESET1 CLK1 SDA1 CLK1 waitms(10); sendCMD(SWRESET); sendCMD(SLEEPOUT); sendCMD(BSTRON); waitms(10); sendCMD(DISON); sendCMD(NORON); sendCMD(INVON); sendCMD(DOR); sendCMD(MADCTL); //sendCMD(RGBX); sendData(RGBY); //sendCMD(INVOFF); #ifdef MODE565 sendCMD(COLMOD); sendData(5); //16-Bit per Pixel #else //sendCMD(COLMOD); //sendData(3); //12-Bit per Pixel (default) #endif /* sendCMD(RGBSET); // setup color lookup table // Setup the color lookup table by choosing evenly spaced color values // for a nice even spread. Blue only has 2 bits, so the spacing is wider // but still spans 0x00 - 0x0f // Bit organisation is RRRGGGBB sendCMD(RGBSET); sendData(0x00); // RED sendData(0x02); sendData(0x04); sendData(0x06); sendData(0x08); sendData(0x0a); sendData(0x0c); sendData(0x0f); sendData(0x00); // GREEN sendData(0x02); sendData(0x04); sendData(0x06); sendData(0x08); sendData(0x0a); sendData(0x0c); sendData(0x0f); sendData(0x00); // BLUE sendData(0x04); sendData(0x09); sendData(0x0f); sendCMD(NOP); // nop sendCMD(INVON); // Inverted display mode int i;; for (i = 0; i < 160; i++) { // this loop adjusts the contrast, change the number of iterations to get sendCMD(SETCON); sendData(63); // desired contrast. This might be different for individual LCDs waitms(2); }*/ } void waitms(int ms) { int i; for (i=0;i } ////////////////////////////////// void shiftBits(byte b) { CLK0 if ((b&128)!=0) SDA1 else SDA0 CLK1 CLK0 if ((b&64)!=0) SDA1 else SDA0 CLK1 CLK0 if ((b&32)!=0) SDA1 else SDA0 CLK1 CLK0 if ((b&16)!=0) SDA1 else SDA0 CLK1 CLK0 if ((b&!=0) SDA1 else SDA0 CLK1 CLK0 if ((b&4)!=0) SDA1 else SDA0 CLK1 CLK0 if ((b&2)!=0) SDA1 else SDA0 CLK1 CLK0 if ((b&1)!=0) SDA1 else SDA0 CLK1 } /////////////////////////////////// //send data void sendData(byte data) { CLK0 SDA1 //1 for param CLK1 shiftBits(data); } ///////////////////////////////// //send cmd void sendCMD(byte data) { CLK0 SDA0 //1 for cmd CLK1 shiftBits(data); } ////////////////////////////////// //converts a 3*8Bit-RGB-Pixel to the 2-Byte-RGBRGB Format of the Display void setPixel(byte r,byte g,byte b) { #ifdef MODE565 sendData((r&248)|g>>5); sendData((g&7)<<5|b>>3); #else if (n==0) { s1=(r & 240) | (g>>4); s2=(b & 240); n=1; } else { n=0; sendData(s1); sendData(s2|(r>>4)); sendData((g&240) | (b>>4)); } #endif } ///////////////////////////////////////// void LCDSetXY(int x, int y) { // Row address set (command 0x2B) sendCMD(PASET); sendData(x); sendData(x); // Column address set (command 0x2A) sendCMD(CASET); sendData(y); sendData(y); } ////////////////////////////////////////////// void LCDSetPixel(int x, int y, int color) { LCDSetXY(x, y); sendCMD(RAMWR); sendData((unsigned char)((color >> 4) & 0xFFFF)); sendData((unsigned char)(((color & 0x0F) << 4) | 0x00)); sendCMD(NOP); } /////////////////////////////////// void draw() { //Column Adress Set sendCMD(0x2A); sendData(0); sendData(131); //Page Adress Set sendCMD(0x2B); sendData(0); sendData(131); //Memory Write sendCMD(RAMWR); int i; //Test-Picture //red bar for (i=0;i<132*33;i++) { setPixel(255,0,0); } //green bar for (i=0;i<132*33;i++) { setPixel(0,255,0); } //blue bar for (i=0;i<132*33;i++) { setPixel(0,0,255); } //white bar for (i=0;i<132*33;i++) { setPixel(255,255,255); } } ////////////////////////////////////////// //***************************************************************************** // Name: GotoXY(u_char x, u_char y) // Copyright: Free to use at will & at own risk. // Author: JCP // Date: 03.30.06 17:10 // Description: Sets position to x-y location on LCD // Useage: GotoXY(param 1,param 2) // param 1: x direction 0-131 // param 2: y direction 0-131 // // Example: GotoXY(32,17); // // Notes: No bounds checking //******************************************************************************* void GotoXY(unsigned char x, unsigned char y) { sendCMD(PASET); // page start/end ram sendData(y); // Start Page to display to sendData(131); // End Page to display to sendCMD(CASET); // column start/end ram sendData(x); // Start Column to display to sendData(131); } //***************************************************************************** // Name: LCD_PixelPut(u_char x, u_char y, u_char color) // Copyright: Free to use at will & at own risk. // Author: JCP // Date: 03.30.06 17:10 // Description: Put One Pixel on LCD // Useage: LCD_PixelPut(param 1,param 2,param 3) // param 1: x direction 0-131 // param 2: y direction 0-131 // param 3: Color of Pixel, RRRGGGBB format // Example: LCD_PixelPut(30,30,0x62) // put a purple pixel @ 30,30 // // Notes: No bounds checking //******************************************************************************* void LCD_PixelPut(unsigned char x, unsigned char y, unsigned char color) { GotoXY(x,y); sendCMD(RAMWR); // Now write the pixel to the display sendData(color); // Write the data in the specified Color } void pixel(unsigned char x, unsigned char y, byte r, byte g, byte b) { GotoXY(x,y); sendCMD(RAMWR); setPixel(r,g,b); } //***************************************************************************** // Name: LCD_Fill (u_char xs,u_char ys,u_char width,u_char height, u_char color) // Copyright: Free to use at will & at own risk. // Author: JCP // Date: 03.30.06 17:10 // Description: Fills an area starting @ xs,ys to width @ heighth with color // Useage: LCD_Fill(param 1,param 2,param 3,param 4,param 5) // param 1: x start direction: 0-131 // param 2: y start direction: 0-131 // param 3: width: 0-131 // param 4: heighth: 0-131 // param 5: Color of Pixel, RRRGGGBB format // // Example: LCD_Fill(0,0,132,132,Black); // fill entire screen with black color // // Notes: No bounds checking //******************************************************************************* void LCD_Fill (unsigned char xs,unsigned char ys,unsigned char width,unsigned char height, byte r, byte g, byte b) { unsigned char i,j; // for (i=0;i < height;i++) // Number of horizontal lines { // GotoXY(xs,ys+i); // Goto start of fill area (Top Left) sendCMD(RAMWR); // Write to display // for (j=0;j < width;j++) // pixels per line { // setPixel(r,g,b); // } // // sendCMD(NOP); // End } } ///****************************************************************************** // Name: LCD_Funct_A(x1, y1, x2, y2, pixel_on_off, ram_or_lcd) // Copyright: Free to use at will & at own risk. // Author: JCP // Date: 03.30.06 17:10 // Description: Used with LCD line function //******************************************************************************* void LCD_Funct_A(unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2, unsigned char color ) { float a,b; unsigned char x,y; // // // b = (float)((y2 - y1) + 1) / (float)((x2-x1) + 1); // // a = y1; // // // for(x = x1;x <= x2; x++) // { // // for(y=(unsigned char)a;y <= (unsigned char)(a + b); y++) // { // if(y <= y2) // { // GotoXY(x,y); // Goto start of fill area (Top Left) sendCMD(RAMWR); // write to display sendData(color); // } // } // // a+=b; // } // } //****************************************************************************** // Name: LCD_Funct_B(x1, y1, x2, y2, pixel_on_off, ram_or_lcd) // Copyright: Free to use at will & at own risk. // Author: JCP // Date: 03.30.06 17:10 // Description: Used with LCD line function //******************************************************************************* void LCD_Funct_B(unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2, unsigned char color ) { float a,b; unsigned char x,y; // // b = (float)((y2 - y1) + 1) / (float)((x1-x2) + 1); // // a = y1; // // for(x = x1;x >= x2; x--) // { // for(y=(unsigned char)a;y <= (unsigned char)(a + b); y++) // { // if(y <= y2) // { // GotoXY(x,y); // Goto start of fill area (Top Left) sendCMD(RAMWR); // write to display sendData(color); // } // } // a+=b; // } // } //****************************************************************************** // Name: LCD_Line(x1, y1, x2, y2, pixel_on_off, ram_or_lcd) // Copyright: Free to use at will & at own risk. // Author: JCP // Date: 03.30.06 17:10 // Description: To draw or remove a line from the LCD // Notes: No bounds checking //******************************************************************************* void LCD_Line(unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2, unsigned char color) { if( (x1 <= x2) && (y1 <= y2) ) // { // LCD_Funct_A(x1,y1,x2,y2,color); // } // // else if( (x1 > x2) && (y1 < y2) ) // { // LCD_Funct_B(x1,y1,x2,y2,color); // } // // else if( (x1 >= x2) && (y1 >= y2) ) // { // LCD_Funct_A(x2,y2,x1,y1,color); // } // // else if( (x1 < x2) && (y1 > y2) ) // { // LCD_Funct_B(x2,y2,x1,y1,color); // } // // } //****************************************************************************** // Name: LCD_Box(x1, y1, x2, y2, pixel_on_off, ram_or_lcd) // Copyright: Free to use at will & at own risk. // Author: JCP // Date: 03.30.06 17:10 // Description: To draw a BOX on the LCD // Notes: No bounds checking //******************************************************************************* void LCD_Box(unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2, byte r, byte g, byte b) { unsigned char x,y; x = x1; // y = y1; // // while(x <= x2) // { // pixel(x,y1,r,g,b); // pixel(x,y2,r,g,b); // // x++; // } // // while(y <= y2) // { // pixel(x1,y,r,g,b); // pixel(x2,y,r,g,b); // // y++; // } // } //****************************************************************************** // Name: LCD_Circle // Copyright: Free to use at will & at own risk. // Date: 03.30.06 17:10 // Description: To Draw a Circle on LCD // Useage: LCD_Circle(param 1,param 2,param 3,param 4) // // param 1: x location on screen, 0 - 127 // param 2: y location on screen, 0 - 63 // param 3: diameter of circle // param 4: Color of Pixel, RRRGGGBB format // // Example: LCD_Circle(40,30,30,LightGreen); // Notes: No bounds checking //******************************************************************************* void LCD_Circle(unsigned char center_x, unsigned char center_y, unsigned int rad, unsigned char color) { unsigned int x; unsigned int y; x = 0; y = rad; while (x <= y) { // We make use of 8 axes of symmetry in a circle. // This way we have fewer points to calculate on its circumference. pixel (center_x + (unsigned char)x, center_y + (unsigned char)y,r,g,b); pixel (center_x - (unsigned char)x, center_y + (unsigned char)y,r,g,b); pixel (center_x + (unsigned char)x, center_y - (unsigned char)y,r,g,b); pixel (center_x - (unsigned char)x, center_y - (unsigned char)y,r,g,b); pixel (center_x + (unsigned char)y, center_y + (unsigned char)x,r,g,b); pixel (center_x - (unsigned char)y, center_y + (unsigned char)x,r,g,b); pixel (center_x + (unsigned char)y, center_y - (unsigned char)x,r,g,b); pixel (center_x - (unsigned char)y, center_y - (unsigned char)x,r,g,b); // This is the most important part of the function. // We go to the right in all cases (x++). // We need to decide whether to go down (y--). // This depends on which point is // closest to the path of the circle. // Good old Pythagoras will tell us what to do. x++; if( abs( (x * x) + (y * y) - (rad * rad) ) > abs( (x * x) + ((y-1)*(y-1)) - (rad * rad)) ) { y--; } } } //****************************************************************************** // Name: LCD_Thick_Circle // Copyright: Free to use at will & at own risk. // Date: 03.30.06 17:10 // Description: To Draw a Definable Thickness Circle on LCD // Useage: LCD_Thick_Circle(param 1,param 2,param 3,param 4,param 5) // param 1: x start direction: 0-131 // param 2: y start direction: 0-131 // param 3: diameter: 0-255 // param 4: Thickness of circle wall in pixels // param 5: Color of Pixel, RRRGGGBB format // // Example: LCD_Thick_Circle(66,66,30,2,0x62); // start @ 66,66, with a diamater of 30, 2 pixels thick in purple // // Notes: No bounds checking //******************************************************************************* void LCD_Thick_Circle(unsigned char center_x, unsigned char center_y,unsigned char diameter, unsigned char thick,unsigned char color) { unsigned int a; for(a=0;a < 360;a++) { // LCD_Circle_Line(center_x,center_y,diameter,(diameter + thick),a,color); } } ///////////////////////////////////////////////////////////////////////////////////////// /*void ShowImage(unsigned char x, unsigned char y, const unsigned char *location) { unsigned char x_max,y_max; unsigned char x_logo,y_logo; x_max = *location; location++; y_max = *location; location++; for(y_logo=0;y_logo { GotoXY(x,y + y_logo); sendCMD(RAMWR); // Now write the pixel to the display for(x_logo=0;x_logo < x_max;x_logo++) { sendData(*location); // Write the data in the specified Color location++; } } } //****************************************************************************** // Name: LCD_String // Copyright: Free to use at will & at own risk. // Date: 03.30.06 17:10 // Description: To print a string of characters to LCD // Useage: LCD_String(param 1,param 2,param 3,param 4,param 5,param 6) // // param 1: String data // param 2: pointer to data lookup table (I.E. Font table) // param 3: x start direction: 0-131 // param 4: y start direction: 0-131 // param 5: Font Color, RRRGGGBB format // param 5: Background color, RRRGGGBB format // // Example: sprintf(thestring,"Hello World"); // LCD_String(thestring,_FONT6x8,52,25,White,Black); // // print "Hello World" in white text on a black background // // Notes: No bounds checking //******************************************************************************* void LCD_String (unsigned char *the_string, unsigned char Size,unsigned char x, unsigned char y, unsigned char fcolor, unsigned char bcolor) { unsigned int i,j; unsigned char Mask,z,xme,yme,mult; // unsigned char *slave; // unsigned char *Data; // // unsigned char FONT8x8F; // // if(Size==FONT8x8F) // { // slave = FONT8x8F; // xme = 8; // yme = 8; // mult= 8; // } // // // // do // { // // Data = slave + (mult * (int)(*the_string - 32)); // // for (i=0;i < yme;i++) // 10 bytes per char 15 { // Mask |=0x80; // // for (j=x;j < (x + xme);j++) // { // // z= y + i; // // if (*Data & Mask) // { // pixel (j,z,0,255,0); // } // else // { // pixel (j,z,0,0,255); // } // // Mask>>=1; // } // // Data++; // } // // x+=xme; // // the_string++; // // }while(*the_string !='\0'); // keep spitting chars until end // sendCMD(NOP); // Recomended to send now and then } */ void LCDPutChar(char c, int x, int y, int size, byte r, byte g, byte b) { extern const unsigned char FONT6x8[97][8]; extern const unsigned char FONT8x8[97][8]; extern const unsigned char FONT8x16[97][16]; int i,j; unsigned int fColor ; unsigned int bColor; unsigned int nCols; unsigned int nRows; unsigned int nBytes; unsigned char PixelRow; unsigned char Mask; unsigned int Word0; unsigned int Word1; unsigned char *pFont; unsigned char *pChar; unsigned char *FontTable[] = {(unsigned char *)FONT6x8,(unsigned char *)FONT8x8,(unsigned char *)FONT8x16};// get pointer to the beginning of the selected font table pFont = (unsigned char *)FontTable;// get the nColumns, nRows and nBytes nCols = *pFont; nRows = *(pFont + 1); nBytes = *(pFont + 2);// get pointer to the last byte of the desired character pChar = pFont + (nBytes * (c - 0x1F)) + nBytes - 1;// Row address set (command 0x2B) sendCMD(PASET); sendData(x); sendData(x + nRows - 1);// Column address set (command 0x2A) sendCMD(CASET); sendData(y); sendData(y + nCols - 1);// WRITE MEMORY sendCMD(RAMWR);// loop on each row, working backwards from the bottom to the top for (i = nRows - 1; i >= 0; i--) { // copy pixel row from font table and then decrement row PixelRow = *pChar--; // loop on each pixel in the row (left to right) // Note: we do two pixels each loop Mask = 0x80; for (j = 0; j < nCols; j += 2) { // if pixel bit set, use foreground color; else use the background color // now get the pixel color for two successive pixels if ((PixelRow & Mask) == 0) { Word0 = bColor; setPixel(r,g,b); } else Word0 = fColor; setPixel(0,255,0); Mask = Mask >> 1; if ((PixelRow & Mask) == 0) { Word1 = bColor; setPixel(r,g,b); } else Word1 = fColor; setPixel(r,g,b); Mask = Mask >> 1; // use this information to output three data bytes sendData((Word0 >> 4) & 0xFF); sendData(((Word0 & 0xF) << 4) | ((Word1 >> & 0xF)); sendData(Word1 & 0xFF); } } // terminate the Write Memory command sendCMD(NOP); } Link spre comentariu
Postări Recomandate
Creează un cont sau autentifică-te pentru a adăuga comentariu
Trebuie să fi un membru pentru a putea lăsa un comentariu.
Creează un cont
Înregistrează-te pentru un nou cont în comunitatea nostră. Este simplu!
Înregistrează un nou contAutentificare
Ai deja un cont? Autentifică-te aici.
Autentifică-te acum