//************************************************************************************
//**  
//**  Source name:   F:\TSIN\Moteur_cc\TP_MLI\dossier_prof\fichier_flowcode_correction\TP_MOTEURDC_prof_v6.fcfx
//**  Title:         
//**  Description:   
//**  Device:        AVR.ATMEGA.ATMEGA32
//**  
//**  Generated by:  Flowcode v6.1.3.2
//**  Date:          Saturday, May 07, 2016 18:05:04
//**  Users:         10
//**  Registered to: LYC-LANGEVIN83-V6
//**  Licence key:   R99GGE
//**  
//**  
//**     POUR UN USAGE NON COMMERCIAL
//**  
//**  http://www.matrixtsl.com
//**  
//************************************************************************************


#define MX_AVR
#define MX_CAL_AVR
#define MX_CLK_SPEED 8000000
#define FCP_NULL Unconnected_Port
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <avr\io.h>
#include <avr\interrupt.h>
#include <avr\eeprom.h>
#include <avr\wdt.h>
#define OCR0A OCR0
#define COM0A0 COM00
#define COM0A1 COM01
//Configuration Start
//Configuration End

/*========================================================================*\
   Use :Inclure les définitions de type
\*========================================================================*/
#include "C:\Flowcode 6\CAL\internals.c"

MX_UINT8 FCLV_LOOP1;
MX_UINT8 FCLV_LOOP2;
MX_UINT8 FCLV_LOOP3;


/*========================================================================*\
   Use :panel
       :Déclarations des variables
       :Déclarations de la fonction macro
\*========================================================================*/
#define FCVsz_COURANT_IMAGE 16
#define FCVsz_AFF 20
#define FCVsz_TENSION1 20
MX_GLOBAL MX_UINT8 FCV_MOTEUR;
MX_GLOBAL MX_CHAR FCV_COURANT_IMAGE[FCVsz_COURANT_IMAGE];
MX_GLOBAL MX_CHAR FCV_AFF[FCVsz_AFF];
MX_GLOBAL MX_CHAR FCV_TENSION1[FCVsz_TENSION1];


/*========================================================================*\
   Use :bezel_radiused1
       :Déclarations des variables
       :Déclarations de la fonction macro
\*========================================================================*/

/*========================================================================*\
   Use :scale_linear
       :Déclarations des variables
       :Déclarations de la fonction macro
\*========================================================================*/

/*========================================================================*\
   Use :dash_scale_vert1
       :Déclarations des variables
       :Déclarations de la fonction macro
\*========================================================================*/

/*========================================================================*\
   Use :ASCII6
       :Déclarations des variables
       :Déclarations de la fonction macro
\*========================================================================*/
#define FCVsz_00fb8_ASCII6__FLOATFIXEDLIST 1
#define FCVsz_00fb8_ASCII6__INTLIST 60
#define FCVsz_00fb8_ASCII6__FLOATLIST 1
#define FCVsz_00fb8_ASCII6__INTFIXEDLIST 1


/*========================================================================*\
   Use :ASCII7
       :Déclarations des variables
       :Déclarations de la fonction macro
\*========================================================================*/
#define FCVsz_00fb7_ASCII7__FLOATFIXEDLIST 1
#define FCVsz_00fb7_ASCII7__INTLIST 55
#define FCVsz_00fb7_ASCII7__FLOATLIST 1
#define FCVsz_00fb7_ASCII7__INTFIXEDLIST 1


/*========================================================================*\
   Use :ASCII5
       :Déclarations des variables
       :Déclarations de la fonction macro
\*========================================================================*/
#define FCVsz_00fb6_ASCII5__FLOATFIXEDLIST 1
#define FCVsz_00fb6_ASCII5__INTLIST 60
#define FCVsz_00fb6_ASCII5__FLOATLIST 1
#define FCVsz_00fb6_ASCII5__INTFIXEDLIST 1


/*========================================================================*\
   Use :ASCII4
       :Déclarations des variables
       :Déclarations de la fonction macro
\*========================================================================*/
#define FCVsz_00fb5_ASCII4__FLOATFIXEDLIST 1
#define FCVsz_00fb5_ASCII4__INTLIST 60
#define FCVsz_00fb5_ASCII4__FLOATLIST 1
#define FCVsz_00fb5_ASCII4__INTFIXEDLIST 1


/*========================================================================*\
   Use :ASCII3
       :Déclarations des variables
       :Déclarations de la fonction macro
\*========================================================================*/
#define FCVsz_00fb4_ASCII3__FLOATFIXEDLIST 1
#define FCVsz_00fb4_ASCII3__INTLIST 60
#define FCVsz_00fb4_ASCII3__FLOATLIST 1
#define FCVsz_00fb4_ASCII3__INTFIXEDLIST 1


/*========================================================================*\
   Use :ASCII2
       :Déclarations des variables
       :Déclarations de la fonction macro
\*========================================================================*/
#define FCVsz_00fb3_ASCII2__FLOATFIXEDLIST 1
#define FCVsz_00fb3_ASCII2__INTLIST 60
#define FCVsz_00fb3_ASCII2__FLOATLIST 1
#define FCVsz_00fb3_ASCII2__INTFIXEDLIST 1


/*========================================================================*\
   Use :ASCII1
       :Déclarations des variables
       :Déclarations de la fonction macro
\*========================================================================*/
#define FCVsz_00fb2_ASCII1__FLOATFIXEDLIST 1
#define FCVsz_00fb2_ASCII1__INTLIST 60
#define FCVsz_00fb2_ASCII1__FLOATLIST 1
#define FCVsz_00fb2_ASCII1__INTFIXEDLIST 1


/*========================================================================*\
   Use :ASCII0
       :Déclarations des variables
       :Déclarations de la fonction macro
\*========================================================================*/
#define FCVsz_00fb1_ASCII0__FLOATFIXEDLIST 1
#define FCVsz_00fb1_ASCII0__INTLIST 60
#define FCVsz_00fb1_ASCII0__FLOATLIST 1
#define FCVsz_00fb1_ASCII0__INTFIXEDLIST 1


/*========================================================================*\
   Use :PWM_Digital
       :Déclarations des variables
       :Déclarations de la fonction macro
\*========================================================================*/
MX_UINT8 FCD_0ba71_PWM_Digital__ReadASCIILUT(MX_UINT8 FCL_POS_STR, MX_UINT8 FCL_COUNT);

/*========================================================================*\
   Use :fcdhelper
       :Déclarations des variables
       :Déclarations de la fonction macro
\*========================================================================*/

/*========================================================================*\
   Use :cal_pwm
       :Déclarations des variables
       :Déclarations de la fonction macro
\*========================================================================*/
#define MX_PWM_REF1 
#define MX_PWM_PRESCALE1 (64)
#define MX_PWM_PIN_1 (5)
#define MX_PWM_PORT_1 portd
#define MX_PWM_PERIOD 255
#define MX_PWM_TRIS_1 trisd
#define MX_PWM_CHANNEL_1 (2)


/*=----------------------------------------------------------------------=*\
   Use :cal_pwm
       :Définitions supplémentaires
\*=----------------------------------------------------------------------=*/
#define MX_PWM
#define MX_PWM_TMR0_CNT 1
#define MX_PWM_TMR1_CNT 2
#define MX_PWM_TMR2_CNT 1
#define MX_PWM_TMR3_CNT 0
#define MX_PWM_TMR4_CNT 0
#define MX_PWM_TMR5_CNT 0
#define MX_PWM_CNT 4

void FC_CAL_PWM_ChangePeriod_1(MX_UINT8 FCL_PERIOD, MX_UINT16 FCL_PRESCALER);
void FC_CAL_PWM_Disable_1();
void FC_CAL_PWM_SetDuty8Bit_1(MX_UINT8 FCL_DUTY);
void FC_CAL_PWM_Enable_1();
void FC_CAL_PWM_SetDuty10Bit_1(MX_UINT16 FCL_DUTY);

/*========================================================================*\
   Use :v5__pwm0
       :Déclarations des variables
       :Déclarations de la fonction macro
\*========================================================================*/
MX_GLOBAL MX_UINT8 FCV_0df41_v5__pwm0__ENABLED = (0x0);

void FCD_0df41_v5__pwm0__ChangePeriod(MX_UINT16 FCL_PERIOD, MX_SINT16 FCL_PRESCALER);
void FCD_0df41_v5__pwm0__Disable();
void FCD_0df41_v5__pwm0__SetDutyCycle(MX_UINT8 FCL_DUTY);
void FCD_0df41_v5__pwm0__Enable();
void FCD_0df41_v5__pwm0__SetDutyCycle10Bit(MX_UINT16 FCL_DUTY);

/*========================================================================*\
   Use :component_label1
       :Déclarations des variables
       :Déclarations de la fonction macro
\*========================================================================*/

/*========================================================================*\
   Use :led_base
       :Déclarations des variables
       :Déclarations de la fonction macro
\*========================================================================*/
void FCD_03d92_led_base__TurnOn();
void FCD_03d92_led_base__TurnOff();

/*========================================================================*\
   Use :component_label1
       :Déclarations des variables
       :Déclarations de la fonction macro
\*========================================================================*/

/*========================================================================*\
   Use :led_base
       :Déclarations des variables
       :Déclarations de la fonction macro
\*========================================================================*/
void FCD_03d91_led_base__TurnOn();
void FCD_03d91_led_base__TurnOff();

/*========================================================================*\
   Use :Inclure la couche d'adaptation de puce
\*========================================================================*/
#include "C:\Flowcode 6\CAL\includes.c"


/*========================================================================*\
   Use :bezel_radiused1
       :Implémentations de la macro
\*========================================================================*/

/*========================================================================*\
   Use :scale_linear
       :Implémentations de la macro
\*========================================================================*/

/*========================================================================*\
   Use :dash_scale_vert1
       :Implémentations de la macro
\*========================================================================*/

/*========================================================================*\
   Use :ASCII6
       :Implémentations de la macro
\*========================================================================*/

/*========================================================================*\
   Use :ASCII7
       :Implémentations de la macro
\*========================================================================*/

/*========================================================================*\
   Use :ASCII5
       :Implémentations de la macro
\*========================================================================*/

/*========================================================================*\
   Use :ASCII4
       :Implémentations de la macro
\*========================================================================*/

/*========================================================================*\
   Use :ASCII3
       :Implémentations de la macro
\*========================================================================*/

/*========================================================================*\
   Use :ASCII2
       :Implémentations de la macro
\*========================================================================*/

/*========================================================================*\
   Use :ASCII1
       :Implémentations de la macro
\*========================================================================*/

/*========================================================================*\
   Use :ASCII0
       :Implémentations de la macro
\*========================================================================*/

/*========================================================================*\
   Use :PWM_Digital
       :Implémentations de la macro
\*========================================================================*/
/*=----------------------------------------------------------------------=*\
   Use :Gets a byte of the embedded ASCII font data.
       :
       :Param??tres pour la macro ReadASCIILUT :
       :  pos_str : ASCII position -32 so A = 'A' - 32 = 33
       :  count : Font column Ranging 0-4
       :
       :Renvoie : MX_UINT8
\*=----------------------------------------------------------------------=*/
MX_UINT8 FCD_0ba71_PWM_Digital__ReadASCIILUT(MX_UINT8 FCL_POS_STR, MX_UINT8 FCL_COUNT)
{
	//Définitions des variables locales
	MX_UINT8 FCL_POSITION;
	MX_UINT8 FCR_RETVAL;


	#if (0) // 0 == 1

	//Le code a été optimisé par le préprocesseur
	// #else

	#endif

	return (FCR_RETVAL);

}


/*========================================================================*\
   Use :fcdhelper
       :Implémentations de la macro
\*========================================================================*/

/*========================================================================*\
   Use :cal_pwm
       :Implémentations de la macro
\*========================================================================*/

/*========================================================================*\
   Use :v5__pwm0
       :Implémentations de la macro
\*========================================================================*/
/*=----------------------------------------------------------------------=*\
   Use :Sets the overall period and prescaler of the output PWM signal.
       :
       :Param??tres pour la macro ChangePeriod :
       :  Period : The maximum number that will represent 100% on, PIC/AVR: 0-255 16-bit PIC: 0-65535
       :  Prescaler : The scaler used to divide the system clock speed down to the PWM rate.
\*=----------------------------------------------------------------------=*/
void FCD_0df41_v5__pwm0__ChangePeriod(MX_UINT16 FCL_PERIOD, MX_SINT16 FCL_PRESCALER)
{

	FC_CAL_PWM_ChangePeriod_1(FCL_PERIOD, FCL_PRESCALER);

}

/*=----------------------------------------------------------------------=*\
   Use :Disables a PWM channel and allows the default output / input state to be resumed
\*=----------------------------------------------------------------------=*/
void FCD_0df41_v5__pwm0__Disable()
{

	FCV_0df41_v5__pwm0__ENABLED = 0;

	FC_CAL_PWM_Disable_1();

}

/*=----------------------------------------------------------------------=*\
   Use :Sets the PWM duty cycle in terms of on/off based on the current period setting.
       :E.g. if period = 255 then duty of 128 is equal to 50% on and 50% off.
       :16-bit PIC users should use the 10bit duty function to access the full range.
       :
       :Param??tres pour la macro SetDutyCycle :
       :  Duty : 8-bit PWM duty 0-255
\*=----------------------------------------------------------------------=*/
void FCD_0df41_v5__pwm0__SetDutyCycle(MX_UINT8 FCL_DUTY)
{

	if (FCV_0df41_v5__pwm0__ENABLED)
	{

		FC_CAL_PWM_SetDuty8Bit_1(FCL_DUTY);

	// } else {

	}

}

/*=----------------------------------------------------------------------=*\
   Use :Enables a PWM channel as an output overriding the default output pin state.
\*=----------------------------------------------------------------------=*/
void FCD_0df41_v5__pwm0__Enable()
{

	FCV_0df41_v5__pwm0__ENABLED = 1;

	FC_CAL_PWM_ChangePeriod_1(255, 64);

	FC_CAL_PWM_Enable_1();

}

/*=----------------------------------------------------------------------=*\
   Use :PIC/AVR - Sets the full scale PWM duty cycle based on the current period setting.
       :If period = 255 then Duty of 512 is equal to 50%.
       :
       :16-bit PICs have a 16-bit period range available.
       :If period = 65535 then Duty of 32768 is equal to 50%.
       :
       :Param??tres pour la macro SetDutyCycle10Bit :
       :  Duty : PWM duty PIC/AVR: 0-1023 16-bit PIC: 0-65535
\*=----------------------------------------------------------------------=*/
void FCD_0df41_v5__pwm0__SetDutyCycle10Bit(MX_UINT16 FCL_DUTY)
{

	if (FCV_0df41_v5__pwm0__ENABLED)
	{

		FC_CAL_PWM_SetDuty10Bit_1(FCL_DUTY);

	// } else {

	}

}


/*========================================================================*\
   Use :component_label1
       :Implémentations de la macro
\*========================================================================*/

/*========================================================================*\
   Use :led_base
       :Implémentations de la macro
\*========================================================================*/
/*=----------------------------------------------------------------------=*\
   Use :Turn the LED off.
\*=----------------------------------------------------------------------=*/
void FCD_03d92_led_base__TurnOn()
{

	FCP_SET(B, D, 0x1, 0x0, 1);

}

/*=----------------------------------------------------------------------=*\
   Use :Turn the LED on.
\*=----------------------------------------------------------------------=*/
void FCD_03d92_led_base__TurnOff()
{

	FCP_SET(B, D, 0x1, 0x0, 1 - 1);

}


/*========================================================================*\
   Use :component_label1
       :Implémentations de la macro
\*========================================================================*/

/*========================================================================*\
   Use :led_base
       :Implémentations de la macro
\*========================================================================*/
/*=----------------------------------------------------------------------=*\
   Use :Turn the LED off.
\*=----------------------------------------------------------------------=*/
void FCD_03d91_led_base__TurnOn()
{

	FCP_SET(B, D, 0x2, 0x1, 1);

}

/*=----------------------------------------------------------------------=*\
   Use :Turn the LED on.
\*=----------------------------------------------------------------------=*/
void FCD_03d91_led_base__TurnOff()
{

	FCP_SET(B, D, 0x2, 0x1, 1 - 1);

}


/*========================================================================*\
   Use :panel
       :Implémentations de la macro
\*========================================================================*/


/*========================================================================*\
   Use :Principale
\*========================================================================*/
int main()
{
	MCUCSR=0x00;
	wdt_disable();

	
	// Appel de la Routine Composant
	// Appel de la Routine Composant: v5__pwm0::Enable()
	FCD_0df41_v5__pwm0__Enable();

	// SENS
	// Sortie: 0 -> D1
	FCP_SET(B, D, 0x02, 1, (0));
	// VALIDATION
	// Sortie: 0 -> D0
	FCP_SET(B, D, 0x01, 0, (0));
	// Pause
	// Pause: 500 ms
	FCI_DELAYINT_MS(500);

	// Boucle
	// Boucle: While 1
	while (1)
	{

		// VALIDATION
		// Sortie: 1 -> D0
		FCP_SET(B, D, 0x01, 0, (1));
		// Calcul
		// Calcul:
		//  moteur = 73
		FCV_MOTEUR = 73;

		// Boucle
		// Boucle: Boucle 6 times
		for (FCLV_LOOP1=0; (FCLV_LOOP1)<(6); (FCLV_LOOP1)++)
		{

			// Appel de la Routine Composant
			// Appel de la Routine Composant: v5__pwm0::SetDutyCycle(moteur)
			FCD_0df41_v5__pwm0__SetDutyCycle(FCV_MOTEUR);

			// Pause
			// Pause: 500 ms
			FCI_DELAYINT_MS(500);

			// Calcul
			// Calcul:
			//  moteur = moteur + 20
			FCV_MOTEUR = FCV_MOTEUR + 20;


		}

		// Pause
		// Pause: 8 s
		FCI_DELAYBYTE_S(8);

		// Boucle
		// Boucle: Boucle 6 times
		for (FCLV_LOOP2=0; (FCLV_LOOP2)<(6); (FCLV_LOOP2)++)
		{

			// Calcul
			// Calcul:
			//  moteur = moteur - 20
			FCV_MOTEUR = FCV_MOTEUR - 20;

			// Appel de la Routine Composant
			// Appel de la Routine Composant: v5__pwm0::SetDutyCycle(moteur)
			FCD_0df41_v5__pwm0__SetDutyCycle(FCV_MOTEUR);

			// Pause
			// Pause: 500 ms
			FCI_DELAYINT_MS(500);


		}

		// VALIDATION
		// Sortie: 0 -> D0
		FCP_SET(B, D, 0x01, 0, (0));
		// Pause
		// Pause: 500 ms
		FCI_DELAYINT_MS(500);


	}

	mainendloop: goto mainendloop;
}



/*========================================================================*\
   Use :Interruption
\*========================================================================*/




