Advertisement
paulogp

ATmega128: T1A - Switchs e LEDs

Jul 13th, 2011
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.01 KB | None | 0 0
  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 "C:\Program Files\WinAVR-20080610\avr\include\avr\io.h"
  11.  
  12.  
  13. int main(void) {
  14.     /* inicializacao das variaveis */
  15.     unsigned char sw1;
  16.  
  17.     /* PORTA entrada */
  18.     DDRA = 0x00;
  19.     PORTA = 0x00;
  20.  
  21.     /* PORTC saida */
  22.     DDRC = 0xFF;
  23.     PORTC = 0xFF;
  24.  
  25.     /* rotina */
  26.     while(1) {
  27.         sw1 = PINA;
  28.  
  29.         switch(sw1) {
  30.             case 0xFE: PORTC = 0x7E;break; // sw1: 0b11111110 | 0b01111110
  31.             case 0xFD: PORTC = 0xBD;break; // sw2: 0b11111101 | 0b10111101
  32.             case 0xFB: PORTC = 0xDB;break; // sw3: 0b11111011 | 0b11011011
  33.             case 0xF7: PORTC = 0xE7;break; // sw4: 0b11110111 | 0b11100111
  34.             case 0xDF: PORTC = 0xFF;break; // sw6: 0b11011111 | 0b11111111: reset
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement