Advertisement
Guest User

Untitled

a guest
Dec 16th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.14 KB | None | 0 0
  1. /* Name: Raghav Vashishtha ID: 10203015
  2. Program to display the number os seconds elapsed on the application shield's LCD*/
  3.  
  4. #include "main.h"
  5. #include "LCD_Display.h"
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include "Small_7.h"
  9. #include "Arial_9.h"
  10. #include "Arial_12.h"
  11. #include "Arial_24.h"
  12. uint32_t seconds=0; //global seconds variable
  13. // System Functions
  14. void SystemClock_Config(void);
  15. void Configure_TIMTimeBase(void);
  16. char outputString[18];
  17.  
  18.  
  19. int main(void)
  20. {
  21. // Configure the system clock to 84.0 MHz
  22. SystemClock_Config();
  23.  
  24. // Configure Display
  25. Configure_LCD_Pins();
  26. Configure_SPI1();
  27. Activate_SPI1();
  28. Clear_Screen();
  29. Initialise_LCD_Controller();
  30. Configure_TIMTimeBase(); //configures timebase to 1Hz and sets an interrupt to it
  31.  
  32. set_font((unsigned char*) Arial_9); //set font and size
  33.  
  34. while (1){ //continuously print the seconds variable
  35. sprintf(outputString, "Fuck my life. Yay.");
  36. put_string(0,0, outputString);
  37. sprintf(outputString, "Yay.");
  38. put_string(45,15, outputString);
  39. LL_mDelay(100);
  40. }
  41. }
  42.  
  43. /**
  44. * The system Clock is configured as follow :
  45. * System Clock source = PLL (HSE)
  46. * SYSCLK(Hz) = 84000000
  47. * HCLK(Hz) = 84000000
  48. * AHB Prescaler = 1
  49. * APB1 Prescaler = 1
  50. * APB2 Prescaler = 2
  51. * HSE Frequency(Hz) = 8000000
  52. * PLL_M = 8
  53. * PLL_N = 336
  54. * PLL_P = 4
  55. * VDD(V) = 3.3
  56. * Main regulator output voltage = Scale2 mode
  57. * Flash Latency(WS) = 2
  58. */
  59. void SystemClock_Config(void)
  60. {
  61. /* Enable HSE oscillator */
  62. LL_RCC_HSE_EnableBypass();
  63. LL_RCC_HSE_Enable();
  64. while(LL_RCC_HSE_IsReady() != 1)
  65. {
  66. };
  67.  
  68. // Set FLASH latency
  69. LL_FLASH_SetLatency(LL_FLASH_LATENCY_2);
  70.  
  71. // Main PLL configuration and activation
  72. LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE, LL_RCC_PLLM_DIV_8, 336, LL_RCC_PLLP_DIV_4);
  73. LL_RCC_PLL_Enable();
  74. while(LL_RCC_PLL_IsReady() != 1)
  75. {
  76. };
  77.  
  78. // Sysclk activation on the main PLL
  79. LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
  80. LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL);
  81. while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL)
  82. {
  83. };
  84.  
  85. // Set APB1 & APB2 prescaler
  86. LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);
  87. LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1);
  88.  
  89. // Set systick to 1ms
  90. SysTick_Config(84000000 / 1000);
  91.  
  92. // Update CMSIS variable (which can be updated also through SystemCoreClockUpdate function) */
  93. SystemCoreClock = 84000000;
  94. }
  95.  
  96. void Configure_TIMTimeBase(void)
  97. {
  98. //* Enable the TIM2 peripheral clock
  99. LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2);
  100.  
  101. // Set the pre-scaler value to have TIM2 counter clock equal to 10 kHz
  102. // Prescaler = (SystemCoreClock /10 KHz) - 1
  103.  
  104. LL_TIM_SetPrescaler(TIM2, __LL_TIM_CALC_PSC(SystemCoreClock, 10000));
  105.  
  106. // Set the auto-reload value to have an initial update event frequency of 1Hz
  107. // TIM2CLK = SystemCoreClock / (APB prescaler & multiplier)
  108. LL_TIM_SetAutoReload(TIM2, __LL_TIM_CALC_ARR(SystemCoreClock, LL_TIM_GetPrescaler(TIM2), 1));
  109.  
  110. // Enable the update interrupt and configure it to TIM2 peripheral
  111. LL_TIM_EnableIT_UPDATE(TIM2);
  112.  
  113. // Configure the NestedVectorInterruptController to handle TIM2 update interrupt
  114. NVIC_SetPriority(TIM2_IRQn, 0); //set its priority to 0
  115. NVIC_EnableIRQ(TIM2_IRQn); //enables it
  116.  
  117. LL_TIM_EnableCounter(TIM2); //start timer
  118.  
  119. /* Force update generation */
  120. LL_TIM_GenerateEvent_UPDATE(TIM2); //enable interrupt to trigger at TIMs event
  121. }
  122. void TIM2_IRQHandler(void) //service routine for the interrupt
  123. {
  124. if(LL_TIM_IsActiveFlag_UPDATE(TIM2) == 1)// Check whether update interrupt is pending, if it is then run the needed code
  125. {
  126. seconds++;
  127. LL_TIM_ClearFlag_UPDATE(TIM2);// Clear the update interrupt flag
  128. }
  129.  
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement