예제 #1
0
파일: main.c 프로젝트: 1i7/snippets
void init_board(void)
{
    /* clkout of 10mhz on 1.27 */
    LPC_PINCON->PINSEL3 &=~(3<<22);
    LPC_PINCON->PINSEL3 |= (1<<22);
    LPC_SC->CLKOUTCFG = (1<<8)|(14<<4); //enable and divide by 12

    UART0_Init(921600);

    if (I2CInit((uint32_t) I2CMASTER) == 0) {
        printf("Fatal error!\n");
        while (1);
    }
}
예제 #2
0
void main()
{
    WDTCN=0XDE;
    WDTCN=0XAD;
    SYSCLK_Init();
    PORT_Init();
    UART0_Init();
    while(1)
    {
        SBUF0 = 'A';
        while(!TI0);
        TI0=0;
    }
}
예제 #3
0
/*---------------------------------------------------------------------------------------------------------*/
int32_t main(void)
{
   	uint8_t unItem;       
    
    /* Unlock protected registers */
    SYS_UnlockReg();

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

    /* Lock protected registers */
    SYS_LockReg();

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

    /* Init UART1 for testing */
    UART1_Init();

    /*---------------------------------------------------------------------------------------------------------*/
    /* SAMPLE CODE                                                                                             */
    /*---------------------------------------------------------------------------------------------------------*/

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

    printf("\nUART PDMA Sample Program");

    /* UART PDMA sample function */
	do
	{
		printf("\n\n");
		printf("+------------------------------------------------------------------------+\n");
	    printf("|                      UART PDMA Driver Sample Code                      |\n");
	    printf("+------------------------------------------------------------------------+\n");                    
		printf("| [1] Using TWO PDMA channel to test. < TX1(CH1)-->RX1(CH0) >            |\n");
	    printf("| [2] Using ONE PDMA channel to test. < TX1-->RX1(CH0) >                 |\n");
		printf("+------------------------------------------------------------------------+\n");                     
		unItem = getchar();
	
		IsTestOver = FALSE;
        if((unItem == '1') || (unItem == '2'))
        {
		    PDMA_UART(unItem);
            printf("\n\n  UART PDMA sample code is complete.\n");
        }
        
    }while(unItem!=27);

    while(1);
}
예제 #4
0
int main(void)
{
    uint32_t u32KeyOption;
    
    /* Init System, IP clock and multi-function I/O */
    SYS_Init();

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

    /* Init SPI */
    SPI_Init();
    
    while(1)
    {
        printf("\n\n");
        printf("+----------------------------------------------------------------------+\n");
        printf("|                              SPI Driver                              |\n");
        printf("+----------------------------------------------------------------------+\n");
        printf("\n");
        printf("+----------------------------------------------------------------------+\n");
        printf("|  [1] SPI loopback test                                               |\n");
        printf("|  [2] SPI loopback test with PDMA                                     |\n");
        printf("|  [3] SPI master mode                                                 |\n");
        printf("|  [4] SPI slave mode                                                  |\n");
        printf("|  [Others] Quit                                                       |\n");
        printf("+----------------------------------------------------------------------+\n");
        printf("Please choose a item: ");
        
        u32KeyOption = getchar();
        printf("\n");
        if(u32KeyOption=='1')
            SpiLoopbackTest();
        else if(u32KeyOption=='2')
            SpiLoopbackTest_WithPDMA();
        else if(u32KeyOption=='3')
            SpiMasterMode();
        else if(u32KeyOption=='4')
            SpiSlaveMode();
        else
            break;
    }

    printf("\n\nExit SPI driver sample code.\n");

    /* Disable SPI0 and SPI1 IP clock */
    SYSCLK->APBCLK &= (~(SYSCLK_APBCLK_SPI0_EN_Msk | SYSCLK_APBCLK_SPI1_EN_Msk));
    return 0;
}
예제 #5
0
int main() 
{
    int adcValue;
    SystemInit();
    ADC_Init();       /* Initialize the ADC module */
    UART0_Init(9600);  /* Initialize UART at 9600 baud rate */
    
    while(1)
    {
        
        adcValue = ADC_GetAdcValue(AD0_1); // Read the ADC value of ADC0_1
        UART0_Printf("ADC0 Value:%4d \n\r",adcValue);     // Send the value on UART
    }  

}
예제 #6
0
int main() 
{
    int adcValue;
    float volt;
    SystemInit();    
    ADC_Init();        /* Initialize the ADC module */
    UART0_Init(9600);  /* Initialize UART at 9600 baud rate */
    
    while(1)
    {
        adcValue = ADC_GetAdcValue(0); // Read the ADC value of channel zero
        volt = (adcValue*(float)3.3)/(float)1023;
        UART0_Printf("ADC0 Value:%4d  Equivalent Voltage:%f\n\r",adcValue,volt);     // Send the value on UART
    }   
}
예제 #7
0
/* HW set up function */
static void SetupHardware(void)
{
	Board_Init();

    UART0_Init(230400);
    NVIC_EnableIRQ(UART0_IRQn);
	xprintf("\n\n\nVectrexador\n");

#ifndef SERIALDEBUG	
    NVIC_DisableIRQ(UART0_IRQn);
	UART0_UnInit();
	VectrexBusInit();
#endif	

	USB_Init(Disk_MS_Interface.Config.PortNumber, USB_MODE_Device);
}
예제 #8
0
/* start the main program */
int main() 
{
    uint8_t eeprom_address = 0x00, write_str[] = "Welcome to LPC1768 programming by Explore Embedded";
    uint8_t read_str[50];

    UART0_Init(9600);

    UART0_Printf("\n\rEeprom Write String: %s", write_str); //Print the message on UART
    EEPROM_WriteString(eeprom_address, write_str);          // Write the string at memoryLocation   0x00


    EEPROM_ReadString(eeprom_address, read_str);            // Read the string from memoryLocation 0x00
    UART0_Printf("\n\rEeprom Read String: %s", read_str);   //Print the message on UART

    while (1);
}
예제 #9
0
int main(void)
{
    uint32_t u32Item;

    /* Unlock protected registers */
    SYS_UnlockReg();

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

    /* Lock protected registers */
    SYS_LockReg();

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

    /* Init UART1 for testing */
    UART1_Init();

    /*---------------------------------------------------------------------------------------------------------*/
    /* SAMPLE CODE                                                                                             */
    /*---------------------------------------------------------------------------------------------------------*/

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

    printf("\n\nUART Sample Program\n");

    /* UART sample LIN function */
    do {
        TestItem();
        u32Item = getchar();
        printf("%c\n", u32Item);
        switch(u32Item) {
        case '1':
            LIN_FunctionTest();
            break;
        case '2':
            LIN_FunctionTestUsingLinCtlReg();
            break;
        default:
            break;
        }
    } while(u32Item != 27);

    while(1);

}
예제 #10
0
/**
 @fn main()
 @brief just to test UART0 module
 @return none
 */
void main()
{
        UART0_Init();
        UART0_PORT_Init();
        OSCILLATOR_Init();
        set_UART0_baudrate(10);    // set UART0 baudrate is 9600
        EA = 1;
        k = 0;
        SBUF0 = UART0_data[k];  // start to transmit data
        while (1)
        {
                if(k >= UART0_data_length)
                {
                        TR1 = 0;        // disable timer1 and stop transmitting data
                }
        }
}
예제 #11
0
파일: main.c 프로젝트: Hzza3/TM4C12x
int main(void)
{
	PLL_Init();   // 80 MHz
	ADCTimerINT_Init(7999);		// 10KHz
	EnableInterrupts(); // Enable global interrupt register flag 
	UART0_Init();
	TLV5618_Init();
	Sound_Init();
	UART0_TxString("Hi, Sir");
	ToggleDebug();
	//Sound_Tone(4780);
	while(1)
	{
		 //delay(20);
		WaitForInterrupt();
	}
}
예제 #12
0
int32_t main (void)
{
    uint32_t u32Result;

    /* Init System, IP clock and multi-function I/O
       In the end of SYS_Init() will issue SYS_LockReg()
       to lock protected register. If user want to write
       protected register, please issue SYS_UnlockReg()
       to unlock protected register if necessary */
    SYS_Init();

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

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

    printf("\nThis sample code demonstrate ADC single mode conversion\n");
    printf("It convert channel 0 and print conversion result\n");

    // Enable channel 0
    ADC_Open(ADC, 0, ADC_OPERATION_MODE_SINGLE, ADC_CH_0_MASK);

    // Set reference voltage to AVDD
    ADC_SET_REF_VOLTAGE(ADC, ADC_REFSEL_POWER);

    // Power on ADC
    ADC_POWER_ON(ADC);

    // Enable ADC ADC_IF interrupt
    ADC_EnableInt(ADC, ADC_ADF_INT);
    NVIC_EnableIRQ(ADC_IRQn);

    u8ADF = 0;

    ADC_START_CONV(ADC);

    while (u8ADF == 0);

    u32Result = ADC_GET_CONVERSION_DATA(ADC, 0);
    printf("Channel 0 conversion result is 0x%x\n",u32Result);

    ADC_DisableInt(ADC, ADC_ADF_INT);

    while(1);
}
예제 #13
0
/*---------------------------------------------------------------------------------------------------------*/
int32_t main (void)
{
    SYS_Init();
    UART0_Init();

    printf("NuMicro USB HID Transfer via Control Transfer\n");
    printf("Windows tool will Read and Write one pair of reports(periodic exchanges of reports).\n");
    USBD_Open(&gsInfo, HID_ClassRequest, NULL);

    /* Endpoint configuration */
    HID_Init();
    NVIC_EnableIRQ(USBD_IRQn);
    USBD_Start();

    while(1)
    {
    }
}
예제 #14
0
파일: main.c 프로젝트: brucetsao/Nuvoton
/*---------------------------------------------------------------------------------------------------------*/
int main(void)
{
    /* Unlock protected registers */
    SYS_UnlockReg();

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

    /* Lock protected registers */
    SYS_LockReg();

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

    printf("\n\nCPU @ %d Hz\n", SystemCoreClock);
    printf("+-------------------------------------------------------+\n");
    printf("|    GPIO Power-Down and Wake-up by PB.3 Sample Code    |\n");
    printf("+-------------------------------------------------------+\n\n");

    /* Configure PB.3 as Input mode and enable interrupt by rising edge trigger */
    PB->MODE = (PB->MODE & (~GPIO_MODE_MODE3_Msk)) | (GPIO_MODE_INPUT << GPIO_MODE_MODE3_Pos);
    PB->INTTYPE |= (GPIO_INTTYPE_EDGE << GPIO_INTTYPE_TYPE3_Pos);
    PB->INTEN |= GPIO_INTEN_RHIEN3_Msk;
    NVIC_EnableIRQ(GPB_IRQn);

    /* Enable interrupt de-bounce function and select de-bounce sampling cycle time is 1024 clocks of LIRC clock */
    GPIO->DBCTL = (GPIO_DBCTL_ICLK_ON | GPIO_DBCTL_DBCLKSRC_LIRC | GPIO_DBCTL_DBCLKSEL_1024);
    PB->DBEN |= BIT3;

    /* Unlock protected registers before entering Power-down mode */
    SYS_UnlockReg();

    /* Waiting for PB.3 rising-edge interrupt event */
    while(1)
    {
        printf("Enter to Power-Down ......\n");

        /* Enter to Power-down mode */
        PowerDownFunction();

        printf("System waken-up done.\n\n");
    }

}
예제 #15
0
파일: main.c 프로젝트: brucetsao/Nuvoton
/*---------------------------------------------------------------------------------------------------------*/
int32_t main(void)
{
    /*
        This sample code demonstrate how to use HID interface to transfer data
        between PC and USB device.
        A demo window tool is also included in "WindowsTool" directory with this
        sample code. User can use it to test data transfer with this sample code.
    */

    /* Unlock write-protected registers */
    SYS_UnlockReg();

    /* Init system and multi-function I/O */
    SYS_Init();

    /* Init UART for debug message */
    UART0_Init();

    printf("\n");
    printf("+--------------------------------------------------------+\n");
    printf("|        NuMicro USB Composite Device Sample Code        |\n");
    printf("|               (USB HID Transfer + Keyboard)            |\n");
    printf("+--------------------------------------------------------+\n");
    printf("If PB.5 = 0, just report key 'a'.\n");
    /* Set PB.5 as Quasi-bidirectional mode */
    PB->MODE = (PB->MODE & ~GPIO_MODE_MODE5_Msk) | (GPIO_MODE_QUASI << GPIO_MODE_MODE5_Pos);

    /* Open USB controller */
    USBD_Open(&gsInfo, HID_ClassRequest, NULL);

    /* Init Endpoint configuration for HID */
    HID_Init();

    /* Start USB device */
    USBD_Start();

    /* Enable USB device interrupt */
    NVIC_EnableIRQ(USBD_IRQn);

    while(1)
    {
    	HID_UpdateKbData();
    }
}
예제 #16
0
/*---------------------------------------------------------------------------------------------------------*/
int32_t main (void)
{
    SYS_Init();
    UART0_Init();

    printf("NuMicro USB HID\n");

    USBD_Open(&gsInfo, HID_ClassRequest, NULL);

    /* Endpoint configuration */
    HID_Init();
    NVIC_EnableIRQ(USBD_IRQn);
    USBD_Start();

    while(1)
    {
        HID_UpdateMouseData();
    }
}
예제 #17
0
int UART_TxRx_Function(void)
{
    /* Init System, IP clock and multi-function I/O */
	SysInit();
    /* Init UART0 for printf */
    UART0_Init();

    /*---------------------------------------------------------------------------------------------------------*/
    /* SAMPLE CODE                                                                                             */
    /*---------------------------------------------------------------------------------------------------------*/

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

    printf("+---------------------+\n");
    printf("| UART function test  |\n");
    printf("+---------------------+\n");

    UART_FunctionTest();
}
예제 #18
0
int32_t PWM_DeadZone(void)
{
    /* Init System, IP clock and multi-function I/O
       In the end of SYS_Init() will issue SYS_LockReg()
       to lock protected register. If user want to write
       protected register, please issue SYS_UnlockReg()
       to unlock protected register if necessary */
    SYS_Init();

    /* Init UART to 115200-8n1 for print message */
    UART0_Init();

    printf("\nThis sample code will output PWM0 channel 0 to with different\n");
    printf("frequency and duty, enable dead zone function of all PWM0 pairs.\n");
    printf("And also enable/disable PWM0 output every 1 second.\n");
    // PWM0 frequency is 100Hz, duty 30%,
    PWM_ConfigOutputChannel(PWM0, 0, 100, 30);
    PWM_EnableDeadZone(PWM0, 0, 400);

    // PWM2 frequency is 300Hz, duty 50%
    PWM_ConfigOutputChannel(PWM0, 2, 300, 50);
    PWM_EnableDeadZone(PWM0, 2, 200);

    // PWM4 frequency is 500Hz, duty 70%
    PWM_ConfigOutputChannel(PWM0, 4, 600, 70);
    PWM_EnableDeadZone(PWM0, 4, 100);

    // Enable complementary mode
    PWM_ENABLE_COMPLEMENTARY_MODE(PWM0);

    // Enable output of all PWM channels
    PWM_EnableOutput(PWM0, 0x3F);

    // Enable PWM channel 0 period interrupt, use channel 0 to measure time.
    PWM_EnablePeriodInt(PWM0, 0, 0);
    NVIC_EnableIRQ(PWM0CH0_IRQn);

    // Start
    PWM_Start(PWM0, 0x3F);

    while(1);

}
예제 #19
0
/*---------------------------------------------------------------------------------------------------------*/
int main(void)
{
    /* Unlock protected registers */
    SYS_UnlockReg();

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

    /* Lock protected registers */
    SYS_LockReg();

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

    printf("\n\nCPU @ %d Hz\n", SystemCoreClock);
    printf("+------------------------------------------------------------+\n");
    printf("|    GPIO EINT0/EINT1 Interrupt and De-bounce Sample Code    |\n");
    printf("+------------------------------------------------------------+\n\n");

    /*-----------------------------------------------------------------------------------------------------*/
    /* GPIO External Interrupt Function Test                                                               */
    /*-----------------------------------------------------------------------------------------------------*/
    printf("EINT0(PB.14) and EINT1(PB.15) are used to test interrupt\n");

    /* Configure PB.14 as EINT0 pin and enable interrupt by falling edge trigger */
    PB->PMD = (PB->PMD & (~GPIO_PMD_PMD14_Msk)) | (GPIO_PMD_INPUT << GPIO_PMD_PMD14_Pos);
    PB->IMD |= (GPIO_IMD_EDGE << 14);
    PB->IEN |= ((uint32_t)BIT14 << GPIO_IEN_IF_EN_Pos);
    NVIC_EnableIRQ(EINT0_IRQn);

    /* Configure PB.15 as EINT1 pin and enable interrupt by rising and falling edge trigger */
    PB->PMD = (PB->PMD & (~GPIO_PMD_PMD15_Msk)) | (GPIO_PMD_INPUT << GPIO_PMD_PMD15_Pos);
    PB->IMD |= (GPIO_IMD_EDGE << 15);
    PB->IEN |= ((uint32_t)BIT15 << GPIO_IEN_IR_EN_Pos) | ((uint32_t)BIT15 << GPIO_IEN_IF_EN_Pos);
    NVIC_EnableIRQ(EINT1_IRQn);

    /* Enable interrupt de-bounce function and select de-bounce sampling cycle time is 1024 clocks of LIRC clock */
    GPIO->DBNCECON = (GPIO_DBNCECON_ICLK_ON_Msk | GPIO_DBCLKSRC_LIRC | GPIO_DBCLKSEL_1024);
    PB->DBEN |= (BIT14 | BIT15);

    /* Waiting for interrupts */
    while(1);
}
예제 #20
0
파일: main.c 프로젝트: brucetsao/Nuvoton
/*---------------------------------------------------------------------------------------------------------*/
int main(void)
{
    /* Unlock protected registers */
    SYS_UnlockReg();

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

    /* Lock protected registers */
    SYS_LockReg();

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

    printf("\n\nCPU @ %d Hz\n", SystemCoreClock);
    printf("+-------------------------------------------------------+\n");
    printf("|    GPIO Power-Down and Wake-up by PB.3 Sample Code    |\n");
    printf("+-------------------------------------------------------+\n\n");

    /* Configure PB.3 as Input mode and enable interrupt by rising edge trigger */
    GPIO_SetMode(PB, BIT3, GPIO_MODE_INPUT);
    GPIO_EnableInt(PB, 3, GPIO_INT_RISING);
    NVIC_EnableIRQ(GPB_IRQn);

    /* Enable interrupt de-bounce function and select de-bounce sampling cycle time is 1024 clocks of LIRC clock */
    GPIO_SET_DEBOUNCE_TIME(GPIO_DBCTL_DBCLKSRC_LIRC, GPIO_DBCTL_DBCLKSEL_1024);
    GPIO_ENABLE_DEBOUNCE(PB, BIT3);

    /* Unlock protected registers before entering Power-down mode */
    SYS_UnlockReg();

    /* Waiting for PB.3 rising-edge interrupt event */
    while(1)
    {
        printf("Enter to Power-Down ......\n");

        /* Enter to Power-down mode */
        PowerDownFunction();

        printf("System waken-up done.\n\n");
    }

}
예제 #21
0
/*---------------------------------------------------------------------------------------------------------*/
void ADC_Example(void)
{
    uint8_t u8Option;

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

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

    printf("\nSystem clock rate: %dHz", SystemCoreClock);

    do{
        printf("\n\nConversion rate: %d samples/second\n", ADC_GetConversionRate());
//        printf("\n");
        printf("+----------------------------------------------------------------------+\n");
        printf("|                            ADC sample code                           |\n");
        printf("+----------------------------------------------------------------------+\n");
        printf("  [1] ADC single mode test\n");
        printf("  [2] ADC single cycle mode test\n");
        printf("  [3] ADC continuous scan mode test\n");
        printf("  [4] ADC compare function test\n");
        printf("  [Q or q] Quit\n");
        printf("Please choose a test item.\n");
        u8Option = uart_getchar();
        printf("%c\n",u8Option);
        switch(u8Option)
        {
            case '1':   AdcSingleModeTest();        break;
            case '2':   AdcSingleCycleModeTest();   break;
            case '3':   AdcContScanModeTest();      break;
            case '4':   AdcResultMonitorTest();     break;
            default:    break;
        }
    }while( (u8Option != 'Q') && (u8Option != 'q') );

    ADC_ResetIP();
    _ADC_DISABLE_CLOCK();
    NVIC_DisableIRQ(ADC_IRQn);
    printf("Exit ADC sample code\n");

    return 0;
}
예제 #22
0
/*---------------------------------------------------------------------------------------------------------*/
int FMC_Example(void)
{
    uint32_t u32Data[3];

    SYS_Init();
    UART0_Init();

    SYS_UnlockReg();                                              //中:解锁被保护的寄存器位,以便用户访问//en:Unlock protected register bits for user to access
    FMC_ENABLE_ISP();

    printf("APROM access to LDROM\n");

    LDROM_Erase();
    LDROM_Erase_Verify();
    LDROM_Program(0x55555555);
    LDROM_Program_Verify(0x55555555);

    FMC_ENABLE_AP_UPDATE();
    printf("APROM access to APROM\n");
    APROM_Erase();
    APROM_Erase_Verify();
    APROM_Program(0x33333333);
    APROM_Program_Verify(0x33333333);

    printf("config area Program\n");
    CONFIG_Erase();
    CONFIG0_Program(0xF8FFFFFF);
    CONFIG1_Program(0xEFFFFFFF);

    printf("Read UID\n");
    DrvFMC_ReadUID(0, &u32Data[0]);
    DrvFMC_ReadUID(1, &u32Data[1]);
    DrvFMC_ReadUID(2, &u32Data[2]);
    printf("UID %x %x %x\n", u32Data[0], u32Data[1], u32Data[2]);

    FMC_DISABLE_ISP();
    SYS_LockReg();                                                //中:重新锁被保护的寄存器位//en:Lock protected register bits again

    printf("ISP test is successful\n");

    return 0;
}
예제 #23
0
/*---------------------------------------------------------------------------------------------------------*/
int32_t main (void)
{
    SYS_Init();
    UART0_Init();

    printf("NuMicro USB CDC One Port\n");

    USBD_Open(&gsInfo, VCOM_ClassRequest, NULL);

    /* Endpoint configuration */
    VCOM_Init();
    NVIC_EnableIRQ(UART0_IRQn);
    NVIC_EnableIRQ(USBD_IRQn);
    USBD_Start();

    while(1)
    {
        VCOM_TransferData();
    }
}
예제 #24
0
int main(void)
{
    /* Init System, IP clock and multi-function I/O */
    SYS_Init();
    /* Init UART0 for printf */
    UART0_Init();

    /* Init UART1 */
    UART1_Init();

    /*---------------------------------------------------------------------------------------------------------*/
    /* SAMPLE CODE                                                                                             */
    /*---------------------------------------------------------------------------------------------------------*/

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

    UART_PDMATest();

    while(1);
}
예제 #25
0
파일: main.c 프로젝트: lazhartel/tinythread
/*---------------------------------------------------------------------------------------------------------*/
int32_t main(void)
{

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

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

    /* Init GPIO P2.0 (output) and P3.2 (EINT0) */
    GPIO_Init();

    /* Init SPI0 and LCD */
    LCD_Init();
    LCD_EnableBackLight();
    LCD_ClearScreen();

    LCD_Print(0, "Boot from LDROM");
    LCD_Print(1, "Press SW_INT   ");

    while (1)
    {
        if (g_u8IsPress)
        {
            g_u8IsPress = FALSE;
            
            /* Switch to boot from APROM */
            SYS_UnlockReg();
            FMC->ISPCON = FMC_ISPCON_BS_APROM;
            _SYS_RESET_CPU();
            while (1);
        }
        else
        {
            /* LED blanking for 1000ms */
            P2->DOUT ^= 1;
            SYS_SysTickDelay(300000);
            SYS_SysTickDelay(200000);
        }
    }
}
예제 #26
0
/*---------------------------------------------------------------------------------------------------------*/
int main(void)
{
    /* Unlock protected registers */
    SYS->REGWRPROT = 0x59;
    SYS->REGWRPROT = 0x16;
    SYS->REGWRPROT = 0x88;

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

    /* Lock protected registers */
    SYS->REGWRPROT = 0x0;

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

    printf("\n\nCPU @ %d Hz\n", SystemCoreClock);
    printf("+------------------------------------------------+\n");
    printf("|    GPIO P1.3 and P4.5 Interrupt Sample Code    |\n");
    printf("+------------------------------------------------+\n\n");

    /*-----------------------------------------------------------------------------------------------------*/
    /* GPIO Interrupt Function Test                                                                        */
    /*-----------------------------------------------------------------------------------------------------*/
    printf("P1.3 and P4.5 are used to test interrupt ......\n");

    /* Configure P1.3 as Input mode and enable interrupt by rising edge trigger */
    P1->PMD = P1->PMD & (~GPIO_PMD_PMD3_Msk) | (GPIO_PMD_INPUT << GPIO_PMD_PMD3_Pos);
    P1->IMD |= (GPIO_IMD_EDGE << 3);
    P1->IEN |= (BIT3 << GPIO_IEN_IR_EN_Pos);
    NVIC_EnableIRQ(GPIO_P0P1_IRQn);

    /*  Configure P4.5 as Quasi-bidirection mode and enable interrupt by falling edge trigger */
    P4->PMD = P1->PMD & (~GPIO_PMD_PMD5_Msk) | (GPIO_PMD_QUASI << GPIO_PMD_PMD5_Pos);
    P4->IMD |= (GPIO_IMD_EDGE << 5);
    P4->IEN |= (BIT5 << GPIO_IEN_IF_EN_Pos);
    NVIC_EnableIRQ(GPIO_P2P3P4_IRQn);

    /* Waiting for interrupts */
    while(1);
}
예제 #27
0
/*---------------------------------------------------------------------------------------------------------*/
int main(void)
{
    /* Unlock protected registers */
    SYS_UnlockReg();

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

    /* Lock protected registers */
    SYS_LockReg();

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

    printf("\n\nCPU @ %d Hz\n", SystemCoreClock);
    printf("+------------------------------------------------------------+\n");
    printf("|    GPIO EINT0/EINT1 Interrupt and De-bounce Sample Code    |\n");
    printf("+------------------------------------------------------------+\n\n");

    /*-----------------------------------------------------------------------------------------------------*/
    /* GPIO External Interrupt Function Test                                                               */
    /*-----------------------------------------------------------------------------------------------------*/
    printf("EINT0(PB.14) and EINT1(PB.15) are used to test interrupt\n");

    /* Configure PB.14 as EINT0 pin and enable interrupt by falling edge trigger */
    GPIO_SetMode(PB, BIT14, GPIO_PMD_INPUT);
    GPIO_EnableEINT0(PB, 14, GPIO_INT_FALLING);
    NVIC_EnableIRQ(EINT0_IRQn);

    /* Configure PB.15 as EINT1 pin and enable interrupt by rising and falling edge trigger */
    GPIO_SetMode(PB, BIT15, GPIO_PMD_INPUT);
    GPIO_EnableEINT1(PB, 15, GPIO_INT_BOTH_EDGE);
    NVIC_EnableIRQ(EINT1_IRQn);

    /* Enable interrupt de-bounce function and select de-bounce sampling cycle time is 1024 * 10 KHz clock */
    GPIO_SET_DEBOUNCE_TIME(GPIO_DBCLKSRC_LIRC, GPIO_DBCLKSEL_1024);
    GPIO_ENABLE_DEBOUNCE(PB, BIT14 | BIT15);

    /* Waiting for interrupts */
    while(1);
}
예제 #28
0
int main() 
{
    int adcValue,temp;
    SystemInit();
    ADC_Init();       /* Initialize the ADC module */
    UART0_Init(9600);  /* Initialize UART at 9600 baud rate */
    
    while(1)
    {
        adcValue = ADC_GetAdcValue(AD0_1); // Read the ADC value of channel zero where the temperature sensor(LM35) is connected
        
        /* Convert the raw ADC value to equivalent temperature with 3.3v as ADC reference
         Step size of AdC= (3.3v/1023)= 3.225mv.
         for every degree celcius the Lm35 provides 10mv voltage change.
         1 step of ADC=3.225mv=0.5'c, hence the Raw ADC value can be divided by 3.1 to get equivalent temp*/
        
        temp = adcValue/(float)3.1; // Divide by 3.1 to get the temp value.
		
        UART0_Printf("ADC0 Value:%4d  Equivalent Temperature:%3d\n\r",adcValue,temp);     // Send the value on UART
    }			    
}
예제 #29
0
int main(void)
{		
	PLL_Init();			 //	Enable the PLL Block and set the main clock frequency to 80 MHz
	GPIOPortF_EdgeTriggerSW();  // Init Edge Interrupt on high Edge on two switches PF0, PF4 
	UART0_Init();
	SysTickInts_Init(8000000);		// 100ms
	// Timer Period = Clock / Period
	// Period = 1 / ClockFrequency
	// for 80Khz, Period= 80MHz / 80KHz = 1000
	// start with 50% DutyCycle on both wheels
	Timer0APWM_Init(1000, High); // 80 KHz, 50% Duty Cycle 
	
	EnableInterrupts();
	
	UART0_TxString("Ready, Sir");
	UART0_NewLine();
	while(1) 
	{
			WaitForInterrupt(); // low power mode
	}
}
예제 #30
0
int main()
{
    char str[50];
    int len = 0;
    SystemInit();

    /*Connect RS->P1_16, RW->P1_17, EN->P1_18 and data bus(D4:D7 - P1_20:P1_23)*/
    LCD_SetUp(P1_16,P1_17,P1_18,P_NC,P_NC,P_NC,P_NC,P1_20,P1_21,P1_22,P1_23);
    LCD_Init(2,16);
    UART0_Init(9600);
    LCD_DisplayString("send data from  serial terminal");
    while(1)
    {
        len = UART0_RxString(str);
        UART0_Printf("Received String:%s   size=%2d\n\r",str,len);
        LCD_Clear();
        LCD_Printf("str:%s size=%2d",str,len);
    }


}