Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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
- }
- }
Add Comment
Please, Sign In to add comment