Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Name: Raghav Vashishtha ID: 10203015
- Program to display the number os seconds elapsed on the application shield's LCD*/
- #include "main.h"
- #include "LCD_Display.h"
- #include <stdio.h>
- #include <string.h>
- #include "Small_7.h"
- #include "Arial_9.h"
- #include "Arial_12.h"
- #include "Arial_24.h"
- uint32_t seconds=0; //global seconds variable
- // System Functions
- void SystemClock_Config(void);
- void Configure_TIMTimeBase(void);
- char outputString[18];
- int main(void)
- {
- // Configure the system clock to 84.0 MHz
- SystemClock_Config();
- // Configure Display
- Configure_LCD_Pins();
- Configure_SPI1();
- Activate_SPI1();
- Clear_Screen();
- Initialise_LCD_Controller();
- Configure_TIMTimeBase(); //configures timebase to 1Hz and sets an interrupt to it
- set_font((unsigned char*) Arial_9); //set font and size
- while (1){ //continuously print the seconds variable
- sprintf(outputString, "Fuck my life. Yay.");
- put_string(0,0, outputString);
- sprintf(outputString, "Yay.");
- put_string(45,15, outputString);
- LL_mDelay(100);
- }
- }
- /**
- * The system Clock is configured as follow :
- * System Clock source = PLL (HSE)
- * SYSCLK(Hz) = 84000000
- * HCLK(Hz) = 84000000
- * AHB Prescaler = 1
- * APB1 Prescaler = 1
- * APB2 Prescaler = 2
- * HSE Frequency(Hz) = 8000000
- * PLL_M = 8
- * PLL_N = 336
- * PLL_P = 4
- * VDD(V) = 3.3
- * Main regulator output voltage = Scale2 mode
- * Flash Latency(WS) = 2
- */
- void SystemClock_Config(void)
- {
- /* Enable HSE oscillator */
- LL_RCC_HSE_EnableBypass();
- LL_RCC_HSE_Enable();
- while(LL_RCC_HSE_IsReady() != 1)
- {
- };
- // Set FLASH latency
- LL_FLASH_SetLatency(LL_FLASH_LATENCY_2);
- // Main PLL configuration and activation
- LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE, LL_RCC_PLLM_DIV_8, 336, LL_RCC_PLLP_DIV_4);
- LL_RCC_PLL_Enable();
- while(LL_RCC_PLL_IsReady() != 1)
- {
- };
- // Sysclk activation on the main PLL
- LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
- LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL);
- while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL)
- {
- };
- // Set APB1 & APB2 prescaler
- LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);
- LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1);
- // Set systick to 1ms
- SysTick_Config(84000000 / 1000);
- // Update CMSIS variable (which can be updated also through SystemCoreClockUpdate function) */
- SystemCoreClock = 84000000;
- }
- void Configure_TIMTimeBase(void)
- {
- //* Enable the TIM2 peripheral clock
- LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2);
- // Set the pre-scaler value to have TIM2 counter clock equal to 10 kHz
- // Prescaler = (SystemCoreClock /10 KHz) - 1
- LL_TIM_SetPrescaler(TIM2, __LL_TIM_CALC_PSC(SystemCoreClock, 10000));
- // Set the auto-reload value to have an initial update event frequency of 1Hz
- // TIM2CLK = SystemCoreClock / (APB prescaler & multiplier)
- LL_TIM_SetAutoReload(TIM2, __LL_TIM_CALC_ARR(SystemCoreClock, LL_TIM_GetPrescaler(TIM2), 1));
- // Enable the update interrupt and configure it to TIM2 peripheral
- LL_TIM_EnableIT_UPDATE(TIM2);
- // Configure the NestedVectorInterruptController to handle TIM2 update interrupt
- NVIC_SetPriority(TIM2_IRQn, 0); //set its priority to 0
- NVIC_EnableIRQ(TIM2_IRQn); //enables it
- LL_TIM_EnableCounter(TIM2); //start timer
- /* Force update generation */
- LL_TIM_GenerateEvent_UPDATE(TIM2); //enable interrupt to trigger at TIMs event
- }
- void TIM2_IRQHandler(void) //service routine for the interrupt
- {
- if(LL_TIM_IsActiveFlag_UPDATE(TIM2) == 1)// Check whether update interrupt is pending, if it is then run the needed code
- {
- seconds++;
- LL_TIM_ClearFlag_UPDATE(TIM2);// Clear the update interrupt flag
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement