#include <stdio.h>
#include <stdlib.h>
#include <xc.h> // Librería XC8
#define _XTAL_FREQ 4000000 // Indicamos a que frecuencia de reloj esta funcionando el micro
// PIC16F648A Configuration Bit Settings
#pragma config FOSC = INTOSCIO // Oscillator Selection bits (INTOSC oscillator: I/O function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = OFF // RA5/MCLR/VPP Pin Function Select bit (RA5/MCLR/VPP pin function is digital input, MCLR internally tied to VDD)
#pragma config BOREN = ON // Brown-out Detect Enable bit (BOD enabled)
#pragma config LVP = OFF // Low-Voltage Programming Enable bit (RB4/PGM pin has digital I/O function, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EE Memory Code Protection bit (Data memory code protection off)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
// FUNCION PRINCIPAL
void main ()
{
TRISB = 0b00000000; // Configuro puerto B como salidas
while (1) // Bucle infinito
{
PORTBbits.RB0 = 0; // Apago pin RB0
__delay_ms(500);
PORTBbits.RB0 = 1; // Enciendo pin RB0
__delay_ms(500);
}
}// Register: PORTB
extern volatile unsigned char PORTB @ 0x006;
#ifndef _LIB_BUILD
asm("PORTB equ 06h");
#endif
// bitfield definitions
typedef union {
struct {
unsigned RB0 :1;
unsigned RB1 :1;
unsigned RB2 :1;
unsigned RB3 :1;
unsigned RB4 :1;
unsigned RB5 :1;
unsigned RB6 :1;
unsigned RB7 :1;
};
} PORTBbits_t;
extern volatile PORTBbits_t PORTBbits @ 0x006;
// bitfield macros
#define _PORTB_RB0_POSN 0x0
#define _PORTB_RB0_POSITION 0x0
#define _PORTB_RB0_SIZE 0x1
#define _PORTB_RB0_LENGTH 0x1
#define _PORTB_RB0_MASK 0x1
#define _PORTB_RB1_POSN 0x1
#define _PORTB_RB1_POSITION 0x1
#define _PORTB_RB1_SIZE 0x1
#define _PORTB_RB1_LENGTH 0x1
#define _PORTB_RB1_MASK 0x2
#define _PORTB_RB2_POSN 0x2
#define _PORTB_RB2_POSITION 0x2
#define _PORTB_RB2_SIZE 0x1
#define _PORTB_RB2_LENGTH 0x1
#define _PORTB_RB2_MASK 0x4
#define _PORTB_RB3_POSN 0x3
#define _PORTB_RB3_POSITION 0x3
#define _PORTB_RB3_SIZE 0x1
#define _PORTB_RB3_LENGTH 0x1
#define _PORTB_RB3_MASK 0x8
#define _PORTB_RB4_POSN 0x4
#define _PORTB_RB4_POSITION 0x4
#define _PORTB_RB4_SIZE 0x1
#define _PORTB_RB4_LENGTH 0x1
#define _PORTB_RB4_MASK 0x10
#define _PORTB_RB5_POSN 0x5
#define _PORTB_RB5_POSITION 0x5
#define _PORTB_RB5_SIZE 0x1
#define _PORTB_RB5_LENGTH 0x1
#define _PORTB_RB5_MASK 0x20
#define _PORTB_RB6_POSN 0x6
#define _PORTB_RB6_POSITION 0x6
#define _PORTB_RB6_SIZE 0x1
#define _PORTB_RB6_LENGTH 0x1
#define _PORTB_RB6_MASK 0x40
#define _PORTB_RB7_POSN 0x7
#define _PORTB_RB7_POSITION 0x7
#define _PORTB_RB7_SIZE 0x1
#define _PORTB_RB7_LENGTH 0x1
#define _PORTB_RB7_MASK 0x80