You are on page 1of 5

#include "p18f4550.

h"
#include <delays.h>
#include "xlcd.h"
#include <timers.h>

#pragma config PLLDIV = 5 // (CRISTAL DE 20 MHz)


#pragma config CPUDIV = OSC1_PLL2
#pragma config USBDIV = 2
#pragma config FOSC = HSPLL_HS
#pragma config FCMEN = OFF
#pragma config IESO = OFF
#pragma config PWRT = ON
#pragma config BOR = OFF
#pragma config BORV = 0
#pragma config VREGEN = OFF //REGULADOR DE VOLTAJE USB
#pragma config WDT = OFF
#pragma config WDTPS = 32768
#pragma config MCLRE = ON
#pragma config LPT1OSC = OFF
#pragma config PBADEN = OFF
#pragma config STVREN = OFF
#pragma config LVP = OFF
#pragma config XINST = OFF // CONJUNTO DE INSTRUCCIONES EXTENDIDAS
#pragma config CP0 = OFF
#pragma config CP1 = OFF
#pragma config CP2 = OFF
#pragma config CPB = OFF
#pragma config CPD = OFF
#pragma config WRT0 = OFF
#pragma config WRT1 = OFF
#pragma config WRT2 = OFF
#pragma config WRTB = OFF // PROTECCIN DE ESCRITURA PARA EL BLOCK DE
BOOT
#pragma config WRTC = OFF
#pragma config WRTD = OFF
#pragma config EBTR0 = OFF
#pragma config EBTR1 = OFF
#pragma config EBTRB = OFF
#pragma config CCP2MX = ON
#pragma config DEBUG = OFF
#define MoveRight() comandXLCD(0x1C)
#define MoveLeft() comandXLCD(0x18)

#define SEG_SEC PORTAbits.RA1


#define SEG_PRI PORTAbits.RA0
#define ON 1
#define OFF 0

unsigned int UM, C, D, U,Numero, N, a=0;


void timer0_isr (void);
void verDisplay();
unsigned char timer0, unidades, numero_d, counter1, counter, i,h =0;
const unsigned char
DIGITOS[]={0b01111110,0b00110000,0b01101101,0b01111001,0b00110011,0b0101
1011,0b00011111,0b01110000,0b01111111,0b01110011};

#pragma code high_vector=0x08

void interrupt (void)


{
_asm GOTO timer0_isr
_endasm
}

#pragma code //Return to default code section


#pragma interrupt timer0_isr

//COMIENZA INTERRUPCION POR DESBORDE DE


TIMER0****************************************
void timer0_isr (void)
{

Numero++;
INTCONbits.TMR0IF = 0;
INTCONbits.INT0IF= 0;
}

//TERMINA INTERRUPCION POR DESBORDE DE


TIMER0****************************************
void DelayFor18TCY (void);
void DelayPORXLCD (void);
void DelayXLCD(void);

void DelayFor18TCY(void){
Delay10TCYx(2);
}
void DelayPORXLCD(void){
Delay1KTCYx(15);
}
void DelayXLCD(void){
Delay1KTCYx(2);
}

// Envia comando al LCD


void comandXLCD(unsigned char a){
BusyXLCD();
WriteCmdXLCD(a);
}
// Ubica cursor en (x = Posicion en linea, y = n de linea)
void gotoxyXLCD(unsigned char x, unsigned char y){
unsigned char direccion;

if(y != 1)
direccion = 0x40;
else
direccion=0;

direccion += x-1;
comandXLCD(0x80 | direccion);
}

void main (void)


{
unsigned char String[4];
unsigned short N=0;
//OSCCON=0b00111110;
//CONFIG1H=0b01001011;
ADCON1=0x0f; //***************FUNDAMENTAL ANULAR COMPARADOR
SINO NO ME TRABAJA EL PORTA
CMCON =0x07; //**************FUNDAMENTAL ANULAR COMPARADOR
TRISA =0b00000000;
TRISB =0x00;
PORTB =0x00;
TRISD =0X00;
PORTD =0X00;

//OpenTimer0(TIMER_INT_ON & T0_SOURCE_EXT & T0_EDGE_RISE & T0_16BIT &


T0_PS_1_256); //

OpenXLCD (FOUR_BIT & LINES_5X7); //Iniciamos LCD


comandXLCD (0x06); //Aseguramos el incremento de direccion, display fijo
comandXLCD (0x0C); //Encendemos el lcd
comandXLCD (0x01) ; //Borra pantalla y vuelve al origen
putrsXLCD ("VEL.ANEMOMETRO="); //Escibe en el LCD

OpenTimer0(TIMER_INT_ON & T0_SOURCE_EXT & T0_EDGE_FALL & T0_16BIT &


T0_PS_1_1);
//INTCONbits.GIE=1; //Habilito las interrupciones globales
INTCONbits.PEIE=1;
//INTCONbits.INT0IE=1;

while(1){
WriteTimer0(0);
gotoxyXLCD(0,2);
itoa(Numero,String);
putsXLCD (String); //Escibe en el LCD
for(a=0;a<15;a++){
Delay10KTCYx(5);
}
}

En lnea

You might also like