示例#1
0
void main( void ){

    TRISB = 0;

    setupServos();
    ADCON0bits.ADON = 1;    // Turn on analog to digital converter
//    ADCON2bits.ADFM = 1;    // Right Justify the results
    while(1){

        // Setup Analog to digital conversion
        ADCON0bits.GO = 1;  // Start analog to digital conversion
        while(ADCON0bits.GO){/*Do Nothing*/}
        updateServoCCP(ADRESH-12,ADRESH-6);
    }

}
int main(void) {
    // Enable FPU for interrupt routines
    // ROM_FPULazyStackingEnable();
    // ROM_FPUEnable();

    // Set clock to 80MHz
    SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

    // Turn off LEDs
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
    ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2|GPIO_PIN_3, 0);

    // Setup buttons
    ButtonsInit();

    // Initialize the UART.
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    ROM_GPIOPinConfigure(GPIO_PA0_U0RX);
    ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
    ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    UARTStdioInit(0);

    // Setup servos and start the timer for them
    setupServos();

    uint16_t servoPosition = SERVO_MIN_PULSE;

    // Continually check which button is pressed and move the servo position that direction
    while(1) {
        switch(ButtonsPoll(0, 0) & ALL_BUTTONS) {
            case LEFT_BUTTON:
                servoPosition -= 10;

                if(servoPosition < SERVO_MIN_PULSE) {
                    servoPosition = SERVO_MIN_PULSE;

                    // Too far, blink red
                    ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, GPIO_PIN_1);
                } else {
                    // Valid position, blink green
                    ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, GPIO_PIN_2);
                }
                break;

            case RIGHT_BUTTON:
                servoPosition += 10;

                if(servoPosition > SERVO_MAX_PULSE) {
                    servoPosition = SERVO_MAX_PULSE;
                    
                    // Too far, blink red
                    ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, GPIO_PIN_1);
                } else {
                    // Valid position, blink blue
                    ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, GPIO_PIN_3);
                }
                break;
        }

        // Update servo positions
        servoSet(servo, servoPosition);
        servoSet(servo2, servoPosition);

        // Wait .002s
        SysCtlDelay((SysCtlClockGet() / 3) / 500);

        // Turn off all LEDs
        ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0);
    }
}
示例#3
0
int main(void) {

	ROM_FPUEnable();
	ROM_FPULazyStackingEnable();

	ROM_SysCtlClockSet(
	SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
	SysTickPeriodSet(SysCtlClockGet() / TICKFREQ); //tickfreq in Hz
	SysTickIntEnable();
	SysTickEnable();
#ifdef DEBUG
	InitConsole();
#endif
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART4);
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART3);
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

	ROM_IntMasterEnable();

	ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE,
	GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);

	GPIOPinConfigure(GPIO_PC6_U3RX);
	GPIOPinConfigure(GPIO_PC7_U3TX);
	GPIOPinConfigure(GPIO_PB0_U1RX);
	GPIOPinConfigure(GPIO_PB1_U1TX);

	ROM_GPIOPinTypeUART(GPIO_PORTC_BASE,
	GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7);
	ROM_GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);
	ROM_UARTFIFOEnable(UART1_BASE);
	ROM_UARTFIFOEnable(UART3_BASE);

	ROM_UARTConfigSetExpClk(UART3_BASE, ROM_SysCtlClockGet(), 115200,
			(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
			UART_CONFIG_PAR_NONE));
	ROM_UARTConfigSetExpClk(UART1_BASE, ROM_SysCtlClockGet(), 38400,
			(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
			UART_CONFIG_PAR_NONE));

	ROM_IntEnable(INT_UART1);
	ROM_UARTIntEnable(UART1_BASE, UART_INT_RX | UART_INT_RT); // ONLY recieve inturrupt

	ROM_IntEnable(INT_UART3);
	ROM_UARTIntEnable(UART3_BASE, UART_INT_RX | UART_INT_RT); // ONLY recieve inturrupt

	I2CSetup(I2C0_MASTER_BASE, true);

	setupServos();
	UARTprintf("init");
	nrf24l01p_init(3);
	nrf24l01p_setRADDR((uint8_t *) "Boat");
	nrf24l01p_setPayLoad(DATA_BUFFER_MAX);
	nrf24l01p_setChannel(1);
	nrf24l01p_config();
	nrf24l01p_setTADDR((uint8_t *) "Base");

//	nrf24l01p_send((unsigned char *) &"Init");
	GPIOPortIntRegister(GPIO_PORTA_BASE, portAIntHandler);
	GPIOIntTypeSet(GPIO_PORTA_BASE, GPIO_PIN_5, GPIO_FALLING_EDGE);
	GPIOPinIntEnable(GPIO_PORTA_BASE, GPIO_PIN_5);
	unsigned char p = 0;
	nrf24l01p_readRegister(0x00, &p, 1);
	UARTprintf("   ");

	while (1) {

		sortGPSSentence();
	}
}