Page 15 - SERIE N11 micro 2
P. 15

Exemple:
       if Button (portA,3,50, 1) then « action1 »
       On teste l'appui sur un bouton poussoir relie a la broche RA3 pendant 50ms pour faire l'action 1
        Compléter le programme :

                                          10k       10k
                                                         déc

         16   OSC1         RA0    17
          15   OSC2        RA1    18                                  program exerciceN_ 15_button;
                           RA2    1                                   var x:byte;
          4   MCLR         RA3    2                      inc          begin
                                  3
                      RA4/T0CKI                                       trisa:=$ ... ;trisb:= .... ;portb: = .... ;x: = ..... ;
                                  6                                   while true do
                        RB0/INT   7                                   begin
                           RB1
                           RB2    8                                   if button(porta,2, 100, 1) then ………
                           RB3    9                                   if x= 10 …………………………….
                           RB4    10                                  if button(porta, 1, 100, 1) then ………….
                           RB5    11                                  if x=255 …………………………….
                                  12
                           RB6    13                                  portb:= …………..;
                           RB7                                        end ;
            PIC16F84A                                                 end·


       Exercice N°16:
       Réaliser un compteur modulo 10 sachant qu'a chaque impulsion sur la broche RB0 le compteur
       s'incrémenté : (Utiliser la procédure d'interruption externe avec la broche RB0)
       1 °) Configurer le registre INTCON :

        INTCON  GIE  EEIE  TOIE  INTE  RBIE  TOIF  INTF  RBIF
                                                                               =(……)hex  =(……………..)2

       2°) Compléter le programme :
                                                         program exercice_N_16_interrupt;
                                                         var i:byte;
                                                         procedure interrupt;
                                                         begin
                                                         intcon :=……. ;i:=……. ;
                                                         end ;
                                                         begin
       16   OSC1        RA0     17

       15                       18                       ..................................... ; intcon :=……… ; i:=……… ;
           OSC2         RA1     1                        while(1=1) do
         4              RA2     2                        begin
           MCLR         RA3     3                        ………………
                   RA4/T0CKI                             If i=10 then i:=……… ;
                     RB0/INT    6                        end ;
                        RB1     7              0         end·
                        RB2     8
                        RB3     9     interruption
                        RB4     10
                                11
                        RB5     12
                        RB6     13
                        RB7
          PIC16F84A



                                                                                                                15
   10   11   12   13   14   15   16   17   18   19   20