示例#1
0
void display_number(unsigned int number)
{
    unsigned char seg_code[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
	unsigned char temp;
	unsigned int i,num;

   for(i=0;i<9;i++)	   
   	 { 
	   num=number;
	   
	   temp = num/1000;
	   num=num%1000;  
	   SegmentSlection=SegOne;
	   SegmentValue = seg_code[temp];
	   DELAY_us(10);

	   temp = num/100;
	   num=num%100;  
	   SegmentSlection=SegTwo;
	   SegmentValue = seg_code[temp];
	   DELAY_us(10);

       temp = num/10;  
	   SegmentSlection=SegThree;
	   SegmentValue = seg_code[temp];
	   DELAY_us(10);

	   temp = num%10;
	   SegmentSlection=SegFour; 
	   SegmentValue = seg_code[temp];
	   DELAY_us(10);  	   
	  }
	 
 }
void seg_test()
{  
 unsigned char seg_code[]={0xC0,0xF9,0xA4,0xB0}; 
 UART_TxString("\n\r Segment DataBus: PORTD    Seg select: S1->PB.0 S2->PB.1 S3->PB.2 S4->PB.3");
 UART_Printf("\n\rMake connections and hit 'k' to test! ");
 while(UART_RxChar()!='k');
 SegValueDirnReg = C_PortOutput_U8;
 SegSelectDirnReg = C_PortOutput_U8;

	while(1)
	{  
	   SegmentSlection=SegOne;
	   SegmentValue = seg_code[0];
	   DELAY_us(10); 
	   SegmentSlection=SegTwo;
	   SegmentValue = seg_code[1];
	   DELAY_us(10);
	   SegmentSlection=SegThree;
	   SegmentValue = seg_code[2];
	   DELAY_us(10);	
	   SegmentSlection=SegFour;  
	   SegmentValue = seg_code[3];
	   DELAY_us(10);
	 }  
}
示例#3
0
/***************************************************************************************************
                         void DELAY_ms(uint16_t ms_count)
****************************************************************************************************
 * I/P Arguments: uint16_t.
 * Return value	: none

 * description:
     This function is used generate delay in ms.
     It generates a delay of 1ms for each count,
     if 1000 is passed as the argument then it generates delay of 1000ms(1sec)
***************************************************************************************************/
void DELAY_ms(uint16_t ms_count)
 {
        while(ms_count!=0)
		 {
	        DELAY_us(C_CountForOneMsDelay_U16);	 //DELAY_us is called to generate 1ms delay
			 ms_count--;
			}

   }
int main(void)
{
	

	  int x,y;
  
      DDRD |= (1<<5)|(1<<6)|(1<<7);     // Configure PORTD5, PORTD6, PORTD7 as output
	  PORTD &= ~(1<<5);                 // Enable driver
	
    while (1) 
    {
		PORTD |= (1<<6);                //Make PORTD6 high to rotate motor in clockwise direction
		
		for(x=0; x<4; x++)              //Give 50 pulses to rotate stepper motor by 90 degree's in full step mode
		{
		 for(y=0; y<50; y++)
		 {
		  PORTD |=(1<<7);
		  DELAY_us(700);
		  PORTD &=~(1<<7);
		   DELAY_us(700);
		 }
		 DELAY_ms(1000);
		}
		
		PORTD &= ~(1<<6);              //Make PORTD6 high to rotate motor in anti-clockwise direction
		
		for(x=0; x<4; x++)             //Give 50 pulses to rotate stepper motor by 90 degree's in full step mode
		{
			for(y=0; y<50; y++)
			{
				PORTD |=(1<<7);
				DELAY_us(700);
				PORTD &=~(1<<7);
				DELAY_us(700);
			}
			DELAY_ms(1000);             
		}
	}
}
/***************************************************************************************************
                    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) ;

  }