Autor Tema: Libreria LCD ST9720 Sitronix CCS  (Leído 1548 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado sirias52

  • PIC10
  • *
  • Mensajes: 40
Libreria LCD ST9720 Sitronix CCS
« en: 12 de Abril de 2013, 04:44:33 »
Hola Colegas, necesito un poco de su ayuda. Estoy tratando de hacer la librería para este LCD, pero resulta que me ha costado comprender de que manera puedo crear la función de dibujar pixeles (drawpixel); ya es algo tarde y por eso ya la cabeza no me da  :(.

Citar
void GLCDInit(void)
{
delay_ms(40);
output_low(GLCD_RST);         //reset LCD
delay_us(1);                     
output_high(GLCD_RST);        //LCD normal operation
//Lcd_SendByte(Cmd,0b00100000);// 4-bit mode.
Lcd_SendByte(Cmd,LCD_CMODE );//8bit mode 0x30
delay_us (100);
//Lcd_SendByte(Cmd,0b00100000);// 4-bit mode again.
Lcd_SendByte(Cmd,LCD_CMODE);// 8-bit mode again. 0x30
delay_us (37);
Lcd_SendByte(Cmd,LCD_ON );// Cursor and blinking cursor disabled. 0x0C
delay_us (100);
Lcd_SendByte(Cmd,LCD_CLS);// Clears screen. 0x01
delay_ms(10);
Lcd_SendByte(Cmd,LCD_ENTRY);// Cursor moves right, no display shift. 0x06
delay_us (72);
Lcd_SendByte(Cmd,LCD_HOME);// Returns to home. Cursor moves to starting point. 0x02


void glcd_checkstate(){
   int1 busy=1;
   output_low(GLCD_RS);      // LOW RS and High RW will put the lcd to
   output_high(GLCD_RW);      // read busy flag and address counter
   while(busy){         // will cycle until busy flag is 0
      output_high(GLCD_E);
      if(!input(PIN_B7)){
         busy=0;
      }
      output_low(GLCD_E);
   }
}

void Lcd_SendByte(int1 DatCmd,unsigned char dByte) // Write Data or Command to LCD
{
  glcd_checkstate();
  if(DatCmd==1){
     output_high(GLCD_RS); //data
  }
  else{
     output_low(GLCD_RS); //command
  }
output_low(GLCD_RW);
output_b(dByte);
output_high(GLCD_E);      // enable
delay_us(1);       
output_low(GLCD_E);      // disable

}
void GLCDWriteText(unsigned char col, unsigned char row, char* string)
{
    switch (row) {
        case 0:
            col |= 0x80;
            break;
        case 1:
            col |= 0x90;
            break;
        case 2:
            col |= 0x88;
            break;
        case 3:
            col |= 0x98;
            break;
        default:
            col |= 0x80;
            break;
    }

    Lcd_SendByte(Cmd,col);

    while (*string)
    Lcd_SendByte(Data,*string++);
}

void GLCDEnableGraphics()
{

   Lcd_SendByte(Cmd,0x34);// Switch to extended instruction mode.
   delay_us(72);
   Lcd_SendByte(Cmd,0x36);         // Enable graphics mode.
   delay_us(72);
 
}


void st7920_drawPixel(int8 x, int8 y)
{

}

Me he guiado con estos dos links

http://www.ccsinfo.com/forum/viewtopic.php?p=173306

http://www.ccsinfo.com/forum/viewtopic.php?p=91958

Decidí hacer mi versión debido a que he probado estas librerías, y no funciona la parte de dibujar pixel, ademas de que ocupa demasiada RAM. Bueno en fin espero podamos resolver este problemilla :)
« Última modificación: 12 de Abril de 2013, 04:58:26 por sirias52 »

Desconectado sirias52

  • PIC10
  • *
  • Mensajes: 40
Re: Libreria LCD ST9720 Sitronix CCS
« Respuesta #1 en: 12 de Abril de 2013, 20:38:49 »
Bueno la librería ya quedaría de estamanera

Citar
void GLCDInit(void)
{
delay_ms(40);
output_low(GLCD_RST);         //reset LCD
delay_us(1);                     
output_high(GLCD_RST);        //LCD normal operation
//Lcd_SendByte(Cmd,0b00100000);// 4-bit mode.
Lcd_SendByte(Cmd,LCD_CMODE );//8bit mode 0x30
delay_us (100);
//Lcd_SendByte(Cmd,0b00100000);// 4-bit mode again.
Lcd_SendByte(Cmd,LCD_CMODE);// 8-bit mode again. 0x30
delay_us (37);
Lcd_SendByte(Cmd,LCD_ON );// Cursor and blinking cursor disabled. 0x0C
delay_us (100);
Lcd_SendByte(Cmd,LCD_CLS);// Clears screen. 0x01
delay_ms(10);
Lcd_SendByte(Cmd,LCD_ENTRY);// Cursor moves right, no display shift. 0x06
delay_us (72);
Lcd_SendByte(Cmd,LCD_HOME);// Returns to home. Cursor moves to starting point. 0x02

}
void glcd_checkstate(){
   int1 busy=1;
   output_low(GLCD_RS);      // LOW RS and High RW will put the lcd to
   output_high(GLCD_RW);      // read busy flag and address counter
   while(busy){         // will cycle until busy flag is 0
      output_high(GLCD_E);
      if(!input(PIN_B7)){
         busy=0;
      }
      output_low(GLCD_E);
   }
}

void Lcd_SendByte(int1 DatCmd,unsigned char dByte) // Write Data or Command to LCD
{
  glcd_checkstate();
  if(DatCmd==1){
     output_high(GLCD_RS); //data
  }
  else{
     output_low(GLCD_RS); //command
  }
output_low(GLCD_RW);
output_b(dByte);
output_high(GLCD_E);      // enable
delay_us(1);       
output_low(GLCD_E);      // disable

}
void GLCDWriteText(unsigned char col, unsigned char row, char* string)
{
    switch (row) {
        case 0:
            col |= 0x80;
            break;
        case 1:
            col |= 0x90;
            break;
        case 2:
            col |= 0x88;
            break;
        case 3:
            col |= 0x98;
            break;
        default:
            col |= 0x80;
            break;
    }

    Lcd_SendByte(Cmd,col);

    while (*string)
    Lcd_SendByte(Data,*string++);
}

void GLCDEnableGraphics()
{

   Lcd_SendByte(Cmd,0x34);// Switch to extended instruction mode.
   delay_us(72);
   Lcd_SendByte(Cmd,0x36);         //  graphics display ON.
   delay_us(72);
 
}


void glcd_pixel(int8 x, int8 y,int1 color )
{
int8 page;
int16 val;
if(y<32){page=0x80;}
else{y-=32;page=0x88;}
val = 0x8000 >> (x & 0xF);
Lcd_SendByte(Cmd,(0x80 | y));
Lcd_SendByte(Cmd,(page | (x >> 4)));
Lcd_SendByte(Data,val >> 8);
Lcd_SendByte(Data,val & 0xFF);
}


/*void Set_CGRAM_DDRAM (int Adresscounter,int adress_counter)
{

Lcd_SendByte(Cmd,Adresscounter);              //DDRAM Horizontal adress (80H-BFH) 0-128 x 4 filas
Lcd_SendByte(Cmd,(adress_counter|0x40));      //CGRAM vertical adress  (00H-3FH) 0-63
Lcd_SendByte(Data,1);
}

void Set_GDRAM (int8  adress_counter_x,int8 adress_counter_y)
{

Lcd_SendByte(Cmd,(0x80|adress_counter_x));              //DDRAM Horizontal adress (80H-BFH) 0-128 x 4 filas
Lcd_SendByte(Cmd,(0x80|adress_counter_y));      //CGRAM vertical adress  (00H-3FH) 0-63
Lcd_SendByte(Data,1);
}*/

void GLCDClearGraphics()
{

   unsigned char x, y;
   for(y = 0; y < 64; y++)
   {
      if(y < 32)
      {
         Lcd_SendByte(Cmd,0x80 | y);
          Lcd_SendByte(Cmd,0x80);
      }
      else
      {
         Lcd_SendByte(Cmd,(0x80 | (y-32)));
         Lcd_SendByte(Cmd,0x88);
      }
      for(x = 0; x < 8; x++)
      {
         Lcd_SendByte(Data,0x00);
         Lcd_SendByte(Data,0x00);
      }
   }
}


Cualquier mejora es bienvenida. Posiblemente suba un video demostrativo