PIC16F-8-Timer-Configuration&Initialization

by Marwen Maghrebi
/*
 * File: main.c
 * Author: Marwen Maghrebi
 * Description:
 * Timer-based LED toggling with UART monitoring.
 * This code initializes multiple interrupt counters and toggles LEDs connected to different pins of 
 * the PIC16F877A microcontroller based on specific time intervals. Additionally, it implements UART 
 * communication to send a message periodically via serial transmission.
 */

#include <xc.h>
#include <stdint.h>
#include <stdio.h>

// Configuration bits (assuming a PIC16F877A microcontroller)
#pragma config FOSC = HS
#pragma config WDTE = OFF
#pragma config PWRTE = ON
#pragma config BOREN = ON
#pragma config LVP = OFF
#pragma config CPD = OFF
#pragma config WRT = OFF
#pragma config DEBUG = OFF

// Define the system clock frequency
#define _XTAL_FREQ 8000000 // 8 MHz

// Global variables for the interrupt counts
volatile uint8_t interrupt_count1 = 0;
volatile uint16_t interrupt_count2 = 0;
volatile uint16_t interrupt_count3 = 0;
volatile uint16_t interrupt_count4 = 0;
volatile uint16_t interrupt_count5 = 0;

// UART initialization function
void UART_Init(void) {
    TRISC6 = 0; // TX pin set as output
    TRISC7 = 1; // RX pin set as input

    TXSTAbits.SYNC = 0;  // Asynchronous mode
    TXSTAbits.BRGH = 1;  // High-speed mode

    SPBRG = 51; // Baud rate 9600 for 8 MHz clock

    RCSTAbits.SPEN = 1;  // Enable serial port
    TXSTAbits.TXEN = 1;  // Enable transmission
}
Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?
-
00:00
00:00
Update Required Flash plugin
-
00:00
00:00