Example #1
0
void repeatSongSelection()
{
	AUDIO_PlayFile(VOIX_REPEAT);
	LCD_ClearAndPrint("Bonne chance!\n");
	LCD_Printf("1\n");
	THREAD_MSleep(1000);
	LCD_Printf("2\n");
	THREAD_MSleep(1000);
	LCD_Printf("3\n");
	THREAD_MSleep(1000);
	LCD_Printf("GO!!!\n");

	//Random number to select the song to play
	int songSelect = rand()%4 + 1;

	switch (songSelect)
	{
		case 1:
			repeat(PATH_CLAIRE_FONTAINE);
			break;
		case 2:
			repeat(PATH_HYMNE_A_LA_JOIE);
			break;
		case 3:
			repeat(PATH_STAR_WARS);
			break;
		case 4:
			repeat(PATH_RENNE_NEZ_ROUGE);
			break;
		default:
			break;
	}
}
void LCD_DisplayTime(unsigned char hr,unsigned char min, unsigned char sec)
{
	uint8_t d_hour, d_min, d_sec;
	uint8_t digit0=0, digit1=0, digit2=0;
	
	d_hour = bcd2dec(hr);
	d_min = bcd2dec(min);
	d_sec = bcd2dec(sec);
	
	if ( Time_Format == 1 )		// 12 hour format
	{
		LCD_SetCursor(1,14);
		
		if (d_hour >12)
		{
			d_hour -= 12;
			LCD_Printf("PM");	
		}
		else
		{
			if ( d_hour == 0)	// time is 12 AM
			{
				d_hour = 12;
			}
			LCD_Printf("AM");
		}		
	}	
		
	if ( Display_Style == 1)	// both date and time are displayed in this style
	{		
		LCD_GoToLine(1);
		LCD_Printf("    %2d:%2d:%2d",d_hour,d_min,d_sec);		
	}	
	else		// only date is displayed, so display big numbers
	{
		digit1 = d_hour/10;
		digit0= d_hour%10;
		LCD_DisplayBigNum(digit1,0);  //display hour
		LCD_DisplayBigNum(digit0,3);
		
		// set colon
		LCD_SetCursor(1,6);
		lcd_DataWrite(0xA5);
		LCD_SetCursor(2,6);
		lcd_DataWrite(0xA5);
		  
		//display min  
		digit1 = d_min/10;
		digit0= d_min%10;
		LCD_DisplayBigNum(digit1,7);  
		LCD_DisplayBigNum(digit0,10);
		
		//display sec
		LCD_SetCursor(2,14);
		LCD_Printf("%2x",sec);	
	}	
}
Example #3
0
void testCouleur()
{
	//TODO: un 'if' qui prend la couleur avec le i2c ou analogue dependant du robot

	//le robot 43 a une pin entre le digital 9 et le Vcc
	bool estRobot43 = (DIGITALIO_Read(9) == 1);

	//initialiser le capteur cest important quand on s'appelle robot 43
	if(estRobot43)
		initCapteurI2C();

	//ofstream fichier;
	//fichier.open("couleur.txt");
	while(1)
	{
		RgbColor readColor;
		//step 1
		if(estRobot43)
			readColor = getColorI2C();
		else
			readColor = getColorAnalog();
		LCD_ClearAndPrint("\nR=%i, G=%i, B=%i", readColor.r, readColor.g, readColor.b);

		//fichier << "background-color: rgb(" <<readColor.r<<","<<readColor.g<<","<<readColor.b<<")"<< endl;
		//step 2
        HsbColor colorsHSB = RGBtoHSB(readColor);
		LCD_Printf("\nH=%.4f, S=%.4f, B=%.4f ", colorsHSB.hue, colorsHSB.saturation, colorsHSB.brightness);

		int laCouleur = currentFloorColor(colorsHSB,estRobot43);
		LCD_Printf("\n");
		switch(laCouleur){
					case 0:
						LCD_Printf("BLANC");break;
					case 1:
						LCD_Printf("BLEU");break;
					case 2:
						LCD_Printf("ROUGE");break;
					case 3:
						LCD_Printf("VERT");break;
					case 4:
						LCD_Printf("JAUNE");break;
					case 5:
						LCD_Printf("WTF");break;
					case 6:
						LCD_Printf("Noir");break;
					default:
						LCD_Printf("default");break;
				}

		//LCD_Printf("%s",laCouleur.c_str());
		/*if(estRobot43)
			laCouleur = currentFloorColor(colorsHSB);*/
		//else
			//laCouleur = currentFloorColorAnalog(colorsHSB);
		//LCD_Printf("%s",laCouleur.c_str());
	}
}
Example #4
0
void DataBackTest(void)
{
	//double i ;
	uint8 *msg;
	
	for(;;)
	{
		LCD_Clear();
		LCD_SetXY(0,0);
		LCD_Printf("Data saved %d" , BackDataCount);
		LCD_SetXY(0,1);
		LCD_Printf("Press Enter to Send" );	
				
		OSMboxAccept(AppKey2Mbox);			//这一句是在清除pevent->OSEventPtr中可能存在的数据
		OSTimeDly(20);	
		msg = OSMboxAccept(AppKey2Mbox);
		switch(*msg)
		{
			/*case 1:
				BackDataInit();
				for(i=0 ; i<10000 ; i++) 
				{
					SaveMovingData();
				}
				LCD_SetXY(0,3);
				LCD_Printf("Save data %d" , BackDataCount);
				break;*/
			
			case 18:
			
			    LCD_Clear();
		        LCD_SetXY(4,3);
		        LCD_Printf("Waiting....." );	
				//PC_WriteIntNew(BackDataCount);
				PC_WriteNumNew(BackDataCount);
				
				//PC_WriteInt(BackDataCount);
				//PC_WriteChar('\n');
				
				SendBackData();
				PC_WriteChar('$');
				 
				//SendEndData();
				
				LCD_Clear();
				LCD_SetXY(4,3);
		        LCD_Printf("Done~!" );
				break;
		}
	}
}
Example #5
0
/*
 * 函数名: RadarTest
 * 描  述: 激光雷达数据显示
 * 输  入: 无
 * 输  出: 无
 * 调  用: 外部调用
 */
void RadarTest(void)
{
	rt_uint32_t key_value;
	
	while(1)
	{
		LCD_Clear();
		LCD_SetXY(0,0);
		LCD_WriteString("=======Radar========");
		LCD_SetXY(0,1);
		LCD_Printf("%d",sonic_data[0].data);
		LCD_SetXY(10, 1);
		LCD_Printf("%d",sonic_data[0].count);
		LCD_SetXY(0,2);
		LCD_Printf("%d",sonic_data[3].data);
		LCD_SetXY(10,2);
		LCD_Printf("%d",sonic_data[3].count);
		
		if(rt_mb_recv(&Mb_Key, &key_value, RT_WAITING_NO) == RT_EOK)
		{
			switch(key_value)
			{
				case key1:
                    
					break;
				case key2:
					
					break;
				case key3:
                    
					break;
				case key4:
					
					break;
				case key5:
					
					break;
				case key6:
					
					break;
				case keyback:
					return;
				default:
					break;
			}
		}
		Delay_ms(10);
	}
}
Example #6
0
/*
 * 函数名: LBTest
 * 描  述: 灯板测试函数
 * 输  入: 无
 * 输  出: 无
 * 调  用: 外部调用
 */
void LBTest(void)
{
	rt_uint32_t key_value;
	
	while(1)
	{
		LCD_Clear();
		LCD_SetXY(0,0);
		LCD_WriteString("=========LB=========");
		LCD_SetXY(0,1);
		LCD_WriteString("LB1:");
		LCD_WriteInt(LB_Count(1));
		LCD_SetXY(10,1);
		LCD_WriteString("LB2:");
		LCD_WriteInt(LB_Count(2));
		LCD_SetXY(0,2);
		LCD_WriteString("LB1:");
		LCD_Printf("%s",itob(LB_recv[0].v));
		LCD_SetXY(0,4);
		LCD_WriteString("LB2:");
		LCD_Printf("%s",itob(LB_recv[1].v));
		LCD_SetXY(0,6);
		LCD_WriteString("1.LB_Init");
		LCD_SetXY(10,6);
		LCD_WriteString("2.LB_State");
		LCD_SetXY(0,7);
		LCD_WriteString("3.LB_Test");
		
		if(rt_mb_recv(&Mb_Key, &key_value, RT_WAITING_NO) == RT_EOK)
		{
			switch(key_value)
			{
				case key1:
					LB_Init();
					break;
				case key2:
					LB_State();
					break;
				case key3:
					LB_Test();
					break;
				case keyback:
					return;
			}
		}
		Delay_ms(10);
	}
}
Example #7
0
/* start the main program */
void main() 
{
  
   unsigned char sec,min,hour,day,month,year;

  /* Initialize the lcd before displaying any thing on the lcd */
    LCD_Init(8,2,16);

  /* Initialize the RTC(ds1307) before reading or writing time/date */
    RTC_Init();


   /*##### Set the time and Date only once. Once the Time and Date is set, comment these lines
         and reflash the code. Else the time will be set every time the controller is reset*/
    RTC_SetTime(0x10,0x40,0x00);  //  10:40:20 am
    RTC_SetDate(0x01,0x01,0x15);  //  1st Jan 2015



   /* Display the Time and Date continuously */ 
   while(1)
    {
		LCD_GoToLine(1);
	   /* Read the Time from RTC(ds1307) */ 
        RTC_GetTime(&hour,&min,&sec);    
		
	   /* Read the Date from RTC(ds1307) */ 
       RTC_GetDate(&day,&month,&year);     		 
        
	   LCD_Printf("\n\rtime:%2x:%2x:%2x  \nDate:%2x/%2x/%2x",(uint16_t)hour,(uint16_t)min,(uint16_t)sec,(uint16_t)day,(uint16_t)month,(uint16_t)year);
	}		

  }
Example #8
0
void testInfrarouge()
{

	LCD_ClearAndPrint("Test Infrarouge\n");

		int sortie = 0;
		sortie = IR_Detect(IR_FRONT);
		switch(sortie)
		{
			case 0: LCD_Printf("RIEN\n");break;
			case 1: LCD_Printf("DROITE\n");break;
			case 2: LCD_Printf("GAUCHE\n");break;
			case 3: LCD_Printf("DROITE ET GAUCHE\n");break;
		}
		THREAD_MSleep(100);
}
int main() 
{
    int adcValue;
    int temp;
    
    ADC_Init();       /* Initialize the ADC module */
    
    /*Connect RS->PB0, RW->PB1, EN->PB2 and data bus PORTB.4 to PORTB.7*/
    LCD_SetUp(PB_0,PB_1,PB_2,P_NC,P_NC,P_NC,P_NC,PB_4,PB_5,PB_6,PB_7);
    LCD_Init(2,16);
    
    while(1)
    {
        adcValue = ADC_GetAdcValue(0); // Read the ADC value of channel zero(PA0) where the temperature sensor(LM35) is connected
        
        /* Convert the raw ADC value to equivalent temperature with 5v as ADC reference
		 Step size of AdC= (5v/1023)=4.887mv = 5mv.
		 for every degree celcius the Lm35 provides 10mv voltage change.
	     1 step of ADC=5mv=0.5'c, hence the Raw ADC value can be divided by 2 to get equivalent temp*/
        
        temp = adcValue/2.0; // Divide by 2 to get the temp value.
        LCD_GoToLine(0);
        LCD_Printf("ADC0 Value:%4d \nTemp:%dC\n\r",adcValue,temp);     // Display adc value and temp LCD
		
    }
    
    return (0);
}
Example #10
0
/*
 * 函数名: RecKin
 * 描  述: 测试 Kinect 接受
 * 输  入: 无
 * 输  出: 无
 * 调  用: 外部调用
 */
void RecKin_Print(void)
{
	rt_uint32_t key_value;
	
	while(1)
	{
		LCD_Clear();
		LCD_SetXY(0,0);
		LCD_WriteString("========Receiving========");
		LCD_SetXY(0,1);
		LCD_Printf("x = %d",(int)uart_data.x);
		LCD_SetXY(0,2);
		LCD_Printf("y = %d",(int)uart_data.y);
		LCD_SetXY(0,3);
		LCD_Printf("z = %d",(int)uart_data.z);
		LCD_SetXY(0,4);
		LCD_Printf("Now Angle:%g  %g  %g",Motor_Pos[W_MOTOR1_OLD_ID-W_MOTOR1_OLD_ID]*360,\
							Motor_Pos[W_MOTOR2_OLD_ID-W_MOTOR1_OLD_ID]*360,Motor_Pos[W_MOTOR3_OLD_ID-W_MOTOR1_OLD_ID]*360);
		LCD_SetXY(0,5);
		LCD_Printf("1.STOP %d %d %d",(int)(Motor_RealAim[W_MOTOR1_OLD_ID-W_MOTOR1_OLD_ID]*360/1000),\
							(int)(Motor_RealAim[W_MOTOR2_OLD_ID-W_MOTOR1_OLD_ID]*360/1000),(int)(Motor_RealAim[W_MOTOR3_OLD_ID-W_MOTOR1_OLD_ID]*360/1000));
		LCD_SetXY(0,7);
		LCD_WriteString("1.Set_XYZ");

		if(rt_mb_recv(&Mb_Key, &key_value, RT_WAITING_NO) == RT_EOK)
		{
			switch(key_value)
			{
				case key1:
					Input_DoubleValue(&uart_data.x,"x"); 
					Input_DoubleValue(&uart_data.y,"y");
					Input_DoubleValue(&uart_data.z,"z");
					Input_IntValue(&pos_speed.v_A,"v_A");
					Input_IntValue(&pos_speed.v_B,"v_B");
// 					Input_IntValue(&pos_speed.v_C,"v_C");
					Data_Processing();
 					W_MOTOR_OLD_FUNC(W_MOTOR2_OLD_ID, (float)pos_speed.pos_A , (int16_t)pos_speed.v_A , CMD_SET_PSG);
					W_MOTOR_OLD_FUNC(W_MOTOR2_OLD_ID, (float)pos_speed.pos_B , (int16_t)pos_speed.v_B , CMD_SET_PSG);
// 					W_MOTOR_OLD_FUNC(W_MOTOR3_OLD_ID, (float)pos_speed.pos_C , (int16_t)pos_speed.v_C , CMD_SET_PSG);
					break;
				case keyback:
					return;
			}
		}
		Delay_ms(10);
	}
}
uint8_t LCD_DisplayMenu()
{ 
	int8_t keycount=0;
	LCD_Clear();
	LCD_GoToLine(1);
	LCD_DisplayString("    Settings    ");
	do
	{       
		if (util_IsBitCleared(Button, cancel))
		{
		   return (-1); 
		}
		
		if(util_IsBitCleared(Button, up))
		{
			keycount++;
			_delay_ms(100);
		}
		
		if(util_IsBitCleared(Button, down))
		{
			keycount--;
			_delay_ms(100);
		}
	
		if((keycount>=menusize)||(keycount <= -menusize))
		{
			keycount=0;
		}
		
		if(keycount<0)
		{
			//make menu index circular. i.e decrement from first 
			//option shows the last option on the menu
			keycount += menusize;   
		}			
		
		LCD_GoToLine(2);
		LCD_DisplayString("                "); //clear second line
		//set cursor at the center of of line 2 depending on string size. 
		LCD_SetCursor(2,(14-strlen(settings[keycount]))/2); 
		LCD_Printf("<%s>", settings[keycount]);
		_delay_ms(100);  //make menu visible or else will overwrite at fast speed
					 
      }while(util_IsBitSet(Button,select));
	  
	 do 
	{
		if (util_IsBitCleared(Button, cancel))
		{
		   return (-1); ; 
		}
	}while(util_IsBitSet(Button, select));
	
	return (keycount); 
}
int main()
{
	DDRC=0xff;   //Configure PORTC(Lcd databus) as output
	DDRD=0xe0;   //Configure INT0,INT1 as input and PORTD5-PORTD7(rs,rw,en) as output
	
	LCD_SetUp(PB_0,PB_1,PB_2,P_NC,P_NC,P_NC,P_NC,PB_4,PB_5,PB_6,PB_7);
	LCD_Init(2,16);
	
	GICR=0xc0;   //Enable External Interrupts INT0 and INT1
	MCUCR=0x08;  //Configure INT0 active low level triggered and INT1 as falling edge
	
	sei();     // Enable global interrupts by setting global interrupt enable bit in SREG
	
	while(1)
	{
		LCD_Printf("EINT0:%4u\n",cnt_zero);
		LCD_Printf("EINT1:%4u\n",cnt_one);
	}
}
Example #13
0
/**@attention: 返回某路涵道的值
 */
double get_fan_duty(u8 pwm_chx)
{
    if(pwm_chx!=L_CH && pwm_chx!=R_CH)
    {
        LCD_Clear();
        
        LCD_Printf("err in [%s]", __FUNCTION__);
    }
    
    return pwm_duty[pwm_chx-1];
}
Example #14
0
void sys_ImgSave(void)
{
	rt_uint32_t key_value;
	
	while(1)
	{
		LCD_Clear();
		LCD_SetXY(0,0);
		LCD_WriteString("======Img Save======");
		LCD_SetXY(0,1);
		LCD_WriteString("1.b_seesaw");
		LCD_SetXY(0,2);
		LCD_WriteString("2.b_polewalk");
    LCD_SetXY(0,3);
		LCD_WriteString("3.b_whitetape");
		LCD_SetXY(0,4);
		LCD_Printf("4.Handover");
		
		if(rt_mb_recv(&Mb_Key, &key_value, RT_WAITING_NO) == RT_EOK)
		{
			switch(key_value)
			{
        u8 res;
                
				case key1:
                    /* save image from camera1 ,file name is "b_seesaw.txt" */
                    res = Save_Img("b_seesaw", 1);
                    _show_res(res);
					break;
				
				case key2:
					res = Save_Img("b_polewalk", 4);
                    _show_res(res);
					break;
				
        case key3:
					res = Save_Img("b_whitetape", 2);
                    _show_res(res);
				  res = Save_Img("b_whitetape", 1);
                    _show_res(res);
					break;		
								
				case key4:
					res = Save_Img("Handover",5);
				            _show_res(res);
				  break;
				
				case keyback:
					return;
			}
		}
		Delay_ms(10);
	}
}
Example #15
0
void PumpRate(void)
{
	
	LCD_SetTextSize(4);
	
	LCD_SetTextColor(BLACK,WHITE);
	while(1)
	{
	if(!Read_UP_Button())
	{
		while(!Read_UP_Button);
		PumpingRate += 10;
		if(PumpingRate>300)
		PumpingRate=300;
		PWM_Freq(PumpingRate);
		
		
	Print_Text_On(Line4,Position4);
  //LCD_Printf("UP");
	//PrintDecimal(PumpingRate);
PrintRate(PumpingRate);
	}
	else if(!Read_DOWN_Button())
	{
		while(!Read_DOWN_Button());
		PumpingRate -= 10;
		if(PumpingRate<10)
		PumpingRate=10;
		PWM_Freq(PumpingRate);
		
		
			Print_Text_On(Line4,Position4);
  //LCD_Printf("DN");
	//PrintDecimal(PumpingRate);
		
		PrintRate(PumpingRate);

	}
	
	else if(!Read_OK_Button())
	{	
		while(!Read_OK_Button());
		
			LCD_SetCursor(2,Line7);
	LCD_SetTextSize(2);
	LCD_SetTextColor(BLUE,WHITE);
  LCD_Printf("     ");
		HAL_Delay(1000);
		//return;
		break;
	}
	
}
}
Example #16
0
void encodeurGaucheTest()
{
	MOTOR_SetSpeed(7,30);
	THREAD_MSleep(100);
	short int encodeurGauche = 0;
	while(encodeurGauche <= 64)
	{
		encodeurGauche += ENCODER_Read(ENCODER_LEFT);
		LCD_Printf("G: %i \n",encodeurGauche);
	}
	MOTOR_SetSpeed(7,0);
}
Example #17
0
void encodeurDroitTest()
{
	MOTOR_SetSpeed(8,30);
	THREAD_MSleep(100);
	short int encodeurDroit = 0;
	while(encodeurDroit <= 64)
	{
		encodeurDroit+=ENCODER_Read(ENCODER_RIGHT);
		LCD_Printf("D: %i \n",encodeurDroit);
	}
	MOTOR_SetSpeed(8,0);
}
Example #18
0
void vitesseTEST(robot &unRobot,short int TRANSITIONS)
{
	MOTOR_SetSpeed(MOTOR_RIGHT, 50);
    MOTOR_SetSpeed(MOTOR_LEFT, 50);
	THREAD_MSleep(500);

	//Distance parcourue en nombre de transitions effectués
	unRobot.encodeurDroit = ENCODER_Read(ENCODER_RIGHT);
    unRobot.encodeurGauche = ENCODER_Read(ENCODER_LEFT);
	//Affichage des encodeurs et des vitesses
	LCD_Printf("D: %i v: %i, G: %i v: %i \n",unRobot.encodeurDroit,50,unRobot.encodeurGauche,50);
}
Example #19
0
static void CalibrateCore( MENU_Event_t event, uint8_t *cal )
{
    if ( event == MENU_EVENT_SELECT )
    {
        memcpy( &cal[ 1 ], &gADC[ 1 ], 5 );

        return;
    }

    if ( event == MENU_EVENT_INIT )
    {
        LCD_Clear();
    }

    LCD_MoveTo( 0, 0 );
    LCD_Printf( "C %02x %02x %02x %02x %02x",  cal[ 4 ],  cal[ 1 ],  cal[ 2 ],  cal[ 3 ],  cal[ 5 ]);

    LCD_MoveTo( 0, 1 );
    LCD_Printf( "L %02x %02x %02x %02x %02x", gADC[ 4 ], gADC[ 1 ], gADC[ 2 ], gADC[ 3 ], gADC[ 5 ]);

} // CalibrateCore
Example #20
0
void _step1(void)
{    
    double dis = 0;
    struct Point goal_point;
    gps_t gps_save = GPS;
    
    SONICx_ENABLE(0X03);
    
    Speed_Y = rbyCoef * -600;
    while((double)(sonic_data[F_SONIC-1].data)>600 || (double)(sonic_data[F_SONIC-1].data)<150)
    {
        LCD_Clear();
        LCD_SetXY(0, 0);
        LCD_Printf("_step2: not see pole");
        LCD_SetXY(0, 1);
        LCD_Printf("angle:%f", GPS.radian);
        Delay_ms(5);
    }
    /* check again */
    Delay_ms(30);
    dis = sonic_data[F_SONIC-1].data;
    if(dis<500 && dis>150)
    {
        /* be sure seeing the first pole */
        
        double l_disx = (dis + 220 - std_overDesign);   /* local delta distance - x_direction */
        double l_disy = -450*rbyCoef;                   /* local delta distance - y_direction */
        double theta = GPS.radian;
        
        Speed_Y = 0;
        msg("see pole, dis:%f", dis);
        
        /* local to global */
        goal_point = GPS.position;
        goal_point.x +=  l_disx*cos(theta) - l_disy*sin(theta);
        goal_point.y +=  l_disx*sin(theta) + l_disy*cos(theta);
        
        _set_keep(goal_point, gps_save.radian, 1000, 150, 5);
    }
}
void LCD_DisplayDate(uint8_t day, uint8_t month, uint8_t year)
{
	unsigned char digit0=0, digit1=0, digit2=0;
		
	if ( Display_Style == 1)
	{
		LCD_GoToLine(2);
		digit0 = bcd2dec(day);
		digit1 = bcd2dec(month);
		digit2 = bcd2dec(year);
		LCD_Printf("    %2d/%2d/%2d",digit0,digit1,digit2);
	}
}
Example #22
0
void LookIt(void)
{
	rt_uint32_t key_value;
//	int i;
	
	while(1)
	{		
		LCD_Clear();
		LCD_SetXY(0,0);LCD_Printf("1.AngleSwing %d",AngleSwing);
		LCD_SetXY(0,1);LCD_Printf("2.AngleHit   %d",AngleHit);
		LCD_SetXY(0,2);LCD_Printf("3.pos_A      %f",pos_speed.pos_A);
		LCD_SetXY(0,3);LCD_Printf("4.pos_B      %f",pos_speed.pos_B);
		
		if(rt_mb_recv(&Mb_Key, &key_value, RT_WAITING_NO) == RT_EOK)
		{
            if(key_value == keyback)
            {
                return ;
            }
		}
		Delay_ms(10);
	}
}
Example #23
0
int main()
{
   uint16_t pot_value,ldr_value, temp_raw, temp_final;
   float voltage;
   
   SystemInit();                              //Clock and PLL configuration

   /* Setup/Map the controller pins for LCD operation 
               RS   RW   EN    D0    D1    D2   D3     D4   D5    D6    D7*/
    LCD_SetUp(P2_0,P2_1,P2_2,P1_20,P1_21,P1_22,P1_23,P1_24,P1_25,P1_26,P1_27);

  
    LCD_Init(2,16);      /* Specify the LCD type(2x16) for initialization*/
    ADC_Init();          /* Initialize the ADC */
    while(1)
    {
        pot_value  = ADC_GetAdcValue(0); /* Read pot value connect to AD0(P0_23) */
        ldr_value  = ADC_GetAdcValue(1); /* Read LDR value connect to AD1(P0_24) */
        temp_raw   = ADC_GetAdcValue(2); /* Read Temp value connect to AD2(P0_25) */

     /* Converting the raw adc value to equivalent temperature with 3.3v as ADC reference using 12bit resolution.
        Step size of ADC= (3.3v/2^12)= 3.3/4096 = 0.0008056640625 = 0.0806mv
        For every degree celcius the Lm35 provides 10mv voltage change.
        1 degree celcius = 10mv = 10mv/0.0806mv = 12.41 uinits            
        Hence the Raw ADC value can be divided by 12.41 to get equivalent temp
        */        
       
         temp_final = temp_raw/12.41;

        /* Vin = (Adc_value * REF)/ 2^12 */
        voltage = (pot_value * 3.3)/ 4096.0;

        LCD_GoToLine(0);
        LCD_Printf("P:%4d %f",pot_value,voltage);
        LCD_Printf("\nL:%4d T:%4d",ldr_value,temp_final);       
    }
}
Example #24
0
static void _can_senddata(CAN_TypeDef *canx, CanTxMsg *tx)
{
    u8 wait_time = 0;
    
    while(CAN_Transmit(canx, tx)==CAN_NO_MB && wait_time<6)
    {
        wait_time ++;
        Delay_ms(5);
    }
    /* delay 30ms */
    if(wait_time>=6)
    {
        extern struct rt_thread *rt_current_thread;
        int i;
        
        LCD_Clear();
        LCD_SetXY(2, 3);
        LCD_Printf("can send timeout!");
        
        f_open (&can_send_file, "can_errInfo.txt", FA_OPEN_ALWAYS | FA_READ | FA_WRITE);
        f_lseek(&can_send_file, can_send_file.fsize);
        SD_Printf2(&can_send_file, "");
        SD_Printf2(&can_send_file, "-----------------------------------------------");
        SD_Printf2(&can_send_file, "-->date:%s", __DATE__);
        SD_Printf2(&can_send_file, "-->time:%s", __TIME__);
        SD_Printf2(&can_send_file, "-->tick:%d", rt_tick_get());
        SD_Printf2(&can_send_file, "-->thread:%s", rt_current_thread->name);
        SD_Printf2(&can_send_file, "-->GPS:");
        SD_Printf2(&can_send_file, "   >x:%f", GPS.position.x);
        SD_Printf2(&can_send_file, "   >y:%f", GPS.position.y);
        SD_Printf2(&can_send_file, "   >a:%f", GPS.radian);
        SD_Printf2(&can_send_file, "-->txMsg:");
        SD_Printf2(&can_send_file, "   >ID  :%d", tx->StdId);
        SD_Printf2(&can_send_file, "   >len :%d", tx->DLC);
        SD_Printf2(&can_send_file, "   >data", tx->DLC);
      for(i=0; i<tx->DLC; i++)
        SD_Printf(&can_send_file, "     %x", tx->Data[i]);
        SD_Printf2(&can_send_file, "");
        SD_Printf2(&can_send_file, "-----------------------------------------------");
        SD_Printf2(&can_send_file, "");
        
        f_close(&can_send_file);
        Delay_ms(500);
    }
}
Example #25
0
int main()
{
    int adcValue;
    float volt;
    SystemInit();
    ADC_Init();       /* Initialize the ADC module, Note: Max ADC Input voltage 3.3v */

    /*Connect RS->P1_16, RW->P1_17, EN->P1_18 and data bus(D4:D7 - P1_20:P1_23)*/
    LCD_SetUp(P1_16,P1_17,P1_18,P_NC,P_NC,P_NC,P_NC,P1_20,P1_21,P1_22,P1_23);
    LCD_Init(2,16);

    while(1)
    {
        adcValue = ADC_GetAdcValue(AD0_1); // Read the ADC value of channel AD0.1, Max ADC voltage 3.3v
        volt = (adcValue*3.3)/1023;       // ADC_REF Voltage=3.3v and ADC resolution 10bit
        LCD_GoToLine(0);
        LCD_Printf("ADC0 Value:%4d\nVolt:%f",adcValue,volt);     // Display Raw adc value and Equivalent temp on LCD
    }
}
/* start the main program */
void main() 
{
   uint16_t adc_result0,adc_result1,adc_result2,adc_result3;		

    LCD_Init(4,2,16);	   /* Initialize 2x16lcd in 8-bit mode */    
    ADC_Init();			   /* Initialize the adc module*/	 
    
   while(1)
    {
       	/* Get the adc value of first four channels */
		 adc_result0= ADC_GetAdcValue(0);
		 adc_result1= ADC_GetAdcValue(1);
		 adc_result2= ADC_GetAdcValue(2);
		 adc_result3= ADC_GetAdcValue(3);		  
	
		 LCD_GoToLine(1);
         LCD_Printf("C0:%d C1:%d \nC2:%d C3:%d ",adc_result0,adc_result1,adc_result2,adc_result3);         	     
    }			 
}
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();
	}				
}
Example #28
0
int main (void) 
{
    SystemInit();

    /*        RS   RW   EN   D0   D1   D2   D3   D4    D5    D6    D7      P_NC(Not connected)*/
    LCD_SetUp(P2_0,P2_1,P2_2,P_NC,P_NC,P_NC,P_NC,P1_24,P1_25,P1_26,P1_27); 
    LCD_Init(2,16);

    /* EINT0 is configured as FallingEdge interrupt and myExtIntrIsr_0 will be called by EINT0_IRQHandler */
    EINT_AttachInterrupt(EINT0,myExtIntrIsr_0,FALLING);  

    /* EINT1 is configured as Active Low interrupt and myExtIntrIsr_1 will be called by EINT1_IRQHandler */
    EINT_AttachInterrupt(EINT1,myExtIntrIsr_1,LOW);

    while(1)
    {
        LCD_GoToLine(0);
        LCD_Printf("EINT0=%8u EINT1:%8u",cnt1,cnt2); /* Display the occurrence of EINT0 and EINT1 */
    }
}
int main() 
{
    int count = 0;
	
    /*Connect RS->P0.0, RW->P0.1, EN->P0.2 and data bus to P0.4 to P0.7*/
    LCD_SetUp(P0_0,P0_1,P0_2,P_NC,P_NC,P_NC,P_NC,P0_4,P0_5,P0_6,P0_7);
    LCD_Init(2,16);
    
    LCD_DisplayString("Decimal");

    while(1)
    {
        LCD_GoToLine(1);
        LCD_Printf("Count=%4d",count);
        DELAY_ms(500);
        count++;
    }
    
    return (0);
}
Example #30
0
int main()
{
    char str[50];
    int len = 0;
    SystemInit();

    /*Connect RS->P1_16, RW->P1_17, EN->P1_18 and data bus(D4:D7 - P1_20:P1_23)*/
    LCD_SetUp(P1_16,P1_17,P1_18,P_NC,P_NC,P_NC,P_NC,P1_20,P1_21,P1_22,P1_23);
    LCD_Init(2,16);
    UART0_Init(9600);
    LCD_DisplayString("send data from  serial terminal");
    while(1)
    {
        len = UART0_RxString(str);
        UART0_Printf("Received String:%s   size=%2d\n\r",str,len);
        LCD_Clear();
        LCD_Printf("str:%s size=%2d",str,len);
    }


}