Advertisement
zujankaaa

Untitled

Mar 25th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. /*
  2. 1. Spojit 7seg, znamenke na PORTB, segmente na PORTD
  3. 2. Key1 datum, Key2 godina
  4. */
  5. #define F_CPU 7372800UL
  6.  
  7. #include <avr/io.h>
  8. #include <util/delay.h>
  9.  
  10. int main(void)
  11. {
  12. DDRD = 0xff;
  13. PORTD = 0x00;
  14.  
  15. DDRB = 0xf0;
  16. PORTB = 0x0f;
  17.  
  18. uint8_t date[] = {0x5b, 0x5b, 0x3f, 0x4f};
  19. uint8_t year[] = {0x5b, 0x3f, 0x06, 0x07};
  20. uint8_t i, state = 0;
  21.  
  22. while (1)
  23. {
  24. if(bit_is_clear(PINB, 0)){
  25. state = 1;
  26. PORTD = 0x00;
  27. PORTB = 0x03;
  28. }else if(bit_is_clear(PINB, 1)){
  29. state = 2;
  30. PORTD = 0x00;
  31. PORTB = 0x03;
  32. }
  33.  
  34. if(state == 1){
  35. for(i = 0; i < 4; i++){
  36. PORTD = date[i];
  37. PORTB = _BV(4 + i);
  38. _delay_us(1000);
  39. }
  40. } else if(state == 2){
  41. for(i = 0; i < 4; i++){
  42. PORTD = year[i];
  43. PORTB = _BV(4 + i);
  44. _delay_us(1000);
  45. }
  46. }
  47. _delay_us(10); // za debounce
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement