/*************************************************************************************************** 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 */ }
/*************************************************************************************************** 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 UART_SetBaudRate(uint8_t var_uartChannel_u8, uint32_t var_baudRate_u32) *************************************************************************************************** * I/P Arguments: uint32_t : var_baudRate_u32 to be configured. * Return value : none * description :This function is used to Set/Change the baudrate on the fly. If the requested baud rate is not within the supported range then the default baudrate of 9600 is set. Refer uart.h file for Supported range of baud rates. ***************************************************************************************************/ void UART_SetBaudRate(uint8_t var_uartChannel_u8, uint32_t var_baudRate_u32) { uint32_t var_UartPclk_u32,var_Pclk_u32,var_RegValue_u32; if(var_uartChannel_u8 < C_MaxUartChannels_U8 ) { /** Baud Rate Calculation : PCLKSELx registers contains the PCLK info for all the clock dependent peripherals. Bit6,Bit7 contains the Uart Clock(ie.UART_PCLK) information. The UART_PCLK and the actual Peripheral Clock(PCLK) is calculated as below. (Refer data sheet for more info) UART_PCLK PCLK 0x00 SystemFreq/4 0x01 SystemFreq 0x02 SystemFreq/2 0x03 SystemFreq/8 **/ var_UartPclk_u32 = (LPC_SC->PCLKSEL0 >> 6) & 0x03; switch( var_UartPclk_u32 ) { case 0x00: var_Pclk_u32 = SystemFrequency/4; break; case 0x01: var_Pclk_u32 = SystemFrequency; break; case 0x02: var_Pclk_u32 = SystemFrequency/2; break; case 0x03: var_Pclk_u32 = SystemFrequency/8; break; } var_RegValue_u32 = ( var_Pclk_u32 / (16 * var_baudRate_u32 )); STR_UartConfig[var_uartChannel_u8].UARTx->DLL = util_ExtractByte0to8(var_RegValue_u32); STR_UartConfig[var_uartChannel_u8].UARTx->DLM = util_ExtractByte8to16(var_RegValue_u32); util_BitClear(STR_UartConfig[var_uartChannel_u8].UARTx->LCR, SBIT_DLAB); // Clear DLAB after setting DLL,DLM }
void checkAlarm() { uint8_t b_hour, b_min, b_sec; RTC_GetTime(&b_hour,&b_min,&b_sec); if ( (alarm_hour == b_hour) & ( alarm_min == b_min) & ( alarm_sec == b_sec) ) { LCD_Clear(); do { LCD_GoToLine(1); LCD_Printf("Press Cancel to Stop Alarm"); }while(util_IsBitSet(Button, cancel)); util_BitClear(buzzer_port,buzzer_pin); LCD_Clear(); } }