Skip to content

Instantly share code, notes, and snippets.

@starhopp3r
Created July 16, 2018 06:37
Show Gist options
  • Save starhopp3r/d9792560586f75300e373c535ea0c194 to your computer and use it in GitHub Desktop.
Save starhopp3r/d9792560586f75300e373c535ea0c194 to your computer and use it in GitHub Desktop.
#include <xc.h>
#include "amt.h"
#include <stdio.h>
#pragma config XINST = OFF
#pragma config FOSC = HS
#pragma config WDT = OFF
void interrupt HighIsr(void) // High priority interrupt
{
}
void interrupt low_priority LowIsr(void) //Low priority interrupt
{
}
void main(void) {
int loop_counter = 0;
TRISJ = 0x00; // Configure PORT J as 8 bits output
PORTJ = 0X00; // Off all the LEDs connected to PORT J
T2CON = 0b01111111; // Enable tmr2, prescaler=16, postscaler=16
PR2 = 224; // For 10ms timing with the Fosc = 25 MHz
PIR1bits.TMR2IF = 0; // Clear the flag before using
while (1) {
while (PIR1bits.TMR2IF == 0); // Waiting for tmr2 flag to be set
loop_counter++; // increment loop_counter by 1 every 10ms
if (loop_counter == 50)
{
PORTJ = PORTJ ^ 0b00000001; // Toggle using XOR
// or PORTJbits.RJ0 = PORTJbits.RJ0 ^ 1;
loop_counter = 0;
}
PIR1bits.TMR2IF = 0; // Clear the flag before using
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment