Buenas estoy empezando a practicar y estoy haciendo un codigo de ccs compiler en el cual hago un cronometro con un display 7 segmentos , esto es lo que llevo
Intente muchas cosas perdon por el desorden , pero hasta ahora eso es lo mejor que he podido hacer , no entiendo porque no me cuenta los numeros
muchas gracias de ante mano. ...
Código:
#include <18F47J53.h>
#device ADC=8
#FUSES NOWDT //WDT disabled (enabled by SWDTEN bit)
#FUSES PLL3 //Divide by 3 (12 MHz oscillator input)
#FUSES NOPLLEN //PLL Disabled
#FUSES NOSTVREN //stack overflow/underflow reset enabled
#FUSES NOXINST //Extended instruction set disabled
#FUSES NOCPUDIV //No CPU system clock divide
#FUSES NOPROTECT //Program memory is not code-protected
#FUSES HSPLL //HS oscillator, PLL enabled, HSPLL used by USB
#FUSES SOSC_HIGH //High Power T1OSC/SOSC circuit selected
#FUSES CLOCKOUT //CLKO output enabled on the RA6 pin
#FUSES NOFCMEN //Fail-Safe Clock Monitor disabled
#FUSES NOIESO //Two-Speed Start-up disabled
#FUSES WDT32768 //Watchdog Postscaler 1:32768
#FUSES DSWDTOSC_INT //DSWDT uses INTOSC/INTRC as clock
#FUSES RTCOSC_INT //RTCC uses INTRC as clock
#FUSES NODSBOR //Zero-Power BOR disabled in Deep Sleep
#FUSES NODSWDT //Deep Sleep Watchdog Timer Disabled
#FUSES DSWDT8192 //Deep Sleep Watchdog Postscaler: 1:8,192 (8.5 seconds)
#FUSES NOIOL1WAY //IOLOCK bit can be set and cleared
#FUSES ADC12 //ADC 10 or 12 Bit Select:12 - Bit ADC Enabed
#FUSES MSSPMSK7 //MSSP 7 Bit address masking
#FUSES NOWPFP //Write Protect Program Flash Page 0
#FUSES NOWPCFG //Write/Erase last page protect Disabled
#FUSES WPDIS //WPFP[5:0], WPEND, and WPCFG bits ignored
#FUSES WPEND //Start protection at page 0
#FUSES LS48MHZ //Low Speed USB mode with 48 MHz System clock at 48 MHz USB CLKEN divide-by is set to 8
#use delay(clock=48000000)
#pin_select U2TX=PIN_D2 //Selecciona hardware UART2
#pin_select U2RX=PIN_D3 //Selecciona hardware UART2
#define LOADER_END 0xFFF
#build(reset=LOADER_END+1, interrupt=LOADER_END+9) //Protege posiciones de memoria desde la 0x0000 hasta la 0x1000
#org 0, LOADER_END {}
#bit PLLEN = 0xf9b.6
#use rs232(baud=9600,parity=N,UART1,bits=8,timeout=30)
/********************************************************/
/*------- Espacio para declaracion de constantes ------*/
/********************************************************/
#define d_unidad PIN_B0 // Pin seleccionado para el control del 7segmento Unidad
#define d_decena PIN_B6 // Pin seleccionado para el control del 7segmento Decena
#define d_centena PIN_B5 // Pin seleccionado para el control del 7segmento Centena
#define d_umil PIN_B7 // Pin seleccionado para el control del 7segmento Unidad de Mil
/********************************************************/
/*--- Espacio para declaracion de variables globales --*/
/********************************************************/
unsigned int16 i,j,z;
char leds1[9]= {0,1,2,4,8,16,32,64,128};
unsigned char hora=0,minuto=0,segundo=0,milseg=0,bcd_unid,bcd_dec=0,bcd_cent=0,bcd_umil=0;
char unidad=0,decena=0,centena=0,umil=0;
//PGFEDCBA
char display[16]= {0b01011111,0b01000010,0b10011011,0b11010011,0b11000110,0b11010101,0b11011101,0b01000011,0b11011111,0b11000111
0b01110111,//A
0b01111100,//B
0b01011000,//C
0b01011110,//D
0b01111011,//E
0b01110001,//F
}; // La anterior Tabla contiene los valores binarios para la visualización de los
// números en los segmentos
/********************************************************/
/********************************************************/
/*-------------- Espacio para funciones ---------------*/
/********************************************************/
#include <stdlib.h> // for atoi32
#INT_TIMER0
void interrupcion (void){
//! if(input(pin_b3)){
set_timer0(60530);
output_toggle(PIN_b3);
if(++unidad==10){
unidad=0;
if(++decena==10){
decena=0;
if(++centena==10){
centena=0;
if(++umil==10){
umil=0;
}
}
}
}
//! }
}
void conver_bcd (unsigned char x){
umil=0,centena=0,decena=0,unidad=0;
while(x>=1000){
x= x-1000;
++umil;
}
while(x>=100){
x= x-100;
++centena;
}
while(x>=10){ // este procedimiento convirte los datos de binario a bcd
x= x-10;
++decena;
}
unidad=x;
}
void mostrar(void){
//! conver_bcd (segundo);
output_d(display[unidad]);
output_low(d_unidad);
delay_ms(2);
output_high(d_unidad);
output_d(display[decena]);
output_low(d_decena);
delay_ms(2);
output_high(d_decena);
output_d(display[centena]);
output_low(d_centena);
delay_ms(3);
output_high(d_centena);
output_d(display[umil]);
output_low(d_umil);
delay_ms(3);
output_high(d_umil);
}
/******************************************************************************/
/******************************************************************************/
/*--------------------- Espacio de codigo principal --------------------------*/
/******************************************************************************/
#zero_ram
void main(){
PLLEN = 1; //Habilita PLL para generar 48MHz de oscilador*/\\
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);
set_timer0(60530);
setup_timer_0(RTCC_DIV_256 | RTCC_INTERNAL);
for(;;){
mostrar();
}
}//end main