PIC ile SSD1963 kullanarak TFT'ye Dizi Basamıyorum

Başlatan Eren Eraslan, 29 Haziran 2014, 14:00:47

Eren Eraslan

Merhabalar. Bir projede PIC18F87K22 kullanarak SSD1963 barındıran TFT ekrana yazı yazdırmak istiyorum. İnternette zibilyon kadar STM32F için örnek kod yada driver olsada PIC için bulamadım. Kendi driver ımı kendim yazmakla başa büyük bela aldım . Fakat biraz ilerleme kaydettim. Şöyleki ekranın tamamına istediğim rengi basabiliyorum istediğim noktada 5x8 font kütüphanesinden 1 tane karakter basabiliyorum . Ama bu karakter basma olayını dizi olarak yapamadım . Yani sadece 1 karakter yazabiliyorum .  Bir cümle yazamadım. Kodlar aşşağıda. İlgili arkadaşlar yardımcı olursa çok memnun olurum teşekkürler.


#include <htc.h>
#include "delay.h"
#include "font5x8.h"
#define RS   RD0
#define nWR  RD1
#define nRD  RD2
#define CS	  RD3
#define RESET RD7
#define UD		RJ1
#define RL		RJ2

#define P1 PORTE



WORD  _color;

#define WriteColor(color1) { RS = 1; \
								P1 = (color1>>8); WR= 0; WR = 1; \
								P1 = (color1>>3); WR= 0; WR = 1; \
								P1 = (color1<<3); WR = 0; WR = 1; \
						   }

delayms(int n)
{
int i,j;
for(i=0;i<n;i++)
 {for(j=0;j<1000;j++)
    {;}
 }
}

Write_Command(unsigned char command)
{
        nRD = 1;
		P1 = command;
        RS = 0;
        nWR  = 0;
		CS = 0;
		CS = 1;
        nWR  = 1;
        
}

Write_Data(unsigned char data1)
{
        nRD = 1;
        P1 = data1;
		RS = 1;
        nWR  = 0;
		CS = 0;
		CS = 1;
        nWR  = 1;
}
//====================================================
Command_Write(unsigned char REG,unsigned char VALUE)
{
Write_Command(REG);
Write_Data(VALUE);
}
//======================================================
SendData(unsigned long color)
{
Write_Data((color)>>16);	//red
Write_Data((color)>>8);		//green
Write_Data(color);			//blue
}
//======================================================
// initialize controller
//======================================================
void Init_SSD1963 (void)
{
		RESET = 0;
		delayms(5);
		RESET = 1;
		delayms(100);
		Write_Command(0x01);     //Software Reset
		Write_Command(0x01);     //Software Reset
		Write_Command(0x01);     //Software Reset
		delayms(10);
		
	
		Command_Write(0xe0,0x01);    //START PLL
		DelayUs(100);
		Write_Command(0xe2);		
		Write_Data(0x34);
		Write_Data(0x02);
		Write_Data(0x04);
		Command_Write(0xe0,0x03);    //LOCK PLL
		
		Command_Write(0xe4,0x04);    //LOCK PLL
		
//		Write_Command(0xe2);		
//		Write_Data(0x34);
//		Write_Data(0x02);
//		Write_Data(0x54);
		
		Write_Command(0xb0);		//SET LCD MODE  SET TFT 18Bits MODE
		Write_Data(0x0c);			//SET TFT MODE & hsync+Vsync+DEN MODE
		Write_Data(0x80);			//SET TFT MODE & hsync+Vsync+DEN MODE
		Write_Data(0x01);			//SET horizontal size=320-1 HightByte
		Write_Data(0x3f);		    //SET horizontal size=320-1 LowByte
		Write_Data(0x00);			//SET vertical size=240-1 HightByte
		Write_Data(0xef);			//SET vertical size=240-1 LowByte
		Write_Data(0x00);			//SET even/odd line RGB seq.=RGB
		Command_Write(0xf0,0x00);	//SET pixel data I/F format=8bit
		//Command_Write(0x3a,0x50);
		
		Write_Command(0xe6);   		//SET PCLK freq=6.4MHz  ; pixel clock frequency
		Write_Data(0x00);
		Write_Data(0xE7);
		Write_Data(0x4f);
		
		Write_Command(0xb4);		//SET HBP, 
		Write_Data(0x01);			//SET HSYNC Total 440
		Write_Data(0xb8);
		Write_Data(0x00);			//SET HBP 68
		Write_Data(0x44);
		Write_Data(0x0f);			//SET VBP 16=15+1
		Write_Data(0x00);			//SET Hsync pulse start position
		Write_Data(0x00);
		Write_Data(0x00);			//SET Hsync pulse subpixel start position
		
		Write_Command(0xb6); 		//SET VBP, 
		Write_Data(0x01);			//SET Vsync total 265=264+1
		Write_Data(0x08);
		Write_Data(0x00);			//SET VBP=19
		Write_Data(0x13);
		Write_Data(0x07);			//SET Vsync pulse 8=7+1
		Write_Data(0x00);			//SET Vsync pulse start position
		Write_Data(0x00);
		
		Write_Command(0x2a);		//SET column address
		Write_Data(0x00);			//SET start column address=0
		Write_Data(0x00);
		Write_Data(0x01);			//SET end column address=319
		Write_Data(0x3f);
		
		Write_Command(0x2b);		//SET page address
		Write_Data(0x00);			//SET start page address=0
		Write_Data(0x00);
		Write_Data(0x00);			//SET end page address=239
		Write_Data(0xef);
		Write_Command(0x29);		//SET display on
}
//======================================================
WindowSet(unsigned int s_x,unsigned int e_x,unsigned int s_y,unsigned int e_y)
{
Write_Command(0x2a);		//SET page address
Write_Data((s_x)>>8);			//SET start page address=0
Write_Data(s_x);
Write_Data((e_x)>>8);			//SET end page address=319
Write_Data(e_x);

Write_Command(0x2b);		//SET column address
Write_Data((s_y)>>8);			//SET start column address=0
Write_Data(s_y);
Write_Data((e_y)>>8);			//SET end column address=239
Write_Data(e_y);

}
//=======================================
FULL_ON(unsigned long dat)
{
unsigned char x,y;
WindowSet(0x0000,0x013f,0x0000,0x00ef);
Write_Command(0x2c);
for(x=0;x<480;x++)
{
 for(y= 0;y<320;y++)
 {
 	SendData(dat);
 }
}
}
//=======================================
QUADS()
{
unsigned int i,j;
WindowSet(0x0000,0x013f,0x0000,0x00ef);
Write_Command(0x2c);
for(j= 0 ;j<120;j++)
  {
   for(i=0;i<160;i++)
   {
    SendData(0x0000FF);             //blue
   }
   for(i=0;i<160;i++)
   {
    SendData(0xFF0000);             //red
   }
 }
for(j= 0 ;j<120;j++)
  {
   for(i=0;i<160;i++)
   {
    SendData(0xFFFF00);             //yellow
   }
   for(i=0;i<160;i++)
   {
    SendData(0x00FF00);             //green
   }
 }
// Write_Command(0x2c);
// for(j= 0 ;j<320;j++)
//	  	 {
//	   		for(i=0;i<240;i++)
//	   		{
//		   				//SET display on
//	    		SendData(0xFF0000);             
//	   		}
//	
//	  	 } 
}
//=======================================

void main()
{

	unsigned int i,j;
	ADCON1=0x00;
	ADCON2=0x00;
	ADCON0=0x00;
	TRISE=0x00;
	TRISD=0x00;
	TRISJ=0x00;
	IRCF2=1;
	IRCF1=1;
	IRCF0=0;
	PLLEN=1;

 Init_SSD1963();
 delayms(1);

//*****************EKRANA ARKA FONT EKLİYOR****************************//
WindowSet(0x0000,0x013f,0x0000,0x00ef);
Write_Command(0x2c);
for(int a=0;a<480;a++)
{
 for(int b= 0;b<320;b++)
 {
 	SendData(0xFFFFFF);
 }
}
	while(1)
	{
//**************** " E " karakterini basan KOD ***********************//
unsigned int i,j,k,m;

WindowSet(100,104,100,107);
Write_Command(0x2c);

for(i=7;i>=0;i--)
  {
   for(j=185;j<190;j++)
   {
		if((font5x8[j]>>i)&0x01)
    	SendData(0x000000);  
	else
		SendData(0xffffff);  	       
   }
	delayms(1);
 }
}
insanın içine işleyen şarkılar ;  https://soundcloud.com/reeraslan

M_B

Merhaba hocam;

void SSD1963_LCD_ShowString(uint16_t x,uint16_t y,const uint8_t *p)
{         
    while(*p!='\0')
    {       
        if(x>LCD_W-16){x=0;y+=16;}
        if(y>LCD_H-16){y=x=0;SSD1963_LCD_Clear(WHITE);}
        SSD1963_LCD_ShowChar(x,y,*p,0); //0 olacak aksi halde yazi farkli cikiyor
        x+=LCD_Currentfonts->Bit;  
				//x+=16;
        p++;
    }  
}


void SSD1963_LCD_ShowChar(uint16_t x,uint16_t y,uint8_t num,uint8_t mode)
{
  uint16_t temp;  // uint8_t temp;
  uint8_t pos,t;
	uint16_t x0=x;
	uint16_t colortemp=POINT_COLOR;  
	uint8_t H,W;
	const uint16_t *cc;
	
	H=LCD_Currentfonts->Height;
	W=LCD_Currentfonts->Width;
	
    if(x>LCD_W-16||y>LCD_H-16)return;	
	
	num=num-' ';

	SSD1963_Address_set(x,y,x+LCD_Currentfonts->Bit-1,y+H-1);     //SSD1963_Address_set(x,y,x+8-1,y+16-1);     
	
	
		for(pos=0;pos<H;pos++)  
		{
			cc = &LCD_Currentfonts->table[(uint16_t)num*H+pos];
   			temp=cc[0];
														
				for(t=0;t<LCD_Currentfonts->Bit;t++)  
						{  
							if(H==24)		   // 16x24
									{
									
									if(temp&0x01)POINT_COLOR=colortemp;
									
											else
												POINT_COLOR=BACK_COLOR;
												LCD_WriteData(POINT_COLOR);	
												temp>>=1; 
												x++;			
									}

								if(H==8&&W==16)			// 16x8
									{ 									
									if(temp&0x01)POINT_COLOR=colortemp;
									
											else
												POINT_COLOR=BACK_COLOR;
												LCD_WriteData(POINT_COLOR);	
												temp>>=1; 
												x++;			
									}
						/***********************************************************/
								if(H==12&&W==12)		  //12x12	   
									{ 									
									if(temp&0x8000)POINT_COLOR=colortemp;
										 	else
												POINT_COLOR=BACK_COLOR;
												LCD_WriteData(POINT_COLOR);	
												temp=temp<<1;
												x++;	
									}	

								if(W==8&&H==8)		  //8x8	   
									{									
									if(temp&0x80)POINT_COLOR=colortemp;
											else
												POINT_COLOR=BACK_COLOR;
												LCD_WriteData(POINT_COLOR);	
												temp=temp<<1;
												x++;								
									}
									 
								if(W==8&&H==12)		  //8x12	   
									{									
									if(temp&0x80)POINT_COLOR=colortemp;
											else
												POINT_COLOR=BACK_COLOR;
												LCD_WriteData(POINT_COLOR);	
												temp=temp<<1;
												x++;								
									}					
									
									 
									}	// H 24 sonu
							 	   
				x=x0;	y++;
		}	
	POINT_COLOR=colortemp;	
}   

kodlarını kendınıze gore duzenleme yapabilirsiniz.
Forumda paylasmıs oldugum kutuphane olacak ordan da yardım alabilirsiniz.
İmkanın sınırlarını görmek için imkansızı denemek lazım.                                                             Fatih Sultan Mehmet

Eren Eraslan

#2
Forumda konuşulan konulardan incelediğim kodlarla şuana kadar dikdörtgen ve çember çizebiliyorum. Fakat bir dizi şeklinde font.h dan dataları alıp yazdıramıyorum .
Kendi yazdığım kodda font5x8 kütüphanesinden çağırdığım dataları ekrana bastırabiliyorum ama 1 adet.
Tek
void DrawChar(unsigned int X_pos, unsigned int Y_pos, unsigned int ASCII)
{
  	unsigned int i ,j;
	WindowSet(X_pos,X_pos+4,Y_pos,Y_pos+7);
	Write_Command(0x2c);

	for(i=7;i>=0;i--)
	  {
	   for(j=ASCII;j<ASCII+5;j++)
	   {
			if((font5x8[j]>>i)&0x01)
	    	SendData(0x000000);  
		else
			SendData(0xffffff);  	       
	   }
	 }

}

kendi yazdığım fonksiyonu aşşağıdaki gibi diziyi basabilen fonksiyonlara nasıl çevirebilirim?

void LCD_DrawChar(uint16_t Xpos, uint16_t Ypos, const uint16_t *c)
{
  uint32_t index = 0, i = 0;
  
  LCD_SetDisplayWindow(Xpos, Ypos, Xpos+(LCD_Currentfonts->Width-1), Ypos+(LCD_Currentfonts->Height-1));
  for(index = 0; index <LCD_Currentfonts->Height; index++)
  {
    for(i = 0; i < LCD_Currentfonts->Width; i++)
    {
      if((((c[index]& ((0x80 << ((LCD_Currentfonts->Width / 12 ) * 8 ) ) >> i)) == 0x00) &&(LCD_Currentfonts->Width <= 12))||
        (((c[index] & (0x1 << i)) == 0x00)&&(LCD_Currentfonts->Width > 12 )))
      {
        LCD_WriteData(BackColor);
      }
      else
      {
        LCD_WriteData(TextColor);
      } 
    }
  }
}

/**
  * @brief  Displays one character (16dots width, 24dots height).
  * @param  Line: the Line where to display the character shape .
  *   This parameter can be one of the following values:
  *     @arg Linex: where x can be 0..9
  * @param  Column: start column address.
  * @param  Ascii: character ascii code, must be between 0x20 and 0x7E.
  * @retval None
  */
void LCD_DisplayChar(uint16_t Line, uint16_t Column, uint8_t Ascii)
{
  Ascii -= 32;
  LCD_DrawChar(Line, Column, &LCD_Currentfonts->table[Ascii * LCD_Currentfonts->Height]);
}


/**
  * @brief  Sets the Text Font.
  * @param  fonts: specifies the font to be used.
  * @retval None
  */
void LCD_SetFont(sFONT *fonts)
{
  LCD_Currentfonts = fonts;
}

/**
  * @brief  Displays a maximum of 20 char on the LCD.
  * @param  Line: the Line where to display the character shape .
  *   This parameter can be one of the following values:
  *     @arg Linex: where x can be 0..9
  * @param  *ptr: pointer to string to display on LCD.
  * @retval None
  */
void LCD_DisplayStringLine(uint16_t Xpos, uint16_t Ypos, uint8_t *ptr)
{
  uint16_t refcolumn = Xpos, refrow = Ypos;

  /* Send the string character by character on lCD */
  while (*ptr != 0)
  {
    /* Display one character on LCD */
    LCD_DisplayChar(refcolumn, refrow, *ptr);
    /* increment the column position by 16 */
    refcolumn += LCD_Currentfonts->Width;
      if (refcolumn>=LCD_PIXEL_WIDTH-1) 
      {
         refcolumn=0;
         refrow+=LCD_Currentfonts->Height;
      }
    /* Point on the next character */
    ptr++;
  }   
}


mesaj birleştirme:: 30 Haziran 2014, 12:54:50

Alıntı yapılan: M_B - 29 Haziran 2014, 15:02:19
Merhaba hocam;

void SSD1963_LCD_ShowString(uint16_t x,uint16_t y,const uint8_t *p)
{         
    while(*p!='\0')
    {       
        if(x>LCD_W-16){x=0;y+=16;}
        if(y>LCD_H-16){y=x=0;SSD1963_LCD_Clear(WHITE);}
        SSD1963_LCD_ShowChar(x,y,*p,0); //0 olacak aksi halde yazi farkli cikiyor
        x+=LCD_Currentfonts->Bit;  
				//x+=16;
        p++;
    }  
}


void SSD1963_LCD_ShowChar(uint16_t x,uint16_t y,uint8_t num,uint8_t mode)
{
  uint16_t temp;  // uint8_t temp;
  uint8_t pos,t;
	uint16_t x0=x;
	uint16_t colortemp=POINT_COLOR;  
	uint8_t H,W;
	const uint16_t *cc;
	
	H=LCD_Currentfonts->Height;
	W=LCD_Currentfonts->Width;
	
    if(x>LCD_W-16||y>LCD_H-16)return;	
	
	num=num-' ';

	SSD1963_Address_set(x,y,x+LCD_Currentfonts->Bit-1,y+H-1);     //SSD1963_Address_set(x,y,x+8-1,y+16-1);     
	
	
		for(pos=0;pos<H;pos++)  
		{
			cc = &LCD_Currentfonts->table[(uint16_t)num*H+pos];
   			temp=cc[0];
														
				for(t=0;t<LCD_Currentfonts->Bit;t++)  
						{  
							if(H==24)		   // 16x24
									{
									
									if(temp&0x01)POINT_COLOR=colortemp;
									
											else
												POINT_COLOR=BACK_COLOR;
												LCD_WriteData(POINT_COLOR);	
												temp>>=1; 
												x++;			
									}

								if(H==8&&W==16)			// 16x8
									{ 									
									if(temp&0x01)POINT_COLOR=colortemp;
									
											else
												POINT_COLOR=BACK_COLOR;
												LCD_WriteData(POINT_COLOR);	
												temp>>=1; 
												x++;			
									}
						/***********************************************************/
								if(H==12&&W==12)		  //12x12	   
									{ 									
									if(temp&0x8000)POINT_COLOR=colortemp;
										 	else
												POINT_COLOR=BACK_COLOR;
												LCD_WriteData(POINT_COLOR);	
												temp=temp<<1;
												x++;	
									}	

								if(W==8&&H==8)		  //8x8	   
									{									
									if(temp&0x80)POINT_COLOR=colortemp;
											else
												POINT_COLOR=BACK_COLOR;
												LCD_WriteData(POINT_COLOR);	
												temp=temp<<1;
												x++;								
									}
									 
								if(W==8&&H==12)		  //8x12	   
									{									
									if(temp&0x80)POINT_COLOR=colortemp;
											else
												POINT_COLOR=BACK_COLOR;
												LCD_WriteData(POINT_COLOR);	
												temp=temp<<1;
												x++;								
									}					
									
									 
									}	// H 24 sonu
							 	   
				x=x0;	y++;
		}	
	POINT_COLOR=colortemp;	
}   

kodlarını kendınıze gore duzenleme yapabilirsiniz.
Forumda paylasmıs oldugum kutuphane olacak ordan da yardım alabilirsiniz.

hocam pointerları birtürlü düzgün kullanamadım daha basit anlatabilir misiniz mesela  const uint16_t *cc; ne oluyor
insanın içine işleyen şarkılar ;  https://soundcloud.com/reeraslan