CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Nokia 6100 color graphic display complete library

 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
opvini



Joined: 27 Apr 2012
Posts: 50
Location: Brazil

View user's profile Send private message

Nokia 6100 color graphic display complete library
PostPosted: Tue May 20, 2014 1:52 pm     Reply with quote

Hi everyone,
i rewrite the nokia 6100 ARM library to PIC.

Code:

//****************************************************************
//                           Nokia 6100
//
//                Color Graphic Display
//
//****************************************************************
//
//            Federal University of Ouro Preto - UFOP
//               Automation Engineer Department
//
//
// Developed by:
//
// Vinicius Nunes Lage
// email: viniciusop[ @ ]gmail.com
// Class 09.1
// Last Modification: 15/04/2014
//
//
////////
////////////////////////////////////////////////////////////////////////////////
////      Routines graphiques pour écran couleur Nokia 6100                 ////
////      Contrôleur graphique Philips PCF8833                              ////
////      Résolution 132 x 132 x 65K couleurs logicielle mais 4K réel       ////
///       Dans ce module j'utilise que 256 couleur , c'est plus speed       ////
////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////
////  Entrer ici les broches utilisé par l'ecran                            ////
////////////////////////////////////////////////////////////////////////////////

#define  glcd_res            PIN_C0
#define  glcd_sdata          PIN_C1
#define  glcd_sclk           PIN_C2
#define  glcd_cs             PIN_C3

////////////////////////////////////////////////////////////////////////////////
////  Entrer ici les delais pour init ,write_data et write command          ////
////  att1 : attente en µSec pour la routine d'initialisation               ////
////  att2 : attente en nanoseconde / 100 pour les routines                 ////
////         glcd_write_command ,glcd_write_data et glcd_write_dorc         ////
////         Pour 40Mhz att2 à 10 represente 1µSec                          ////
////////////////////////////////////////////////////////////////////////////////

#define  att1           1
#define  att2           0

////////////////////////////////////////////////////////////////////////////////

#define  SCREEN_COLOR   BLACK
#define  USE_GRFCN

////////////////////////////////////////////////////////////////////////////////
////  Les valeurs limite de l'ecran                                         ////
////////////////////////////////////////////////////////////////////////////////
#define  GCLCDX         132
#define  GCLCDY         132
#define  X_START        0
#define  Y_START        0
#define  X_END          GCLCDX
#define  Y_END          GCLCDY

////////////////////////////////////////////////////////////////////////////////
////  Les commande du PCF8833                                               ////
////////////////////////////////////////////////////////////////////////////////

#define  LCD_NOP        0x00
#define  SOFT_RESET     0x01
#define  COLOR_8_BIT    0x02
#define  COLOR_16_BIT   0x05
#define  BOOSTER_ON     0x03
#define  BOOSTER_OFF    0x02
#define  SLEEP_OUT      0x11
#define  SLEEP_IN       0x10
#define  DISPLAY_ON     0x29
#define  DISPLAY_OFF    0x28
#define  PIXELS_OFF     0x22
#define  MEM_CONTROL    0x36
#define  COLMOD         0x3A
#define  SETCON         0x25
#define  ADDRX          0x2A
#define  ADDRY          0x2B
#define  MEMWRITE       0x2C
#define  RGBSET         0x2D
#define  NORMAL         0x20
#define  INVERT         0x21

#define  MEM_RGB        0x03 // 00001000    "0": ordre RGB, "1": BGR
#define  MEM_LAO        0x10 // 00010000    "0":haut vers bas, "1":bas vers haut
#define  MEM_VW         0x20 // 00100000    "0":écriture ds le sens X
                             //             "1":écriture ds le sens Y
#define  MEM_MX         0x00 // 01000000    "0":normal, "1":miroir en X
#define  MEM_MY         0x80 // 10000000    "0":normal, "1":miroir en Y
                             // Valeur utilisé ici = 0b11000000
                             //   Ordre RGB            ----0---
                             //   Haut vers Bas        ---0----
                             //   Sens X               --0-----
                             //   Mirroir X            -1------
                             //   Mirroir Y            1-------

#ifndef  ON
#define  ON           1
#endif

#ifndef  OFF
#define  OFF          0
#endif

#ifndef  YES
#define  YES          1
#endif

#ifndef  NO
#define  NO           0
#endif


#define  RGB(r,g,b)     ((r & 0xE0) | ((g & 0xE0) >> 3) | (b >> 6))
#define  NONE           RGB(0x00, 0x20, 0x00)  // == transparent, un vert en moin


#define BLUE        0x03
#define YELLOW      0xFC
#define RED         0XE0
#define GREEN       0X1C
#define BLACK       0X00
#define WHITE       0XFF
#define BRIGHTGREEN 0X3D
#define DARKGREEN   0X14
#define DARKRED     0XA0
#define DARKBLUE    0X02
#define BRIGHTBLUE  0X1F
#define ORANGE      0XF8

// Definições de cores do LCD
// cores em 12bits
#define BRANCO 0xFFF
#define PRETO 0x000
#define VERMELHO 0xF00
#define VERDE 0x0F0
#define AZUL 0x00F
#define CIANO 0x0FF
#define MAGENTA 0xF0F
#define AMARELO 0xFF0
#define MARRON 0xB22
#define LARANJA 0xFA0
#define ROSA 0xF6A


#byte    SSPCON1  =     0xFC6
#bit     SSPEN    =     SSPCON1.5


////////////////////////////////////////////////////////////////////////////////
////                                                                        ////
////                           Declaration des fonctions                    ////
////                                                                        ////
////////////////////////////////////////////////////////////////////////////////

void glcd_init(char contrast);
void glcd_off(void);
void glcd_write_command(char byteforglcd_command);
void glcd_write_data(char byteforglcd_data);
void glcd_write_dorc(char byteforglcd);
void glcd_cls(char color);
void glcd_setarea(char startx, char endx, char starty, char endy);
void glcd_contrast(char contrast);
void glcd_img(char x, char y);
void glcd_anim(char x, char y, int8 frame, int16 wait);
void glcd_font(void);
//int glcd_putc(int16 c);
void glcd_newline(void);
void glcd_gotoxy(char x, char y);
void glcd_fillscreen(char x1, char y1, char x2, char y2,char color);
void glcd_pixel(char x, char y, char color);
void glcd_line(char x1, char y1, char x2, char y2, char couleur);
void glcd_bar(char x1, char y1, char x2, char y2, char width, char color);
void glcd_rect(char x1, char y1, char x2, char y2, char width, int1 fill, char color);
void glcd_circle(char x, char y, char radius, int1 fill, char color);
void glcd_text57(char x, char y, char* textptr, char size, char color, char bkcolor);
void glcd_text812(char x, char y, char* textptr, char color, char bkcolor);
void glcd_color(char newColor);

////////////////////////////////////////////////////////////////////////////////
////                                                                        ////
////                 Librairie des fontes et images                         ////
////                                                                        ////
////////////////////////////////////////////////////////////////////////////////

#include <FONT57.c>
#include <FONT812.c>
#include <image.c>

////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//        Initialisation de l'afficheur                                       //
//                                                                            //
//        Param : contraste                                                   //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////


unsigned int32 i;
char color;


void glcd_init(char contrast)
{
   set_tris_c(0x00);

   output_bit(glcd_cs,TRUE);  // Controleur non sélectionné (CE = "1")
   delay_us(att1);
   output_bit(glcd_res,TRUE); // et pas de reset (RST = "1")
   delay_ms(10);             // Délai de 0,5s
   output_bit(glcd_res,FALSE);//Reset controleur (RST = "0")
   delay_ms(10);             // Délai de 0,5s
   output_bit(glcd_res,TRUE); //Arrêt reset (RST = "1")
   delay_us(att1);
   output_bit(glcd_cs,FALSE);// Sélection du controleur (CE = "0")
   delay_us(att1);   
   glcd_write_command(SOFT_RESET); // Software Reset
   delay_us(att1);
   glcd_write_command(SLEEP_OUT);  // Sleep Out
   delay_us(att1);
   glcd_write_command(BOOSTER_ON); // Booster ON
   delay_ms(10);
   glcd_write_command(DISPLAY_ON); // Display ON
   delay_us(att1);
   glcd_write_command(NORMAL);     // Mode NORMAL
   delay_us(att1);
   glcd_write_command(COLMOD);     // Commande mode couleur
   delay_us(att1);
   glcd_write_data(COLOR_8_BIT);   // envoyer Mode 256 couleurs
   delay_us(att1);
   glcd_write_command(RGBSET);     // Commande definition de la palette
                                   // de couleurs
   delay_us(att1);

   // Envoyer les données de la  palette pour RGB 256 couleurs
   // ROUGE
   glcd_write_data(0);
   delay_us(att1);
   glcd_write_data(2);
   delay_us(att1);
   glcd_write_data(4);
   delay_us(att1);
   glcd_write_data(6);
   delay_us(att1);
   glcd_write_data(8);
   delay_us(att1);
   glcd_write_data(10);
   delay_us(att1);
   glcd_write_data(12);
   delay_us(att1);
   glcd_write_data(15);
   delay_us(att1);
   // VERT
   glcd_write_data(0);
   delay_us(att1);
   glcd_write_data(2);
   delay_us(att1);
   glcd_write_data(4);
   delay_us(att1);
   glcd_write_data(6);
   delay_us(att1);
   glcd_write_data(8);
   delay_us(att1);
   glcd_write_data(10);
   delay_us(att1);
   glcd_write_data(12);
   delay_us(att1);
   glcd_write_data(15);
   delay_us(att1);
   // BLEU
   glcd_write_data(0);
   delay_us(att1);
   glcd_write_data(4);
   delay_us(att1);
   glcd_write_data(9);
   delay_us(att1);
   glcd_write_data(15);
   delay_us(att1);

   glcd_write_command(LCD_NOP);
   delay_us(att1);

   glcd_write_command(MEM_CONTROL);
   delay_us(att1);
   
   glcd_write_data(MEM_MY|MEM_MX);
   delay_us(att1);

   glcd_contrast(contrast);      // Ajuster le contraste ( 65 est pas mal )
   delay_us(att1);

   //glcd_cls(WHITE);              // Effacer l'ecran
   //delay_us(att1);

}
////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//        Arrêt de l'afficheur                                                //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////
void glcd_off(void)
{
   glcd_write_command(PIXELS_OFF);    // All pixels Off
   glcd_write_command(DISPLAY_OFF);   // Display Off
   glcd_write_command(BOOSTER_OFF);   // Booster Off
   glcd_write_command(SLEEP_IN);      // Sleep In
}

////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//        Envoie une commande                                                 //
//                                                                            //
//        Param : Commande                                                    //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////
void glcd_write_command(char byteforglcd_command)
{
   output_bit(glcd_sclk,FALSE);
   output_bit(glcd_cs,FALSE);

   // fala que sera enviado um comando
   output_bit(glcd_sdata,FALSE);
   output_high(glcd_sclk);
   output_low(glcd_sclk);

   glcd_write_dorc(byteforglcd_command);

   output_bit(glcd_cs,TRUE);
}

////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//        Envoie une donnée                                                   //
//                                                                            //
//        Param : donnée                                                      //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////
void glcd_write_data(char byteforglcd_data)
{
   output_bit(glcd_sclk,FALSE);
   output_bit(glcd_cs,FALSE);

   // seta que sera enviado um dado
   output_bit(glcd_sdata,TRUE);
   output_high(glcd_sclk);
   output_low(glcd_sclk);
   
   glcd_write_dorc(byteforglcd_data);

   output_bit(glcd_cs,TRUE);
}

////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//        Envoie d'un octet en mode série                                     //
//                                                                            //
//        Param : octet                                                       //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////
void glcd_write_dorc(char byteforglcd)
{
      output_bit(glcd_sdata,byteforglcd&0x80);
      output_high(glcd_sclk);
      output_low(glcd_sclk);
     
      output_bit(glcd_sdata,byteforglcd&0x40);
      output_high(glcd_sclk);
      output_low(glcd_sclk);
     
      output_bit(glcd_sdata,byteforglcd&0x20);
      output_high(glcd_sclk);
      output_low(glcd_sclk);
     
      output_bit(glcd_sdata,byteforglcd&0x10);
      output_high(glcd_sclk);
      output_low(glcd_sclk);
     
      output_bit(glcd_sdata,byteforglcd&0x08);
      output_high(glcd_sclk);
      output_low(glcd_sclk);
     
      output_bit(glcd_sdata,byteforglcd&0x04);
      output_high(glcd_sclk);
      output_low(glcd_sclk);
     
      output_bit(glcd_sdata,byteforglcd&0x02);
      output_high(glcd_sclk);
      output_low(glcd_sclk);
     
      output_bit(glcd_sdata,byteforglcd&0x01);
      output_high(glcd_sclk);
      output_low(glcd_sclk);
}

////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//        Efface l'écran                                                      //
//                                                                            //
//        Param : couleur 00 - FF                                             //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////
void glcd_cls(char color)
{
   unsigned int16 i,n;

   //glcd_write_command(DISPLAY_OFF);
   n = X_END*Y_END;
   glcd_setarea(X_START, X_END, Y_START, Y_END);
   glcd_write_command(MEMWRITE);
   for(i=n; i>0; i--)
   {
      glcd_write_data(color);
   }
   //glcd_write_command(DISPLAY_ON);
}

////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//        Délimite la zone d'écriture sur l'écran                             //
//                                                                            //
//        Param : startx, endx, starty, endy                                  //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////
void glcd_setarea(char startx, char endx, char starty, char endy)
{
   glcd_write_command(ADDRX);
   glcd_write_data(startx);
   glcd_write_data(endx);
   glcd_write_command(ADDRY);
   glcd_write_data(starty);
   glcd_write_data(endy);
}

////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//        Défini le contraste de l'affichage                                  //
//                                                                            //
//        Param : contraste  (65 = niveau standard)                           //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////
void glcd_contrast(char contrast)
{
   output_bit(glcd_cs,FALSE);
   delay_cycles(att2);
   glcd_write_command(SETCON);
   glcd_write_data(contrast);
   output_bit(glcd_cs,TRUE);
   delay_cycles(att2);
}

////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//        Affiche un pixel                                                    //
//                                                                            //
//        Param : x - absyse du pixel                                         //
//                y - ordonnée du pixel                                       //
//                color - 00 - FF                                             //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////
void glcd_pixel(char x, char y, char color)
{
   glcd_setarea(x, x, y, y);
   glcd_write_command(MEMWRITE);
   glcd_write_data(color);
}

////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//        Envoi une image sur l'afficheur                                     //
//                                                                            //
//        Param : x - absyse du pixel                                         //
//                y - ordonnée du pixel                                       //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////
void glcd_img(char x, char y)
{
   unsigned int16 i,n;
   char IMGENDX, IMGENDY;

   IMGENDX = img[0];
   IMGENDY = img[1];

   glcd_setarea(x,IMGENDX-1+x,y,IMGENDY-1+y);
   n = (IMGENDX*IMGENDY)+2;
   glcd_write_command(MEMWRITE);
   for(i=2; i<n; i++)
   {
      glcd_write_data(img[i]);
   }
}

////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//        Envoi une sequence d'image sur l'afficheur                          //
//                                                                            //
//        Param : x - absyse du pixel                                         //
//                y - ordonnée du pixel                                       //
//                frame - nombre d'images                                     //
//                wait - attente entre chaque image en ms                     //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////
void glcd_anim(char x, char y, int8 frame, int16 wait)
{
   unsigned int16 i,j,n;
   char IMGENDX, IMGENDY;

   IMGENDX = img_a[0];
   IMGENDY = img_a[1];

   glcd_setarea(x,IMGENDX-1+x,y,IMGENDY-1+y);
   n = IMGENDX*IMGENDY;
   glcd_write_command(MEMWRITE);
   for (j=0;j<frame;j++)
   {
     for(i=2; i<n+2; i++)
     {
         glcd_write_data(img_a[(j*n)+i]);
     }
     delay_ms(wait);
   }
}

////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//        positionne le curseur                                               //
//                                                                            //
//        Param : x - absyse du pixel                                         //
//                y - ordonnée du pixel                                       //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////
void glcd_gotoxy(char x, char y)
{
   glcd_setarea(x, x, y, y);
}

////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//        Modifie la couleur en cours                                         //
//                                                                            //
//        Param : newColor 00 - FF                                            //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////
void glcd_color(char newColor)
{
   color = newColor;
}

////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//        Rempli une partie de l'écran avec la couleur                        //
//                                                                            //
//        Param : startx, endx, starty, endy                                  //
//                Couleur du pixel 00 - FF                                    //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////
void glcd_fillscreen(char x1, char y1, char x2, char y2,char color)
{
   int16 dx,dy;
   int16 i,n;

   glcd_setarea(x1,x2,y1,y2);
   dx = (int16)abs((signed int16)(x2 - x1))+1;
   dy = (int16)abs((signed int16)(y2 - y1))+1;
   n = dx*dy;
   glcd_write_command(MEMWRITE);
   for(i=n; i>0; i--)
   {
      glcd_write_data(color);
   }
}

////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//        Trace une ligne                                                     //
//                                                                            //
//        Param : x1,y1 - coordonnée de départ                                //
//                x2,y2 - coordonnée de fin                                   //
//                color - 00 - FF                                             //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////
void glcd_line(char x1, char y1, char x2, char y2, char couleur)
{
   int16        dy, dx;
   signed int8  addx=1, addy=1;
   signed int16 P, diff;

   int8 i=0;
   dx = abs((signed int8)(x2 - x1));
   dy = abs((signed int8)(y2 - y1));

   if(x1 > x2)
      addx = -1;
   if(y1 > y2)
      addy = -1;

   if(dx >= dy)
   {
      dy *= 2;
      P = dy - dx;
      diff = P - dx;

      for(; i<=dx; ++i)
      {
         glcd_pixel(x1, y1, couleur);

         if(P < 0)
         {
            P  += dy;
            x1 += addx;
         }
         else
         {
            P  += diff;
            x1 += addx;
            y1 += addy;
         }
      }
   }
   else
   {
      dx *= 2;
      P = dx - dy;
      diff = P - dy;

      for(; i<=dy; ++i)
      {
         glcd_pixel(x1, y1, couleur);

         if(P < 0)
         {
            P  += dx;
            y1 += addy;
         }
         else
         {
            P  += diff;
            x1 += addx;
            y1 += addy;
         }
      }
   }

}


////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//        Trace une barre                                                     //
//                                                                            //
//        Param : x1,y1 - coordonnée de départ                                //
//                x2,y2 - coordonnée de fin                                   //
//                width - largeur de la barre                                 //
//                color - 00 - FF                                             //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////
void glcd_bar(char x1, char y1, char x2, char y2, char width, char color)
{
   signed int  x, y, addx, addy, j;
   signed long P, dx, dy, c1, c2;
   int i;

   dx = abs((signed int)(x2 - x1));
   dy = abs((signed int)(y2 - y1));
   x = x1;
   y = y1;
   c1 = -dx*x1 - dy*y1;
   c2 = -dx*x2 - dy*y2;

   if(x1 > x2)
   {
      addx = -1;
      c1 = -dx*x2 - dy*y2;
      c2 = -dx*x1 - dy*y1;
   }
   else
      addx = 1;
   if(y1 > y2)
   {
      addy = -1;
      c1 = -dx*x2 - dy*y2;
      c2 = -dx*x1 - dy*y1;
   }
   else
      addy = 1;

   if(dx >= dy)
   {
      P = 2*dy - dx;

      for(i=0; i<=dx; ++i)
      {
         for(j=-(width/2); j<width/2+width%2; ++j)
         {
            if(dx*x+dy*(y+j)+c1 >= 0 && dx*x+dy*(y+j)+c2 <=0)
               glcd_pixel((char)x, (char)(y+j), color);
         }
         if(P < 0)
         {
            P += 2*dy;
            x += addx;
         }
         else
         {
            P += 2*dy - 2*dx;
            x += addx;
            y += addy;
         }
      }
   }
   else
   {
      P = 2*dx - dy;

      for(i=0; i<=dy; ++i)
      {
         if(P < 0)
         {
            P += 2*dx;
            y += addy;
         }
         else
         {
            P += 2*dx - 2*dy;
            x += addx;
            y += addy;
         }
         for(j=-(width/2); j<width/2+width%2; ++j)
         {
            if(dx*x+dy*(y+j)+c1 >= 0 && dx*x+dy*(y+j)+c2 <=0)
               glcd_pixel((char)(x+j), (char)y, color);
         }
      }
   }
}

////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//        Trace un rectangle                                                  //
//                                                                            //
//        Param : x1,y1 - coordonnée de départ                                //
//                x2,y2 - coordonnée de fin                                   //
//                width - largeur du cadre                                    //
//                fill  - plein YES ou NO                                     //
//                color - couleur 00 - FF                                     //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////
void glcd_rect(char x1, char y1, char x2, char y2, char width, int1 fill, char color)
{
   if(fill)
   {
      int y, ymax;                          // Find the y min and max
      if(y1 < y2)
      {
         y = y1;
         ymax = y2;
      }
      else
      {
         y = y2;
         ymax = y1;
      }

      glcd_fillscreen(x1,y,x2,ymax,color);  // Draw box to fill the rectangle
   }
   else
   {
      if(width)
      {
         glcd_bar(x1, y1, x2, y1, width, color);      // Draw the 4 sides
         glcd_bar(x1, y2, x2, y2, width, color);
         glcd_bar(x1, y1, x1, y2, width, color);
         glcd_bar(x2, y1, x2, y2, width, color);
      }
      else
      {
         glcd_line(x1, y1, x2, y1, color);
         glcd_line(x1, y2, x2, y2, color);
         glcd_line(x1, y1, x1, y2, color);
         glcd_line(x2, y1, x2, y2, color);
      }
   }
}

////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//        Trace un cercle                                                     //
//                                                                            //
//        Param : x,y - centre du cercle                                      //
//                radius - rayon du cercle                                    //
//                fill  - plein YES ou NO                                     //
//                color - couleur 00 - FF                                     //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////
void glcd_circle(char x, char y, char radius, int1 fill, char color)
{
   signed int a, b, P;
   a = 0;
   b = radius;
   P = 1 - radius;

   do
   {
      if(fill)
      {
         glcd_line(x-a, y+b, x+a, y+b, color);
         glcd_line(x-a, y-b, x+a, y-b, color);
         glcd_line(x-b, y+a, x+b, y+a, color);
         glcd_line(x-b, y-a, x+b, y-a, color);
      }
      else
      {
         glcd_pixel(a+x, b+y, color);
         glcd_pixel(b+x, a+y, color);
         glcd_pixel(x-a, b+y, color);
         glcd_pixel(x-b, a+y, color);
         glcd_pixel(b+x, y-a, color);
         glcd_pixel(a+x, y-b, color);
         glcd_pixel(x-a, y-b, color);
         glcd_pixel(x-b, y-a, color);
      }

      if(P < 0)
         P+= 3 + 2*a++;
      else
         P+= 5 + 2*(a++ - b--);
    } while(a <= b);
}

////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//        Ecrit un texte avec la fonte 5 x 7 pixels                           //
//                                                                            //
//        Param : x,y - coordonnée supérieure gauche du premier caractère     //
//                textptr _ pointer sur un tableau chaine                     //
//                size - taille du texte : 1 = 5x7, 2 = 10x14                 //
//                color - couleur 00 - FF                                     //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////
void glcd_text57(char x, char y, char* textptr, char size, char color, char bkcolor)
{
   int8 j, k, l, m;                       // Loop counters
   int8 pixelData[5];                     // Stores character data

   for(; *textptr != '\0'; ++textptr, ++x)// Loop through the passed string
   {
      if(*textptr < 'S') // Checks if the letter is in the first font array
         memcpy(pixelData, FONT[*textptr - ' '], 5);
      else if(*textptr <= '~') // Check if the letter is in the second font array
         memcpy(pixelData, FONT2[*textptr - 'S'], 5);
      else
         memcpy(pixelData, FONT[0], 5);   // Default to space

       // Handles newline and carriage returns
      switch(*textptr)
      {
         case '\n':
            y += 7*size + 1;
            continue;
         case '\r':
            x = 0;
            continue;
      }

      if(x+5*size > X_END)          // Performs character wrapping
      {
         x = 0;                           // Set x at far left position
         y += 7*size + 1;                 // Set y at next position down
      }
      for(j=0; j<5; ++j, x+=size)         // Loop through character byte data
      {
         for(k=0; k < 7; ++k)             // Loop through the vertical pixels
         {
            if(bit_test(pixelData[j], k)) // Check if the pixel should be set
            {
               for(l=0; l < size; ++l)    // These two loops change the
               {                          // character's size
                  for(m=0; m < size; ++m)
                  {
                     glcd_pixel(x+m, y+k*size+l, color); // Draws the pixel
                  }


               }
            }
            else if (bkcolor != NONE)
               {
                  for(l=0; l < size; ++l)    // These two loops change the
                  {                          // character's size
                     for(m=0; m < size; ++m)
                     {
                        glcd_pixel(x+m, y+k*size+l, bkcolor); // Draws the pixel
                     }
                  }
               }
         }
      }
   }
}

////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//        Ecrit un texte avec la fonte 8 x 12 caracteres                      //
//                                                                            //
//        Param : x,y - coordonnée supérieure gauche du premier caractère     //
//                textptr _ pointer sur un tableau chaine                     //
//                color - couleur 00 - FF - NONE                              //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////
void glcd_text812(char x, char y, char* textptr, char color, char bkcolor)
{
   int8 j, k;                              // Loop counters
   int8 pixelData[16];                     // Stores character data

   for(; *textptr != '\0'; ++textptr)// Loop through the passed string
   {
      if(*textptr <= '~') //
         memcpy(pixelData, FONT812[*textptr - ' '], 16);
      else
         memcpy(pixelData, FONT812[0], 16);   // Default to space

       // Handles newline and carriage returns
      switch(*textptr)
      {
         case '\n':
            y += 12 + 1;
            continue;
         case '\r':
            x = 0;
            continue;
      }

      if(x+8 > X_END)          // Performs character wrapping
      {
         x = 0;                           // Set x at far left position
         y += 12 + 1;                 // Set y at next position down
      }
      for(j=0; j<8; j++, ++x)         // Loop through character byte data
      {
         for(k=0; k < 8; ++k)             // Loop through the vertical pixels
         {
            if(bit_test(pixelData[j], k)) // Check if the pixel should be set
            {
               glcd_pixel(x, y+k, color); // Draws the pixel
            }
            else if (bkcolor != NONE)
            {
               glcd_pixel(x, y+k, bkcolor); // Draws the pixel
            }

         }
         for(k=0; k < 4; ++k)             // Loop through the vertical pixels
         {
            if(bit_test(pixelData[j+8], k)) // Check if the pixel should be set
            {
               glcd_pixel(x, y+(k+8), color); // Draws the pixel
            }
              else if (bkcolor != NONE)
            {
               glcd_pixel(x, y+(k+8), bkcolor); // Draws the pixel
            }

         }

      }
      ++x;
   }
}



EXAMPLE with 18F4520:

Code:

//****************************************************************
//
//                           EXAMPLE_nokia6100.c
//
//****************************************************************

#include <18f452.h>

#use delay(clock=20000000)
#fuses HS


#define use_portb_lcd true
#include <pcf8833.c>
#include <string.h>

#define INC_X 2
#define INC_Y 2

void main(){
 
   char a[50];
   int i=20, j=20, xcl=0, ycl=0, tamX=10, tamY=10;
   signed int incX=0, incY=0;
   
   set_tris_c(0x00);          // Port C en sorties
   output_c(0x00);            // tout le port C à 0

   glcd_init(65);
   glcd_cls(PRETO);
   glcd_cls(BRANCO);
   glcd_cls(PRETO);
   
   
   while(1){

      glcd_fillscreen(i, j, i+tamX, j+tamY, PRETO);
     
      i += incX;
      j += incY;
     
      if(i>132 && incX > 0) i=0;
      else if(i==0 && incX < 0) i=132;
     
      if(j>132 && incY > 0) j=0;
      else if(j==0 && incY < 0) j=132;
     
      glcd_fillscreen(i, j,      i+tamX, j+tamY, BRANCO);
     
      if( input(PIN_D0) ) { incX = -INC_X; incY = 0; }
      if( input(PIN_D1) ) { incX =  INC_X; incY = 0; }
     
      if( input(PIN_D2) ) { incX = 0; incY = -INC_Y; }
      if( input(PIN_D3) ) { incX = 0; incY =  INC_Y; }
     
      delay_ms(100);
     
   /*
      strcpy(a, "Opa");
      glcd_text812(10,10,a,WHITE,PRETO);
      delay_ms(2000);
     
      strcpy(a, "Tudo bom?");
      glcd_text812(10,10,a,WHITE,PRETO);
      delay_ms(2000);
     
      strcpy(a, "Aqui tudo joia!");
      glcd_text812(10,10,a,WHITE,PRETO);
      delay_ms(2000);
     
      strcpy(a, "Abracao...");
      glcd_text812(10,10,a,WHITE,PRETO);
      delay_ms(2000);
     
      strcpy(a, "Opa");
      glcd_text812(10,10,a,WHITE,PRETO);
      delay_ms(2000);
      */
   }
   
}

opvini



Joined: 27 Apr 2012
Posts: 50
Location: Brazil

View user's profile Send private message

PostPosted: Tue May 20, 2014 1:57 pm     Reply with quote

I need to attach the includes:
Code:

#include <FONT57.c>
#include <FONT812.c>
#include <image.c>


I will attach on my webSite and post again the link to download all the files.

Thanks
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group