Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Pretende-se controlar o estados leds D1...D8 utilizando para isso os interruptores SW. O estados dos leds deve obedecer à seguinte tabela:
- Interruptor Activo | Leds Ligados
- SW1 | D1, D8
- SW2 | D2, D7
- SW3 | D3, D6
- SW4 | D4, D5
- SW6 | LEDs desligados */
- #include "C:\Program Files\WinAVR-20080610\avr\include\avr\io.h"
- int main(void) {
- /* inicializacao das variaveis */
- unsigned char sw1;
- /* PORTA entrada */
- DDRA = 0x00;
- PORTA = 0x00;
- /* PORTC saida */
- DDRC = 0xFF;
- PORTC = 0xFF;
- /* rotina */
- while(1) {
- sw1 = PINA;
- switch(sw1) {
- case 0xFE: PORTC = 0x7E;break; // sw1: 0b11111110 | 0b01111110
- case 0xFD: PORTC = 0xBD;break; // sw2: 0b11111101 | 0b10111101
- case 0xFB: PORTC = 0xDB;break; // sw3: 0b11111011 | 0b11011011
- case 0xF7: PORTC = 0xE7;break; // sw4: 0b11110111 | 0b11100111
- case 0xDF: PORTC = 0xFF;break; // sw6: 0b11011111 | 0b11111111: reset
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement