Advertisement
dzieciol

Mikro zajecia 3

Oct 27th, 2017
416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.96 KB | None | 0 0
  1. #include<avr/io.h>
  2. #include<avr/delay.h>
  3.  
  4. int main(void){
  5.     DDRA = 0xF0;
  6.     DDRB = 0xFF;
  7. char x;
  8.        
  9.     while(1){
  10.     PORTA = 0xFF;
  11.     for (int i= 4 ; i<8 ; i++){
  12.         PORTA = ~(_BV(i));
  13.         _delay_ms(1);
  14.         x = PINA & 0x0F;
  15.        
  16.         if(i==4){
  17.             if(x == 0b00001110)PORTB = 0x00; //0
  18.             if(x == 0b00001101)PORTB = 0x20; //4
  19.             if(x == 0b00001011)PORTB = 0x10; //8
  20.             if(x == 0b00000111)PORTB = 0x30; //12
  21.         }
  22.         if(i==5){
  23.             if(x == 0b00001110)PORTB = 0x80; //1
  24.             if(x == 0b00001101)PORTB = 0xA0; //5
  25.             if(x == 0b00001011)PORTB = 0x90; //9
  26.             if(x == 0b00000111)PORTB = 0xB0; //13
  27.         }
  28.         if(i==6){
  29.             if(x == 0b00001110)PORTB = 0x40; //2
  30.             if(x == 0b00001101)PORTB = 0x60; //6
  31.             if(x == 0b00001011)PORTB = 0x50; //10
  32.             if(x == 0b00000111)PORTB = 0x70; //14
  33.         }
  34.         if(i==7){
  35.             if(x == 0b00001110)PORTB = 0xC0; //3
  36.             if(x == 0b00001101)PORTB = 0xE0; //7
  37.             if(x == 0b00001011)PORTB = 0xD0; //11
  38.             if(x == 0b00000111)PORTB = 0xf0; //15
  39.         }
  40.        
  41.     }
  42.        
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement