/***********************
#include "mask.c"
/*Header******************************************************/
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections
unsigned short mask(unsigned short num);
long digit_no,digit1000, digit100, digit10, digit1, i,digit;
long temp, temp2,temp3,temp4, digit_1,digit_2,digit_3,digit_4;
long cont1,cont,cnt;
char texto1[7];
long rpm, numflancos=0;
//int rads;
void main() {
OSCCON=0x60; //Oscilador interno a 4MHz.
//OSCCON=0x40; //Oscilador interno a 1MHz.
ANSEL=0;
ANSELH=0;
OPTION_REG = 0x80; // Set timer TMR0 0x80
TMR0 = 0;
INTCON = 0xA4; //A0 // Disable interrupt PEIE,INTE,RBIE,T0IE
PORTD = 0; // Turn off both displays
TRISD = 0; // All port A pins are configured as outputs
PORTC = 0; // Turn off all display segments
TRISC = 0; // All port D pins are configured as outputs
PORTA = 0;
TRISA = 0b00110011;// RA0,RA1,RA2 como entradas
PORTB = 0;
TRISB = 0;
porte=0;
TRISE=0;
C1ON_bit = 0; // Disable comparators
C2ON_bit = 0;
Lcd_Init(); //Inicializa el LCD.
Lcd_Cmd(_LCD_CLEAR); //Borra el display.
Lcd_Cmd(_LCD_CURSOR_OFF); //Apaga el cursor.
Lcd_Out(1,1,"TacometroDigital");
//Lcd_Out(2,1,"Wmax=15.300 rpm");
Delay_ms(1500);
Lcd_Cmd(_LCD_CLEAR); //Borra el display.
T1CON=49;
PIR1.TMR1IF=0;
TMR1H=0x9E;
TMR1L=0x58;
PIE1.TMR1IE=1;
cnt=0;
digit_no=0;
cont=0;
do {
if(PORTA.F0==0 && PORTA.F1==1){
PORTA=0x04;
if(PORTA.F5==0){
cont++;
temp = cont % 1000;
digit_1 = cont/1000;
digit1000= mask(digit_1); // Prepare mask for displaying ones
temp2 = temp%100;
digit_2 = temp/100;
digit100 = mask(digit_2); // Prepare mask for displaying tens
temp3 = temp2%10;
digit_3 = temp2/10;
digit10 = mask(digit_3); // Prepare mask for displaying centenas
temp4 = temp3%1;
digit_4 = temp3/1;
digit1= mask(digit_4); // Prepare mask for displaying miles
Delay_ms(150);
}
if(cont==9999){
cont=0;
}
}
if(PORTA.F0==1 && PORTA.F1==0){
PORTA=0x08;
OPTION_REG = 0xA0; //Contador de pulsos en T0CKI
TMR0=0;
Delay_ms(1000); //Cuenta durante 1 segundo.
numflancos=TMR0; //numflancos=velocidad en rps.
rpm=(long)(60+(60*numflancos)); //Transformación a rpm.
IntToStr(rpm,texto1); //Transformación de rpm a texto.
Lcd_Out(1,1,"W[rpm]=");
Lcd_Out(1,8,texto1);
if(rpm >= 9999){
rpm=9999;
temp = rpm % 1000;
digit_1 = rpm/1000;
digit1000= mask(digit_1); // Prepare mask for displaying ones
temp2 = temp%100;
digit_2 = temp/100;
digit100 = mask(digit_2); // Prepare mask for displaying tens
temp3 = temp2%10;
digit_3 = temp2/10;
digit10 = mask(digit_3); // Prepare mask for displaying centenas
temp4 = temp3%1;
digit_4 = temp3/1;
digit1= mask(digit_4); // Prepare mask for displaying miles
}
temp = rpm % 1000;
digit_1 = rpm/1000;
digit1000= mask(digit_1); // Prepare mask for displaying ones
temp2 = temp%100;
digit_2 = temp/100;
digit100 = mask(digit_2); // Prepare mask for displaying tens
temp3 = temp2%10;
digit_3 = temp2/10;
digit10 = mask(digit_3); // Prepare mask for displaying centenas
temp4 = temp3%1;
digit_4 = temp3/1;
digit1= mask(digit_4); // Prepare mask for displaying miles
cont=0;
}
} while (1); // Endless loop
}
void interrupt() {
if (digit_no==0) {
PORTD = 1; // 1=mil
PORTC = digit1; //
PORTD = 1; //
digit_no = 1;
}
if(digit_no==1) {
PORTD = 8; //
PORTC = digit10; // 8=CENTENAS
PORTD = 8; //
digit_no = 2;
}
if(digit_no==2) {
PORTD = 4; // 4=DECENAS
PORTC = digit100; //
PORTD = 4; //
digit_no = 3;
}
else{
PORTD = 2; // 2=Unidades
PORTC = digit1000; //
PORTD = 2; //
digit_no = 0;
}
TMR0 = 0; // Reset counter TMRO
INTCON = 0x20; // Bit T0IF=0, T0IE=1
}