Beispiel #1
0
void loop() {
//
//
//
 	if (!digitalread(I)) izquierda();
//
	if (!digitalread(D))  derecha();
	ServoWrite(LI,500); // enciende los led y varia su brillo
	ServoWrite(LD,20);
	adelante();
	
}
Beispiel #2
0
void Vis_LCD ( volatile uint32_t Estado_LCD, volatile uint32_t AUX_LCD)
{

//volatile uint32_t Estado_LCD;
//volatile uint32_t AUX_LCD;


//Variable para el switch del E
    uint8_t a=1;

//Estados de inicializacion y escritura
    uint8_t estado_0=0;
    uint8_t estado_1=0;
    uint8_t estado_2=0;
    uint8_t estado_3=0;
    uint8_t estado_4=0;
    uint8_t estado_5=0;
    uint8_t estado_6=0;


//Contador de instrucciones LCD
    uint8_t cont_0=1;
    uint8_t cont_1=1;
    uint8_t cont_2=1;
    uint8_t cont_3=1;
    uint8_t cont_4=1;
    uint8_t cont_5=1;
    uint8_t cont_6=1;

    while(1) {

        if(t()==a) {

////inicio

            switch(Estado_LCD) { // corchete Estado_LCD

            // Bienvenido Key_PI

            case 0: //case 0 Estado_LCD

                switch(estado_0) {		//switch(estado_0)

                case 0:
                    lcd_iniciar(cont_0);
                    cont_0=cont_0+1;
                    if(cont_0==5)estado_0=estado_0+1;
                    break; //break del case 0

                case 1:
                    titulo1(cont_0);
                    cont_0=cont_0+1;
                    if(cont_0==16)estado_0=estado_0+1;
                    break; //break del case 1


                default:
                    if (cont_0==16)
                        cont_0=16;

                }	// end switch(estado_0)

                break;  //break case 0 Estado_LCD

            // Elegir cancion

            case 1://case 1 Estado_LCD

                switch (estado_1) { // 	//switch(estado_1)

                case 0:
                    lcd_iniciar(cont_1);
                    cont_1=cont_1+1;
                    if(cont_1==5)estado_1=estado_1+1;
                    break; //break del case 0

                case 1:
                    song(cont_1);
                    cont_1=cont_1+1;
                    if(cont_1==21)estado_1=estado_1+1;
                    break; //break del case 1

                case 2:
                    lcd_linea2(cont_1);
                    cont_1=cont_1+1;
                    if(cont_1==22)estado_1=estado_1+1;
                    break; //break del case 2

                case 3:

                    switch(AUX_LCD) {

                    case 0:
                        song1(cont_1);		//cancion 1
                        cont_1=cont_1+1;
                        if(cont_1==25)estado_1=estado_1+1;
                        break; //0

                    case 1:
                        song2(cont_1);		//cancion 2
                        cont_1=cont_1+1;
                        if(cont_1==25)estado_1=estado_1+1;
                        break; //1

                    case 2:
                        song3(cont_1);		//cancion 3
                        cont_1=cont_1+1;
                        if(cont_1==25)estado_1=estado_1+1;
                        break; //2

                    case 3:
                        song4(cont_1);		//cancion 4
                        cont_1=cont_1+1;
                        if(cont_1==25)estado_1=estado_1+1;
                        break;	//3

                    case 4:
                        song5(cont_1);		//cancion 5
                        cont_1=cont_1+1;
                        if(cont_1==25)estado_1=estado_1+1;
                        break;	//4

                    default:
                        if (cont_1==25)
                            cont_1=25;

                    } // End switch AUX_LCD

                    break;	//break del case 3


                } 	//switch(estado_1)

                break; //break case 1 Estado_LCD

//
            //Case 2 Elegir nivel
            case 2: //case 2 Estado_LCD

                switch (estado_2) { // 	//switch(estado_2)

                case 0:
                    lcd_iniciar(cont_2);
                    cont_2=cont_2+1;
                    if(cont_2==5)estado_2=estado_2+1;
                    break; //break del case 0

                case 1:
                    elige(cont_2);
                    cont_2=cont_2+1;
                    if(cont_2==21)estado_2=estado_2+1;
                    break; //break del case 1

                case 2:
                    lcd_linea2(cont_2);
                    cont_2=cont_2+1;
                    if(cont_2==22)estado_2=estado_2+1;
                    break; //break del case 2

                case 3:

                    switch(AUX_LCD) {

                    case 0:
                        normal(cont_2);
                        cont_2=cont_2+1;
                        if(cont_2==25)estado_2=estado_2+1;

                        break; //break del case 0 normal()

                    case 1:
                        experto(cont_2);
                        cont_2=cont_2+1;
                        if(cont_2==25)estado_2=estado_2+1;
                        break; //break del case 1 experto

                    default:
                        if (cont_2==25)
                            cont_2=25;

                    } //end switch AUX_LCD

                    break;	//break del case 3

                } //end switch(estado_2)


                break; // break //case 2 Estado_LCD

            //

            //Escuchar

// Escuchar cancion
            case 3: //case 3 Estado_LCD

                switch(estado_3) {		//switch(estado_3)

                case 0:
                    lcd_iniciar(cont_3);
                    cont_3=cont_3+1;
                    if(cont_3==5)estado_3=estado_3+1;
                    break; //break del case 0

                case 1:
                    escuchar(cont_3);
                    cont_3=cont_3+1;
                    if(cont_3==13)estado_3=estado_3+1;
                    break; //break del case 1

                default:
                    if (cont_3==13)
                        cont_3=13;

                }	//end //switch(estado_3)

                break;//case 3 Estado_LCD

// Preparado?????????????''''''

            case 4: //case 4 Estado_LCD

                switch(estado_4) {		//switch(estado_4)

                case 0:
                    lcd_iniciar(cont_4);
                    cont_4=cont_4+1;
                    if(cont_4==5)estado_4=estado_4+1;
                    break; //break del case 0

                case 1:
                    preparado(cont_4);
                    cont_4=cont_4+1;
                    if(cont_4==14)estado_4=estado_4+1;
                    break; //break del case 1

                default:
                    if (cont_4==14)
                        cont_4=14;

                }	//end //switch(estado_4)

                break;//case 4 Estado_LCD

// Adelante

            case 5: //case 5 Estado_LCD

                switch(estado_5) {		//switch(estado_5)

                case 0:
                    lcd_iniciar(cont_5);
                    cont_5=cont_5+1;
                    if(cont_5==5)estado_5=estado_5+1;
                    break; //break del case 0

                case 1:
                    adelante(cont_5);
                    cont_5=cont_5+1;
                    if(cont_5==14)estado_5=estado_5+1;
                    break; //break del case 1

                default:
                    if (cont_5==14)
                        cont_5=14;

                }	//end //switch(estado_5)

                break;//case 5 Estado_LCD

//Again
            case 6: //case 6 Estado_LCD

                switch (estado_6) { // 	//switch(estado_6)

                case 0:
                    lcd_iniciar(cont_6);
                    cont_6=cont_6+1;
                    if(cont_6==5)estado_6=estado_6+1;
                    break; //break del case 0

                case 1:
                    again(cont_6);
                    cont_6=cont_6+1;
                    if(cont_6==21)estado_6=estado_6+1;
                    break; //break del case 1

                case 2:
                    lcd_linea2(cont_6);
                    cont_6=cont_6+1;
                    if(cont_6==22)estado_6=estado_6+1;
                    break; //break del case 2

                case 3:

                    switch(AUX_LCD) {

                    case 0:
                        si(cont_6);
                        cont_6=cont_6+1;
                        if(cont_6==26)estado_6=estado_6+1;

                        break; //break del case 0 normal()

                    case 1:
                        no(cont_6);
                        cont_6=cont_6+1;
                        if(cont_6==26)estado_6=estado_6+1;
                        break; //break del case 1 experto

                    default:
                        if (cont_6==26)
                            cont_6=26;

                    } //end switch AUX_LCD

                    break;	//break del case 3

                } //end switch(estado_6)


                break; // break //case 6 Estado_LCD

            default:
                if (cont_6==0)
                    cont_6=0;



//

            } //corchete Estado_LCD
//fin del switch estado LCD
            a=0;
        }


        if(t()==0) a=1;

    }



//return 0;

}	//end main
int main(void)
{
	unsigned int temp;

	// Configure the device for maximum performance but do not change the PBDIV
	// Given the options, this function will change the flash wait states, RAM
	// wait state and enable prefetch cache but will not change the PBDIV.
	// The PBDIV value is already set via the pragma FPBDIV option above..
	SYSTEMConfig(GetSystemClock(), SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);

/*PORT CONFIGURATION for UART*/
	// Blinky LED for Uart activity
	//mPORTAClearBits(BIT_7);
	//mPORTASetPinsDigitalOut(BIT_7);

// PINS used for the buttons
    PORTSetPinsDigitalIn(IOPORT_B, BIT_2 | BIT_3 | BIT_4);
	#define CONFIG          (CN_ON | CN_IDLE_CON)
	#define INTERRUPT       (CHANGE_INT_ON | CHANGE_INT_PRI_2)
	mCNOpen(CONFIG, CN4_ENABLE | CN5_ENABLE | CN6_ENABLE,
			CN4_PULLUP_ENABLE | CN5_PULLUP_ENABLE | CN6_PULLUP_ENABLE);
	temp = mPORTBRead();

//Analog input
	CloseADC10();
	#define PARAM1 ADC_MODULE_ON | ADC_FORMAT_INTG32 | ADC_CLK_AUTO | ADC_AUTO_SAMPLING_ON
	#define PARAM2 ADC_VREF_AVDD_AVSS | ADC_SCAN_ON | ADC_SAMPLES_PER_INT_2 | ADC_BUF_16 | ADC_ALT_INPUT_OFF
	#define PARAM3 ADC_CONV_CLK_INTERNAL_RC | ADC_SAMPLE_TIME_5
	#define PARAM4	ENABLE_AN0_ANA | ENABLE_AN1_ANA
	#define PARAM5	SKIP_SCAN_AN2 | SKIP_SCAN_AN3 | SKIP_SCAN_AN4 | SKIP_SCAN_AN5 | SKIP_SCAN_AN6 | SKIP_SCAN_AN7 | SKIP_SCAN_AN8 | SKIP_SCAN_AN9 | SKIP_SCAN_AN10 | SKIP_SCAN_AN11 | SKIP_SCAN_AN12 | SKIP_SCAN_AN13 | SKIP_SCAN_AN14 | SKIP_SCAN_AN15
	SetChanADC10( ADC_CH0_NEG_SAMPLEA_NVREF | ADC_CH0_POS_SAMPLEA_AN0);
	OpenADC10( PARAM1, PARAM2, PARAM3, PARAM4, PARAM5 );
	EnableADC10();

//PORT D for motors
	mPORTDClearBits(BIT_0 | BIT_1 | BIT_2 | BIT_3 |
					BIT_4 | BIT_5 | BIT_6 | BIT_7 |
					BIT_8 | BIT_9 | BIT_10 | BIT_11 |
					BIT_12 | BIT_13 | BIT_14 | BIT_15); 		// Turn off PORTD on startup.
	mPORTDSetPinsDigitalOut(BIT_0 | BIT_1 | BIT_2 | BIT_3 |
					BIT_4 | BIT_5 | BIT_6 | BIT_7 |
					BIT_8 | BIT_9 | BIT_10 | BIT_11 |
					BIT_12 | BIT_13 | BIT_14 | BIT_15);	// Make PORTD output.


	// Explorer-16 uses UART2 to connect to the PC.
	// This initialization assumes 36MHz Fpb clock. If it changes,
	// you will have to modify baud rate initializer.
    UARTConfigure(UART2, UART_ENABLE_PINS_TX_RX_ONLY);
    UARTSetFifoMode(UART2, UART_INTERRUPT_ON_TX_NOT_FULL | UART_INTERRUPT_ON_RX_NOT_EMPTY);
    UARTSetLineControl(UART2, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1);
    UARTSetDataRate(UART2, GetPeripheralClock(), DESIRED_BAUDRATE);
    UARTEnable(UART2, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_RX | UART_TX));

	// Configure UART2 RX Interrupt
	INTEnable(INT_SOURCE_UART_RX(UART2), INT_ENABLED);
    INTSetVectorPriority(INT_VECTOR_UART(UART2), INT_PRIORITY_LEVEL_2);
    INTSetVectorSubPriority(INT_VECTOR_UART(UART2), INT_SUB_PRIORITY_LEVEL_0);


	// Congifure Change/Notice Interrupt Flag
	ConfigIntCN(INTERRUPT);

    // configure for multi-vectored mode
    INTConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);

    // enable interrupts
    INTEnableInterrupts();


	WriteString("*** UART Interrupt-driven Example ***\r\n");

	unsigned int channel1, channel2;
	unsigned int motor1Time, motor2Time;
	// Let interrupt handler do the work
	while (1) {
		
		while ( ! mAD1GetIntFlag() );

		channel1 = ReadADC10(0);
		channel2 = ReadADC10(1);
		motor1Time = (channel1*(60000)/(1023) + 80000);
		motor2Time = (channel2*(60000)/(1023) + 80000);
		//maximo valor de motorTime = 140000

		//use motor time for stepping delay		
		if (MotorsON) {
			if (M1forward) {
				adelante(1, motor1Time, 1);
			} else {
				atras(1, motor1Time, 1);
			}

			if (M2forward) {
				adelante(1, motor2Time, 3);
			} else {
				atras(1, motor2Time, 3);
			}

		}
	
			mAD1ClearIntFlag();
		}
			
		return 0;
}