예제 #1
0
int main(void) {
    initArray(&uartData, 5);

    // Enable 80Mhz clock.
    PLLInitialize(4);

    // Use 1ms gradation for 80 Mhz clock.
    SysTickInitialize(80000UL);

    UARTInitialize(UART1Module, 115200, 80);

    // Activate GPIO port B (Chip Select).
    System_CTRL_RCGCGPIO_R |= System_CTRL_RCGCGPIO_GPIOB_MASK;

    chipSelectPort->AFSEL &= ~chipSelectPin;
    chipSelectPort->AMSEL &= ~chipSelectPin;
    chipSelectPort->PCTL &= ~chipSelectPin;
    chipSelectPort->DIR |= chipSelectPin;
    chipSelectPort->DEN |= chipSelectPin;

    Nokia5110_Init();
    Nokia5110_Clear();
    Nokia5110_WriteString("GPS");

    toggleSensor();

    // On the current hardware we receive to messages:
    // 1. A0A20001470047B0B3 - SiRF IV: Hardware Configuration Request, MID_HW_CONFIG_REQ, unused.
    // 2. A0A2000212000012B0B3 - OkToSend SiRF binary message.

    while (1) {
        if (uartData.used == 0) {
            Nokia5110_Clear();
            Nokia5110_WriteString("No data!");
        } else {
            char symbol[4];
            for (uint32_t i = 0; i < uartData.used; i++) {
                if (i % 17 == 0) {
                    SysTickDelay(5000);
                    Nokia5110_Clear();
                }

                sprintf(symbol, "_%02x_", uartData.array[i]);

                Nokia5110_WriteString(symbol);
            }

            SysTickDelay(5000);
            Nokia5110_Clear();
            Nokia5110_WriteString("End of data!");
        }
    }
}
예제 #2
0
/*---------------------------------------------------------------------------------------------------------*/
int32_t main(void)
{
    int32_t i;

    /* Init System, IP clock and multi-function I/O */
    SYS_Init();

    /* Init UART0 for printf */
    UART0_Init();

    /*
        This is a simple sample code for LDROM in new IAP mode.
        The base address is 0x100000.
        The base address for function table is defined by FUN_TBL_BASE.
    */

    printf("+------------------------------------------------------------------+\n");
    printf("|    M05xx Flash Memory Controller Driver Sample Code for LDROM    |\n");
    printf("+------------------------------------------------------------------+\n");

    printf("\nCPU @ %dHz\n\n", SystemCoreClock);

    // Delay 3 seconds
    for(i = 0; i < 30; i++)
    {
        printf(".");
        SysTickDelay(10000);
    }
    printf("\n");

    printf("Function table @ 0x%08x\n", g_funcTable);

    while(SYS->PDID)__WFI();
}
예제 #3
0
/**
 * @brief 	Initialize the LCD to wrap at 16 chars,
 * 			cursor off, and clear the screen.
 *
 * @param 	none
 *
 * @retval 	none
 */
void LCDInit(void)
{
	// Wait for LCD to power up
	SysTickDelay(ST_MS * 20);

	LCD_DISPLAY_MODE(0x30);
	LCD_CURSOR_MODE(0x32);
	LCD_CLEAR();
}
/**
 * @brief	Gather input and return it as an 8-bit integer
 *
 * @param 	none
 *
 * @retval	The nes controller input.
 *
 * 			1 = Button pressed
 * 			0 = Button not pressed
 */
NesData GetInput(void)
{
	int i = 1;
	uint8_t temp_data;	// Data grabbed from the controller
	NesData data;	// Final parsed controller data

	NESPORT &= ~ALL_NES_PINS;

	// Toggle latch pin
	NESPORT |= NES_LATCH;
	SysTickDelay(12 * ST_US);
	NESPORT &= ~NES_LATCH;

	// Grab A button data
	temp_data = (NESPORT & NES_DATA) >> NES_DATA_S;

	// Grab rest of data from controller
	for(; i < 8; i++)
	{
		NESPORT |= NES_CLK;
		SysTickDelay(6 * ST_US);
		NESPORT &= ~NES_CLK;
		temp_data |= ((NESPORT & NES_DATA) >> NES_DATA_S) << i;
		SysTickDelay(6 * ST_US);
	}

	// Parse controller input and create NesData structure
	data.A = temp_data & 1;
	data.B = (temp_data >> 1) & 1;
	data.Select= (temp_data >> 2) & 1;
	data.Start = (temp_data >> 3) & 1;
	data.Up = (temp_data >> 4) & 1;
	data.Down = (temp_data >> 5) & 1;
	data.Left = (temp_data >> 6) & 1;
	data.Right = (temp_data >> 7) & 1;

	return data;

}
예제 #5
0
void
Nokia5110_Init(void){
  // Nokia 5110 LCD max clock frequency is 4Mhz, so with 50Mhz system clock,
  // clock prescale divisor (must be even number) is calculated via
  // SysClk/(CPSDVSR*(1+SCR)) formula, where SCR=0, so 50 / (14 * (1 + 0)) =
  // 3.571 MHz (slower than 4 MHz).
  InitializeSSI(SSI0Module, 14);

  // 6 - command chooser pin, 7 - reset pin.
  uint32_t servicePins = GPIO_PORT_PIN_6 | GPIO_PORT_PIN_7;

  SERVICE_PORT->DIR |= servicePins;
  SERVICE_PORT->AFSEL &= ~servicePins;
  SERVICE_PORT->AMSEL &= ~servicePins;
  SERVICE_PORT->DEN |= servicePins;
  SERVICE_PORT->PCTL &= 0x00FFFFFF;

  // Reset to a known state, wait for 100ms between writes.
  SERVICE_PORT->PIN7 = 0x0;
  SysTickDelay(100);
  SERVICE_PORT->PIN7 = 0x80;

  // Chip active;
  // Horizontal addressing mode (V = 0);
  // Use extended instruction set (H = 1).
  writeCommand(0x21);

  // Set LCD Vop (contrast), minimal contrast is 0xA0 and maximum is 0xCF.
  writeCommand(0xB1);

  // Set temp coefficient.
  writeCommand(0x04);

  // LCD bias mode 1:48: try 0x13 or 0x14.
  writeCommand(0x14);

  // We must send 0x20 before modifying the display control mode.
  writeCommand(0x20);

  // Set display control to normal mode: 0x0D for inverse.
  writeCommand(0x0C);
}
예제 #6
0
void
toggleSensor() {
    chipSelectPort->PIN2 = 0x1;
    SysTickDelay(200);
    chipSelectPort->PIN2 = 0x0;
}
예제 #7
0
int main(void) {
  // Enable 80Mhz clock.
  PLLInitialize(4);

  // Use 1ms gradation for 80 Mhz clock.
  SysTickInitialize(80000UL);

  const ADC_PIN = GPIO_PORT_PIN_3;

  const DAC_PINS = GPIO_PORT_PIN_0 | GPIO_PORT_PIN_1 | GPIO_PORT_PIN_2 |
      GPIO_PORT_PIN_3 | GPIO_PORT_PIN_4 | GPIO_PORT_PIN_5 | GPIO_PORT_PIN_6 |
      GPIO_PORT_PIN_7;

  // Active ADC0.
  System_CTRL_RCGCADC_R |= System_CTRL_RCGCADC_ADC0_MASK;

  // Activate GPIO port B (DAC) and E (ADC).
  System_CTRL_RCGCGPIO_R |= System_CTRL_RCGCGPIO_GPIOB_MASK | System_CTRL_RCGCGPIO_GPIOE_MASK;

  unsigned long volatile delay;

  // Activate Timer0
  System_CTRL_RCGCTIMER_R |= System_CTRL_RCGCTIMER_TIMER0_MASK;

  delay = System_CTRL_RCGCTIMER_R;

  GPIOE->AFSEL |= ADC_PIN;
  GPIOE->AMSEL |= ADC_PIN;
  GPIOE->DIR &= ~ADC_PIN;
  GPIOE->DEN &= ~ADC_PIN;

  GPIOB->AFSEL &= ~DAC_PINS;
  GPIOB->AMSEL &= ~DAC_PINS;
  GPIOB->PCTL &= ~DAC_PINS;
  GPIOB->DIR |= DAC_PINS;
  GPIOB->DEN |= DAC_PINS;

  // Sequencer 3 is highest priority.
  ADC0->ADCSSPRI = 0x0123;

  // Disable sample sequencer 3.
  ADC0->ADCACTSS &= ~0x0008;

  // Sequencer 3 is software trigger.
  ADC0->ADCEMUX &= ~0xF000;

  // Clear SS3 field, saying that AIN0 will be used.
  ADC0->ADCSSMUX3 &= ~0x000F;

  // No TS0 D0, yes IE0 END0.
  ADC0->ADCSSCTL3 = 0x0006;

  // Enable sample sequencer 3.
  ADC0->ADCACTSS |= 0x0008;

  // Disable Timer0.
  Timer0->GPTMCTL = 0x0UL;

  // Choose 32 bit mode.
  Timer0->GPTMCFG = 0x0UL;

  // Choose periodic mode.
  Timer0->GPTMTAMR = 0x2UL;

  // Reload value
  Timer0->GPTMTAILR = 7256;

  // Clock resolution
  Timer0->GPTMTAPR = 0;

  // Clear timeout flag
  Timer0->GPTMICR = 0x1UL;

  // Arm timeout
  Timer0->GPTMIMR = 0x1UL;

  // Timer0A is 35th in vector table, interrupt number is 19.
  // Setting priority 4 (100, last 3 bits).
  NVIC->PRI4 = (NVIC->PRI4 & 0x00FFFFFF) | 0x80000000;

  // Enable IRQ 19
  NVIC->EN0 = 1 << 19;

  // Enable Timer0A
  Timer0->GPTMCTL = 0x1UL;

  Nokia5110_Init();

  Nokia5110_Clear();

  while (1) {
    Nokia5110_Clear();
    Nokia5110_WriteDec(ReadADC0());
    SysTickDelay(1000);
  }
}