int main(void)
{
  hours_tens = 1;
  hours_ones = 3;
  minutes_tens = 3;
  minutes_ones = 6;
  seconds_tens = 4;
  seconds_ones = 9;
	
  GLCD_Initalize();
  GLCD_ClearScreen();

/*//Draw the Hackaday Logo:
  GLCD_GoTo(0,0);
  for (unsigned char j=0; j<8; j++)
  {
    GLCD_GoTo(0,j);
    for (unsigned char i=0; i<64; i++)
    {
      GLCD_WriteData(skull[i+(j*64)]);
    }
  }
*/

  while(1)
  {
    //FIXME: Optimize so we don't redraw the entire screen every second.
    ShowBigTime(hours_tens, hours_ones, minutes_tens, minutes_ones);
    GLCD_GoTo(0,7);

    //Easter Egg:
    if ((hours_tens == 1) && (hours_ones == 3) && (minutes_tens == 3) && (minutes_ones == 7))
    {
      //Display Hackaday URL when time is 13:37
      GLCD_WriteString(" http://hackaday.com ");
      
    }
    else
    {
      //Display Day, Date, and Seconds
      GLCD_WriteString("Tuesday 12/3/2013  ");
      GLCD_WriteChar(seconds_tens+48); //ASCII offset
      GLCD_WriteChar(seconds_ones+48); //ASCII offset
    }
    IncSecond();

    //FIXME: This should be a hardware timer for accuracy
    //FIXME: This should use an RTC for accuracy
    Delay_ms(1000);
    
    
  }
}
Exemplo n.º 2
0
void main (void)
    {
    CMCON |= 7;
    ADCON1=0x0F;
    GLCD_Initialize();
    GLCD_ClearScreen();
while(1)
    {
    GLCD_WriteString("ETIQ TECHNOLOGIES");
    Delay_s(2);
    GLCD_Circle(64, 32, 28);
    Delay_s(2);
    GLCD_ClearScreen();
    GLCD_Rectangle(30, 12, 70,40);
    Delay_s(2);
    GLCD_ClearScreen();
    }
}
Exemplo n.º 3
0
Arquivo: lcd.c Projeto: maxk9/etro_new
//-------------------------------------------------------------------------------------------------
// ÷иклически перезаписывает строки на дисплее
//-------------------------------------------------------------------------------------------------
void GLCD_PutString(char * stringToPut)
{
    static unsigned char str=1;
    unsigned char i=0;
    
    if(str<8)
    {
      GLCD_GoTo(0,str);
      for(i = 0; i < KS0108_SCREEN_WIDTH; i++)
              GLCD_WriteData(0x00);
      GLCD_GoTo(0,str);
      GLCD_WriteString(stringToPut);
      ++str;
    }
    else
    {
      str=1;
    }
}
Exemplo n.º 4
0
//////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                          //
//                                        Main function                                     //
//                                                                                          //
//////////////////////////////////////////////////////////////////////////////////////////////
int main(void)
{	//Test
	int last_nombre = 4;
	char str[64] = "Test de String...";
	unsigned char distanceActuel = 0;
	
	//Variables protocole de liaison de donnée
	char trame_a_envoye = 0, trame_complete = 0, trameRX[NBROCTET], trameTX[NBROCTET];
	
	//Initial configuration
	setup_oscillator();
	config();
	
	//Init fifo
	fifo_init();
	radio_dir(TRM_RX);		//Module en réception

	//Display welcome screen:	ToDo
	#ifdef USE_GLCD
	GLCD_Bitmap((char*)Base1, 0, 0, 128, 64);
	#endif
	

	
	//Test
//	index = 0;
//	while(1)
//	{
//	//	result = get_offset(dirty_buf[index], dirty_buf[index + 1], flag);
//		result = get_flag(flag);
//		Nop();
//		clean_buffer(result, 16);
//		Nop();
//	}
	
	//Main loop
	while (1)
	{

		#ifdef AUTO
		routine_auto(&trame_a_envoye, &trame_complete, trameTX, trameRX);
		#endif

		#ifdef BORNE
		routine_borne(&trame_a_envoye, &trame_complete, trameTX, trameRX);
		#endif
	
		
		//Test: encodeur et GLCD
		if((last_nombre != nombre) || buttonPress)	//Si une transition a eu lieu
		{
			#ifdef USE_GLCD
			
			GLCD_ClearScreen();
			GLCD_Bitmap((char*)Base1, 0, 0, 128, 64);
			if(buttonPress && !toEcran1)
			{
				BORNERESERVE = nombre;
				GLCD_GoTo(0,5);
				GLCD_WriteString(RESERVE);
				toEcran1 = 1;
			}
			else if(buttonPress && toEcran1)
			{
				toEcran1 = 0;
				BORNERESERVE = 3;
				confirm=2;
			}
			sprintf(str,"%d",SERIALBATTERIE);
			GLCD_GoTo(107,0);
			GLCD_WriteString(str);

			#endif
				switch(nombre)
				{
					case 0:
						#ifdef USE_GLCD
						DISTANCE = D1;
						GLCD_GoTo(0,2);
						GLCD_WriteString(ADR1A);
					if(!toEcran1)
					{
						GLCD_GoTo(0,3);
						GLCD_WriteString(ADR2);
						GLCD_GoTo(0,4);
						GLCD_WriteString(ADR3);
					}
						#endif
						break;
					case 1:
						#ifdef USE_GLCD
						DISTANCE = D2;
						GLCD_GoTo(0,3);
						GLCD_WriteString(ADR2A);
					if(!toEcran1)
					{
						GLCD_GoTo(0,2);
						GLCD_WriteString(ADR1);
						GLCD_GoTo(0,4);
						GLCD_WriteString(ADR3);
					}
						#endif
						break;
					case 2:
						#ifdef USE_GLCD
						DISTANCE = D3;
					if(!toEcran1)
					{
						GLCD_GoTo(0,2);
						GLCD_WriteString(ADR1);
						GLCD_GoTo(0,3);
						GLCD_WriteString(ADR2);
					}
						GLCD_GoTo(0,4);
						GLCD_WriteString(ADR3A);
						#endif
						break;
					default:
						#ifdef USE_GLCD
						GLCD_ClearScreen();
						GLCD_Bitmap((char*)Base1, 0, 0, 128, 64);
						#endif
						break;
				}
			#ifdef USE_GLCD
			
			GLCD_GoTo(90,7);
			GLCD_WriteString(METER);
			distanceActuel = DISTANCE;	
			buttonPress = 0;		
			last_nombre = nombre;
			if(confirm==2)
			{
				if(D1<DISTANCEPROCHE){
					borneProche(0);	
				}
				else if(D2<DISTANCEPROCHE){
					borneProche(1);
				}
				else if(D3<DISTANCEPROCHE){
					borneProche(2);
				}
				if(confirm==1)
				{
					buttonPress=1;
					toEcran1=0;
				}
				else if(confirm==0)
				{
					buttonPress=0;
					toEcran1=0;
					last_nombre=4;	
				}
			}
			#endif
		}	
		
		//Données sortantes
		if(trame_a_envoye == 1)
		{
			envoie = rf_envoie(trameTX, (char *)clean_buf);
			
			if(envoie == 1)
				trame_a_envoye = 0;
		}
		
		//Flags - Données entrantes	
		if(rf_flag == 1)//&& trame_complete == 0)
		{
			//Actualise la batterie
			#ifdef USE_GLCD
			getBatt();
			sprintf(str,"%03i",BATTERIE);			
			GLCD_GoTo(80,0);
			if(nombre==0)
			{DISTANCE = D1;}
			else if(nombre==1)
			{DISTANCE = D2;}
			else if(nombre==2)
			{DISTANCE = D3;}
			
			GLCD_WriteString(str);
			sprintf(str,"%i",DISTANCE);
			GLCD_GoTo(40,7);
			GLCD_WriteString(str);
			#endif

			result = get_flag(flag);
			if(result != 10)
			{
				clean_buffer(result, 32);

				//Extraction des octets vers la couche application
				trame_complete = rf_gerer_RX((char *)clean_buf, trameRX);			
			}
			
			//Remise à zéro de la détection
			rf_flag = 0;
			result = 10;
		}
		
		//
		
		#ifdef GPS_FEEDTHROUGH
		//TestGPS
		#ifdef DEBUG_MPSIM
			gps_flag =1;  //REMOVE
		#endif
		
		if(gps_flag)
		{
			gps_flag = 0;
			//Filtre les données quand le buffer est plein
			
			#ifdef DEBUG_MPSIM
				(gpsstr[3]='R'); //REMOVE
			#endif
			
			if((gpsstr[3]=='R'))
			{
				for(a =0;a<47;a++)
				{
					gps[a] = gpsstr[a]; //Buffer de travail
				}
			//	puts_usart1(gpsstr);
				//gps[] = "$GPRMC,174254.000,V,4522.75800,N,07155.43400,W";
				#ifdef DEBUG_MPSIM
					gps[20]='4';
					gps[21]='5';
					gps[22]='2';
					gps[23]='2';
					gps[25]='7';
					gps[26]='5';
					gps[27]='8';
					
					gps[33]='0';
					gps[34]='7';
					gps[35]='1';
					gps[36]='5';
					gps[37]='5';
					gps[39]='4';
					gps[40]='3';
					gps[41]='4';
					gps[45]='W';
				#endif
				convStr();
				
				//LaA = 45.3793;
				//LoA= -71.9239;
				
				assignDist(LaA,LoA);				
			}
		}
		#endif
/*
		#ifdef USE_GLCD

		if(buttonPress)
		{
			switchScreen(last_nombre);
			buttonPress = 0;
		}
		
		if(distanceActuel < DISTANCEBATT && BATTERIE < 50 && ecran ==2)
		{
			switchBatt();
		}
		#endif
*/
		
		if(buttonPress)
		{
			#ifdef BORNE
			buttonPress = 0;
			char donnee_test[NBROCTET] = {0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37};
			envoie = rf_envoie(donnee_test, (char *)clean_buf);
			#endif
			#ifdef AUTO
			puts_usart1(gps);
			#endif
		}
		
		
		
		if(rssi_flag)
		{
			rssi_flag = 0;
			//Filtre les données quand le buffer est plein
			rssi = get_rssi();
		}
		
	}
    return 0;
}
Exemplo n.º 5
0
int main(void)
{
    BL_OUTPUT;
//    DS_OUTPUT;
    BL_ON;

    GLCD_Initalize(); // Initalize LCD
    GLCD_ClearText(); // Clear text area
    GLCD_ClearCG(); // Clear character generator area
    GLCD_ClearGraphic(); // Clear graphic area

    GLCD_TextGoTo(0,0);// set text coordinates
    GLCD_WriteString("Hello"); // write text
    GLCD_Circle(32,32,20); // draw circle
    GLCD_Rectangle(8,8,24, 48); // draw rectangle
//    GLCD_FillRectangle(0, 0, 96, 8);

    USART_Init(MYUBRR);
    USART_Transmit_string("Hi\n");

    LED_OUTPUT;
    BLINK3;
    GLCD_ClearText();
    GLCD_TextGoTo(0,0);// set text coordinates

    ADCSRA = 0b10000111;

    data_flag=0;


    sei();
    uint16_t T = 0;
    uint8_t i;
    while(1)
    {
      if (data_flag == 1)
      {
          //BLINK00; // Heh nasty error when it is here, if 'g' followed by newline comes, because it rewrites data here :D
          if (data == 't')
          {
              T = DS_get(6);
              GLCD_TextGoTo(0,0);

              i = (uint8_t)(T>>8);
              USART_Transmit_num(i);
              GLCD_WriteChar(i/10 + '0');
              GLCD_WriteChar(i%10 + '0');

              USART_Transmit('.');
              GLCD_WriteChar('.');

              i = (uint8_t)(T);
              USART_Transmit_num(i);
              GLCD_WriteChar(i/10 + '0');
              GLCD_WriteChar(i%10 + '0');

              USART_Transmit('C');
              GLCD_WriteChar('C');

              USART_Transmit('\n');
          }

          if (data == 'g')
          {
              ADMUX = 0x00;
              sbi(ADCSRA, ADSC);
              while (qbi(ADCSRA, ADSC))
                  ;
              uint16_t val = ADC;
              GLCD_TextGoTo(0,0);

          }
          data_flag=0;
      }
    }
Exemplo n.º 6
0
// Main function
int main (void) 
{  
// Local variable definations
emxArray_uint8_T *xaxis;
emxArray_uint8_T *yaxis;
emxArray_uint8_T *norm_xaxis_filt;
emxArray_uint8_T *norm_yaxis_filt;

uint16_T count;
uint8_T xaxis2,yaxis2;

long j = 0;

int again = 1;

char letter;
char letterstr[10];
int i=0;
letterstr[i] = '\0';

// Variable Initialisation
	for(j=0;j<MAX_VALUE;j++)
	{
		xdata[j] = 0;
		ydata[j] = 0;
	}

	
// Function Initialisation
	PINSEL2 &= ~((1<<2)|(1<<3));
	GLCD_Initalize();				  //Initialize the LCD
	Init_UART();
	InitADC();

// Welcome message
	GLCD_ClearScreen();
	GLCD_GoTo(10,4);	
	GLCD_WriteString("Intelligent e-book");
//	for(j=0;j<999999;j++);
	delay_ms(2000);

// Calibration
	//Left bottom
	GLCD_ClearScreen();
	GLCD_GoTo(10,0);	
	GLCD_WriteString("Calibration");
	GLCD_GoTo(10,4);	
	GLCD_WriteString("Touch the point");
	GLCD_GoTo(0,7);	
	GLCD_WriteString("o");

	do
	{
	xaxis1 = Read_xaxis();
	yaxis1 = Read_yaxis();

	if(xaxis1<10)
		xaxis1 = 0;
	if(yaxis1<10)
		yaxis1 = 0;
	}while(xaxis1==0 && yaxis1==0);
	for(j=0;j<25;j++)
	capture();


	x1 = xaxis1;
	y1 = yaxis1;

	GLCD_GoTo(10,5);	
	GLCD_WriteString("Stored");
	delay_ms(1000);

	//Right top
	GLCD_ClearScreen();
	GLCD_GoTo(10,0);	
	GLCD_WriteString("Calibration");
	GLCD_GoTo(10,4);	
	GLCD_WriteString("Touch the point");
	GLCD_GoTo(120,0);	
	GLCD_WriteString("o");

	do
	{
	xaxis1 = Read_xaxis();
	yaxis1 = Read_yaxis();

	if(xaxis1<10)
		xaxis1 = 0;
	if(yaxis1<10)
		yaxis1 = 0;
	}while(xaxis1==0 && yaxis1==0);
	for(j=0;j<25;j++)
	capture();

	x2 = xaxis1;
	y2 = yaxis1;

	GLCD_GoTo(10,5);	
	GLCD_WriteString("Stored");
	delay_ms(1000);


while(again==1)
{
again = 0;

// Capturing xaxis and yaxis

GLCD_ClearScreen();
GLCD_GoTo(10,0);	
GLCD_WriteString("Intelligent e-book");
GLCD_GoTo(12,4);		
GLCD_WriteString("Waiting for input");
do
{
xaxis1 = Read_xaxis();
yaxis1 = Read_yaxis();

if(xaxis1<10)
	xaxis1 = 0;
if(yaxis1<10)
	yaxis1 = 0;

}while(xaxis1==0 && yaxis1==0);

xyelem = 0;
count = 0;
GLCD_ClearScreen();
GLCD_GoTo(0,0);		

// Eliminate first 25 samples
	for(j=0;j<25;j++)
	capture();

while(count!=250)
{
	capture();

	if(xaxis1!=0 && yaxis1!=0 && count==0)
	{
		
//	xaxis2 = (uint8_T)(((xaxis1-80)*255)/730);
//	yaxis2 = (uint8_T)(((yaxis1-100)*255)/650);
	xaxis2 = (uint8_T)(((xaxis1-x1)*255)/(x2-x1));
	yaxis2 = (uint8_T)(((yaxis1-y1)*255)/(y2-y1));

		count = 0;
	  	xdata[xyelem] = xaxis2;
		ydata[xyelem] = yaxis2;
		xyelem = xyelem + 1;
		GLCD_SetPixel(xaxis2/2,255-(yaxis2/4),1);

		if(xyelem>MAX_VALUE - 1)
		{
			GLCD_ClearScreen();
			GLCD_GoTo(10,0);	
			GLCD_WriteString("Intelligent e-book");
			GLCD_GoTo(10,4);		
			GLCD_WriteString("Overflow!!!");
			while(1);
		}
	}
	else if(xaxis1!=0 && yaxis1!=0)
	{
		xyelem = xyelem - 2;
		// Eliminate first 25 samples
		for(j=0;j<25;j++)
		capture();
		count = 0;
	}
	else
	{
	 	count = count + 1;
	}

//	delay(1000);
}
GLCD_ClearScreen();
GLCD_GoTo(10,0);	
GLCD_WriteString("Intelligent e-book");
GLCD_GoTo(0,1);	
GLCD_WriteString(letterstr);

//GLCD_GoTo(10,4);		
//GLCD_WriteString("Scanning ended");
//delay_ms(500);


// Transmitting data to PC
//	transmit();

// Remove noise
	remove_noise();

// Allocating space for pointers  
	xaxis = emxCreateWrapper_uint8_T(xdata,1,xyelem);	//xdata1
	yaxis = emxCreateWrapper_uint8_T(ydata,1,xyelem);	//ydata1
	emxInit_uint8_T(&norm_xaxis_filt, 2);
	emxInit_uint8_T(&norm_yaxis_filt, 2);

/*	GLCD_ClearScreen();
	GLCD_GoTo(10,0);	
	GLCD_WriteString("Intelligent e-book");
	GLCD_GoTo(0,2);		
	GLCD_WriteString("Step1");
	GLCD_GoTo(37,2);		
	GLCD_WriteString("In");
*/
//	for(j=0;j<999999;j++);

	step1(xaxis, yaxis, norm_xaxis_filt, norm_yaxis_filt);

//	GLCD_ClearScreen();
//	GLCD_GoTo(10,0);	
//	GLCD_WriteString("Intelligent e-book");
//	GLCD_GoTo(54,2);	
//	GLCD_WriteString("Out");
//	for(j=0;j<999999;j++);

	emxDestroyArray_uint8_T(xaxis);
	emxDestroyArray_uint8_T(yaxis);
	
//	GLCD_ClearScreen();
//	GLCD_GoTo(10,0);	
//	GLCD_WriteString("Intelligent e-book");
//	GLCD_GoTo(0,3);	
//	GLCD_WriteString("Step2");
//	GLCD_GoTo(37,3);		
//	GLCD_WriteString("In");
//	for(j=0;j<999999;j++);

// char_bin is stored in column first fashion... each column vector are concatenated	
	step2(norm_xaxis_filt, norm_yaxis_filt, char_bin);

//	GLCD_ClearScreen();
//	GLCD_GoTo(10,0);	
//	GLCD_WriteString("Intelligent e-book");
//	GLCD_GoTo(54,3);	
//	GLCD_WriteString("Out");
//	for(j=0;j<999999;j++);
	
	emxFree_uint8_T(&norm_xaxis_filt);
	emxFree_uint8_T(&norm_yaxis_filt);

//	GLCD_ClearScreen();
//	GLCD_GoTo(10,0);	
//	GLCD_WriteString("Intelligent e-book");
//	GLCD_GoTo(0,4);	
//	GLCD_WriteString("Step3");
//	GLCD_GoTo(37,4);		
//	GLCD_WriteString("In");
//	for(j=0;j<999999;j++);

	for(j=0;j<10;j++)
	char_vec[j] = 1;
	
	step3(char_bin, char_vec);
	
//	GLCD_ClearScreen();
//	GLCD_GoTo(10,0);	
//	GLCD_WriteString("Intelligent e-book");
//	GLCD_GoTo(54,4);	
//	GLCD_WriteString("Out");
//	for(j=0;j<999999;j++);
  

	for(j=0;j<26;j++)
	char_vec1[j] = char_vec[j];
	
	// Feeding char_vec to trained neural network
	char_recog_nn(char_vec1,Y);

	letter = character();

	letterstr[i] = letter;
	letterstr[i+1] = '\0';

//	GLCD_ClearScreen();
//	GLCD_GoTo(10,0);	
//	GLCD_WriteString("Intelligent e-book");
//	GLCD_GoTo(0,6);	
//	GLCD_WriteString("Letter is: ");
	GLCD_GoTo(0,1);	
	GLCD_WriteString(letterstr);
	GLCD_GoTo(0,7);	
	GLCD_WriteString("Continue");

	do
	{
	xaxis1 = Read_xaxis();
	yaxis1 = Read_yaxis();

	if(xaxis1<10)
		xaxis1 = 0;
	if(yaxis1<10)
		yaxis1 = 0;

	}while(xaxis1==0 && yaxis1==0);

again = 1;
i = i + 1;
/*
GLCD_ClearScreen();
GLCD_GoTo(10,0);	
GLCD_WriteString("Intelligent e-book");
GLCD_GoTo(20,4);		
GLCD_WriteString("Restarting.");
delay_ms(200);
GLCD_WriteString(".");
delay_ms(200);
GLCD_WriteString(".");
delay_ms(200);
GLCD_WriteString(".");
*/
delay_ms(400);
}

  while(1); 
}
Exemplo n.º 7
0
void main()
{
	unsigned char i2cdata = 0, usartdata = 0;
	unsigned char data = 0;
	unsigned char str[] = "nom de la toune";
	unsigned char AUTO[] = "Auto";
	unsigned char NORMAL[] = "Normal";
	unsigned char CUTOM1[] = "Custom 1";
	unsigned char CUTOM2[] = "Custom 2";
	unsigned char CUTOM3[] = "Custom 3";
	// Config position
	short xposMMODE = 40;
	short yposMMODE = 2; //(tranche de 8)


	initialisation();	//Initialise tout


LED1=0;
LED2=1;
LED3=1;
		while(debut)
		{
			//chech dsp pour signal autocorrélation puis debut à 1
			if (read1==0xFF)
				debut=0;
			LED1 = 0;
		}
		LED1 = 1;	
		//Boucle infinie
	while(1)
	{
		//Affichage de l'écran initial
		if(!debut)
		{
			GLCD_Bitmap(logo, 0, 0, 128, 64);
			Delay10KTCYx(0);
			Delay10KTCYx(0);
			Delay10KTCYx(0);
			Delay10KTCYx(0);
			Delay10KTCYx(0);
			Delay10KTCYx(0);
			Delay10KTCYx(0);
			Delay10KTCYx(0);
			GLCD_ClearScreen();
			GLCD_Bitmap(PAUSE, 47, 2, 35, 24);
			debut=1;
		}

		if(last_nombre != nombre)	//Si une transition a eu lieu, gérer les menus d'affichage
		{
			switch(nombre)
			{
				case 0:
					
					GLCD_Bitmap(ICONES, 0, 6, 128, 16);
					GLCD_Bitmap(MODEselec, 1, 6, 68, 16);
					GLCD_GoTo(5,7);
					if(modeselect == 0)
						GLCD_WriteString(AUTO,1);
					else if(modeselect == 1)
						GLCD_WriteString(NORMAL,1);	
					else if(modeselect == 2)
						GLCD_WriteString(CUTOM1,1);							
					else if(modeselect == 3)
						GLCD_WriteString(CUTOM2,1);
					else if(modeselect == 4)
						GLCD_WriteString(CUTOM3,1);							
					if(proj)
						GLCD_Bitmap(flecheICO, 75, 5, 8, 8); //SPOT
					else
						GLCD_Bitmap(flecheNULL, 75, 5, 8, 8); //SPOT
					if(strob)
						GLCD_Bitmap(flecheICO, 95, 5, 8, 8); //STROB
					else
						GLCD_Bitmap(flecheNULL, 95, 5, 8, 8); //STROB	
					if(vu)
						GLCD_Bitmap(flecheICO, 115, 5, 8, 8); //BARR
					else
						GLCD_Bitmap(flecheNULL, 115, 5, 8, 8); //BARR
					break;
				case 1:
					//GLCD_ClearScreen();
					GLCD_Bitmap(ICONES, 0, 6, 128, 16);
					GLCD_Bitmap(SPOTselec, 70, 6, 18, 16);
					GLCD_GoTo(5,7);
					if(modeselect == 0)
						GLCD_WriteString(AUTO,0);
					else if(modeselect == 1)
						GLCD_WriteString(NORMAL,0);	
					else if(modeselect == 2)
						GLCD_WriteString(CUTOM1,0);							
					else if(modeselect == 3)
						GLCD_WriteString(CUTOM2,0);
					else if(modeselect == 4)
						GLCD_WriteString(CUTOM3,0);							
					if(proj)
						GLCD_Bitmap(flecheICO, 75, 5, 8, 8); //SPOT
					else
						GLCD_Bitmap(flecheNULL, 75, 5, 8, 8); //SPOT
					if(strob)
						GLCD_Bitmap(flecheICO, 95, 5, 8, 8); //STROB
					else
						GLCD_Bitmap(flecheNULL, 95, 5, 8, 8); //STROB	
					if(vu)
						GLCD_Bitmap(flecheICO, 115, 5, 8, 8); //BARR
					else
						GLCD_Bitmap(flecheNULL, 115, 5, 8, 8); //BARR
					break;
				case 2:
					//GLCD_ClearScreen();
					GLCD_Bitmap(ICONES, 0, 6, 128, 16);
					GLCD_Bitmap(STROBselec, 90, 6, 18, 16);
					GLCD_GoTo(5,7);
					if(modeselect == 0)
						GLCD_WriteString(AUTO,0);
					else if(modeselect == 1)
						GLCD_WriteString(NORMAL,0);	
					else if(modeselect == 2)
						GLCD_WriteString(CUTOM1,0);							
					else if(modeselect == 3)
						GLCD_WriteString(CUTOM2,0);
					else if(modeselect == 4)
						GLCD_WriteString(CUTOM3,0);							
					if(proj)
						GLCD_Bitmap(flecheICO, 75, 5, 8, 8); //SPOT
					else
						GLCD_Bitmap(flecheNULL, 75, 5, 8, 8); //SPOT
					if(strob)
						GLCD_Bitmap(flecheICO, 95, 5, 8, 8); //STROB
					else
						GLCD_Bitmap(flecheNULL, 95, 5, 8, 8); //STROB	
					if(vu)
						GLCD_Bitmap(flecheICO, 115, 5, 8, 8); //BARR
					else
						GLCD_Bitmap(flecheNULL, 115, 5, 8, 8); //BARR
					break;
				case 3:
					//GLCD_ClearScreen();
					GLCD_Bitmap(ICONES, 0, 6, 128, 16);
					GLCD_Bitmap(BARRselec, 110, 6, 18, 16);
					GLCD_GoTo(5,7);
					if(modeselect == 0)
						GLCD_WriteString(AUTO,0);
					else if(modeselect == 1)
						GLCD_WriteString(NORMAL,0);	
					else if(modeselect == 2)
						GLCD_WriteString(CUTOM1,0);							
					else if(modeselect == 3)
						GLCD_WriteString(CUTOM2,0);
					else if(modeselect == 4)
						GLCD_WriteString(CUTOM3,0);								
					if(proj)
						GLCD_Bitmap(flecheICO, 75, 5, 8, 8); //SPOT
					else
						GLCD_Bitmap(flecheNULL, 75, 5, 8, 8); //SPOT
					if(strob)
						GLCD_Bitmap(flecheICO, 95, 5, 8, 8); //STROB
					else
						GLCD_Bitmap(flecheNULL, 95, 5, 8, 8); //STROB	
					if(vu)
						GLCD_Bitmap(flecheICO, 115, 5, 8, 8); //BARR
					else
						GLCD_Bitmap(flecheNULL, 115, 5, 8, 8); //BARR
					break;
				case 4:
					GLCD_ClearScreen();
					GLCD_Bitmap(titreMODE, 0, 0, 128, 16);
					GLCD_GoTo(xposMMODE,yposMMODE);
					GLCD_WriteString(AUTO,1);
					GLCD_GoTo(xposMMODE,yposMMODE+1);
					GLCD_WriteString(NORMAL,0);
					GLCD_GoTo(xposMMODE,yposMMODE+2);
					GLCD_WriteString(CUTOM1,0);
					GLCD_GoTo(xposMMODE,yposMMODE+3);
					GLCD_WriteString(CUTOM2,0);
					GLCD_GoTo(xposMMODE,yposMMODE+4);
					GLCD_WriteString(CUTOM3,0);
					break;	
				case 5:
					GLCD_ClearScreen();
					GLCD_Bitmap(titreMODE, 0, 0, 128, 16);
					GLCD_GoTo(xposMMODE,yposMMODE);
					GLCD_WriteString(AUTO,0);
					GLCD_GoTo(xposMMODE,yposMMODE+1);
					GLCD_WriteString(NORMAL,1);
					GLCD_GoTo(xposMMODE,yposMMODE+2);
					GLCD_WriteString(CUTOM1,0);
					GLCD_GoTo(xposMMODE,yposMMODE+3);
					GLCD_WriteString(CUTOM2,0);
					GLCD_GoTo(xposMMODE,yposMMODE+4);
					GLCD_WriteString(CUTOM3,0);
					break;
				case 6:
					GLCD_ClearScreen();
					GLCD_Bitmap(titreMODE, 0, 0, 128, 16);
					GLCD_GoTo(xposMMODE,yposMMODE);
					GLCD_WriteString(AUTO,0);
					GLCD_GoTo(xposMMODE,yposMMODE+1);
					GLCD_WriteString(NORMAL,0);
					GLCD_GoTo(xposMMODE,yposMMODE+2);
					GLCD_WriteString(CUTOM1,1);
					GLCD_GoTo(xposMMODE,yposMMODE+3);
					GLCD_WriteString(CUTOM2,0);
					GLCD_GoTo(xposMMODE,yposMMODE+4);
					GLCD_WriteString(CUTOM3,0);
					break;
				case 7:
					GLCD_ClearScreen();
					GLCD_Bitmap(titreMODE, 0, 0, 128, 16);
					GLCD_GoTo(xposMMODE,yposMMODE);
					GLCD_WriteString(AUTO,0);
					GLCD_GoTo(xposMMODE,yposMMODE+1);
					GLCD_WriteString(NORMAL,0);
					GLCD_GoTo(xposMMODE,yposMMODE+2);
					GLCD_WriteString(CUTOM1,0);
					GLCD_GoTo(xposMMODE,yposMMODE+3);
					GLCD_WriteString(CUTOM2,1);
					GLCD_GoTo(xposMMODE,yposMMODE+4);
					GLCD_WriteString(CUTOM3,0);
					break;
				case 8:
					GLCD_ClearScreen();
					GLCD_Bitmap(titreMODE, 0, 0, 128, 16);
					GLCD_GoTo(xposMMODE,yposMMODE);
					GLCD_WriteString(AUTO,0);
					GLCD_GoTo(xposMMODE,yposMMODE+1);
					GLCD_WriteString(NORMAL,0);
					GLCD_GoTo(xposMMODE,yposMMODE+2);
					GLCD_WriteString(CUTOM1,0);
					GLCD_GoTo(xposMMODE,yposMMODE+3);
					GLCD_WriteString(CUTOM2,0);
					GLCD_GoTo(xposMMODE,yposMMODE+4);
					GLCD_WriteString(CUTOM3,1);
					break;					
			}
			last_nombre = nombre;
			}
			//Si on appuit sur le bouton, activer l'actuateur en question ou changer de menu
			if(!ENC_SW)
			{
				while(!ENC_SW);
				Delay10KTCYx(125);
				switch(nombre)
					{
						case 0:
							emplacement=2;
							nombre=modeselect+4;
							last_nombre=0;
						break;
						case 1:
						if(proj)
							proj=0;
						else
							proj=1;
						last_nombre=0;
						break;
						case 2:
						if(strob)
							strob=0;
						else
							strob=1;
						last_nombre=0;
						break;
						case 3:
						if(vu)
							vu=0;
						else
							vu=1;
						last_nombre=0;
						break;
						case 4:
							modeselect=0;
							emplacement=1;
							nombre=0;
							GLCD_ClearScreen();
						break;
						case 5:
							modeselect=1;
							emplacement=1;
							nombre=0;
							GLCD_ClearScreen();
						break;
						case 6:
							modeselect=2;
							emplacement=1;
							nombre=0;
							GLCD_ClearScreen();
						break;
						case 7:
							modeselect=3;
							emplacement=1;
							nombre=0;
							GLCD_ClearScreen();
						break;
						case 8:
							modeselect=4;
							emplacement=1;
							nombre=0;
							GLCD_ClearScreen();
						break;
					}	
			}
		
		//Si la pédale est appuyée, changer de on-off
		if(!PORTBbits.RB3)
		{
			while(!PORTBbits.RB3);		//Attente que la pédale soit relâché
			if(etatplay==0)
			{
				play=1;
				pause=0;
				etatplay=1;
			}
			else
			{
				pause=1;
				last_nombre=9;
				etatplay=0;
			}
		}
// ---------------------------------------------------------------------------------------
// PLAY
		if(play)
		{
			//Affiche play à l'écran
			GLCD_Bitmap(PLAY, 47, 2, 35, 24);
			
			//Envoie le mode vers le dsp
			euart_out=modeselect;
			while(BusyUSART());
			putcUSART(euart_out);
			Delay10KTCYx(0);
			Delay10KTCYx(0);
			Delay10KTCYx(0);
			GLCD_ClearScreen();
			last_nombre=9;	
			play=1;
		}
// ---------------------------------------------------------------------------------------
// PAUSE
		if(emplacement == 1)
		{
			//Si non-pause, afficher les barres graphiques
			if(pause==0)
			{
				graphVU(chan_L,chan_R);
			}
			//Si pause, afficher l'image du pause
			else if(pause==1 && last_nombre!=nombre)
			{
				GLCD_ClearScreen();			
				GLCD_Bitmap(PAUSE, 47, 2, 35, 24);
				last_nombre=9;
			}
			//Affiche le nom de la chanson en cours
			GLCD_GoTo(2,0);
			if(toune==1)
				GLCD_WriteString(music_1,0);						
			else if(toune==2)
				GLCD_WriteString(music_2,0);
			else if(toune==3)
				GLCD_WriteString(music_3,0);			
		}

// I2C,  actualiser la FFT et envoyer les données vers le contrôleur principal
		if(flag_i2c)
		{
			flag_i2c=0;
			//Si trame FFT initiale détecté, commence à mettre à jour la FFT
			if((read3&0b00010000)==0x10)
			{
				compteur_fft=1; 
			}
			//Met à jour chaque trame de la FFT
			switch(compteur_fft)
					{
						case 1:
							fft1=(read3&0b00001111);
						break;
						case 2:
							fft2=(read3&0b00001111);
						break;
						case 3:
							fft3=(read3&0b00001111);
						break;
						case 4:
							fft4=(read3&0b00001111);
						break;
						case 5:
							fft5=(read3&0b00001111);
						break;
						case 6:
							fft6=(read3&0b00001111);
						break;
						case 7:
							fft7=(read3&0b00001111);
						break;
						case 8:
							fft8=(read3&0b00001111);
						break;
						case 9:
							fft9=(read3&0b00001111);
						break;
						case 10:
							fft10=(read3&0b00001111);
						break;
						case 11:
							fft11=(read3&0b00001111);
						break;
						case 12:
							fft12=(read3&0b00001111);
						break;
						case 13:
							fft13=(read3&0b00001111);
						break;
						case 14:
							fft14=(read3&0b00001111);
						break;
						case 15:
							fft15=(read3&0b00001111);
						break;
						case 16:
							fft16=(read3&0b00001111);
							compteur_fft=0;
						break;
						default:
							LED2=1;
						break;
					}	
			//Lorsque la FFT est actualiser, la faire afficher à l'écran
			if(compteur_fft==1 && (emplacement ==1)  && (etatplay==1))
				graphFFT(2*fft1,2*fft2,2*fft3,2*fft4,2*fft5,2*fft6,2*fft7,2*fft8,2*fft9,2*fft10,2*fft11,2*fft12,2*fft13,2*fft14,2*fft15,2*fft16);	
			compteur_fft++;
			//Choix de la chanson selon les données reçu
			if((read4&0b00001111)==0b00000001)
				toune=1;
			else if((read4&0b00001111)==0b00000010)
				toune=2;
			else if((read4&0b00001111)==0b00000011)
				toune=3;
			//Masques pour savoir les actuateurs à activer
			i2c_actuateur=0b00001000;
			if(vu && !pause)
				i2c_actuateur |= 0b00000001;			
			if(proj && !pause)
				i2c_actuateur |= 0b00000010;
			if(strob && !pause)
				i2c_actuateur |= 0b00000100;
			
			//Émet I2C uniquement sur nouvelles données
			if((last_i2c_1 != read2) || (last_i2c_2 != i2c_actuateur))
			{
				tst_str[1] = read2;
				tst_str[2] = i2c_actuateur;
				send_str_I2C(0x40, tst_str);
			}
			last_i2c_1 = read2;		
			last_i2c_2 = i2c_actuateur;	
		}
		if(play)
		{
			while(BusyUSART());
			putcUSART(euart_out);
			play=0;
		}
	}
}