コード例 #1
0
/***************************************************************************************************
                    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) ;

  }
コード例 #2
0
void UART_TxNumber(uint8_t var_uartChannel_u8, uint8_t var_numericSystem_u8, uint32_t var_number_u32, uint8_t var_numOfDigitsToTransmit_u8)
{
    uint8_t i=0,a[10];

    if(C_BINARY_U8 == var_numericSystem_u8)
    {
        while(var_numOfDigitsToTransmit_u8!=0)
        {
            /* Start Extracting the bits from the specified bit positions.
             Get the Acsii values of the bits and transmit */
            i = util_GetBitStatus(var_number_u32,(var_numOfDigitsToTransmit_u8-1));
            UART_TxChar(var_uartChannel_u8,util_Dec2Ascii(i));
            var_numOfDigitsToTransmit_u8--;
        }    
    }     
    else if(var_number_u32==0)
    {
        /* If the number is zero then update the array with the same for transmitting */
        for(i=0;((i<var_numOfDigitsToTransmit_u8) && (i<C_MaxDigitsToTransmit_U8)) ;i++)
            UART_TxChar(var_uartChannel_u8,'0');
    }
    else
    {
        for(i=0;i<var_numOfDigitsToTransmit_u8;i++)
        {
            /* Continue extracting the digits from right side
               till the Specified var_numOfDigitsToTransmit_u8 */
            if(var_number_u32!=0)
            {
                /* Extract the digits from the number till it becomes zero.
                First get the remainder and divide the number by 10 each time.

                example for Decimal number:
                If var_number_u32 = 123 then extracted remainder will be 3 and number will be 12.
                The process continues till it becomes zero or max digits reached*/
                a[i]=util_GetMod32(var_number_u32,var_numericSystem_u8);
                var_number_u32=var_number_u32/var_numericSystem_u8;
            }
            else if( (var_numOfDigitsToTransmit_u8 == C_DefaultDigitsToTransmit_U8) ||
                    (var_numOfDigitsToTransmit_u8 > C_MaxDigitsToTransmit_U8))
            {
                /* Stop the iteration if the Max number of digits are reached or
                 the user expects exact(Default) digits in the number to be transmitted */ 
                break;
            }
            else
            {
                /*In case user expects more digits to be transmitted than the actual digits in number,
                  then update the remaining digits with zero.
                Ex: var_number_u32 is 123 and user wants five digits then 00123 has to be transmitted */
                a[i]=0;
            }
        }

        while(i)
        { 
            /* Finally get the ascii values of the digits and transmit*/
            UART_TxChar(var_uartChannel_u8,util_Hex2Ascii(a[i-1]));
            i--;
        }
    }


}
コード例 #3
0
ファイル: lcd.c プロジェクト: ExploreEmbedded/LPC2148_Stick
void LCD_DisplayNumber(uint8_t v_numericSystem_u8, uint32_t v_number_u32, uint8_t v_numOfDigitsToDisplay_u8)
{
    uint8_t i=0,a[10];
    
    if(C_BINARY_U8 == v_numericSystem_u8)
    {
        while(v_numOfDigitsToDisplay_u8!=0)
        {
          /* Start Extracting the bits from the specified bit positions.
          Get the Acsii values of the bits and display */
          i = util_GetBitStatus(v_number_u32,(v_numOfDigitsToDisplay_u8-1));
          LCD_DisplayChar(util_Dec2Ascii(i));
          v_numOfDigitsToDisplay_u8--;
        }        
    }    
    else if(v_number_u32==0)
    {
        /* If the number is zero then display Specified number of zeros*/
        /*TODO: Display single zero or multiple. Currently single zero is displayed*/
        for(i=0;((i<v_numOfDigitsToDisplay_u8) && (i<C_MaxDigitsToDisplay_U8));i++)
            LCD_DisplayChar('0');
    }
    else
    {
        for(i=0;i<v_numOfDigitsToDisplay_u8;i++)
        {
            /* Continue extracting the digits from right side
               till the Specified v_numOfDigitsToDisplay_u8 */
            if(v_number_u32!=0)
            {
                /* Extract the digits from the number till it becomes zero.
                First get the remainder and divide the number by TypeOfNum(10-Dec, 16-Hex) each time.
                
                example for Decimal number: 
                If v_number_u32 = 123 then extracted remainder will be 3 and number will be 12.
                The process continues till it becomes zero or max digits reached*/
                a[i]=util_GetMod32(v_number_u32,v_numericSystem_u8);
                v_number_u32=v_number_u32/v_numericSystem_u8;
            }
            else if( (v_numOfDigitsToDisplay_u8 == C_DisplayDefaultDigits_U8) ||
                     (v_numOfDigitsToDisplay_u8 > C_MaxDigitsToDisplay_U8))
            {
                /* Stop the iteration if the Max number of digits are reached or 
                 the user expects exact(Default) digits in the number to be displayed */ 
                break;
            }
            else
            {
                /* In case user expects more digits to be displayed than the actual digits in number,
                  then update the remaining digits with zero.
               Ex: v_num_u32 is 123 and user wants five digits then 00123 has to be displayed */
                a[i]=0;
            }
        }
        
         while(i!=0)
        { 
          /* Finally get the ascii values of the digits and display*/
          LCD_DisplayChar(util_Hex2Ascii(a[i-1]));
          i--;
        }
    }
}