Advertisement
bart_moran

Untitled

May 18th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.85 KB | None | 0 0
  1. #define F_CPU 8000000
  2. #include <avr/io.h>
  3. #include "util/delay.h"
  4.  
  5. int main(void)
  6. {
  7.     DDRA = 0xff;
  8.     UCSRB = (1<<TXEN)|(1<<RXEN);
  9.     UCSRC = (1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0);
  10.     UBRRH = 0;
  11.     UBRRL = 25;
  12.     char p;
  13.    
  14.     int count1=1;
  15.     int count2=1;
  16.     int count3=1;
  17.     int count4=1;
  18.     int count5=1;
  19.     int temp=0b00000000;
  20.    
  21.     int c1=0b00000001;
  22.     int c2=0b00000010;
  23.     int c3=0b00000100;
  24.     int c4=0b00001000;
  25.     int c5=0b00010000;
  26.    
  27.     while (1)
  28.     {
  29.         get_byte();
  30.         p=UDR;
  31.        
  32.     if (p == '0')
  33.     {  
  34.          count1=1;
  35.          count2=1;
  36.          count3=1;
  37.          count4=1;
  38.          count5=1;
  39.         temp=temp=0b00000000;
  40.         PORTA=temp;
  41.         }      
  42.        
  43.        
  44.     if (p == '9')
  45.     {
  46.        
  47.         temp=temp<<1;
  48.         if (PINA&(1<<4)){temp=temp+c1;}
  49.         PORTA=temp;
  50.        
  51.     }
  52.    
  53.    
  54.    
  55.          if(p == '1')
  56.         {
  57.             if (count1==1)
  58.             {
  59.                 temp=temp+c1;
  60.                 count1=2;
  61.                 PORTA=temp;
  62.             }
  63.        
  64.            
  65.             else if (count1==2)
  66.             {
  67.                 temp=temp-c1;
  68.                 count1=1;
  69.                 PORTA=temp;
  70.             }
  71.         }    
  72.        
  73.        
  74.         if(p == '2')
  75.         {
  76.             if (count2==1)
  77.             {
  78.                 temp=temp+c2;
  79.                 count2=2;
  80.                 PORTA=temp;
  81.             }
  82.            
  83.            
  84.             else if (count2==2)
  85.             {
  86.                 temp=temp-c2;
  87.                 count2=1;
  88.                 PORTA=temp;
  89.             }
  90.         }
  91.        
  92.        
  93.        
  94.         if(p == '3')
  95.         {
  96.             if (count3==1)
  97.             {
  98.                 temp=temp+c3;
  99.                 count3=2;
  100.                 PORTA=temp;
  101.             }
  102.            
  103.            
  104.             else if (count3==2)
  105.             {
  106.                 temp=temp-c3;
  107.                 count3=1;
  108.                 PORTA=temp;
  109.             }
  110.         }
  111.        
  112.        
  113.        
  114.         if(p == '4')
  115.         {
  116.             if (count4==1)
  117.             {
  118.                 temp=temp+c4;
  119.                 count4=2;
  120.                 PORTA=temp;
  121.             }
  122.            
  123.            
  124.             else if (count4==2)
  125.             {
  126.                 temp=temp-c4;
  127.                 count4=1;
  128.                 PORTA=temp;
  129.             }
  130.         }
  131.        
  132.        
  133.        
  134.         if(p == '5')
  135.         {
  136.             if (count5==1)
  137.             {
  138.                 temp=temp+c5;
  139.                 count5=2;
  140.                 PORTA=temp;
  141.             }
  142.            
  143.            
  144.             else if (count5==2)
  145.             {
  146.                 temp=temp-c5;
  147.                 count5=1;
  148.                 PORTA=temp;
  149.             }
  150.         }
  151.          
  152.  
  153.     }
  154. }
  155.  
  156.  
  157. int get_byte(void)
  158. {
  159.     while(!(UCSRA&(1<<RXC)))
  160.     {}
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement