Advertisement
Guest User

Untitled

a guest
May 17th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.90 KB | None | 0 0
  1. #define __AVR_ATmega644P__
  2. #include <avr/io.h>
  3.  
  4.  
  5.  
  6. uint8_t getPortA4() {
  7.     return (PINA & 0b00010000) >> 4;
  8. }
  9.  
  10. uint8_t getPortB54() {
  11.     return (PINB & 0b00110000) >> 4;
  12. }
  13.  
  14. void init() {
  15.     //DDR -> Data Direction Register
  16.     DDRA = 0b11110111;
  17.     DDRB = 0b11110011;
  18.     DDRC = 0b11111111;
  19.     DDRD = 0b00000000;
  20. }
  21.  
  22. int main(void) {
  23.     init();
  24.  
  25.     while(1) {
  26.         if(getPortA4() == 0) {
  27.             if(getPortB54() == 0b00) {
  28.                 PORTC = 0x00;
  29.             } else if(getPortB54() == 0b01) {
  30.                 PORTC = PIND;
  31.             } else if(getPortB54() == 0b10) {
  32.                 // 0101 0001
  33.                 uint8_t links = PIND << 4; //  0001 0000
  34.                 uint8_t rechts = PIND >> 4; // 0000 0101
  35.                 PORTC = links | rechts;
  36.             } else if(getPortB54() == 0b11) {
  37.                 PORTC = 0xFF;
  38.             }
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement