!"#$                    %         & (     )* + , &%&          -
!                    "                                                                              #                     ...
! " #         $           # % &"     ( )    * +                 ( )                                          ,      * +   ...
# (                       ) *     * (, -                  &" <,                                  =            )       %,  ...
,5               /=            -5     5                                                                            2     5...
-       &0            &0              8                 &"       8D > ?                 &"       8D B > ?                 ...
. /+                               (                    <                      #    = #                                   ...
;                                                       $                     #+                            4             ...
= " #                 0                                                              $      = ;                           ...
*                                                                                                    1       #           (...
C="                                                     3   ND"H" ,K,"                                     ( .         31 ...
. /        ( ) *+)                                                                                           #            ...
#                                      4"                                  #                                    (       ) ...
;         (        (               ? @                ? @ <                                 =                          ( >...
,              -                                    .                    $/"            &                              5 :...
*                                                                               ?            @                 !          ...
) "G      )                                      #                                       <             S=                 ...
-$ >   F?            - >: F?    (                                     2                                             2     ...
,        , 8                                                O                                (    !    < A)S =            ...
# .5,,8        &                                                       1*/                                                ...
8"                                           .            < =                         < =                                 ...
>"                !            *       #         (                      (D, ,G            #                               ...
. /                                                    01                                                    21           ...
" &       >J, ,                                              $            #   !                      2                    ...
; 6                                                ,;                                                                     ...
#                                      2 33                     3                                       $         4    "  ...
"                                                     A   (            >J, ,        )                                     ...
. /                         !             " #               # !;   .          " B;         !                              ...
<       2 = #                                         (            &           ()                 5              -        ...
;       &                   &"           1                                                                 #   (          ...
"                                                                 #            (                                 (     .  ...
)                            %                                              A^ <                    $     !     =         ...
*                                      !                                                       (#                         ...
#include<at89x52.h>                         //contém as definições do chip    #define LAMPADA P0_0    const LIGADO=1;    v...
J               (                                                                  #     #include<at89x52.h>              ...
;             (                                             #                                                             ...
Q                      4 %   ( 9       F                     %-- -       Nsfr   at      0x80   P0                         ...
O        &           ( #                     ?           @# !                   (8                ]                       ...
. /                                               $    )%                   (%"                1                          ...
)                     (       #                       2              ;           1    .int y=10;int z=5;int x=0;          ...
int contagem=0;contagem++;8int contagem=10;                                  8contagem--;      (%)                        ...
(%          -            6"                                &                      1    )                            8   ( ...
.       &              ,                       (if(x | y)cont=cont+5;        . &           )/                             ...
. /                                           !                                                   "<       )%            $...
#                                   > ? U          #                                          #                 * %;      ...
int j=5;if(i==1)j++;if(i!=10)i=5;if(i==j)i--;<     (9       & " . %)                      (                       1 <b=   ...
if(P3_0==1){               //se a entrada P3.0 receber +5V,           P0_0=1;         // Ativa saída P0.0           P0_1=1...
<;        $,                                                     %                               <           $=           ...
<         $"                 3                                                                (              8            ...
<< $                                   %<<        )%                      %"                             <        2 =     ...
(                ;                                    <                    ="              !                              ...
&                             &              *                           2                              #                 ...
<          (                                       7         :"                                              F            ...
)                       (                             #X               1                    ;                             ...
. /                                        "                                    %>   (            #    .    *    G        ...
Port P1>                                                  <Port P0                                                        ...
!                      !             *                                                             T EQ                   ...
)             T       #                                                        *    *    #                                ...
D      ( .#include <at89x52.h>#include <delay.h>void main(){     while(1){           P2_0=1;                              ...
"                                          #                                   A)S <            = ( .    J       J       J...
C66 #                   *       *C     !    &                   <            =;   #                                       ...
. /                                                   #                                                     $ &        )% ...
%                                  (   .       6#                                      ,        ./* IE */sbit at 0xA8     ...
8051 teoria
8051 teoria
8051 teoria
8051 teoria
8051 teoria
8051 teoria
8051 teoria
8051 teoria
8051 teoria
8051 teoria
8051 teoria
8051 teoria
8051 teoria
8051 teoria
8051 teoria
8051 teoria
8051 teoria
8051 teoria
8051 teoria
8051 teoria
8051 teoria
8051 teoria
8051 teoria
8051 teoria
8051 teoria
8051 teoria
8051 teoria
8051 teoria
8051 teoria
8051 teoria
8051 teoria
8051 teoria
8051 teoria
8051 teoria
Upcoming SlideShare
Loading in …5
×

8051 teoria

964 views

Published on

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
964
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
47
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

8051 teoria

  1. 1. !"#$ % & ( )* + , &%& -
  2. 2. ! " # $" # % & ( # ) # # #* $ $ # + % ! ( # # , ( - ./ ! (#* ( % 0 1 !* # 2 ! & 333 4567) % & $
  3. 3. ! " # $ # % &" ( ) * + ( ) , * + - $. / &0 $, * ( ) 12 *345 !"# #$ %& 6 7 $ $8-( - &" 7 $ $8-( 9 &" 7 $ $8-( , ,, : * , * , * $ $ 7 $ $8-( $ &" &" 2 $ &" 2 ,; 4 % # &" 5
  4. 4. # ( ) * * (, - &" <, = ) %, % %,, 3, ( 8 , , 8 / &0,2 &0 , ,2 $ &0 , ,2 (,5 ,5 - % ( = , + : , , ;( , + # )2 ( $ ,,2 $ /> ? ,, 2 @ % &" - ,22 $ / A ,22, $ / /AAAAAAAAA AAAAAA A AA ,2 $ B 6AAAAA AAAAAAAAA A AA ,22 $ AAAA AAAAAAAAAA AA A 22 ( 22 / 2 @ 1 2 22 B6 22 $ &" - / , ,
  5. 5. ,5 /= -5 5 2 5 5 5 5 5 55 $. % 5 - + ( - &" 2 - &0 2 - &0 $. 22 ( 8 - &0 $. 22 , $. % 2 ( . $ ( 5 * &" ( 5 * > 2@ ? 5 $. % 5, ( ) C ) ; 5 ( " &" 8 &" D 1 E>? &" 6 >? F B &" ) , : 4GH $ / ) $ 8 E 8 8 &" 8I * @ 2 , * ,@ 2
  6. 6. - &0 &0 8 &" 8D > ? &" 8D B > ? &" 8D B > ? , &" 8D >? &" 8D >?2 $. %0 1 #2 2
  7. 7. . /+ ( < # = # ! ( 8 $# &1 ( > 1 ( # # ! !) 1 # 1 (1 1 ! (" 1 794: # $ ( (1$"; " ( 1 (* 1 0 # 5
  8. 8. ; $ #+ 4 #* 3 ( # ! :5 F5 8 ? ! @ # 2< & 2 = ( +1 C " . "A8 & *B+ & ,C*D)+ ( " E55 2) # "G ) ( +1 C -? ! @ $ #)0 ( & # )0 $ 2 # ( $ $ ( ! "
  9. 9. = " # 0 $ = ; 3 ( ( ( $ % % * $ * " &G # ! " #" 1 ., 1 # < ! = $ < ! =) (H 1 3 (* "G ) )+ )+)# I
  10. 10. * 1 # ( J # # % #, ( , 2 # ( , +# - # & 1 " " " ; . ) ) / 0 * #8 # # ( ,K < = # ( ( # # & $ % # & "" & ( # < # ( ,K= "G ) * ( *1 < 0 =1 ( ! "G ) ! # < ( ,K M ;= ( - ( . = " 3 ",1L * ,K,
  11. 11. C=" 3 ND"H" ,K," ( . 31 < . ( = 31 3 H # ( < # ,K= 3 1 *1 3G # < ,K M ;= ( <",1L * ,K, ND"H" ,K,=O # ( , # # ! . 3 #4 54 ( PHH "G )
  12. 12. . / ( ) *+) # ? @ , 3 < & 1+) =# 4 1*/ 4 2 4Q R D)+ < & = C6FMR D"+ < = :C ! < A)= + ( * + 3 $ G A ( 1 ( * B 8 G , ( ! ) & + ) ( F9 *F9 * ( & < 0 = " ( , J H) ( ) # %
  13. 13. # 4" # ( ) . 5 5 ( ( * )F @ -) % &" ( ( 5 5* . ! :C A)S # ( ( ? @ (# . J J J # ! ( 4G A1 . ( 2 ) ( ) A " 3 3
  14. 14. ; ( ( ? @ ? @ < = ( > ,? ( > ? ; ( <G G =( K , 2 . ( ( # " ( ( 3 ( # # # ( ( . 3 ( ( < ( = " (* . ( &# 2 * # D D ,D TCC " # ( & N* & 2+ & <D)+=. <D)+=. & $ 6 7 ( / . *1 0 ! & D)+ + , - ) *+; ! 4Q R & D)+ $ 6 7 2 MR & D"+ # ( . 3 MR < = 3 MR 2 (58 5$ ( 4 ! ( P # ( . 6 ,
  15. 15. , - . $/" & 5 : 5 : & & " MR ( MR 2< JDS = # ( ! " % 0 ; 4 " 9 0 & ) 0 % ( 2 ! & D"+ # ? @# 2 ! 1 ! 2 . ( , (, 2 ( 2 &D"+ % ( , ? @# " ! M MR ! ! "
  16. 16. * ? @ ! & D"+, JDS # ! > F? > F? > F? >: F?*5 *7 *C *: ( 2 & D"+ # U # % !+) 2 (.3)$ ) > F?O $# $ ( , 2 */ *)* 2 1"VVAD,G/D; # ( $ ; 1 ( ().,$ ).,$ (F > 8F? ( > :F? (F > F? ( > F? 2
  17. 17. ) "G ) # < S= < =) 4 G GV % 7F ; A ( 7F).,$ (3) ( $#.+)$ ( ; > F? ( > :F? (F > F? ( > F?).,$ ,(4$ $#.+)$ (*8 > F?* ( (5$ (3) ( $#.+)$ ; > 5F?O ( +)8 ( (+$ . 6 $ ): > F?" ( M/J J M/J ( ( 3 & M/J. .$ 7. % 8 . % $ 9 : 5
  18. 18. -$ > F? - >: F? ( 2 2 ) * 3 2 ) , 2 H# ! # 2 ; , ) *+ $ !%& # 5 L" ( M ! 67$ 5 CG
  19. 19. , , 8 O ( ! < A)S = O * # ( ! ( ( 3 ; ! < = * ! ! * ,J5Q ( WH11 , ! < ! = 2 # M !, , 8 O ( !< A)S = 8 ( T * # # ,K & * * * # ( * (, , 8 O ( ! < A)S = ( 2 !, , 8 2 ( ( 2 < ( = * < A)= G ( . .8J (.8J -;( J &" . -;( J &" . , ( J ( J 2 5J ( && 8 D, ,G (
  20. 20. # .5,,8 & 1*/ ,K <D)+= & & ! ? @ & < = ? @ V # &9 ) 9 ) 8 # # 0 ) "G ) ( #X * 0 #X ! ! ( 2 < 0= # ( )1 & #X ( #X , # # # # & 8 ( # # # ( ( - #X . J J 1 )* 8 , $ ; 7 < 7 < % *4 " " # * % "=/
  21. 21. 8" . < = < = < = ( $ &) $ & !% $ & < , =1 # # ( #X ( # # #<, > :?@; 1 ( <*= / #X < F= # #<, > :?@; G (" 1 1V) 8, +YU/ ;" ! < F= # " #X < # = . (:; < =>?@A .D ( # #<, > :?@; . 34 34 * " +, - !./
  22. 22. >" ! * # ( (D, ,G # , ! D G # ! & # ## * ( # 3,A 5 , 5" # ( # # < = ,; ( ) ! D)+ 8 ! ( ! < = 0 -
  23. 23. . / 01 21 #1 ? @ $ $4.)() >J, , ; < 7 6 B6< B6 = 1" ( # ( # ,K 811 > # # 3 V ;/K ( & V ;/K % V 1 2 1& # 811 ) ( ! * ( 2 . J Z,V , J)D B V, B G1 1" , H 4 4 $ D & $ $ 1 . " @ $$; ! ( ( >## # #
  24. 24. " & >J, , $ # ! 2 ( , ( ) $ ; 0 -(4 ,: ) 0 A " @ $$" & ( ( # ! 1.[ ) # # 1 2 33) ( 8 ( 1 ; 811 # ( 2 ) >J, # 2 33 ,
  25. 25. ; 6 ,; # ( H ( ; , J ; 3 N ( J ) " # J 1 J # # J 2 J " # J , >J, , ; , $ / 8 ( D D ( / 1 D * 1 J * D $ % @ $ $ $ ", ( . 3" ( < NO OP/ . = 3" ( 2 # 3 ( 3 8 # < ,+ , *") = ( 1 # ( < =
  26. 26. # 2 33 3 $ 4 " # % $ , >## ) ; $ " 3 4 $ ) " " # % "8 # $ # ( < # ( &= * (# (C ; # 1 # ( < # &= $ % ") >## # ( . , ( < #X = G # , *") *" 1,8 V " , 3 # # NO1 ( < = $ 2
  27. 27. " A ( >J, , ) & 6 4 / # # 35 +," A ( >J, , 1 ; 3 = & % "U ( ) >### " # # . " 6 7 1 ! 3 ( ",1L * ,K, 3 ND"H" ,D "V ,K, " D 1 ! 3 ( ND"H" ,D "V ,K, ) ( 3 # " M 5
  28. 28. . / ! " # # !; . " B; ! 1 4 $ ( * * 1 # ; #4 > #EE4 * *) $ $ # ( ( ! ( J &H & #. #include<at89x52.h> //contém as definições do chip void main(){ //declara início do programa P2_0=1; //liga o pino P2.0 } //declara fim do programa1 2 ! * $
  29. 29. < 2 = # ( & () 5 - (1 ! 5 - )+ 1 # # ( Q 4 % . 6 . 7 $$ N:040000000200383290:01000B0032C2:0100130032BA:01001B0032B2:0100230032AA:01002B0032A2:100038007581CF120034E582600302002C7900E953:100048004400601B7A00900080780075A000E4935B:10005800F2A308B8000205A0D9F4DAF275A0FF7877:1000680000E84400600C7900900000E4F0A3D8FC9C:08007800D9FAF6D8FD02002CB4:0C002C0012003180FED28022758200227A:00000001FF ; * * $ $ *; C # # % % ) . #, >,54 4 # ( ( $ $ ( , $ $ $ # ) % .2 4 4
  30. 30. ; & &" 1 # ( " 1< ( "; = ( . F & $ $ $ $ % 2 $ 2 6 , 7 8-" ( #X 3 $ * #* ! ! >## # $ ( 1. $ - 9 , 7 8-/ 1 ( " . while = 1; int = 200;
  31. 31. " # ( ( . TCON Timer/counter control SCON Serial port control IE Interrupt Enable IP Interrupt priority control PSW Program status word ACC Accumulador B B SP Stack pointer DPL Data pointer Low Word DPH Data pointer High Word PCON Power control TMOD Timer/counter mode control TL0 Timer/counter 0 low Byte TL1 Timer/counter 1 low Byte TH0 Timer/counter 0 high Byte TH1 Timer/counter 1 high Byte SBUF Serial data port P0 Port P0 P1 Port P1 P2 Port P2 P3 Port P3 # - 9" . int B = 10; int SBUF = 3;;( M/J M/J;;) ? ( @ ] ) >### . %
  32. 32. ) % A^ < $ ! = ^A < $ = . /* TUDO OQUE ESTIVER ENTRE OS MARCADORES DE COMENTÁRIO É IGNORADO PELO COMPILADOR */) AA < = # . #include<at89x52.h> //contém as definições do chip void main(){ //declara início do programa P2_0=1; //liga o pino P2.0 } //declara fim do programa; )% 4G % M < = # ! " . ( @ :E @ 6 C M 5 6 2 C 52 M 525 2 2 , C ,5, 2, M ,5, 2, , , , 25 / , R J 5 , ,$C R J, $M (; D
  33. 33. * ! (# !; ( $! , . const LIGADO=1; const DESLIGADO=0; const TEMPO_MAXIMO=100;" & ( !; 4 0 D; & ( " 2 ! # # ; ( $ ! , . #define MOTOR P2_0 #define LAMPADA P2_1 $ $ #4 G * ; H " * ++ 1$ &) ( G ! # % # ( ( ( &" H ( (, ( .
  34. 34. #include<at89x52.h> //contém as definições do chip #define LAMPADA P0_0 const LIGADO=1; void main(){ //declara início do programa P0=0; //desliga todos os pinos LAMPADA=LIGADO; //liga o pino P0.0 } //declara fim do programa, ( . #include<at89x52.h> //contém as definições do chip void main(){ //declara início do programa P0=0; //desliga todos os pinos P0_0=1; //liga o pino P0.0 } //declara fim do programa;< 0U # ( ( " 2 ( # ? @ # ( $ ! $ $ # * / ; 4 " % $ $ #;< $ 0" 2" 2 ] # 2 (* ( # < 1"VV = ,
  35. 35. J ( # #include<at89x52.h> //contém as definições do chip #include<delay.h> //contém as definições do chip void piscaLED(){ //declara início da função piscaLED P2_0=1; //liga o pino P2.0 delay_ms(1000); //aguarda 1 segundo P2_0=0; //desliga o pino P2.0 delay_ms(1000); //aguarda 1 segundo } //declara fim da função piscaLED void main(){ //declara início do programa piscaLED(); //chama a função pisca led } //declara fim do programaO # 2 (;< () %) # # ? @ 2 # ( 2 # ( ] " ( ( # ( ( ]8 -V 1 2 ( ( ( (;> () # < = 2 # # 1
  36. 36. ; ( # & ( 2 " 2 ( & ( & F $ < ( # # 1 # =G 1 # ) #G ! ( _ S _1S _1S. AT89C51 ou AT89S51 AT89C52 ou AT89S52 %; + < = > =->" ( ! < ( = ; ? @ ( + 3 $ & # ( ; ? ?1@ ( ( # ( ! * ?1@ ( ", ( ( ?1@ ? @ # # 2 ( 9 F " ?K@ # ? @ ! <?1@ ? @= , - - * : 1 $ * 4 - $ *; - + $ * * $ * 3 4 * - 1 $ - $ 2
  37. 37. Q 4 % ( 9 F %-- - Nsfr at 0x80 P0 sfr at 0x99 SBUFsfr at 0x81 SP sfr at 0xA0 P2sfr at 0x82 DPL sfr at 0xA8 IEsfr at 0x83 DPH sfr at 0xB0 P3sfr at 0x87 PCON sfr at 0xB8 IPsfr at 0x88 TCON sfr at 0xC8 T2CONsfr at 0x89 TMOD sfr at 0xC9 T2MODsfr at 0x8A TL0 sfr at 0xCC TL2sfr at 0x8B TL1 sfr at 0xCD TH2sfr at 0x8C TH0 sfr at 0xD0 PSWsfr at 0x8D TH1 sfr at 0xE0 ACCsfr at 0x90 P1 sfr at 0xE0 Asfr at 0x98 SCON sfr at 0xF0 B/* P0 */ /* P1 */sbit at 0x80 P0_0 sbit at 0x90 P1_0sbit at 0x81 P0_1 sbit at 0x91 P1_1sbit at 0x82 P0_2 sbit at 0x92 P1_2sbit at 0x83 P0_3 sbit at 0x93 P1_3sbit at 0x84 P0_4 sbit at 0x94 P1_4sbit at 0x85 P0_5 sbit at 0x95 P1_5sbit at 0x86 P0_6 sbit at 0x96 P1_6sbit at 0x87 P0_7 sbit at 0x97 P1_7/* TCON */ /* P2 */sbit at 0x88 IT0 sbit at 0xA0 P2_0sbit at 0x89 IE0 sbit at 0xA1 P2_1sbit at 0x8A IT1 sbit at 0xA2 P2_2sbit at 0x8B IE1 sbit at 0xA3 P2_3sbit at 0x8C TR0 sbit at 0xA4 P2_4sbit at 0x8D TF0 sbit at 0xA5 P2_5sbit at 0x8E TR1 sbit at 0xA6 P2_6sbit at 0x8F TF1 sbit at 0xA7 P2_7) # ( S F # & $ < DJS =) . < = *)DGsfr at 0x80 P0 Special function register at 0x80 P0 # ( & . 5
  38. 38. O & ( # ? @# ! (8 ] #include<microcontrolador.h> ( # # 1;> .* 1 .#include<nome do arquivo.h>" .#include<at89x52.h> ou#include<AT89X52.h> A 24 " * * ; H H 4 $ $ # $ H
  39. 39. . / $ )% (%" 1 ) ( <# 2 = )* # . " . D . V . 2 M . 2 (% C( ( 2 . ) ( ! ( + ( 8 ( D ( < = 8
  40. 40. ) ( # 2 ; 1 .int y=10;int z=5;int x=0; % %x=(y+z); & (int a=10;int b=5;int c=0; %c=(b-a);+ (int a=1;int b=20;int c=2; + %a=(b*c);8 (int a=0;int b=20;int c=2; 8 %a=(b/c);D ( < =int a=1;int b=25;int c=2; 8 %a=(b c); ( ,
  41. 41. int contagem=0;contagem++;8int contagem=10; 8contagem--; (%) 2 ( ( > ? > ? , ( % & ( ) 8 ( TT UT 8 V + # W + # VT + WT +G ( , 5 99 9 #include<at89x52.h> void main(){ unsigned char cont=0; while(1){ if(P3_0==1){ //se a entrada P3.0 receber nível alto if(cont<9) cont++;//e se a contagem for menor que 9, incrementa else cont=0; //se não, retorna a zero } } } ,
  42. 42. (% - 6" & 1 ) 8 ( U ) ( ;)G <;`)= X ) ( ";8 <,= * XX ) ( ";8 <,= * 4 4 $ Y ) ( )D <)/= YY ) ( )D <)/= 4 4 $ Z ) ( K)D <)/ =G < = (, .if((P3_0==1)|(P3_1==1)) C=1; . ! & )/ ! & ( 1int A=0;if((A>0)&&(A<10)) A++; . " # , " # ( "int A=0;int B=0;int C=0;if((A!=B)||(A!=C)) A--; . " M )/ " 1 ("" & ) &(, .bit x=0;bit y=1;int cont=0;if(x & y)cont++; ,
  43. 43. . & , (if(x | y)cont=cont+5; . & )/ (if(x & !y)cont--; . & , ( ( ; ( (% 3()) <;)G$ = ( ( ! _ Sabit x=0;if(P3_0==1)x=~x; . <M ! = ( # <bit x=0=if(P3_0==0)x=~x; . < H= ( #) .if(P3_0) x=~x; . ( #if(!P3_0)x=~x; . ( ( # x bit x=1 x=~x; #x # ,
  44. 44. . / ! "< )% $" ( # # 2 (" 1 % 2 2< $ 7 :" <_ S = ( & .if(condição) comando;if(condição){ comando 1; comando 2; comando n; }, 1 # # % ) # # ( 1 & # ,,
  45. 45. # > ? U # # * %; ( * % ( ( (, . #include<at89x52.h> //contém as definições do chip void main(){ //declara início do programa int contagem=0; //declara variável e inicializa em 0 if(P3_0) contagem++; //se P3.0 receber nível alto, //incrementa contagem em 1 } //declara fim do programa; < *% = *: 5 W H $ EEH ( $ EE < ! & = #include<at89x52.h> //contém as definições do chip void main(){ //declara início do programa int contagem=10; //declara variável e inicializa em 10 if(P3_0==1) contador++; //se entrada P3.0 estiver em 1 //decrementa uma unidade, } //fim do programa" # ( ( 1 ( H .int i=10; ,
  46. 46. int j=5;if(i==1)j++;if(i!=10)i=5;if(i==j)i--;< (9 & " . %) ( 1 <b= <bb= * <bb= , .int a=10;if(a==10)a++;H ( , , .if(a=10)a++; ( <b= ( .if(a=10)a++; a=10 ( )# # . if(10)a++; < * % = ( ( a< $" ## < ( = < =int i=10;int j=5;if(i==10)j++; //se i for igual a 10, incrementa jelse j--; //senão, decrementa j", . ,2
  47. 47. if(P3_0==1){ //se a entrada P3.0 receber +5V, P0_0=1; // Ativa saída P0.0 P0_1=1; // Ativa saída P0.1 }else{ // senão, se entrada P3.0 receber 0V P0_0=0; // desliga saída P0.0 (0 Volt) P0_1=0; // desliga saída P1.0 (0 Volt)}1% , .if(P3_5==1)P0=15; //se P3_6 receber +5V, ativa P0.0 a P0.3if(P3_6==1)P0=240; //se P3_5 receber +5V, ativa P0.4 a P0.7else P0=0;; # ( $ # 2 G () ( .if(i==1)P0_0=1; P0_1=1;else P0=0;; ( # ( P0_0=1if(i==1) * ( D T (1 . if(i==1){ P0_0=1; P0_1=1; ; $ 0 } else P0=0; ,5
  48. 48. <; $, % < $= * .if(condição 1){ commandos; } else if(condição 2){ commandos; } else if(condição 3){ commandos; }}" 2 & " # ( # # ( ( ( H .if(P3_0==1) P2=1; //se o pino P3.0 tiver nível 1if(P3_1==1) P2=2; //se o pino P3.1 tiver nível 1if(P3_2==1) P2=4; //se o pino P3.2 tiver nível 1if(P3_3==1) P2=8; //se o pino P3.3 tiver nível 1if(P3_4==1) P2=16; //se o pino P3.4 tiver nível 1; if(P3_0==1) * ! 7 ; 2"if(P3_0==1) P2=0;else if(P3_1==1) P2=1;else if(P3_2==1) P2=2;else if(P3_3==1) P2=4;else if(P3_4==1) P2=8;; O # & ( & * ## ,
  49. 49. < $" 3 ( 8 2 ( 2 ( * 2 2 ) 2 ( < 2 = # " # 2J 3 .switch(variável){ case constante 1: commando 1; commando 2; break; case constante 2: commando 3; break; case constante n: commando 4; break; default: commando 5; break;}, 2 .contador=2;switch(contador){ case 0: x++; P2_0=1; break; case 1: P2_1=1; break; case 2: P2_2=1; break; default: P2_3=1; break;}* 2 # , < ( ( = # # 2 ,
  50. 50. << $ %<< )% %" < 2 = ( 2 " 1 ( . 2 *<< () # 2 ( " ( 1 ( " # < 2 =H .for(inicialização;condição;incremento){ comandos que devem ser repetidos;}H .for(i=0;i<10;i++){ P2_0=1; //liga P2_0 delay_ms(1000); //aguarda 1 segundo P2_0=0; //desliga P2_0 delay_ms(1000); //aguarda 1 segundo}; i ( <T = ( " & ( ( < WW= ( " ( #
  51. 51. ( ; < =" ! H .#include <at89x52.h>#include <delay.h>void main(){ int i=0; for(i=10;i>0;i--){ P2_0=1; //liga P2_0 delay_ms(1000); //aguarda 1 segundo P2_0=0; ; //desliga P2_0 delay_ms(1000); //aguarda 1 segundo }c # ( V,8 , ( 2 . 6 % $)$( * - ?3%< ( 7= 9 :)1 F # 2 U #
  52. 52. & & * 2 # F H .#include <at89x52.h>#include <delay.h>void main(){ int i=0; for(i=0;i<10;i++){ if(P3_0==1) break;//se o pino P3.0 receber nível 1 ;//se P2_0=1; //liga P2_0 delay_ms(1000); //aguarda 1 segundo P2_0=0; ; //desliga P2_0 delay_ms(1000); //aguarda 1 segundo }c; <# = * ! < = *#" 3 . ( ( [@ 1I * 6 @
  53. 53. < ( 7 :" F # ( # ( (H . #include <at89x52.h> #include <delay.h> void main(){ int i=0; for(i=0;i<10;i++){ P2_0=1; //liga P2.0 delay_ms(1000); //aguarda 1 segundo if(P3_0==1) continue; //se P3.0 receber nivel alto P2_0=0; //desliga P2.0 delay_ms(1000); //aguarda 1 segundo } c; % D T ED > ?P ( ( !<< (" 2 ( 1 2 ( " ( P 2 & 2" 2 .while(condição){ commandos;}" * ( , .while(x<50){ //enquanto x for menor do que 50 x++; //incrementa uma unidade de x} //fim do comando while, #
  54. 54. ) ( #X 1 ; 2 * * +% , .bit a=1;while(a){ //enquanto a for diferente de zero x++; //incrementa uma unidade de x} //fim do comando while; 2 _ S 1 2<< $ % " .* ( 2 .while(1){ //enquanto 1 for verdadeiro(diferente de zero) x++; //incrementa uma unidade de x} //fim do comando while, ( 2 . #include <at89x52.h> #include <delay.h> void main(){ while(1){ P2_0=1; //liga P2.0 delay_ms(1000); //aguarda 1 segundo P2_0=0; //desliga P2.0 delay_ms(1000); //aguarda 1 segundo } c ,
  55. 55. . / " %> ( # . * G 2 *,>) ! - ( " !& < = V,8) ! ! < A)= # ( # .
  56. 56. Port P1> <Port P0 <Port P2 Port P3> 0 6H # !/V" </ V& " = 2 4; 2 J J # ( 2 D"+ # < A)S =U # % !" ! . , ,* ( ! < A)S = O* # ( ! ( ! < = * 2
  57. 57. ! ! * T EQ ( WH11 , ! < ! = 2 # M ! , ,O ( ! < A)S = 8 ( T * # # ,K & * * # ( * ( , ,* ( ! < A)S = ( 2 ! , ,* 2 ( ( 2 < ( = * < A)= G ( . .8J (.8J -;( J &" . -;( J &" . , ( J ( J 2 5J ( &" . #include<at89x52.h> //contém as definições do chip void main(){ //declara início do programa P2=255; //liga todos os pinos(nível 1) do Port P2 } //declara fim do programa 5
  58. 58. ) T # * * # * ! &*" & . #include<at89x52.h> //contém as definições do chip Int valor=09; int valor=0; void main(){ //declara início do programa valor=P2; //guarda na variável o valor lido no port } //declara fim do programa) % T # * **> $/ &H # # V,8 ;*; )" # . 3 $ D %% 5 -4 $ 6 3 4 - ) 3 + $"5 1 % 4 . - " 1 3435 0
  59. 59. D ( .#include <at89x52.h>#include <delay.h>void main(){ while(1){ P2_0=1; //liga P2.0 delay_ms(500); //aguarda 500 milisegundos P2_0=0; //desliga P2.0 delay_ms(500); //aguarda 500 milisegundos }cH ! .* V,8 ! & $ ! &* V,8 < # = < # # (/ ( 2 !" ( D T !& > ? V,8" ( ED > ? #" ( D T !& > ? V,8* *V,8S R < & = * # 2; 1 # ( & ( 2 # ( $
  60. 60. " # A)S < = ( . J J J * 4 & 43 ) 4 -; $ $ #1 * 2 4 -" . D D D D D D D D D D D D " D, D $ D, D 3 D, D 0 D, D D2 D2 D2 D2 D5 D5 D5 D51 * ! & . < = !* .P2_7=0; //coloca o pino 28 em nível 0 (0V)P2_7=1; //coloca o pino 28 em nível 1 (+5V) ; . , ! &" * ! % < MR =* .P2=0; //coloca todo Port P2 em nível 0 (0V)P2=255; //coloca todo Port P2 em nível 1 (+5V)H ( MR 1 * MR <4 = " . bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 D5 D2 D D, D D D DValor em decimal 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 =255 2
  61. 61. C66 # * *C ! & < =; # ( & ! & , ( *H * . % D5 D2 D D, D D D D 2, 2 , T T T T, T T 2 T T2, T T T2 T T 0 ( 6 6 AB ; , ! & 2
  62. 62. . / # $ & )% . %") ( . )(J -;( J &" . -;( J &" . , ( J ( J .8J (.8J" ( # # , # ( # ( # " & ( #* 2 2 < JDS = # () 1 - 2 # < # ( ? H 2
  63. 63. % ( . 6# , ./* IE */sbit at 0xA8 EX0 ; apelida o bit na posição 0xA8 como EX0sbit at 0xA9 ET0 ; apelida o bit na posição 0xA9 como ET0sbit at 0xAA EX1 ; apelida o bit na posição 0xAA como EX1sbit at 0xAB ET1 ; apelida o bit na posição 0xAB como ET1sbit at 0xAC ES ; apelida o bit na posição 0xAC como ESsbit at 0xAD ET2 ; apelida o bit na posição 0xAD como ET2sbit at 0xAF EA ; apelida o bit na posição 0xAF como EA; 1 2 2 .EA=1; //habilita a chave geral das interrupçõesEA=0; //desabilita todas as interrupções, ( ? @ 2 U 2+ 2 2 #; 2 ! , . Registrador IE ; * J ( ( ( EX0 External interrupt 0 TR0 Timer 0 interrupt 1 EX1 External interrupt 2 TR1 Timer 1 interrupt 3 RI Serial data received interrupt Serial data transmit interrupt interrupt 4 TI TR2 Timer 2 interrupt 5 EA Chave geral das interrupções 2

×