Hi, i need make a digital clock with functions mentioned in the subject with EK-TM4C123GXL, i have 7 segment display with 4 digits, and I'm having difficulty implementing the code using interrupts.
The functions should be able to run in the background, for example, have already activated chronometer and Watch function is on, the timer is still running in the background.
see the code below, this does not work, very unnecessary thing and written wrongly.I thought to implement with the switch case, that when he arrived in value compare with the pre-defined cases.
#include <stdint.h> #include <stdbool.h> #include "inc/tm4c123gh6pm.h" //Definitions for the interrupt and register assignments on the Tiva C Series device on the LaunchPad board #include "inc/hw_memmap.h" #include "inc/hw_types.h" #include "driverlib/sysctl.h" #include "driverlib/interrupt.h" // Defines and macros for NVIC Controller (Interrupt) API of driverLib. This includes API functions such as IntEnable and IntPrioritySet. #include "driverlib/gpio.h" #include "driverlib/timer.h" // Defines and macros for Timer API of driverLib. This includes API functions such as TimerConfigure and TimerLoadSet. uint32_t ui32Period; //essa variavel é para a contagem do tempo uint32_t ui32unidademin; int main(void) { //-------------------Clock Setup-------------------// SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); //40mhz SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); //função habilita o periferico TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); //configura o timer, configura o timer para utilizar o todo o periodo ui32Period = (SysCtlClockGet())*60; //60 segundos TimerLoadSet(TIMER0_BASE, TIMER_A, ui32Period -1); //???????This function con?gures the timer load value; if the timer is running then the value is immediately loaded into the timer. IntEnable(INT_TIMER0A); //The speci?ed interrupt is enabled in the interrupt controller. The ui32Interrupt parameter must be one of the valid INT_* values listed in Peripheral Driver Library User’s Guide and de?ned in the inc/hw_ints.h header ?le. Other enables for the interrupt (such as at the peripheral level) are unaffected by this function. TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); //This function enables the indicated timer interrupt sources. Only the sources that are enabled can be re?ected to the processor interrupt; disabled sources have no effect on the processor.The ui32IntFlags parameter must be the logical OR of any combination of the following: TIMER_TIMB_TIMEOUT - Timer B timeout interrupt IntMasterEnable(); //This function allows the processor to respond to interrupts. This function does not affect the set of interrupts enabled in the interrupt controller; it just gates the single interrupt from the controller to the processor TimerEnable(TIMER0_BASE, TIMER_A); //This function enables operation of the timer module. The timer must be con?gured before it is enabled. //MODELO //SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); //GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, 0b00000100); //GPIOPadConfigSet(GPIO_PORTD_BASE,0b00000100,GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD); //limitador de corrente //GPIOPinWrite(GPIO_PORTD_BASE, 0b00000100, 0x04); //0x04 sinal alto só para o d2 //0xFF = todas as portas SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, 0b00000100); GPIOPadConfigSet(GPIO_PORTD_BASE,0b11010100,GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD); //limitador de corrente //GPIOPinWrite(GPIO_PORTD_BASE, 0b00000100, 0x04); //0x04 sinal alto só para o d2 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE,0b00000010); GPIOPadConfigSet(GPIO_PORTB_BASE,0xFF,GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD); GPIOPinWrite(GPIO_PORTB_BASE, 0x02, 0b00000000); //0xFF = todas as portas while(1) {;} } void unidade_min(void) //adicionar prototipos { switch(ui32Period){ case 0: //caso o periodo tenha atingido 60 segundos GPIOPinWrite(GPIO_PORTD_BASE, 0b10000000, 0x80); GPIOPinWrite(GPIO_PORTB_BASE, 0b01111110, 0b00000000); ui32unidademin = 0; case 60: //caso o periodo tenha atingido 60 segundos GPIOPinWrite(GPIO_PORTD_BASE, 0b10000000, 0x80); GPIOPinWrite(GPIO_PORTB_BASE, 0b00110000, 0b00000000); ui32unidademin = 1; case 120: GPIOPinWrite(GPIO_PORTD_BASE, 0b10000000, 0x80); GPIOPinWrite(GPIO_PORTB_BASE, 0b01101101, 0b00000000); ui32unidademin = 2; case 180: GPIOPinWrite(GPIO_PORTD_BASE, 0b10000000, 0x80); GPIOPinWrite(GPIO_PORTB_BASE, 0b00111001, 0b00000000); ui32unidademin = 3; case 240: GPIOPinWrite(GPIO_PORTD_BASE, 0b10000000, 0x80); GPIOPinWrite(GPIO_PORTB_BASE, 0b00110011, 0b00000000); ui32unidademin = 4; case 300: GPIOPinWrite(GPIO_PORTD_BASE, 0b10000000, 0x80); GPIOPinWrite(GPIO_PORTB_BASE, 0b01011011, 0b00000000); ui32unidademin = 5; case 360: GPIOPinWrite(GPIO_PORTD_BASE, 0b10000000, 0x80); GPIOPinWrite(GPIO_PORTB_BASE, 0b01011111, 0b00000000); ui32unidademin = 6; case 420: GPIOPinWrite(GPIO_PORTD_BASE, 0b10000000, 0x80); GPIOPinWrite(GPIO_PORTB_BASE, 0b01110000, 0b00000000); ui32unidademin = 7; case 480: GPIOPinWrite(GPIO_PORTD_BASE, 0b10000000, 0x80); GPIOPinWrite(GPIO_PORTB_BASE, 0b01111111, 0b00000000); ui32unidademin = 8; case 540: GPIOPinWrite(GPIO_PORTD_BASE, 0b10000000, 0x80); GPIOPinWrite(GPIO_PORTB_BASE, 0b01111011, 0b00000000); ui32unidademin = 9; } } void dezena_min(uint32_t unidademin) //adicionar prototipos { switch(ui32unidademin){ case 0: //caso o periodo tenha atingido 60 segundos GPIOPinWrite(GPIO_PORTD_BASE, 0b10000000, 0x80); GPIOPinWrite(GPIO_PORTB_BASE, 0b01111110, 0b00000000); case 60: //caso o periodo tenha atingido 60 segundos GPIOPinWrite(GPIO_PORTD_BASE, 0b10000000, 0x80); GPIOPinWrite(GPIO_PORTB_BASE, 0b00110000, 0b00000000); case 120: GPIOPinWrite(GPIO_PORTD_BASE, 0b10000000, 0x80); GPIOPinWrite(GPIO_PORTB_BASE, 0b01101101, 0b00000000); case 180: GPIOPinWrite(GPIO_PORTD_BASE, 0b10000000, 0x80); GPIOPinWrite(GPIO_PORTB_BASE, 0b00111001, 0b00000000); case 240: GPIOPinWrite(GPIO_PORTD_BASE, 0b10000000, 0x80); GPIOPinWrite(GPIO_PORTB_BASE, 0b00110011, 0b00000000); case 300: GPIOPinWrite(GPIO_PORTD_BASE, 0b10000000, 0x80); GPIOPinWrite(GPIO_PORTB_BASE, 0b01011011, 0b00000000); case 420: GPIOPinWrite(GPIO_PORTD_BASE, 0b10000000, 0x80); GPIOPinWrite(GPIO_PORTB_BASE, 0b01110000, 0b00000000); case 480: GPIOPinWrite(GPIO_PORTD_BASE, 0b10000000, 0x80);// sinal alto somente para D4 GPIOPinWrite(GPIO_PORTB_BASE, 0b01111111, 0b00000000); case 540: GPIOPinWrite(GPIO_PORTD_BASE, 0b10000000, 0x80);// sinal alto somente para D4 GPIOPinWrite(GPIO_PORTB_BASE, 0b01111011, 0b00000000); } }