Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define F_CPU 8000000
- #include <avr/io.h>
- #include "util/delay.h"
- int main(void)
- {
- DDRA = 0xff;
- UCSRB = (1<<TXEN)|(1<<RXEN);
- UCSRC = (1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0);
- UBRRH = 0;
- UBRRL = 25;
- char p;
- int count1=1;
- int count2=1;
- int count3=1;
- int count4=1;
- int count5=1;
- int temp=0b00000000;
- int c1=0b00000001;
- int c2=0b00000010;
- int c3=0b00000100;
- int c4=0b00001000;
- int c5=0b00010000;
- while (1)
- {
- get_byte();
- p=UDR;
- if (p == '0')
- {
- count1=1;
- count2=1;
- count3=1;
- count4=1;
- count5=1;
- temp=temp=0b00000000;
- PORTA=temp;
- }
- if (p == '9')
- {
- temp=temp<<1;
- if (PINA&(1<<4)){temp=temp+c1;}
- PORTA=temp;
- }
- if(p == '1')
- {
- if (count1==1)
- {
- temp=temp+c1;
- count1=2;
- PORTA=temp;
- }
- else if (count1==2)
- {
- temp=temp-c1;
- count1=1;
- PORTA=temp;
- }
- }
- if(p == '2')
- {
- if (count2==1)
- {
- temp=temp+c2;
- count2=2;
- PORTA=temp;
- }
- else if (count2==2)
- {
- temp=temp-c2;
- count2=1;
- PORTA=temp;
- }
- }
- if(p == '3')
- {
- if (count3==1)
- {
- temp=temp+c3;
- count3=2;
- PORTA=temp;
- }
- else if (count3==2)
- {
- temp=temp-c3;
- count3=1;
- PORTA=temp;
- }
- }
- if(p == '4')
- {
- if (count4==1)
- {
- temp=temp+c4;
- count4=2;
- PORTA=temp;
- }
- else if (count4==2)
- {
- temp=temp-c4;
- count4=1;
- PORTA=temp;
- }
- }
- if(p == '5')
- {
- if (count5==1)
- {
- temp=temp+c5;
- count5=2;
- PORTA=temp;
- }
- else if (count5==2)
- {
- temp=temp-c5;
- count5=1;
- PORTA=temp;
- }
- }
- }
- }
- int get_byte(void)
- {
- while(!(UCSRA&(1<<RXC)))
- {}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement