Advertisement
Electgpl

PIC - Reloj despertador con RTC

Jun 19th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.15 KB | None | 0 0
  1. #include <16F883.h>
  2. #device adc=8
  3. #FUSES NOWDT
  4. #FUSES INTRC_IO
  5. #FUSES NOPUT
  6. #FUSES MCLR
  7. #FUSES NOBROWNOUT
  8. #FUSES NOLVP
  9. #FUSES NOCPD
  10. #FUSES NOWRT
  11. #FUSES NODEBUG
  12. #FUSES NOPROTECT
  13. #use delay(int=4000000)
  14. #define RTC_RST    PIN_A0
  15. #define RTC_SCLK   PIN_A1
  16. #define RTC_IO     PIN_A2
  17. #include <DS1302.C>
  18. #include <LCD.C>
  19. void main()
  20. {
  21. int HH, MIN, SS;
  22. int HHSet, MMset;
  23. int HHAlarm, MMAlarm;
  24. int i;
  25.    lcd_init();
  26.    lcd_putc("Electgpl Clock");
  27.    delay_ms(1000);
  28.    rtc_init();
  29.    lcd_init();
  30.    while(1)
  31.    {
  32.    if (input(PIN_A5)==1)
  33.       {
  34.       if (input(PIN_A4)==1)
  35.          {
  36.          lcd_gotoxy(15,1);
  37.          lcd_putc("ST");
  38.          rtc_set_datetime(0,0,0,0,HHSet,MMSet);
  39.          MMSet = MMSet + 1;
  40.          if (MMSet > 59)
  41.             {
  42.             delay_ms(100);
  43.             MMSet = 0;
  44.             HHSet = HHSet + 1;
  45.             }  
  46.             if (HHSet > 23)
  47.                {
  48.                HHSet = 0;
  49.                }
  50.          lcd_gotoxy(1,1);
  51.          printf(lcd_putc,"HORA %02d:%02d:00   ",HHSet,MMSet);              
  52.          }
  53.       else
  54.          {
  55.          if (input(PIN_A3)==1)
  56.             {
  57.             lcd_gotoxy(15,1);
  58.             lcd_putc("AL");
  59.             MMAlarm = MMAlarm + 1;
  60.             if (MMAlarm > 59)
  61.                {
  62.                delay_ms(100);
  63.                MMAlarm = 0;
  64.                HHAlarm = HHAlarm + 1;
  65.                }  
  66.                if (HHAlarm > 23)
  67.                   {
  68.                   HHAlarm = 0;
  69.                   }
  70.             lcd_gotoxy(1,1);
  71.             printf(lcd_putc,"HORA %02d:%02d:00   ",HHAlarm,MMAlarm);    
  72.             write_eeprom(8,HHAlarm);
  73.             write_eeprom(9,MMAlarm);
  74.             }
  75.          }
  76.       }  
  77.    else    
  78.       {
  79.       rtc_get_time(HH,MIN,SS);
  80.       lcd_gotoxy(1,1);
  81.       printf(lcd_putc,"HORA %02d:%02d:%02d   ",HH,MIN,SS);
  82.       HHAlarm=read_eeprom(8);
  83.       MMAlarm=read_eeprom(9);
  84.       lcd_gotoxy(1,2);
  85.       printf(lcd_putc,"ALARMA  %02d:%02d   ",HHAlarm,MMAlarm);
  86.       if((HH == HHAlarm) && (MIN == MMAlarm))
  87.          output_high(pin_a6);
  88.       else
  89.          output_low(pin_a6);      
  90.       }
  91.    }  
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement