C Programlama diliyle şamatalar

Başlatan z, 23 Ekim 2011, 15:32:04

armsistem

#435
Arkadaşlar merhaba işlemcinin Flash memory'sini okurken problem yaşıyorum (C diline tam hakim olmamamdan kaynaklanıyor)

Aşağıdaki diziyi flash memory yazıyorum.
unsigned char const demo_messg[] = 
{
0x70, 0x40, 0x2D, 0xE9, 0x00, 0x40, 0xA0, 0xE1, 0x01, 0x50, 0xA0, 0xE1, 0x05, 0x10, 0xA0, 0xE1
} ;


Okumak için aşağıdaki kodları kullanıyorum.
char *oku; // 8 bit değişken

oku = (char*)0x7000;   // flash memory yazılı olduğun adresi

u1_string_gonder(oku); // çıktı  70 40 2D E9


Buraya kadar problem yok.
Adresleme mantığı aşağıdaki gibi midir ?
0x7000 ---- 70
0x7001 ---- 40
0x7002 ---- 2D
0x7003 ---- E9
......................


Kodları aşağıdaki gibi değiştirdiğimde
oku = (char*)0x7003;   // flash memory yazılı olduğun adresi

u1_string_gonder(oku); // çıktı   E9


7000-7001-7002-7003 ----- bir hücremidir ?
7000-7001-7002-7003 = char mıdır ?
adres arttırma yoluyla oku=oku+4; şeklinde mi olur ?

Aşağıdaki bloklar halinde nasıl okurum.
7000-7001-7002-7003
7004-7005-7006-7007

haydarpasamikro

demo_messg zaten dizinin başlangış adresini tutar. Yani adrestir. Siz bunun adrsinin 7000 olduğunu nerden biliyorsunuz? Bilseniz bile derleyici bu adresi kendi atadığı için sabit adres üzerinden gitmek doğru olmaz. Kısaca bu işi derleyiciye bırakın. Siz dizinin adresini alın.

Örnek:
char dizim[]={0x01,0x02,0x03,0x04};
char *a;

a= dizi;
a=&dizi[0] gibi... dizinin adresini karakteri gösteren a göstericisine yüklüyoruz. Böylece a içerisinde dizinin adresi tutuluyor.
*a dersek, a nın gösterdiği adresteki(dizi[0], 0x01) eleman kastedilmiş olur.
Mikro Dünyası.Haydarpaşa Teknik ve Endüstri Meslek Lisesi Mikrodenetleyici Atl. Şefi

armsistem

#437
Merhaba , 7000 olduğunu nereden biliyorum , çünkü o adrese ben yazıyorum orası işlemcinin flash memory adresi. Okumaya çalıştığım ve kısmen okuduğum yer flash memory.

Mucit23

Ekrana içi dolu bir daire çizmek istiyorum. Elimde sadece nokta koyma fonksiyonum var. verdiğim X ve Y koordinatlarına Nokta koyuyor.

İnternette çok fazla kod var. Çember çizebiliyorum ama içini nasıl doldururum. Örnek bir kod parçacığı verebilirmisiniz.

AsHeS

#439
Alıntı yapılan: Mucit23 - 18 Mart 2013, 22:01:15
Ekrana içi dolu bir daire çizmek istiyorum. Elimde sadece nokta koyma fonksiyonum var. verdiğim X ve Y koordinatlarına Nokta koyuyor.

İnternette çok fazla kod var. Çember çizebiliyorum ama içini nasıl doldururum. Örnek bir kod parçacığı verebilirmisiniz.
Şimdi hocam ben bir algoritma önereyim elinde merkezin olsun,bir d diye bir açı değişkeni olsun  x=r*cos(d);ve y=r*sin(d) olarak pixel noktalarını tarayabilirsin.Tabii ki döngünün değişkeni r ve d olmak üzere.
EDİT:Şimdi ekranın göbek noktasının 0,0 olarak kabul etmişim ama diyelim ki 50,50 olsun  x=r*cos(d)+50; y=r*sin(d)+50; olur.

Mucit23

Evet hocam o kodlarla çember çiziyorum. Fakat Çemberin içi dolu olmasıni istersem ne yapmam gerekir.

AsHeS

Alıntı yapılan: Mucit23 - 18 Mart 2013, 22:19:45
Evet hocam o kodlarla çember çiziyorum. Fakat Çemberin içi dolu olmasıni istersem ne yapmam gerekir.
E tamam işte daire dediğin şey iç içe geçmiş çemberlerdir tabii senin kullandığın GLCD ya da TFT pixellerden oluşuyor dolayısıyla r yi sabit tutarsan 1 çember r yi değişken yaparsan ve maksimum değeride istediğin sayıya eşitlersen oldu sana içi dolu daire :)

Mucit23

anladım. yarı çap kadar iç içer geçmiş çember çizmek gerekiyor sanırım.

AsHeS

Alıntı yapılan: Mucit23 - 18 Mart 2013, 22:31:19
anladım. yarı çap kadar iç içer geçmiş çember çizmek gerekiyor sanırım.
Aynen hocam mesela yarıçap ve derecenin değişim miktarını en iyi deneyerek görebilirsiniz,mesela r aralıkları geniş olursa aralıklarla çemberler çıkar daha sıkı olursa daire olur eğer derece değişkeninin aralıkları dar olursa daire kesik kesik çıkar mesela bunları optimize edebilirsiniz.

Mucit23

Tamam Hocam. Aklıma bir iki yöntem geldi. Yarın deneyeceğim

AsHeS

Alıntı yapılan: Mucit23 - 18 Mart 2013, 22:56:03
Tamam Hocam. Aklıma bir iki yöntem geldi. Yarın deneyeceğim
Hocam mesela çember çizdirmek için değişik bir algoritmanız varsa onu da kullanabilirsiniz aralıklarla çoklu çember çizdirerek.

Mucit23

Hocam yaptım birşeyler hem oldu hemde oldu.

Bu iş için şöyle bir fonksiyon yazdım.

void GLCD_Point(unsigned int x, unsigned int y, unsigned int size)
{
	int pointx=0, pointy=0;
	int angle, temp; 
	for(temp=1;temp<size+1;temp++)
	{
	  for(angle=0;angle<360;angle++)
	  {                                   
	  		pointx = x + (temp * cos((pi * angle)/180));
	      pointy = y + (temp * sin((pi * angle)/180));
		    GLCD_PutPixel(pointx,pointy);
    }
  }

}


Çalıştı bu şekilde. Çember çizip içini doldurabiliyorum. Lakin bu kodlar çok yavaş çalıştı. Yani Size değerini 10 verirsem eğer ekranda bir dairenin çizilmesi 700-800 ms yi buluyor. Dairenin içinin dolduğunu görüyorum. TFT ekranda bunu yapmaya çalışıyorum. Kullandığım işlemci STM32, 64Mhz de çalıştırıyorum.

bocek

#447
@mucit23 bir de bunu dener misin?
/**************************************************************************************************
* File name		: graphic.c
* Programmer 	: jaruwit supa
* Web presence  : [url=http://www.thaibestlink.com]www.thaibestlink.com[/url]
* Note			: lcd graphic support
* Language		: avrGCC
* Hardware		: atmega16
* Date			: 01/05/2009
************************************************************************************************/

/* _____STANDARD INCLUDES____________________________________________________ */
#include <avr/io.h>
#include <stdlib.h>

/* _____PROJECT INCLUDES_____________________________________________________ */
#include "graphic.h"

/* _____LOCAL DEFINE_________________________________________________________ */

/* _____LOCAL VARIABLES______________________________________________________ */

/* _____LOCAL FUNCTIONS______________________________________________________ */

/* _____PUBLIC FUNCTIONS_____________________________________________________ */

/*********************************************************************
* Function     : void Line(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2)
* Description  : Draw a line on a graphic LCD using Bresenham's
* PreCondition : SetColor()
* Input        : x1,y1 - starting coordinates
*              : x2,y2 - ending coordinates
* Output       : none
* Note         : none
********************************************************************/
void Line(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2)
{
	signed int  x, y, addx, addy, dx, dy;
	signed long P;
	int i;
/*
	if (x1>x2)
	{
		dx = x1; x1 = x2; x2 = dx;
		dy = y1; y1 = y2; y2 = dy;
	}

	// vertical line
	if ((x1 == x2) || (y1 == y2))
	{
		FillRectangle(x1, y1, x2, y2);
		return;
	}
*/
	dx = abs((signed int)(x2 - x1));
	dy = abs((signed int)(y2 - y1));
	x = x1;
	y = y1;

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

	if (dx >= dy)
	{
		P = 2L*dy - dx;
		for (i=0; i<=dx; ++i)
		{
	  		DrawPixel(x, y);
			if(P < 0)
	  		{
	    		P += 2*dy;
	    		x += addx;
	  		}
			else
			{
	    		P += 2*dy - 2*dx;
	    		x += addx;
	    		y += addy;
	  		}
		}
	}
	else
	{
		P = 2L*dx - dy;
		for(i=0; i<=dy; ++i)
		{
	  		DrawPixel(x, y);
	  		if(P < 0)
	  		{
	    		P += 2*dx;
	    		y += addy;
	  		}
	  		else
	  		{
	    		P += 2*dx - 2*dy;
	    		x += addx;
	    		y += addy;
	  		}
		}
	}
}

/*********************************************************************
* Function    : void Rectangle(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, unsigned int rad)
* Description : Draws a beveled figure on the screen. 
* PreCondition: None
* Input       : x1, y1 - coordinate position of the upper left center
*		      : x2, y2 - coordinate position of the lower right center
*             : rad - defines the redius of the circle,
* Output      : None
* Note        : None
********************************************************************/
void Rectangle(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, unsigned int radius)
{
	signed int a, b, P;
	signed int bx, ay;

	// adjust size
	x1 = x1 + radius;
	x2 = x2 - radius;
	y1 = y1 + radius;
	y2 = y2 - radius;

	DrawRect(x1       , y1-radius, x2       , y1-radius);	// top
	DrawRect(x1       , y2+radius, x2       , y2+radius);	// bottom
	DrawRect(x1-radius, y1       , x1-radius, y2       );	// left
	DrawRect(x2+radius, y1       , x2+radius, y2       );	// right

	if (radius == 0)
		return;

	// draw broder
	a = 0;       // increment by 1
	b = radius;  // decrement by 1 using P
	P = 1 - radius;
	bx = b;
	ay = a;

	do
	{
		if (a && (a != b))
		{
			DrawPixel(x1-b, y1-a);
			DrawPixel(x1-b, y2+a);
			DrawPixel(x2+b, y1-a);
			DrawPixel(x2+b, y2+a);
		}
		DrawPixel(x1-a, y1-b);
		DrawPixel(x2+a, y1-b);
		DrawPixel(x1-a, y2+b);
		DrawPixel(x2+a, y2+b);

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

void RectangleFill(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, unsigned int radius)
{
	signed int a, b, P;
	signed int bx, ay;

	if (radius == 0)
	{
	    DrawRect(x1, y1, x2, y2);
		return;
	}
	// adjust size
	x1 = x1 + radius;
	x2 = x2 - radius;
	y1 = y1 + radius;
	y2 = y2 - radius;

	a = 0;       // increment by 1
	b = radius;  // decrement by 1 using P
	P = 1 - radius;
	bx = b;
	ay = a;
	
	DrawRect(x1, y1-radius, x2, y2+radius);
	do
	{
		if (bx != b)
		{
			DrawRect(x1-bx, y1-ay, x1-bx, y2+ay); // left in
			DrawRect(x2+bx, y1-ay, x2+bx, y2+ay); // right in
			bx = b;
		}
  		ay = a;
		if (a != b)
		{ 
			DrawRect(x1-a, y1-b, x1, y2+b); // left out
			DrawRect(x2  , y1-b, x2+a, y2+b); // rigth out
  		}
		if(P < 0)
			P+= 3 + 2*a++;
		else
			P+= 5 + 2*(a++ - b--);
	} while(a <= b);

	if (bx != b)
	{
		DrawRect(x1-bx, y1-ay, x1-bx, y2+ay); // left in
		DrawRect(x2+bx, y1-ay, x2+bx, y2+ay); // right in
	}
}
/*********************************************************************
* Function    : void Circle(unsigned int x, unsigned int y, unsigned int radius, unsigned char fill)
* Description : Draw a circle on the screen. 
* PreCondition: None
* Input       : x,y - the center of the circle
*             : rad - defines the redius of the circle,
*             : fill - fill yes or no
* Output      : None
* Note        : None
********************************************************************/
void CircleFill(unsigned int x, unsigned int y, unsigned int radius, unsigned char fill)
{
   signed int a, b, P;
   a = 0;
   b = radius;
   P = 1 - radius;

   do
   {
      if(fill)
      {
         DrawRect(x-a, y+b, x+a, y+b);
         DrawRect(x-a, y-b, x+a, y-b);
         DrawRect(x-b, y+a, x+b, y+a);
         DrawRect(x-b, y-a, x+b, y-a);
      }
      else
      {
         DrawPixel(a+x, b+y);
         DrawPixel(b+x, a+y);
         DrawPixel(x-a, b+y);
         DrawPixel(x-b, a+y);
         DrawPixel(b+x, y-a);
         DrawPixel(a+x, y-b);
         DrawPixel(x-a, y-b);
         DrawPixel(x-b, y-a);
      }

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

tabii uyarlaması sana kalmış.
1 ya da 0. işte 'bit'ün mesele..

Mucit23

Alıntı yapılan: bocek - 19 Mart 2013, 10:34:04
@mucit23 bir de bunu dener misin?
/**************************************************************************************************
* File name		: graphic.c
* Programmer 	: jaruwit supa
* Web presence  : [url=http://www.thaibestlink.com]www.thaibestlink.com[/url]
* Note			: lcd graphic support
* Language		: avrGCC
* Hardware		: atmega16
* Date			: 01/05/2009
************************************************************************************************/

/* _____STANDARD INCLUDES____________________________________________________ */
#include <avr/io.h>
#include <stdlib.h>

/* _____PROJECT INCLUDES_____________________________________________________ */
#include "graphic.h"

/* _____LOCAL DEFINE_________________________________________________________ */

/* _____LOCAL VARIABLES______________________________________________________ */

/* _____LOCAL FUNCTIONS______________________________________________________ */

/* _____PUBLIC FUNCTIONS_____________________________________________________ */

/*********************************************************************
* Function     : void Line(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2)
* Description  : Draw a line on a graphic LCD using Bresenham's
* PreCondition : SetColor()
* Input        : x1,y1 - starting coordinates
*              : x2,y2 - ending coordinates
* Output       : none
* Note         : none
********************************************************************/
void Line(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2)
{
	signed int  x, y, addx, addy, dx, dy;
	signed long P;
	int i;
/*
	if (x1>x2)
	{
		dx = x1; x1 = x2; x2 = dx;
		dy = y1; y1 = y2; y2 = dy;
	}

	// vertical line
	if ((x1 == x2) || (y1 == y2))
	{
		FillRectangle(x1, y1, x2, y2);
		return;
	}
*/
	dx = abs((signed int)(x2 - x1));
	dy = abs((signed int)(y2 - y1));
	x = x1;
	y = y1;

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

	if (dx >= dy)
	{
		P = 2L*dy - dx;
		for (i=0; i<=dx; ++i)
		{
	  		DrawPixel(x, y);
			if(P < 0)
	  		{
	    		P += 2*dy;
	    		x += addx;
	  		}
			else
			{
	    		P += 2*dy - 2*dx;
	    		x += addx;
	    		y += addy;
	  		}
		}
	}
	else
	{
		P = 2L*dx - dy;
		for(i=0; i<=dy; ++i)
		{
	  		DrawPixel(x, y);
	  		if(P < 0)
	  		{
	    		P += 2*dx;
	    		y += addy;
	  		}
	  		else
	  		{
	    		P += 2*dx - 2*dy;
	    		x += addx;
	    		y += addy;
	  		}
		}
	}
}

/*********************************************************************
* Function    : void Rectangle(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, unsigned int rad)
* Description : Draws a beveled figure on the screen. 
* PreCondition: None
* Input       : x1, y1 - coordinate position of the upper left center
*		      : x2, y2 - coordinate position of the lower right center
*             : rad - defines the redius of the circle,
* Output      : None
* Note        : None
********************************************************************/
void Rectangle(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, unsigned int radius)
{
	signed int a, b, P;
	signed int bx, ay;

	// adjust size
	x1 = x1 + radius;
	x2 = x2 - radius;
	y1 = y1 + radius;
	y2 = y2 - radius;

	DrawRect(x1       , y1-radius, x2       , y1-radius);	// top
	DrawRect(x1       , y2+radius, x2       , y2+radius);	// bottom
	DrawRect(x1-radius, y1       , x1-radius, y2       );	// left
	DrawRect(x2+radius, y1       , x2+radius, y2       );	// right

	if (radius == 0)
		return;

	// draw broder
	a = 0;       // increment by 1
	b = radius;  // decrement by 1 using P
	P = 1 - radius;
	bx = b;
	ay = a;

	do
	{
		if (a && (a != b))
		{
			DrawPixel(x1-b, y1-a);
			DrawPixel(x1-b, y2+a);
			DrawPixel(x2+b, y1-a);
			DrawPixel(x2+b, y2+a);
		}
		DrawPixel(x1-a, y1-b);
		DrawPixel(x2+a, y1-b);
		DrawPixel(x1-a, y2+b);
		DrawPixel(x2+a, y2+b);

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

void RectangleFill(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, unsigned int radius)
{
	signed int a, b, P;
	signed int bx, ay;

	if (radius == 0)
	{
	    DrawRect(x1, y1, x2, y2);
		return;
	}
	// adjust size
	x1 = x1 + radius;
	x2 = x2 - radius;
	y1 = y1 + radius;
	y2 = y2 - radius;

	a = 0;       // increment by 1
	b = radius;  // decrement by 1 using P
	P = 1 - radius;
	bx = b;
	ay = a;
	
	DrawRect(x1, y1-radius, x2, y2+radius);
	do
	{
		if (bx != b)
		{
			DrawRect(x1-bx, y1-ay, x1-bx, y2+ay); // left in
			DrawRect(x2+bx, y1-ay, x2+bx, y2+ay); // right in
			bx = b;
		}
  		ay = a;
		if (a != b)
		{ 
			DrawRect(x1-a, y1-b, x1, y2+b); // left out
			DrawRect(x2  , y1-b, x2+a, y2+b); // rigth out
  		}
		if(P < 0)
			P+= 3 + 2*a++;
		else
			P+= 5 + 2*(a++ - b--);
	} while(a <= b);

	if (bx != b)
	{
		DrawRect(x1-bx, y1-ay, x1-bx, y2+ay); // left in
		DrawRect(x2+bx, y1-ay, x2+bx, y2+ay); // right in
	}
}
/*********************************************************************
* Function    : void Circle(unsigned int x, unsigned int y, unsigned int radius, unsigned char fill)
* Description : Draw a circle on the screen. 
* PreCondition: None
* Input       : x,y - the center of the circle
*             : rad - defines the redius of the circle,
*             : fill - fill yes or no
* Output      : None
* Note        : None
********************************************************************/
void CircleFill(unsigned int x, unsigned int y, unsigned int radius, unsigned char fill)
{
   signed int a, b, P;
   a = 0;
   b = radius;
   P = 1 - radius;

   do
   {
      if(fill)
      {
         DrawRect(x-a, y+b, x+a, y+b);
         DrawRect(x-a, y-b, x+a, y-b);
         DrawRect(x-b, y+a, x+b, y+a);
         DrawRect(x-b, y-a, x+b, y-a);
      }
      else
      {
         DrawPixel(a+x, b+y);
         DrawPixel(b+x, a+y);
         DrawPixel(x-a, b+y);
         DrawPixel(x-b, a+y);
         DrawPixel(b+x, y-a);
         DrawPixel(a+x, y-b);
         DrawPixel(x-a, y-b);
         DrawPixel(x-b, y-a);
      }

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

tabii uyarlaması sana kalmış.

Uyarlıyorum hocam. Yanlız çok eksiğim var. Sadece elimde plot(x,y) fonksiyonu var. Bunu kullanıp sizin verdiğiniz kodları benim yazılıma uyarlıyarak çember çizdim. Bayağıda hızlı çizdi.

Yanlız DrawRect fonksiyonuda lazım. Bunuda verebilirmisiniz. Veyahut başka hızlı çalışabilecek Rectangle fonksiyonuda olur.

bocek

seninkinden daha hızlı rectangle çizen bir algoritma olacağını zannetmiyorum. çünkü algoritma belli, sol üstten sağ üste çizgi çek, sağ üstten sağ alta vs.. diye gider. yine de vereyim kodları.

gerekli 'define' lar şöyle:
#define DrawRect(x1,y1,x2,y2)	LCD_Rect(x1, y1, x2, y2, GetColor())

#define LCD_OPEN_WRITE()		LCD_CLR_CS();\
								LCD_SET_RS();

#define LCD_FAST_WRITE(val)		LCD_SET_DBH((val)>>8); \
								LCD_SET_DBL(val); \
								LCD_CLR_WR(); \
								LCD_SET_WR();

LCD_Rect ise şöyle (burda lcd'ye ve avr'ye özgü kodlar var. onları sen uyarlayacaksın.)

void LCD_Rect(unsigned int left, unsigned int top, unsigned int right, unsigned int bottom, unsigned int color)
{
	register unsigned int x,y;

	LCD_SetArea(left, top, right, bottom);
	LCD_OPEN_WRITE(); // portlar çıkış olarak ayarlanıyor.
    for(y=top; y<=bottom; y++)
	{
        for(x=left; x<=right; x++)
		{
			LCD_FAST_WRITE(color); // buraya senin lcd'ye yazma fonk gelecek
        }
    }
	LCD_CLOSE();
	LCD_SetArea(0, 0, GetMaxX(), GetMaxY());
}

avr işlemciler için olan kodların tamamını ve daha fazlasını şurda bulabilirsin:
sayfa: http://www.circuitidea.com/dev-board/BL-TFT240320PLUS-V2.html
direkt link: http://www.circuitidea.com/images/column_1259887831/CID.rar
ayrıca bir de  Font editor written by H. Reddmann programını öneririm.
1 ya da 0. işte 'bit'ün mesele..