/*************************************************************************************************** void TIMER_Start(uint8_t timerNumber_u8) **************************************************************************************************** * I/P Arguments: uint8_t: Timer number(TIMER0-TIMER3) that needs to be started. * Return value: none * description :This function turns on the timer and it starts incrementing. ##Note: Before calling the TIMER_Start function the timers should to be initialized by calling TIMER_Init() ****************************************************************************************************/ void TIMER_Start(uint8_t timerNumber_u8) { switch(timerNumber_u8) { case 0 : v_Timer0_OvfCount_U16 = 0; TCNT0 = v_Timer0_ReloadValue_U8; // Load the timer value util_BitSet(TIMSK,TOIE0); //Enable timer interrupt TCCR0 = v_Timer0_Prescaler_U8; //Start the timer by loading the required presacaler value break; case 1 : v_Timer1_OvfCount_U16 = 0; TCNT1= v_Timer1_ReloadValue_U16; // Load the timer value util_BitSet(TIMSK,TOIE1); //Enable timer interrupt TCCR1A = 0x00; TCCR1B = v_Timer1_Prescaler_U8; //Start the timer by loading the required presacaler value break; case 2 : v_Timer2_OvfCount_U16 = 0; TCNT2 = v_Timer2_ReloadValue_U8; // Load the timer value util_BitSet(TIMSK,TOIE2); //Enable timer interrupt TCCR2 = v_Timer2_Prescaler_U8; //Start the timer by loading the required presacaler value break; } }
/*************************************************************************************************** void EEPROM_WriteByte(uint16_t var_eepromAddres_u16, uint8_t var_eepromData_u8) *************************************************************************************************** * I/P Arguments: uint16_t: eeprom_address at which eeprom_data is to be written uint8_t: byte of data to be to be written in eeprom. * Return value : none * description: This function is used to write the data at specified EEPROM_address.. **************************************************************************************************/ void EEPROM_WriteByte(uint16_t var_eepromAddress_u16, uint8_t var_eepromData_u8) { while(util_IsBitSet(EECR,EEWE)); // Wait for completion of previous write. // EEWE will be cleared by hardware once Eeprom write is completed. EEAR = var_eepromAddress_u16; //Load the eeprom address and data EEDR = var_eepromData_u8; util_BitSet(EECR,EEMWE); // Eeprom Master Write Enable util_BitSet(EECR,EEWE); // Start eeprom write by setting EEWE }
/*************************************************************************************************** uint8_t EEPROM_ReadByte(uint16_t var_eepromAddres_u16) *************************************************************************************************** * I/P Arguments: uint16_t: eeprom_address from where eeprom_data is to be read. * Return value : uint8_t: data read from Eeprom. * description: This function is used to read the data from specified EEPROM_address. ***************************************************************************************************/ uint8_t EEPROM_ReadByte(uint16_t var_eepromAddress_u16) { while(util_IsBitSet(EECR,EEWE)); //Wait for completion of previous write if any. EEAR = var_eepromAddress_u16; //Load the address from where the data needs to be read. util_BitSet(EECR,EERE); // start eeprom read by setting EERE return EEDR; // Return data from data register }
/*************************************************************************************************** uint16_t ADC_GetAdcValue(uint8_t var_adcChannel_u8) **************************************************************************************************** * I/P Arguments: uint8_t(channel number). * Return value : uint16_t(10 bit ADC result) * description :This function does the ADC conversion for the Selected Channel and returns the converted 10bit result The adc value per bit depends on the resolution of the ADC. For AVR/PIC(10-bit adc) the adc value per lsb will be 5/1023=0048v ***************************************************************************************************/ uint16_t ADC_GetAdcValue(uint8_t var_adcChannel_u8) { ADMUX = var_adcChannel_u8; /* Select the required channel */ util_BitSet(ADCSRA,ADSC); /* Start the ADC conversion by setting ADSC bit */ while(util_IsBitCleared(ADCSRA,ADIF)); /* Wait till the conversion is over */ /* ADIF will be set once ADC conversion is complete */ return(ADCW); /* Return the 10-bit result */ }
/*************************************************************************************************** void TIMER_Stop(uint8_t timerNumber_u8) **************************************************************************************************** * I/P Arguments: uint8_t: Timer number(TIMER0-TIMER3) that needs to be stopped. * Return value: none * description :This function turns OFF the timer incrementing. ****************************************************************************************************/ void TIMER_Stop(uint8_t timerNumber_u8) { switch(timerNumber_u8) { case TIMER_0 : util_BitSet(TIMSK,TOIE0); //Disable timer interrupt TCCR0 = v_Timer0_Prescaler_U8; //Stop the timer by loading the 0x00 as presacaler value break; case TIMER_1 : util_BitSet(TIMSK,TOIE1); //Disable timer interrupt TCCR1B = v_Timer1_Prescaler_U8; //Stop the timer by loading the 0x00 as presacaler value break; case TIMER_2 : util_BitSet(TIMSK,TOIE2); //Disable timer interrupt TCCR2 = v_Timer2_Prescaler_U8; //Stop the timer by loading the 0x00 as presacaler value break; } }
/*************************************************************************************************** uint16_t ADC_GetAdcValue(uint8_t var_adcChannel_u8); **************************************************************************************************** * I/P Arguments: uint8_t(channel number). * Return value : uint16_t(16 bit ADC result) * description :This function does the ADC conversion for the Selected Channel and returns the converted 16bit result. The adc value per bit depends on the resolution of the ADC. For ADC0809(8-bit ADC)) the adc value per lsb will be 5/255=0.0196V. For AVR/PIC(10-bit adc) the adc value per lsb will be 5/1023=0048v ___ ___ ___ ___ ___ ___ ___ ___ ___ | | | | | | | | | | | | | | | | | | | Clock: |___| |___| |___| |___| |___| |___| |___| |___| |___| |__ Address ----------(Address A,B,C)-------------------------------------------------- (Channel number) ______ | | ALE: __________________________| |_________________________________________ _______ | | Start; _____________________________| |_____________________________________ __________________________________________ ______________________ | | EOC: |________| ______________ | | OE; ________________________________________________________| |____ Data: -----------------------------------------------------------(adc result)----- ***************************************************************************************************/ uint16_t ADC_GetAdcValue(uint8_t var_adcChannel_u8) { uint16_t adc_result; /* adc_A=((var_adcChannel_u8>>0) & 0x01); //Selectthe channel adc_B=((var_adcChannel_u8>>1) & 0x01); //for which the conversion needs to be done adc_C=((var_adcChannel_u8>>2) & 0x01); */ util_UpdateBit(adc_controlbus,adc_A,util_GetBitStatus(var_adcChannel_u8,0X00)); util_UpdateBit(adc_controlbus,adc_B,util_GetBitStatus(var_adcChannel_u8,0X01)); util_UpdateBit(adc_controlbus,adc_C,util_GetBitStatus(var_adcChannel_u8,0X02)); util_BitSet(adc_controlbus,adc_ALE); // Latch the address by making the ALE high. DELAY_us(50); util_BitSet(adc_controlbus,adc_Start); //Start the conversion after latching the channel address DELAY_us(25); util_BitClear(adc_controlbus,adc_ALE); //Pull ALE line to zero after starting the conversion. DELAY_us(50); util_BitClear(adc_controlbus,adc_Start);; //Pull Start line to zero after starting the conversion. while(util_GetBitStatus(adc_controlbus,adc_EOC)==0); // Wait till the ADC conversion is completed, // EOC will be pulled to HIGH by the hardware(ADC0809) // once conversion is completed. util_BitSet(adc_controlbus,adc_OE); //Make the Output Enable high //to bring the ADC data to port pins DELAY_us(25); adc_result=adc_databus; //Read the ADC data from ADC bus util_BitClear(adc_controlbus,adc_OE); //After reading the data, disable th ADC output line. return(adc_result) ; }
/*************************************************************************************************** void ADC_Init() **************************************************************************************************** * I/P Arguments: none. * Return value : none * description :This function initializes the ADC module. ***************************************************************************************************/ void ADC_Init() { util_BitClear(adc_controlbus,adc_Start); util_BitClear(adc_controlbus,adc_ALE); util_BitClear(adc_controlbus,adc_OE); util_BitSet(adc_controlbus,adc_OE); adc_databus=0xff; /* adc_Start=0; //Initialize all the control lines to zero. adc_ALE=0; adc_OE=0; adc_EOC=1; //Configure the EOC pin as I/P adc_databus=0xff; //configure adc_databus as input */ }
/*************************************************************************************************** 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); } }