Hi Alessandro,

I tried to compile my file directly with this command : gcc lcd.c -o lcd -lm
but i found this error:  erreur: «ETRAXGPIO_IOCTYPE" undeclared (first use in 
this function)
It seems that the gcc compiler is not able to find the default library. How to 
do??

Thank Sébastien

PS: Please find my projects files.

> Message du 20/05/08 à 22h41
> De : "Alessandro Rubini" <[EMAIL PROTECTED]>
> A : [email protected]
> Copie à : 
> Objet : Re: [foxboard] Trigonometrics function
> 
> 
> > lcd.c:126: undefined reference to `cos'
> 
> This is definitely a missing libm.
> 
> > Even if i include "math.h" with or not -lm compilation parameters
> 
> "-lm" works for me, as expected:
> 
>   ostro% cat > /tmp/trig.c
>   int main(int argc, char **argv) {return sin(atof(argv[1]));}
>   ^D
>   ostro% gcc /tmp/trig.c -o /tmp/trig
>   /tmp/cc6DCmZH.o(.text+0x2c): In function `main': undefined reference to 
> `sin'
>   collect2: ld returned 1 exit status
>   Exit 1
>   ostro% gcc -lm /tmp/trig.c -o /tmp/trig
>   ostro%
> 
> But please note that some toolchains require "-lm" to go last (i.e., _after_
> the source or object file where the undefined symbol is encountered).
> 
> /alessandro
> 

____________________________________________________

Vous aussi bénéficiez d'1 Go de stockage gratuit en ligne avec Voila  
http://macle.voila.fr
#include "stdio.h"     
#include "stdlib.h"     
#include "unistd.h"    
#include "sys/ioctl.h"
#include "fcntl.h"     
#include "asm/etraxgpio.h"
#include "stdarg.h"
#include "string.h"
#include "math.h"

#define GIO_LINE_8  (1<<8)
#define GIO_LINE_9  (1<<9)
#define GIO_LINE_10 (1<<10)
#define GIO_LINE_11 (1<<11)

#define GIO_LINE_16 (1<<16)
#define GIO_LINE_17 (1<<17)
#define GIO_LINE_18 (1<<18)
#define GIO_LINE_19 (1<<19)
#define GIO_LINE_20 (1<<20)
#define GIO_LINE_21 (1<<21)
#define GIO_LINE_22 (1<<22)
#define GIO_LINE_23 (1<<23)

#define WR   GIO_LINE_8
#define CE   GIO_LINE_9
#define CD   GIO_LINE_10
#define RD   GIO_LINE_11

#define D0   GIO_LINE_16
#define D1   GIO_LINE_17
#define D2   GIO_LINE_18
#define D3   GIO_LINE_19
#define D4   GIO_LINE_20
#define D5   GIO_LINE_21
#define D6   GIO_LINE_22
#define D7   GIO_LINE_23

#define IO_SETGET_INPUT  	0x12
#define IO_SETGET_OUTPUT  	0x13

#define G_BASE 0x0200            // base address of graphics memory
#define T_BASE 0x0000            // base address of text memory
#define BYTES_PER_ROW 40         // how many bytes per row on screen

#define home() dput(T_BASE%256);dput(T_BASE>>8);cput(0x24); // upper-left

#define XMAX 239        // limits of (x,y) LCD graphics drawing
#define XMIN 0
#define YMAX 63
#define YMIN 0

#define sgn(x) ((x)>0?1:-1)
#define frand() ((float)rand()/RAND_MAX)
#define PI 3.1415926536

#define UI unsigned int
#define UL unsigned long


void delay(UL d);  // delay proportional to "d" value
void dput(int byte); // write data byte to LCD module
int dget(void);      // get data byte from LCD module
int sget(void);      // check LCD display status pbrt
void cput(int byte); // write command byte to LCD module
void lcd_setup();    // make sure control lines are at correct levels
void lcd_init();     // initialize LCD memory and display modes
void lcd_print(char *string);  // send string of characters to LCD
void lcd_clear_text(void);     // clear text memory of LCD
void lcd_xy(int x, int y); // set memory pointer to (x,y) position (text)
void lcd_setpixel(int column, int row);  // set single pixel in 240x64 array
void lcd_clear_graph(void);
void lcd_drawline(int columnA, int rowA,int columnB, int rowB);
void lcd_drawsquare(int columnA, int rowA,int columnB, int rowB);
void lcd_line(unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2);

int fd =0;

int main()
{
int c;                  // character to write to display
float x,y;                // coordinates on graphics screen
float xinc=0,yinc=0;
float r,theta;           // polar coords. for point dV
float theta_inc;
char string[320];        // string to print to display

 if ((fd = open("/dev/gpiog", O_RDWR))<0) {
  	printf("ERROR opening /dev/gpiog\n");
  	return 1;
  }
  
  printf("LCD control program.\n");
  lcd_setup();  // make sure control lines are at correct levels
  printf("Setup lcd sucessfully.\n");
  lcd_init();   // initialize LCD memory and display modes
  printf("Initialized lcd sucessfully.\n");

   lcd_clear_text();
   //cput(0x97);  // Graphics & Text ON, cursor blinking
   cput(0x9F);  // Graphics & Text ON, cursor blinking
   for (c=0;c<10;c++) {
    lcd_xy(0,0);        // write text from upper left corner
    }
    strcpy(string, "Hello world.");
    lcd_print(string);
    lcd_xy(0,1);        // first character, second line
    lcd_print("This is the second line.");
   
    lcd_xy(10,5);
    lcd_print("Press any key to exit.");
    lcd_xy(0,7);
    lcd_print("Display by Sebastien PHILIPPE YOU!OUOUOUOU ");


  /* ------ bouncing line graphics "screensaver" demo ---------- */

   lcd_clear_graph();        // fill graphics memory with 0x00
   lcd_clear_text();
   //cput(0x98);  // Graphics ON, Text OFF

   x=(XMAX-XMIN)/2;
   y=(YMAX-YMIN)/2;
   r=0.3; theta = 2*PI*frand();
   theta_inc = (0.01 * frand()) - 0.005;
   for (c=0;c<12000;c++) {
     lcd_setpixel((int)x,(int)y);       // draw pixel on LCD screen
     xinc = r*cos(theta);
     yinc = r*sin(theta);
     theta += theta_inc;
     x += xinc;
     y += yinc;
     if (x>XMAX) {x=XMAX; theta = PI-theta;}
     if (y>YMAX) {y=YMAX; theta = -theta;}
     if (x<XMIN) {x=XMIN; theta = PI-theta;}
     if (y<YMIN) {y=YMIN; theta = -theta;}
     } // end for(c)
	lcd_drawsquare(5, 7,200, 60);
	lcd_xy(1,5);
    	lcd_print("SQUARE SEB");
	lcd_line(230,0, 230,63);
return 0;
} // end main

/* Block writes would, I think, run faster if you used the DATA AUTO
   mode, eg command 0xB0. I didn't bother.
 */
void lcd_clear_graph(void)    // clear graphics memory of LCD
{
int i;

 dput(G_BASE%256);
 dput(G_BASE>>8);
 cput(0x24);       // addrptr at address G_BASE

 for (i=0;i<2560;i++) {
      dput(0); cput(0xc0);               // write data, inc ptr.
 } // end for(i)
} // end lcd_clear_graph()

void lcd_clear_text(void)
{
 int i;

 dput(T_BASE%256);
 dput(T_BASE>>8);
 cput(0x24);       // addrptr at address T_BASE

 for (i=0;i<320;i++) {
      dput(0); cput(0xc0);               // write data, inc ptr.
 } // end for(i)

} // lcd_clear_text()


void lcd_print(char *string)  // send string of characters to LCD
{
int i;
int c;

  for (i=0;i<strlen(string);i++) {
      c = string[i] - 0x20;     // convert ASCII to LCD char address
      if (c<0) c=0;
      dput(c);
      cput(0xc0);               // write character, increment memory ptr.
  } // end for

} // end lcd_string

void lcd_setpixel(int column, int row)  // set single pixel in 240x64 array
{

int addr;       // memory address of byte containing pixel to write

  addr =  G_BASE + (row*BYTES_PER_ROW)  + (column/6);
  dput(addr%256); dput(addr>>8); cput(0x24);  // set LCD addr. pointer
  cput(0xf8 | (5-(column%6)) );  // set bit-within-byte command

} // end lcd_setpixel()

void swap(unsigned char *a, unsigned char *b)
{
	unsigned char c;
	c=*a;
	*a=*b;
	*b=c;
}

signed char abs_char(signed char a) {
	if(a < 0) return -a;
	return a;
}

void lcd_line(unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2){
	unsigned char x, y;
	signed char a, c;
	signed int b;

	// Calul des Coefficients
	a = y1-y2;
	b = x1*y2-y1*x2;
	c = x1-x2;
	printf("Draw line a= %d, b= %d, c= %d\n",a,b,c);
	if ((x1<240) & (x2<240) & (y1<64) & (y2<64)) // Limits of the lcd check
	{	
		// ligne horizontale
		if (c==0) {
			if (y1>y2) swap(&y1, &y2);
			for(y=y1; y<=y2; y++)
			{
				lcd_setpixel(x1, y);
				printf("horizontale x1= %d, y= %d\n",x1,y);
			}
			return;
		}

		// ligne verticale
		if (a==0) {
			if (x1>x2) swap(&x1, &x2);
			for(x=x1; x<=x2; x++) 
			{
				lcd_setpixel(x, y1);
				printf("verticale x= %d, y1= %d\n",x,y1);
			}
			return;
		}
	
		// ligne y=(ax+b)/c
		if (abs_char(c) >= abs_char(a)) {		// Delta x > Delta y
			if (x1>x2) {
				swap(&x1, &x2);
				swap(&y1, &y2);				
			}
			for(x=x1; x<=x2; x++){
				y = (a*x+b)/c;
				lcd_setpixel(x, y);
				printf("cas 3 x= %d, y= %d\n",x,y);
			}	
		}
		// ligne x = (y*c-b)/a
		else {											// Delta y > Delta x
			if (y1>y2) {
				swap(&x1, &x2);
				swap(&y1, &y2);				
			}
			for(y=y1; y<=y2; y++){
				x = (y*c-b)/a;
				lcd_setpixel(x, y);
				printf("cas 4 x= %d, y= %d\n",x,y);
			}	
		}	
	}
	else
		printf("Coordonnées incompatibles");	
		
}

void lcd_drawsquare(int columnA, int rowA,int columnB, int rowB)  // Draw a sqaure between 2 points
{
	int i;
	if ((columnA<240) & (columnB<240) & (rowA<64) & (rowB<64))// Limits of the lcd check
	{
		for (i=columnA;i<=columnB;i++)
		{
			lcd_setpixel(i, rowA);		
			lcd_setpixel(i, rowB);
		}
	 	for (i=rowA;i<=rowB;i++)
		{
			lcd_setpixel(columnA, i);		
			lcd_setpixel(columnB, i);
		} 
	}
	else
		printf("Coordonnées incompatibles");

} // end lcd_setpixel()

void lcd_xy(int x, int y)  // set memory pointer to (x,y) position (text)
{
int addr;

  addr = T_BASE + (y * BYTES_PER_ROW) + x;
  dput(addr%256); dput(addr>>8); cput(0x24);  // set LCD addr. pointer

} // lcd_xy()

void delay(UL d)  // delay proportional to "d" value
{
UL i;
double a;

 a = 1.000;
 for (i=0;i<d;i++) {
   a = a / 1.001;
 }

} // end delay()


// Set WR line JP11 IOG8
void lcd_wr_hi(int fda) {
  ioctl(fda, _IO(ETRAXGPIO_IOCTYPE, IO_SETBITS), WR);
}

// Reset WR line JP11 IOG8
void lcd_wr_lo(int fda) {
  ioctl(fda, _IO(ETRAXGPIO_IOCTYPE, IO_CLRBITS), WR);
}

// Set CE line JP11 IOG9
void lcd_ce_hi(int fda) {
  ioctl(fda, _IO(ETRAXGPIO_IOCTYPE, IO_SETBITS), CE);
}

// Reset CE line JP11 IOG9
void lcd_ce_lo(int fda) {
  ioctl(fda, _IO(ETRAXGPIO_IOCTYPE, IO_CLRBITS), CE);
}

// Set CD line JP11 IOG10
void lcd_cd_hi(int fda) {
  ioctl(fda, _IO(ETRAXGPIO_IOCTYPE, IO_SETBITS), CD);
}

// Reset CD line JP11 IOG10
void lcd_cd_lo(int fda) {
  ioctl(fda, _IO(ETRAXGPIO_IOCTYPE, IO_CLRBITS), CD);
}

// Set RD line JP11 IOG11
void lcd_rd_hi(int fda) {
  ioctl(fda, _IO(ETRAXGPIO_IOCTYPE, IO_SETBITS), RD);
}

// Reset RD line JP11 IOG11
void lcd_rd_lo(int fda) {
  ioctl(fda, _IO(ETRAXGPIO_IOCTYPE, IO_CLRBITS), RD);
}

// Read data (8 bits) of the LCD
int lcd_port_read(int fda)
{
	return(ioctl(fda,_IO(ETRAXGPIO_IOCTYPE, IO_READBITS)));
}

// Send a nibble (8 bits) to LCD
void lcd_put_nibble(int fda, int value) 
{
	if (value&0x01) ioctl(fda, _IO(ETRAXGPIO_IOCTYPE, IO_SETBITS), GIO_LINE_16);
	else ioctl(fd, _IO(ETRAXGPIO_IOCTYPE, IO_CLRBITS), GIO_LINE_16);
	if (value&0x02) ioctl(fda, _IO(ETRAXGPIO_IOCTYPE, IO_SETBITS), GIO_LINE_17);
	else ioctl(fd, _IO(ETRAXGPIO_IOCTYPE, IO_CLRBITS), GIO_LINE_17);
	if (value&0x04) ioctl(fda, _IO(ETRAXGPIO_IOCTYPE, IO_SETBITS), GIO_LINE_18);
	else ioctl(fd, _IO(ETRAXGPIO_IOCTYPE, IO_CLRBITS), GIO_LINE_18);
	if (value&0x08) ioctl(fda, _IO(ETRAXGPIO_IOCTYPE, IO_SETBITS), GIO_LINE_19);
	else ioctl(fd, _IO(ETRAXGPIO_IOCTYPE, IO_CLRBITS), GIO_LINE_19);
	if (value&0x10) ioctl(fda, _IO(ETRAXGPIO_IOCTYPE, IO_SETBITS), GIO_LINE_20);
	else ioctl(fd, _IO(ETRAXGPIO_IOCTYPE, IO_CLRBITS), GIO_LINE_20);
	if (value&0x20) ioctl(fda, _IO(ETRAXGPIO_IOCTYPE, IO_SETBITS), GIO_LINE_21);
	else ioctl(fd, _IO(ETRAXGPIO_IOCTYPE, IO_CLRBITS), GIO_LINE_21);
	if (value&0x40) ioctl(fda, _IO(ETRAXGPIO_IOCTYPE, IO_SETBITS), GIO_LINE_22);
	else ioctl(fd, _IO(ETRAXGPIO_IOCTYPE, IO_CLRBITS), GIO_LINE_22);
	if (value&0x80) ioctl(fda, _IO(ETRAXGPIO_IOCTYPE, IO_SETBITS), GIO_LINE_23);
	else ioctl(fd, _IO(ETRAXGPIO_IOCTYPE, IO_CLRBITS), GIO_LINE_23);
}

void lcd_port_input(int fda)
{
	int port;

	port = D0 | D1 | D2 | D3 | D4 | D5 | D6 | D7; 	
	if (ioctl(fda, _IO(ETRAXGPIO_IOCTYPE, IO_SETGET_INPUT),&port))
		printf("\tError ioctl => port input\n");		
}

void lcd_port_output(int fda)
{
	int port;

	port = D0 | D1 | D2 | D3 | D4 | D5 | D6 | D7; 
	if (ioctl(fda, _IO(ETRAXGPIO_IOCTYPE, IO_SETGET_OUTPUT),&port))
		printf("\tError ioctl => port output\n");		
}

void lcd_setup()  // make sure control lines are at correct levels
{
	lcd_ce_hi(fd);  // disable chip
	lcd_rd_hi(fd);  // disable reading from LCD
	lcd_wr_hi(fd);  // disable writing to LCD
	lcd_cd_hi(fd);  // command/status mode
	lcd_port_output(fd);//DATAOUT; // make 8-bit parallel port an output port
} // end lcd_setup()

void lcd_init()  // initialize LCD memory and display modes
{
 dput(G_BASE%256);
 dput(G_BASE>>8);
 cput(0x42);       // set graphics memory to address G_BASE

 dput(BYTES_PER_ROW%256);
 dput(BYTES_PER_ROW>>8);
 cput(0x43);  // n bytes per graphics line

 dput(T_BASE%256);
 dput(T_BASE>>8);
 cput(0x40);       // text memory at address T_BASE

 dput(BYTES_PER_ROW%256);
 dput(BYTES_PER_ROW>>8);
 cput(0x41);  // n bytes per text line

 cput(0x80);  // mode set: Graphics OR Text, ROM CGen

 cput(0xa7);  // cursor is 8 lines high
 dput(0x00);
 dput(0x00);
 cput(0x21);  // put cursor at (x,y) location

 cput(0x97);  // Graphics & Text ON, cursor blinking
	      // (For cursor to be visible, need to set up position)

} // end lcd_init()

int sget(void)  // get LCD display status byte
{
  int lcd_status;

  lcd_port_input(fd);// make 8-bit parallel port an input
  lcd_cd_hi(fd);         // bring LCD C/D line high (read status byte)
  lcd_rd_lo(fd);         // bring LCD /RD line low (read active)
  lcd_ce_lo(fd);         // bring LCD /CE line low (chip-enable active)
  lcd_status = lcd_port_read(fd);// read LCD status byte
  lcd_ce_hi(fd);         // bring LCD /CE line high, disabling it
  lcd_rd_hi(fd);         // deactivate LCD read mode
  lcd_port_output(fd);// make 8-bit parallel port an output port

  return(lcd_status>>16);
} // sget()


void dput(int byte) // write data byte to LCD module over par. port assume PC port in data OUTPUT mode
{
  do {} while ((0x03 & sget()) != 0x03); // wait until display ready
  lcd_cd_lo(fd);
  lcd_wr_lo(fd);         // activate LCD's write mode
  lcd_put_nibble(fd, byte);// write value to data port
  lcd_ce_lo(fd);                       // pulse enable LOW > 80 ns (hah!)
  lcd_ce_hi(fd);                       // return enable HIGH
  lcd_wr_hi(fd);                       // restore Write mode to inactive
} // end dput()


int dget(void)      // get data byte from LCD module
{
  int lcd_byte;

  do {} while ((0x03 & sget()) != 0x03); // wait until display ready
  lcd_port_input(fd);// make PC's port an input port
  lcd_wr_hi(fd);   // make sure WRITE mode is inactive
  lcd_cd_lo(fd);   // data mode
  lcd_rd_lo(fd);    // activate READ mode
  lcd_ce_lo(fd);   // enable chip, which outputs data
  lcd_byte = lcd_port_read(fd);// read data from LCD
  lcd_ce_hi(fd);   // disable chip
  lcd_rd_hi(fd); // turn off READ mode
  lcd_port_output(fd);//DATAOUT; // make 8-bit parallel port an output port

  return(lcd_byte>>16);// Attention D0 est à IOG16
} // dget()

void cput(int byte) // write command byte to LCD module assumes port is in data OUTPUT mode
{
  do {} while ((0x03 & sget()) != 0x03); // wait until display ready
  lcd_put_nibble(fd, byte);// present data to LCD on PC's port pins
  lcd_cd_hi(fd);         // control/status mode
  lcd_rd_hi(fd);         // make sure LCD read mode is off
  lcd_wr_lo(fd);         // activate LCD write mode
  lcd_ce_lo(fd);         // pulse ChipEnable LOW, > 80 ns, enables LCD I/O
  lcd_ce_hi(fd);         // disable LCD I/O
  lcd_wr_hi(fd);         // deactivate write mode
} // cput

Attachment: /home/user/Fox/devboard-R2_01/apps/lcd_graphique/Makefile
Description: Binary data

Reply via email to