Пример #1
0
//Ë¢ÐÂÆÁÄ»
void lcd_refresh(void)
{

    uint8_t message[50];
    sprintf(message,"  Voltage: %.1f V",(float)(Get_Voltage()/223.58));//12λAD
    LCD_DisplayStringLine(LINE(1), message);

    sprintf(message,"  Speed: %.2f m/s      ",velocity);
    LCD_DisplayStringLine(LINE(2), message);
//
    sprintf(message,"  p.x:%.2f**p.y:%.2f**     ",point_now.x, point_now.y);
    LCD_DisplayStringLine(LINE(3), message);

//   LCD_DisplayStringLine(LINE(5), Command0);

// 	LCD_DisplayStringLine(LINE(6), (uint8_t*)RxBuffer);
    sprintf(message," ax=%d ,ay=%d az=%d******",  ax, ay, az);
    LCD_DisplayStringLine(LINE(6), message);

    sprintf(message," spd: %.8f   ",GPSMsg.hor_spd);
    LCD_DisplayStringLine(LINE(7), message);

    sprintf(message," gnd:%.8f   ", GPSMsg.trk_gnd);
    LCD_DisplayStringLine(LINE(8), message);

    sprintf(message," lat=%.10f   ", GPSMsg.lat);
    LCD_DisplayStringLine(LINE(9), message);

    sprintf(message," lat=%.10f   ", GPSMsg.lon);
    LCD_DisplayStringLine(LINE(10), message);

// 	sprintf(message," direction=%.2f", Dire);
// 	LCD_DisplayStringLine(LINE(10), message);

// 	sprintf(message," dir_deg=%.2f gy=%d ", dir_deg, gy );
// 	LCD_DisplayStringLine(LINE(11), message);

    sprintf(message," PWM_set=%d    ",PWM_set);
    LCD_DisplayStringLine(LINE(12), message);
    //	printf("mxmax=%d mxmin=%d mymax=%d mymin=%d mzmax=%d mzmin=%d\r\n",mx_max,mx_min,my_max,my_min,mz_max,mz_min);


}
Пример #2
0
void main(void)
  {

	ATD_initialization(2);		// Allows use of Get_Voltage.  The value passed (2) means pin RA2. See ATDroutines for more explanation

	InterruptInitialization();	// Initializes flags in order for the interrupt to work on the hardware side of things.




#if defined(_16F883)
//	IRCF2=1;	IRCF1=0;	IRCF0=0;				//1 MHz, Internal Oscillator Frequency Select bits || This refers to the Internal Oscillator which
													//  determines how fast the clock goes and in turn affects the PWM speed.

	IRCF2=1;	IRCF1=1;	IRCF0=1;				//8 MHZ ||Sets the oscillator to 8MHz by setting all three bits to 1.  The settings vary from 000: 31kHz to 111 8Mhz
#endif
	
	PWM1PinDirection								//4x PWM Motors 
	PWM2PinDirection
	PWMPin3Configuration	
	PWMPin4Configuration
	TRISB5=0; ANS13=0; IOCB5=0; WPUB5=0, nRBPU = 0;	
	TRISB0=1; ANS12=0; IOCB0=1; WPUB0=1; 			//Switches for spin
	TRISB1=1; ANS10=0; IOCB1=1; WPUB1=1; 			//TRIS: 0/1:output/input
	TRISB2=1; ANS8=0;  IOCB2=1; WPUB2=1;			//ANSxx=0/1 toggles analog input on switch.  Analog is enabled by default. This disables it for digital use 
	TRISB3=1; ANS9=0;  IOCB3=1; WPUB3=1;  			//B1-B5 is used for switches (digital) 
	TRISB4=1; ANS11=0; IOCB4=1; WPUB4=1;			//IOCB: Must be enabled for Port B interrupt. 
	TRISB5=1; ANS13=0; IOCB5=1; WPUB5=1;			//WPUB: Weak Pull-ups Port B. Sets B1-B5 as pull-ups. Necessary for Port B interrupt.
	TRISA1 = 0;										//Servo: TRISA1 makes it an output
	TMR2ON=1;										//Turns on Timer2 
	TRISA0 = 0;
	RA0 = 1;
	
	
	InterruptInitialization();						//Calls the Initialization function
	PulsePeriod = ph;								//Sets the PulsePeriod to the same value as the length which sets the motors to full speed

	PWM1Pin=1;										// Turns on the motors by sending power to the pin the motor is connected to
	PWM2Pin=1;
	PWM3Pin=1;
	PWM4Pin=1;

	PULSELENGTH1=ph;								// Sets all motors to full speed 
	PULSELENGTH2=ph;
	PULSELENGTH3=ph;
	PULSELENGTH4=ph;
	

	while(1){
	Get_Voltage(&Voltage);					//Gets a reading of the voltage 

	if(Voltage<100)							//Conditionals to adjust the speed of the motors based on the current position of the potentiometer.
	PulsePeriod = 512;						//a greater period means that the pulse runs longer which means that the motors go slower
											//as the Voltage increases, the resistance from the potentiometer must be decreasing so as the knob turns the Pulse is 
											//decreased to change the speed as the knob is turned.

	if((Voltage<=200)&&(Voltage>=100))
	PulsePeriod = 450;	

	if((Voltage>200)&&(Voltage<=300))
	PulsePeriod = 400;

	if((Voltage>300)&&(Voltage<=400))
	PulsePeriod = 350;

	if((Voltage>400)&&(Voltage<=500))
	PulsePeriod = 300;

	if((Voltage>500)&&(Voltage<=600))
	PulsePeriod = 250;

	if((Voltage>700)&&(Voltage<=800))
	PulsePeriod = 200;

	if((Voltage>800)&&(Voltage<=900))
	PulsePeriod = 250;

	if((Voltage>900)&&(Voltage<1000))
	PulsePeriod = 200;

	if(Voltage>=1000)
	PulsePeriod = 100;

}

}