Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * GccApplication4.c
- *
- * Created: 3/19/2019 4:12:32 PM
- * Author : dspuser
- */
- #define F_CPU 14745600UL
- #include <avr/io.h>
- #include <avr/interrupt.h>
- #include <util/delay.h>
- void led_toggle(int bit){
- PORTB &= ~(1<<1);//stingem toate LED-urile 1->4
- PORTB &= ~(1<<2);
- PORTB &= ~(1<<3);
- PORTB &= ~(1<<4);
- PORTB |= 1<<bit;//aprind LED(bit);
- }
- int main(void)
- {
- /* Replace with your application code */
- DDRB&=~((1<<5)|(1<<6)); //Pb5 & PB6 as input
- DDRB|=(1<<1)|(1<<2)|(1<<3)|(1<<4);//il setam pe output pe PB1 ca sa aprinda ledul
- unsigned int ok=0;
- unsigned int invers=5;
- while (1)
- {
- if((PINB&(1<<5))==0){
- _delay_ms(100);
- if((PINB&(1<<5))==0){//BUTONUL E PE PB2 si e aprins SI LED1 e aprins
- if(ok<5){
- while((PINB&(1<<5))==0);//BUTONUL E PE PB5 si e aprins
- led_toggle(ok++);
- _delay_ms(50);
- }
- if(ok>=5){
- ok=0;
- }
- }
- }
- if((PINB&(1<<6))==0){
- _delay_ms(50);
- if((PINB&(1<<6))==0){//BUTONUL E PE PB2 si e aprins SI LED1 e aprins
- if(invers<=5){
- while((PINB&(1<<6))==0);//BUTONUL E PE PB2 si e aprins
- led_toggle(invers--);
- _delay_ms(50);
- }
- if(invers==0){
- invers=5;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement