Beispiel #1
0
int main() 
{
    uint8_t value;
    SystemInit();                               /* Clock and PLL configuration */

    GPIO_PinFunction(MY_SWITCH,PINSEL_FUNC_0);  /* Configure Pin for Gpio */
    GPIO_PinDirection(MY_SWITCH,INPUT);         /* Configure the switch pin as Input */

    GPIO_PinFunction(MY_LED,PINSEL_FUNC_0);     /* Configure Pin for Gpio */
    GPIO_PinDirection(MY_LED,OUTPUT);           /* Configure the Led pin as OUTPUT */

    while(1)
    {
        value = GPIO_PinRead(MY_SWITCH);         /* Read the switch status */
        GPIO_PinWrite(MY_LED,value);             /*  ON/OFF the led as per switch status */  
    }
}
/***************************************************************************************************
                    void UART_Init(uint8_t var_uartChannel_u8, uint32_t var_baudRate_u32)
 ****************************************************************************************************
 * I/P Arguments: uint32_t : Baudrate to be configured.
 * Return value    : none

 * description  :This function is used to initialize the UART at specified baud rate.
                 If the requested baud rate is not within the supported range then
                 the default baud rate of 9600 is set.


            Refer uart.h file for Supported(range) baud rates.        
 ***************************************************************************************************/
void UART_Init(uint8_t var_uartChannel_u8, uint32_t var_baudRate_u32)
{    
    if(var_uartChannel_u8< C_MaxUartChannels_U8)
    {	 
        GPIO_PinFunction(STR_UartConfig[var_uartChannel_u8].TxPin,STR_UartConfig[var_uartChannel_u8].PinFunSel);
        GPIO_PinFunction(STR_UartConfig[var_uartChannel_u8].RxPin,STR_UartConfig[var_uartChannel_u8].PinFunSel);
		util_BitSet(LPC_SC->PCONP,STR_UartConfig[var_uartChannel_u8].pconBit);
        
        /* Enable FIFO and reset Rx/Tx FIFO buffers */
        STR_UartConfig[var_uartChannel_u8].UARTx->FCR = (1<<SBIT_FIFO) | (1<<SBIT_RxFIFO) | (1<<SBIT_TxFIFO); 

        /* 8bit data, 1Stop bit, No parity */
        STR_UartConfig[var_uartChannel_u8].UARTx->LCR = (0x03<<SBIT_WordLenght) | (1<<SBIT_DLAB);

        UART_SetBaudRate(var_uartChannel_u8,var_baudRate_u32);    
    }
}
/***************************************************************************************************
                         void PWM_SetDutyCycle( uint32_t pin, uint32_t dutyCycle )
 ****************************************************************************************************
 * I/P Arguments: uint32_t: Pin number at which PWM needs to be generated.(PWM_1 - PWM_5).
                  uint32_t : required dutyCycle at the pwm pin.
 * Return value    : none

 * description :This function initializes the internal PWM1 module of lpc1768.
                By default the pwm  cycle(Ton+Toff) is set 255 to match the arduino style.
 ***************************************************************************************************/
void PWM_SetDutyCycle( uint32_t pin, uint32_t dutyCycle )
{  
    uint32_t pinSelect=0;

    if(pwmInitDoneFlag_u32 == 0)
    {
        PWM_Init(PWM_CYCLE);   // Set the PWM_CYCLE to 255 if user has not called the PWM_Init function.
        pwmInitDoneFlag_u32 = 1;
    }  

    pin = pin & PWM_CHANNEL_MASK; /* Ensure only supported channel bits are set */


    while(pin)
    {
        pinSelect = ((~pin)+1) & pin; /* Extract the first bit  from left side */
        pin = pin & (~pinSelect);     /* Clear the Bit after extracting, as it is being processed now*/

        switch(pinSelect)
        {
        case PWM_1:
            GPIO_PinFunction(P2_0,PINSEL_FUNC_1);
            LPC_PWM1->MR1 = dutyCycle;
            LPC_PWM1->LER|= LER1_EN; 

            break;

        case PWM_2:
            GPIO_PinFunction(P2_1,PINSEL_FUNC_1);
            LPC_PWM1->MR2 = dutyCycle;
            LPC_PWM1->LER|= LER2_EN;

            break;

        case PWM_3:
            GPIO_PinFunction(P2_2,PINSEL_FUNC_1);
            LPC_PWM1->MR3 = dutyCycle;
            LPC_PWM1->LER|= LER3_EN; 

            break;

        case PWM_4:
            GPIO_PinFunction(P2_3,PINSEL_FUNC_1);
            LPC_PWM1->MR4 = dutyCycle;
            LPC_PWM1->LER|= LER4_EN; 
            break;

        case PWM_5:
            GPIO_PinFunction(P2_4,PINSEL_FUNC_1);
            LPC_PWM1->MR5 = dutyCycle;
            LPC_PWM1->LER|= LER5_EN; 
            break;

        case PWM_6:
            GPIO_PinFunction(P2_5,PINSEL_FUNC_1);
            LPC_PWM1->MR6 = dutyCycle;
            LPC_PWM1->LER|= LER6_EN; 
            break;

        default :
            break;            
        }
    }
}