Professional Documents
Culture Documents
Correction TD Microcontroleur
Correction TD Microcontroleur
Exercice 1.2 :
Question 1 :
#define B1 RA0_bit PORTB=0x00; Delay_ms(500);
void main() }
{ else
{ PORTB=0xAA; Delay_ms(500);
if(B1==0) }
{ }
PORTB=0xFF; Delay_ms(500); }
Question 2 :
#define B1 RA0_bit PORTB=0xFF; Delay_ms(500);
void main() }
{ }
TRISA=0xFF; else
TRISB=0x00; {
{ PORTB=0x30; Delay_ms(3000);
{ PORTB=0x00; Delay_ms(1000);
{ }
Exercice 1.3 :
1.
void main()
int i, CHIFFRE[10] = {0x3F, 0x06, 0x51011, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F};
while(1)
if(RA0_Bit==1)
if(RA1_Bit==1)
2.
void main()
int i, CHIFFRE[10] = {0x3F, 0x06, 0x51011, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F};
while(1)
if(RA0_Bit==1)
if(RA1_Bit==1)
Exercice 1.5 :
#define B1 RB2_bit D1 = 0; D2 = 0; D3 = 0;
#define B3 RB0_bit {
#define D2 RC3_bit {
char msg1[]="BONJOUR"; }
char msg3[]="SALAM"; {
{ D1 = 0; D2 = 0; D3 = 0;
Lcd_Init(); }
Lcd_Cmd(_LCD_CLEAR); }
Lcd_Cmd(_LCD_CURSOR_OFF); }
Exercice 2.1 :
TRISB=0x00; // Equation de S5
{ }
// Equation de S1 }
Exercice 2.3
#define C2 RB6_Bit {
void main() }
{ if(BP==1&C5==1)
TRISA=0x01; TRISB=0x07; {
{ }
if(BP==1&C1==1) }
{ }
Exercice 3.1 :
delay_ms (1000); }
do }
{ while (1);
kpi = 0; }
Exercice 3.3
{ Lcd_Init ( );
Exercice 4.1
int CHIFFRE[3] = {0B01101101, 0B01111001, 0B00000110};
unsigned int temp_res0, temp_res1;
float tension0, tension1;
void main()
{
TRISA=0xFF; TRISB=0x00;
while(1)
{
temp_res0=ADC_Read(0); temp_res1=ADC_Read(1);
tension0=(float)(temp_res0*5)/1024; tension1=(float)(temp_res1*5)/1024;
if(tension0 > tension1) PORTB = CHIFFRE[0];
if(tension0 == tension1) PORTB = CHIFFRE[1];
if(tension0 < tension1) PORTB = CHIFFRE[2];
}
}
Exercice 4.2
int i, j, chiffre [11] = {0b00111111, 0b00000110, 0b01011011, 0b01001111, 0b01100110,
0b01101101, 0b01111101, 0b00000111, 0b01111111, 0b01101111,0b01110110};
unsigned int temp_res0, temp_res1;
float tension0, tension1;
void main()
{
TRISA=0xFF; TRISB=0x00; TRISC=0x00;
while(1)
{
temp_res0=ADC_Read(0); temp_res1=ADC_Read(1);
tension0=(float)(temp_res0*5)/1024; tension1=(float)(temp_res1*5)/1024;
if(tension0 > tension1)
{
for(i=0; i<2; i++)
{
PORTB = CHIFFRE[i];
for(j=0;j<10;j++)
{
PORTC = CHIFFRE[j]; delay_ms(500);
}
}
}
if(tension0 == tension1)
{
PORTB = CHIFFRE[10]; PORTC = CHIFFRE[10];
}
if(tension0 < tension1)
{
for(i=0; i<2; i++)
{
PORTB = CHIFFRE[1-i];
for(j=0; j<10; j++)
{
PORTC = CHIFFRE[9-j]; delay_ms(500);
}
}
}
}
}
Exercice 5.1
{ while(1)
TRISB = 0xFF; {
PORTC = 0; }
delay_ms(2000); }
PWM1_Init(1000);
Exercice 5.2
void initMain () {
TRISD = 0; {
PORTD = 0; od = cd;
} }
{ }
initMain (); }
PWM1_Start ();