Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <xc.h>
- #include <stdio.h>
- #include "config.h"
- #include "GLCD.h"
- #define TMR0_1_SEC_H 0x0B
- #define TMR0_1_SEC_L 0xDB
- unsigned long long freq = 0;
- volatile unsigned long long ticks = 0;
- void interrupt high_priority timer0_interrupt()
- {
- if (INTCONbits.TMR0IE && INTCONbits.TMR0IF) {
- INTCONbits.TMR0IF = 0;
- freq = ticks + TMR1L + (TMR1H<<8);
- ticks = 0;
- //Reset TMR0
- TMR0H = TMR0_1_SEC_H;
- TMR0L = TMR0_1_SEC_L;
- //Reset TMR1
- TMR1H = 0;
- TMR1L = 0;
- }
- return;
- }
- void interrupt low_priority timer1_interrupt()
- {
- if (PIE1bits.TMR1IE && PIR1bits.TMR1IF) {
- PIR1bits.TMR1IF = 0;
- ticks += 0xFFFF;
- }
- return;
- }
- void main(void)
- {
- TMR0H = TMR0_1_SEC_H;
- TMR0L = TMR0_1_SEC_L;
- TMR1H = 0;
- TMR1L = 0;
- INTCONbits.TMR0IF = 0; //Clear flag
- INTCONbits.TMR0IE = 1; //Enable interrupt TIMER0
- INTCON2bits.TMR0IP = 1; //High priority
- PIR1bits.TMR1IF = 0; //Clear flag
- PIE1bits.TMR1IE = 1; //Enable interrupt TIMER1
- IPR1bits.TMR1IP = 0; //Low priority
- RCONbits.IPEN = 1; //Enable priority interrupts
- T0CON = 0b10000100; //Enables Timer0
- //Timer0 is configured as a 16-bit timer
- //Instruction cycle clock
- //Increment on falling edge transition on T0CKI pin
- //Timer0 prescaler is assigned
- //1:32 prescaler value
- T1CON = 0b10000011; //Enable read/w rite of T im er1 in 16-bit operation
- //1:1 prescale value
- //Timer1 oscillator is shut of
- //Synchronize external clock input
- //External clock from pin R C 0/T 1O SO /T 13C K I
- //Enables T im er1
- INTCONbits.GIE = 1; //Enable global interrupts
- INTCONbits.GIEH = 1; // Enable high priority interrupts
- INTCONbits.GIEL = 1; // Enable low priority interrupts
- TRISD = 0x00;
- GLCDinit();
- clearGLCD(0, 7, 0, 127);
- char buf[32];
- char buf2[32];
- while (1) {
- sprintf(buf, "%i Hz", freq);
- sprintf(buf2, "Ticks: %i ", ticks);
- writeTxt(0, 0, buf);
- writeTxt(1, 0, buf2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement