Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. /*
  2. * GccApplication4.c
  3. *
  4. * Created: 3/19/2019 4:12:32 PM
  5. * Author : dspuser
  6. */
  7.  
  8.  
  9. #define F_CPU 14745600UL
  10. #include <avr/io.h>
  11. #include <avr/interrupt.h>
  12. #include <util/delay.h>
  13.  
  14. void led_toggle(int bit){
  15.  
  16. PORTB &= ~(1<<1);//stingem toate LED-urile 1->4
  17. PORTB &= ~(1<<2);
  18. PORTB &= ~(1<<3);
  19. PORTB &= ~(1<<4);
  20. PORTB |= 1<<bit;//aprind LED(bit);
  21. }
  22. int main(void)
  23. {
  24. /* Replace with your application code */
  25.  
  26. DDRB&=~((1<<5)|(1<<6)); //Pb5 & PB6 as input
  27. DDRB|=(1<<1)|(1<<2)|(1<<3)|(1<<4);//il setam pe output pe PB1 ca sa aprinda ledul
  28. unsigned int ok=0;
  29. unsigned int invers=5;
  30. while (1)
  31. {
  32. if((PINB&(1<<5))==0){
  33. _delay_ms(100);
  34. if((PINB&(1<<5))==0){//BUTONUL E PE PB2 si e aprins SI LED1 e aprins
  35. if(ok<5){
  36. while((PINB&(1<<5))==0);//BUTONUL E PE PB5 si e aprins
  37. led_toggle(ok++);
  38. _delay_ms(50);
  39. }
  40. if(ok>=5){
  41. ok=0;
  42. }
  43. }
  44.  
  45. }
  46.  
  47. if((PINB&(1<<6))==0){
  48. _delay_ms(50);
  49. if((PINB&(1<<6))==0){//BUTONUL E PE PB2 si e aprins SI LED1 e aprins
  50. if(invers<=5){
  51. while((PINB&(1<<6))==0);//BUTONUL E PE PB2 si e aprins
  52. led_toggle(invers--);
  53. _delay_ms(50);
  54. }
  55. if(invers==0){
  56. invers=5;
  57. }
  58. }
  59. }
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement