Hello. Mi project consist of a 7 segment display in which i write them once a at time and very quickly using a PIT interrupt. So, the PIT ISR (that works correctly) is in charge of the display. In this ISR, what i want to display is what I write on the vector unsigned int DISPB[5]; which is a global variable in the Events.c.
Now, what I want to do is to display the time. I do the following procedure:
initialize the RTC (using fuctions provided by processor expert)
getting the time (using fuctions provided by processor expert)
call a fuction in which I overwrite the DISPB with the new time
my problem is that I watch the initialized time, but not the current time. In other words, I cant overwrite DISPB more than one time.
I attach my main.c and my evects.c.
Thanks
/* ###################################################################
** Filename : main.c
** Project : MEGALUX II
** Processor : MKE02Z64VLH2
** Version : Driver 01.01
** Compiler : GNU C Compiler
** Date/Time : 2015-03-04, 12:31, # CodeGen: 0
** Abstract :
** Main module.
** This module contains user's application code.
** Settings :
** Contents :
** No public methods
**
** ###################################################################*/
/*!
** @file main.c
** @version 01.01
** @brief
** Main module.
** This module contains user's application code.
*/
/*!
** @addtogroup main_module main module documentation
** @{
*/
/* MODULE main */
/* Including needed modules to compile this module/procedure */
#include "Cpu.h"
#include "Events.h"
#include "PTD5.h"
#include "BitIoLdd1.h"
#include "PTH0.h"
#include "BitIoLdd2.h"
#include "PTB0.h"
#include "BitIoLdd3.h"
#include "PTA0.h"
#include "BitIoLdd4.h"
#include "PTB2.h"
#include "BitIoLdd5.h"
#include "PTB3.h"
#include "BitIoLdd6.h"
#include "Red.h"
#include "BitIoLdd7.h"
#include "Blue.h"
#include "BitIoLdd8.h"
#include "PTD0.h"
#include "BitIoLdd9.h"
#include "PTD1.h"
#include "BitIoLdd10.h"
#include "RTC1.h"
#include "PIT.h"
/* Including shared modules, which are used for whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"
LDD_TDeviceData *MyRTCPtr;
LDD_RTC_TTime Time;
LDD_TError Error;
int i;
int k;
char *DayOfWeekName[] = {
"Sunday",
"Monday",
"Tuesady",
"Wensday",
"Thursday",
"Friday",
"Saturday"
};
unsigned int buffer_hora;
void inicializar_rtc (){
MyRTCPtr = RTC1_Init((LDD_TUserData *)NULL, FALSE); /* Initialize the device, reset all RTC registers */
}
/*void mostrar_fecha_y_hora (){
RTC1_GetTime(MyRTCPtr, &Time);
DISPB[0] = 0;
asignar_numero(Time.Minute / 10);
DISPB[1] = buffer_hora;
asignar_numero(Time.Minute % 10);
DISPB[2] = buffer_hora;
asignar_numero(Time.Second / 10);
DISPB[3] = buffer_hora;
asignar_numero(Time.Second % 10);
DISPB[4] = buffer_hora;
}
*/
/* User includes (#include below this line is not maintained by Processor Expert) */
/*lint -save -e970 Disable MISRA rule (6.3) checking. */
int main(void)
/*lint -restore Enable MISRA rule (6.3) checking. */
{
/* Write your local variable definition here */
/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
PE_low_level_init();
/*** End of Processor Expert internal initialization. ***/
/* Write your code here */
/* For example: for(;;) { } */
/*** Don't write any code pass this line, or it will be deleted during code generation. ***/
/*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
#ifdef PEX_RTOS_START
PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of RTOS startup code. ***/
/*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
MyRTCPtr = RTC1_Init((LDD_TUserData *)NULL, FALSE);
for(;;){
RTC1_GetTime(MyRTCPtr, &Time);
asignar_hora_a_DISPB(Time.Minute/10, Time.Minute%10,Time.Second/10,Time.Second%10);
}
/*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/
/* END main */
/*!
** @}
*/
/*
** ###################################################################
**
** This file was created by Processor Expert 10.3 [05.09]
** for the Freescale Kinetis series of microcontrollers.
**
** ###################################################################
*/
/* ###################################################################
** Filename : Events.c
** Project : MEGALUX II
** Processor : MKE02Z64VLH2
** Component : Events
** Version : Driver 01.00
** Compiler : GNU C Compiler
** Date/Time : 2015-03-04, 12:31, # CodeGen: 0
** Abstract :
** This is user's event module.
** Put your event handler code here.
** Settings :
** Contents :
** Cpu_OnNMIINT - void Cpu_OnNMIINT(void);
**
** ###################################################################*/
/*!
** @file Events.c
** @version 01.00
** @brief
** This is user's event module.
** Put your event handler code here.
*/
/*!
** @addtogroup Events_module Events module documentation
** @{
*/
/* MODULE Events */
#include "Cpu.h"
#include "Events.h"
unsigned int DISPC=0; //variable global para ser utlizada en el ISR del display
unsigned int DISPB[5]= {0x8E,0x9E,0x9C,0x6E,0xEE};
//unsigned int DISPB[5]= {0x00,0x02,0x02,0x02,0x00};
unsigned int numero_display = 0;
unsigned int boton_apretado;
unsigned int ultimo_display_escrito;
unsigned int cont=0;
unsigned int buffer_hora;
int i;
int k;
void seleccionar_display(int numero_display){
switch (numero_display){
case 0:
PTA0_ClrVal ();
PTB0_ClrVal ();
PTB2_ClrVal (); //queremos que se prenda el primer display
break;
case 1:
PTA0_SetVal ();
PTB0_ClrVal ();
PTB2_ClrVal (); //queremos que se prenda el segundo display
break;
case 2:
PTA0_ClrVal ();
PTB0_SetVal ();
PTB2_ClrVal (); //queremos que se prenda el tercer display
break;
case 3:
PTA0_SetVal ();
PTB0_SetVal ();
PTB2_ClrVal (); //queremos que se prenda el cuarto display
break;
case 4:
PTA0_ClrVal ();
PTB0_ClrVal ();
PTB2_SetVal (); //queremos que se prenda el quinto
break;
case 5:
PTA0_SetVal ();
PTB0_ClrVal ();
PTB2_SetVal (); //queremos que se prenda el quinto
break;
case 6:
PTA0_ClrVal ();
PTB0_SetVal ();
PTB2_SetVal (); //queremos que se prenda el quinto
break;
case 7:
PTA0_SetVal ();
PTB0_SetVal ();
PTB2_SetVal (); //queremos que se prenda el quinto
break;
default:
PTA0_SetVal ();
PTB0_SetVal ();
PTB2_SetVal (); //queremos que se prenda ningun display
break;
}
}
void mandar_dato_a_display(unsigned int dato){
for(i=0;i<8;i++){
unsigned char bit_salida = dato & 1;
dato = dato >> 1;
//mandamos el bit
if (bit_salida == 0) PTD5_ClrVal ();
else PTD5_SetVal ();
for(k=0;k<10;k++) //software delay para clock del CD4015
PTH0_SetVal (); //subimos ponemos el clock en alto por un tiempo
PTH0_ClrVal (); //bajamos el clock por un tiempo
for(k=0;k<100;k++) {}
}
}
void buscar_boton_apretado (){
if ( !PTD1_GetVal ()){
if (DISPC == 0)
boton_apretado = 0xBE ; // 6
if (DISPC == 1)
boton_apretado = 0x66 ; // 4
if (DISPC == 2)
boton_apretado = 0x3E ; // B
if (DISPC == 3)
boton_apretado = 0xB6 ; // 5
if (DISPC == 4)
boton_apretado = 0x9C ; // C
if (DISPC == 5)
boton_apretado = 0xE0 ; // 7
if (DISPC == 6)
boton_apretado = 0xFE ; // 8
if (DISPC == 7)
boton_apretado = 0xF6 ; // 9
}
if ( !PTD0_GetVal ()){
if (DISPC == 0)
boton_apretado = 0xF2 ; // 3
if (DISPC == 1)
boton_apretado = 0x60 ; // 1
if (DISPC == 2)
boton_apretado = 0xEE ; // A
if (DISPC == 3)
boton_apretado = 0xDA ; // 2
if (DISPC == 4)
boton_apretado = 0x7A ; // D
if (DISPC == 5)
boton_apretado = 0x9E ; // E
if (DISPC == 6)
boton_apretado = 0xFC ; // 0
if (DISPC == 7)
boton_apretado = 0x8E ; // F
}}
void ingresar_boton_a_la_izquierda (){
for ( i=0 ; i<4 ; i++)
DISPB[i] = DISPB[i+1];
DISPB[4] = boton_apretado;
}
void asignar_numero(unsigned int numero){
if (numero == 0)
buffer_hora = 0xFC;
if (numero == 1)
buffer_hora = 0x60;
if (numero == 2)
buffer_hora = 0xDA;
if (numero == 3)
buffer_hora = 0xF2;
if (numero == 4)
buffer_hora = 0x66;
if (numero == 5)
buffer_hora = 0xB6;
if (numero == 6)
buffer_hora = 0xBE;
if (numero == 7)
buffer_hora = 0xE0;
if (numero == 8)
buffer_hora = 0xFE;
if (numero == 9)
buffer_hora = 0xF6;
}
void asignar_hora_a_DISPB (int MM, int mm, int SS, int ss){
DISPB[0] = 0;
asignar_numero(MM);
DISPB[1] = buffer_hora;
asignar_numero(mm);
DISPB[2] = buffer_hora;
asignar_numero(SS);
DISPB[3] = buffer_hora;
asignar_numero(ss);
DISPB[4] = buffer_hora;
}
void ISR_PIT_display (void){
Red_SetVal ();
Blue_ClrVal();
PTB3_SetVal (); //inicialmente el enable esta en alto
if(DISPC <= 4 ){
unsigned int dato = DISPB [DISPC];
mandar_dato_a_display(dato);
}
seleccionar_display(numero_display);
PTB3_ClrVal (); //seteamos el enable en alto para mandar los datos
for(k=0;k<2000;k++){}
if (cont == 8)
if ( !PTD1_GetVal () || !PTD0_GetVal () ){
buscar_boton_apretado();
ingresar_boton_a_la_izquierda ();
}
PTB3_SetVal ();
if(numero_display == 7 ) numero_display = 0;
else numero_display ++;
if(DISPC == 7 ) DISPC = 0;
else DISPC ++;
if(cont == 8 ) cont = 0; //contador para prevenir rebotes
else cont ++;
}
#ifdef __cplusplus
extern "C" {
#endif
/* User includes (#include below this line is not maintained by Processor Expert) */
/*
** ===================================================================
** Event : Cpu_OnNMIINT (module Events)
**
** Component : Cpu [MKE02Z64QH2]
*/
/*!
** @brief
** This event is called when the Non maskable interrupt had
** occurred. This event is automatically enabled when the [NMI
** interrupt] property is set to 'Enabled'.
*/
/* ===================================================================*/
void Cpu_OnNMIINT(void)
{
/* Write your code here ... */
}
/* END Events */
#ifdef __cplusplus
} /* extern "C" */
#endif
/*!
** @}
*/
/*
** ###################################################################
**
** This file was created by Processor Expert 10.3 [05.09]
** for the Freescale Kinetis series of microcontrollers.
**
** ###################################################################
*/