Ejemplo n.º 1
0
void Init_Periphs()			  
{

 Init_Clock_System();
 Init_PortA();
 Init_PortB();
 Init_PortC();
 #ifdef BLINK_ON_START
 	Blink_Leds(BLINK_NBR,DUREE_LENTE);
 #endif

 #ifdef USE_ADC
  Setup_Adc();
  Adc_On();
  Start_Conversion();
 #endif

 #ifdef USE_PWM
 Init_Timer2();
 Fixe_Rapport(0);
 #endif

 #ifdef USE_POSITION
 Init_Timer3();
 #endif

 #ifdef USE_SPEED
 Init_Timer4();
 #endif


}
Ejemplo n.º 2
0
void main(void)
{
	WDTCN = 0xDE;
	WDTCN = 0xAD;
	EA = 0;
	
	Init_Clock();
	Init_Port();

	Init_Timer0(SYSCLK);
	Init_Timer2(SYSCLK);
	Init_Timer3(SYSCLK);

	EA = 1;

	PIN_MOTOR_DIR = 0xFF;	//set motor direction to clockwise;

	while(1) { }
}
Ejemplo n.º 3
0
int main(){
	
	int memo_bit_0[4]={0, 0, 0, 0}, memo_bit_1[4]={0, 0, 0, 0};			//Utilisé pour détecter les fronts (up/down) des boutons
	unsigned int memo_cran_levier=0;									//Mémorise dans quel cran se trouve le levier 	

	/* Paramète d'affichage de l'ADC du pitch variable */
	float BUFF[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};											// initialise 16 BUFFER
	float OFFSET[16]={0.005f,0,0.005f,0,0.005f,0,0.005f,0,0.005f,0,0.005f,0,0.005f,0,0.005f,0};	// ajout d'un offset pour un réglage précis
	int BUFF_val[16]={1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0};											// 1 = affichage du buffer

	float Pot_Pitch_Volt=0;					//valeur en volt du potentiomètre pour les pitchs variables 
	unsigned int *Levier_num_cran=0;		//numéro du cran dans lequel se trouve le levier pour le pitch variable

	Setup(); //Initialisation PIC, UART,...

	/* initialisation de l'encodeur et can*/
	initialisation_CAN();
	initialisation_message_Tx_CAN();
	chinookpack_fbuffer_init(&buf, dataArray, 8);						//initialisation des buffer
	chinookpack_packer_init(&pk, &buf, chinookpack_fbuffer_write);		//initialisation du pack pour le message

    Init_Timer3(TIMER3_FREQ);											//CAN timeout timer

	while(1)
	{
		Analyse_ADC(BUFF, OFFSET, BUFF_val);							//Analyse les entrées analogiques 
	    Pot_Pitch_Volt = BUFF[0];										//recopie de la valeur du potentiomètre

		if(variation_pitch(Pot_Pitch_Volt, &Levier_num_cran)){			//Envoie du message commande des pitchs variables seulement s'il y a eu un changement de cran sur le levier

			chinookpack_pack_uint8(&pk, Levier_num_cran);

			Set_Timeout();
			send_CAN_msg(&can_msg_manual_pitch, dataArray, 2);							// envoie du message Can_manual_pitch
			while(is_CAN_msg_send(&can_msg_manual_pitch) != TRUE && !can_time_out);		// test si le message est envoyé
            Reset_Timeout();
			
		}
		chinookpack_fbuffer_clear(&buf);

		/*détecte si un bouton change et envoie des messages can seulement s'il y a changement sur un bouton*/
		if((!BP1 && !memo_bit_1[0]) || (!BP2 && !memo_bit_1[1]) || (!BP3 && !memo_bit_1[2]) ||(!BP4 && !memo_bit_1[3])){
			if(!BP1) {memo_bit_0[0]=0;memo_bit_1[0]=1;Led1=1;Nop();}					// mémorise le bouton 1 comme étant à l'état haut
			if(!BP2) {memo_bit_0[1]=0;memo_bit_1[1]=1;Led2=1;Nop();}					// mémorise le bouton 2 comme étant à l'état haut
			if(!BP3) {memo_bit_0[2]=0;memo_bit_1[2]=1;Led3=1;Nop();}					// mémorise le bouton 3 comme étant à l'état haut
			if(!BP4) {memo_bit_0[3]=0;memo_bit_1[3]=1;Led4=1;Nop();}					// mémorise le bouton 4 comme étant à l'état haut
		
			chinookpack_pack_uint8(&pk,(memo_bit_0[3]<<3)|(memo_bit_0[2]<<2)|(memo_bit_0[1]<<1)|(memo_bit_0[0])); 	//concatène les quatre boutons
			Set_Timeout();
			send_CAN_msg(&can_msg_button_cmd, dataArray, 2);							// Envoie du message CAN des boutons
			while(is_CAN_msg_send(&can_msg_button_cmd) != TRUE && !can_time_out);		// test si le message est envoyé
          	Reset_Timeout();
		    
		}
		else if((BP1 && !memo_bit_0[0]) || (BP2 && !memo_bit_0[1]) || (BP3 && !memo_bit_0[2]) ||(BP4 && !memo_bit_0[3])){
			if(BP1) {memo_bit_0[0]=1;memo_bit_1[0]=0;Led1=0;Nop();}						// mémorise le bouton 1 comme étant à l'état bas
			if(BP2) {memo_bit_0[1]=1;memo_bit_1[1]=0;Led2=0;Nop();}						// mémorise le bouton 2 comme étant à l'état bas
			if(BP3) {memo_bit_0[2]=1;memo_bit_1[2]=0;Led3=0;Nop();}						// mémorise le bouton 3 comme étant à l'état bas
			if(BP4) {memo_bit_0[3]=1;memo_bit_1[3]=0;Led4=0;Nop();}						// mémorise le bouton 4 comme étant à l'état bas
		
			chinookpack_pack_uint8(&pk,(memo_bit_0[3]<<3)|(memo_bit_0[2]<<2)|(memo_bit_0[1]<<1)|(memo_bit_0[0])); 	//concatène les quatre boutons	
			Set_Timeout();
			send_CAN_msg(&can_msg_button_cmd, dataArray, 2);							// Envoie du message CAN des boutons
			while(is_CAN_msg_send(&can_msg_button_cmd) != TRUE && !can_time_out);		// test si le message est envoyé
         	Reset_Timeout();			
		}
		chinookpack_fbuffer_clear(&buf);											// vide le buffer pour le pack de l'encodeur message can
	}//while	
}