0% found this document useful (0 votes)
57 views5 pages

Correction TP 7

The document is a correction for exercises in an embedded systems course. Exercise 7.1 demonstrates using an interrupt service routine to toggle an LED connected to PORTB whenever an interrupt occurs. Exercise 7.2 toggles an LED connected to PORTA depending on the state of buttons connected to PORTB in the interrupt routine. Exercise 7.3 increments the value held in PORTD in the interrupt routine and displays a changing counter value on an LCD.

Uploaded by

houssem 4275
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views5 pages

Correction TP 7

The document is a correction for exercises in an embedded systems course. Exercise 7.1 demonstrates using an interrupt service routine to toggle an LED connected to PORTB whenever an interrupt occurs. Exercise 7.2 toggles an LED connected to PORTA depending on the state of buttons connected to PORTB in the interrupt routine. Exercise 7.3 increments the value held in PORTD in the interrupt routine and displays a changing counter value on an LCD.

Uploaded by

houssem 4275
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Module : Introduction aux systèmes embarqués

Année universitaire : 2022 – 2023

Correction TRAVAUX PRATIQUES N° : 7

INTRODUCTION A LA PROGRAMMATION DES MICROCONTROLEURS

Exercice 7.1

void interrupt ( )

if (INTCON.INTF)

INTCON.INTF=0;

PORTB.B7=~PORTB.F7;

void main ( )

TRISB = 0x01;

PORTB = 0x00;

INTCON.GIE = 1;

INTCON.INTE = 1;

INTCON.INTF = 0;

PORTB.B7 = 1;

Delay_ms (500);

PORTB.B7 = 0;

Mr Nizar TOUJENI 1/5


while (1)

Exercice 7.2

#define LED PORTA.B0

void interrupt ( )

if (INTCON.RBIF)

INTCON.RBIF = 0;

If (!PORTB.B4) LED = 1;

if (!PORTB.B7) LED = 0;

void main ( )

TRISA = 0x00;

TRISB = 0xFF;

OPTION_REG.B7 = 0; // Activer les résistances de pull-up sur PORTB

INTCON.GIE = 1;

INTCON.RBIE = 1;

INTCON.RBIF = 0;

Mr Nizar TOUJENI 2/5


LED = 0;

while (1)

Delay_ms (500);

Exercice 7.3

Question 1

void interrupt (void)

PORTD++;

INTCON.INTF = 0; // Effacer le drapeau d'interruption

void main (void)

TRISB = 0x01;

TRISD = 0x00;

INTCON.GIE = 1; // Autoriser l'interruption globale

INTCON.INTE = 1; // Autoriser l'interruption externe RB0/INT

INTCON.PEIE = 0; // Désactiver toutes les interruptions non masquables

OPTION_REG.INTEDG = 1; // Interruption sur front montant

PORTD = 0;

while (1) { }

Mr Nizar TOUJENI 3/5


}

Question 2

sbit LCD_RS at RD2_bit;

sbit LCD_EN at RD3_bit;

sbit LCD_D4 at RD4_bit;

sbit LCD_D5 at RD5_bit;

sbit LCD_D6 at RD6_bit;

sbit LCD_D7 at RD7_bit;

sbit LCD_RS_Direction at TRISD2_bit;

sbit LCD_EN_Direction at TRISD3_bit;

sbit LCD_D4_Direction at TRISD4_bit;

sbit LCD_D5_Direction at TRISD5_bit;

sbit LCD_D6_Direction at TRISD6_bit;

sbit LCD_D7_Direction at TRISD7_bit;

int i = 0;

char valeur [10];

void interrupt (void)

i++;

INTCON.INTF = 0; // Effacer le drapeau d'interruption

void main (void)

Mr Nizar TOUJENI 4/5


TRISB = 0x01;

INTCON.GIE = 1; // Autoriser l'interruption globale

INTCON.INTE = 1; // Autoriser l'interruption externe RB0/INT

INTCON.PEIE = 0; // Désactiver toutes les interruptions non masquables

OPTION_REG.INTEDG = 1; // Interruption sur front montant

Lcd_Init ( );

Lcd_Cmd (_LCD_CLEAR);

Lcd_Cmd (_LCD_CURSOR_OFF);

while (1)

IntToStr (i, valeur);

Lcd_Out (1, 1,"Nombre:");

Lcd_Out_Cp (valeur);

Mr Nizar TOUJENI 5/5

You might also like