You are on page 1of 3

/*

* File: secuencia de leds.c


* Author: Teofilo
*
* Created on 6 de noviembre de 2019, 6:52
*/
// PIC16F18875 Configuration Bit Settings

// 'C' source line config statements

// CONFIG1
#pragma config FEXTOSC = ECH // External Oscillator mode selection bits (EC
above 8MHz; PFM set to high power)
#pragma config RSTOSC = EXT1X
// Power-up default value for COSC bits (EXTOSC operating per FEXTOSC bits)
#pragma config CLKOUTEN = OFF // Clock Out Enable bit (CLKOUT function is
disabled; i/o or oscillator function on OSC2)
#pragma config CSWEN = ON // Clock Switch Enable bit (Writing to NOSC and
NDIV is allowed)
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable bit (FSCM timer
enabled)

// CONFIG2
#pragma config MCLRE = ON // Master Clear Enable bit (MCLR pin is Master
Clear function)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config LPBOREN = OFF // Low-Power BOR enable bit (ULPBOR disabled)
#pragma config BOREN = ON // Brown-out reset enable bits (Brown-out Reset
Enabled, SBOREN bit is ignored)
#pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out
Reset Voltage (VBOR) set to 1.9V on LF, and 2.45V on F Devices)
#pragma config ZCD = OFF // Zero-cross detect disable (Zero-cross detect
circuit is disabled at POR.)
#pragma config PPS1WAY = ON // Peripheral Pin Select one-way control (The
PPSLOCK bit can be cleared and set only once in software)
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable bit (Stack
Overflow or Underflow will cause a reset)

// CONFIG3
#pragma config WDTCPS = WDTCPS_31// WDT Period Select bits (Divider ratio 1:65536;
software control of WDTPS)
#pragma config WDTE = OFF // WDT operating mode (WDT enabled regardless of
sleep; SWDTEN ignored)
#pragma config WDTCWS = WDTCWS_7// WDT Window Select bits (window always open
(100%); software control; keyed access not required)
#pragma config WDTCCS = SC // WDT input clock selector (Software Control)

// CONFIG4
#pragma config WRT = OFF // UserNVM self-write protection bits (Write
protection off)
#pragma config SCANE = available// Scanner Enable bit (Scanner module is available
for use)
#pragma config LVP = ON // Low Voltage Programming Enable bit (Low Voltage
programming enabled. MCLR/Vpp pin function is MCLR.)

// CONFIG5
#pragma config CP = OFF // UserNVM Program memory code protection bit
(Program Memory code protection disabled)
#pragma config CPD = OFF // DataNVM code protection bit (Data EEPROM code
protection disabled)

// #pragma config statements should precede project file includes.


// Use project enums instead of #define for ON and OFF.
#include <stdio.h>
#include <stdlib.h>// archivos de funciones o librer�as que nos permitir�n utilizar
caracter�sticas especiales
#include <xc.h> // Librer�a XC8
#define _XTAL_FREQ 4000000// Indicamos a que frecuencia de reloj esta funcionando
el micro
void cont();// funcion de delay o retardo
int h=1; // variables globales
int co=0;
void cont (void){
for(co=0; co<=h; co++){//
__delay_ms(100);
}
}
void __interrupt () INTERRUPT_interruptL(void){
if(IOCAFbits.IOCAF0==1){// 0V PREGUNTO DE LA BANDERA DE INTERRUPSION EXTERNA
__delay_ms(100);
if(IOCAPbits.IOCAP0==1){

if(h<10){
h++;
}
}
IOCAFbits.IOCAF0=0;
}
if(IOCAFbits.IOCAF1==1){ //pregunta por la vandera si esta en 1 si no hay
pregunto por el puerto
__delay_ms(100);
if(IOCAPbits.IOCAP1==1){
if(h>0){
h--;
}
}
IOCAFbits.IOCAF1=0;
}
}
void main() {
TRISC = 0b00000111;
TRISD = 0b00000000;// salidas
TRISA = 0b00000011;
ANSELA = 0b00000000;// declaro como entradas digitales
ANSELC = 0b00000000;// si estas en 0 se declara como entrada digital
ANSELD = 0b00000000;
PORTC = 0b00000000;
PORTA = 0b00000000;
INTCONbits.GIE=1; // habilitacion de interrupciones globales
INTCONbits.PEIE=1;//habilito el conteo la bandera como flanco de subida
PIE0bits.IOCIE = 1;
PIR0bits.INTF = 0;// preguntando de la bandera
IOCAPbits.IOCAP0=1;// puerto o
IOCAPbits.IOCAP1=1;
while(1){ // variable infinito varias veces hasta recibir un valor
if(PORTCbits.RC0==1){ // primera secuencia
PORTD=0b01011100;
cont();
PORTD=0b01111100;
cont();
PORTD=0b01111000;
cont();
PORTD=0b01011110;
cont();
}
else{
PORTD=0b00000000;
}
if(PORTCbits.RC1==1){
PORTD=0b01100111;
cont();
PORTD=0b01111111;
cont();
PORTD=0b01000111;
cont();
PORTD=0b01111100;
cont();
}
else{
PORTD=0b00000000;
}
if(PORTCbits.RC2==1){
PORTD=0b00111111;
cont();
PORTD=0b00000110;
cont();
PORTD=0b01011011;
cont();
PORTD=0b01001111;
cont();
}
else{
PORTD = 0b0000000;
}
}
}

You might also like