Advertisement
paulogp

ATmega128: T1A - Switchs e LEDs

Jul 13th, 2011
391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Pretende-se controlar o estados leds D1...D8 utilizando para isso os interruptores SW. O estados dos leds deve obedecer à seguinte tabela:
  2.  
  3. ; Interruptor Activo | Leds Ligados
  4. ; SW1 | D1, D8
  5. ; SW2 | D2, D7
  6. ; SW3 | D3, D6
  7. ; SW4 | D4, D5
  8. ; SW6 | LEDs desligados
  9.  
  10. .include<m128def.inc>
  11.  
  12. .cseg
  13. .org 0
  14.  
  15. jmp main
  16.  
  17. main:
  18.         ; saida
  19.         ser r16
  20.         out DDRA, r16
  21.  
  22.         ser r16
  23.         out PORTA,r16
  24.  
  25.         ; entrada
  26.         clr r16
  27.         out DDRE, r16
  28.  
  29.         clr r16
  30.         out PORTE,r16
  31.  
  32. test:
  33.         in r17,PINE
  34.  
  35.         mov r16, r17
  36.         andi r16, 0x01; 0b00000001
  37.         breq sw10
  38.  
  39.         mov r16, r17
  40.         andi r16, 0x02; 0b00000010
  41.         breq sw20
  42.  
  43.         mov r16, r17
  44.         andi r16, 0x04; 0b00000100
  45.         breq sw30
  46.  
  47.         mov r16, r17
  48.         andi r16, 0x08; 0b00001000
  49.         breq sw40
  50.  
  51.         mov r16, r17
  52.         andi r16, 0x10; 0b00010000
  53.         breq sw50
  54.  
  55.         mov r16, r17
  56.         andi r16, 0x20; 0b00100000
  57.         breq sw60
  58.         jmp test
  59.  
  60. sw10:  
  61.         ldi r16, 0x7E; 0b01111110
  62.         out PORTA, r16
  63.         jmp test
  64.  
  65. sw20:  
  66.         ldi r16, 0xBD; 0b10111101
  67.         out PORTA, r16
  68.         jmp test
  69.  
  70. sw30:  
  71.         ldi r16, 0xDB; 0b11011011
  72.         out PORTA, r16
  73.         jmp test
  74.  
  75. sw40:  
  76.         ldi r16, 0xE7; 0b11100111
  77.         out PORTA, r16
  78.         jmp test
  79.  
  80. sw50:  
  81.         ldi r16, 0x42; 0b01000010
  82.         out PORTA, r16
  83.         jmp test
  84.  
  85. sw60:  
  86.         ldi r16, 0xFF; 0b11111111
  87.         out PORTA, r16
  88.         jmp test
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement