Advertisement
chayanforyou

PIC timer1

Jul 13th, 2021
675
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.97 KB | None | 0 0
  1. // PIC12F675
  2. // 1Hz Time Base Osc.
  3. // Timer1 Module
  4. // 32.768 KHz
  5. unsigned short tick;
  6.  
  7. void interrupt ()
  8. {
  9.         if (PIR1.TMR1IF)
  10.         {
  11.                 TMR1H = 0xE0;
  12.                 PIR1.TMR1IF = 0;
  13.                 tick = 1;
  14.         }
  15. }
  16.  
  17. void Init ()
  18. {
  19.         TRISIO = 0;
  20.         //Make all pins as output ports
  21.         GPIO = 0;
  22.         //Use Timer1 module
  23.         INTCON.GIE = 1;
  24.         INTCON.PEIE = 1;
  25.         T1CON = 0x01;
  26.         //Overflow every 8192
  27.         TMR1H = 0xE0;
  28.         TMR1L = 0x00;
  29.         //  Enable TMR1 interrupt
  30.         PIE1.TMR1IE = 1;
  31. }
  32.  
  33. void main ()
  34. {
  35.         tick = 0;
  36.         //Initialize Ports and Timer1 Module
  37.         Init ();
  38.         while (1)
  39.         {
  40.                 if (tick)
  41.                 {
  42.                         tick = 0;
  43.                         GPIO = (1 << 0);
  44.                 }
  45.                 if (TMR1H > 0xF0)
  46.                 {
  47.                         GPIO = 0;
  48.                 }
  49.         }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement