Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- ******************************************************************************
- * @file Project/STM32F10x_StdPeriph_Template/main.c
- * @author MCD Application Team
- * @version V3.5.0
- * @date 08-April-2011
- * @brief Main program body
- ******************************************************************************
- * @attention
- *
- * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
- * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
- * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
- * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
- * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
- * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
- *
- * <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
- ******************************************************************************
- */
- /* Includes ------------------------------------------------------------------*/
- #include "stm32f10x.h"
- #include "stm32_eval.h"
- #include <stdio.h>
- #include "stm3210b_eval_lcd.h"
- #include "main.h"
- #include "math.h"
- #define MESSAGE1 "STM32 Medium Density"
- #define MESSAGE2 " Device running on "
- #define MESSAGE3 " STM3210B-EVAL "
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_ClocksTypeDef RCC_Clocks;
- NVIC_InitTypeDef NVIC_InitStructure;
- USART_InitTypeDef USART_InitStructure;
- int s;
- int m;
- int h;
- double M_PI=3.141592654;
- int centerX = 50;
- int centerY = 50;
- double status_degree;
- double oldS, oldM, oldH;
- int hr_x_coordinate,hr_y_coordinate,min_x_coordinate,min_y_coordinate,sec_x_coordinate,sec_y_coordinate;
- double degree_to_radian(double degree)
- {
- double radian;
- radian=(degree*(0.0174));
- return radian;
- }
- void Draw_clock_hand(int xcoordinate,int ycoordinate)
- {
- LCD_DrawUniLine(centerX, centerY, xcoordinate, ycoordinate);
- }
- int min_x_coordinate_finder(int min, int radius, double degree)
- {
- int xcoordinate,intermediate;
- double actualdegree;
- double radian;
- actualdegree= (90-(degree*min));
- status_degree=actualdegree;
- radian= degree_to_radian(actualdegree);
- intermediate= radius*(cos(radian));
- xcoordinate= (64+intermediate);
- return xcoordinate;
- }
- int min_y_coordinate_finder(int min, int radius, double degree)
- {
- int ycoordinate,intermediate;
- double actualdegree;
- double radian;
- actualdegree= (90-(degree*min));
- status_degree=actualdegree;
- radian= degree_to_radian(actualdegree);
- intermediate= radius*(sin(radian));
- ycoordinate= (32-intermediate);
- return ycoordinate;
- }
- int sec_x_coordinate_finder(int sec, int radius, double degree)
- {
- int ycoordinate,intermediate;
- double actualdegree;
- double radian;
- actualdegree= (90-(degree*sec));
- radian= degree_to_radian(actualdegree);
- intermediate= radius*(cos(radian));
- ycoordinate= (64+intermediate);
- return ycoordinate;
- }
- int sec_y_coordinate_finder(int sec, int radius, double degree)
- {
- int ycoordinate,intermediate;
- double actualdegree;
- double radian;
- actualdegree= (90-(degree*sec));
- radian= degree_to_radian(actualdegree);
- intermediate= radius*(sin(radian));
- ycoordinate= (32-intermediate);
- return ycoordinate;
- }
- int hr_x_coordinate_finder(int hr, int radius, double degree)
- {
- int xcoordinate,intermediate;
- double actualdegree;
- double radian;
- actualdegree= (90-(degree*hr));
- actualdegree= (actualdegree-((90-status_degree)/12));
- radian= degree_to_radian(actualdegree);
- intermediate= radius*(cos(radian));
- xcoordinate= (64+intermediate);
- return xcoordinate;
- }
- int hr_y_coordinate_finder(int hr, int radius, double degree)
- {
- int ycoordinate,intermediate;
- double actualdegree;
- double radian;
- actualdegree= (90-(degree*hr));
- actualdegree= (actualdegree-((90-status_degree)/12));
- radian= degree_to_radian(actualdegree);
- intermediate= radius*(sin(radian));
- ycoordinate= (32-intermediate);
- return ycoordinate;
- }
- /*
- double angle = 0;
- double radius = 50;
- double hourSize = .9;
- double minuteSize = .6;
- double secondSize = .3;
- double xCoord = 50;
- double yCoord = 50;
- double xCoordHour, yCoordHour;
- double xCoordSecond, yCoordSecond;
- double xCoordMinute, yCoordMinute;
- double oldS, oldM, oldH;
- void drawClock()
- {
- //godziny
- angle = ((M_PI / 2) - ((double)h)/12 * 2 *M_PI);
- xCoordHour = xCoord + (int)(radius * cos(angle) * hourSize);
- yCoordHour = yCoord - (int)(radius * sin(angle) * hourSize);
- LCD_DrawUniLine(xCoord, yCoord, xCoordHour, yCoordHour);
- //minuty
- angle = ((M_PI / 2) - (((double)m)/60) * 2 * M_PI);
- xCoordMinute = xCoord + (int)(radius * cos(angle) * minuteSize);
- yCoordMinute = yCoord - (int)(radius * sin(angle) * minuteSize);
- LCD_DrawUniLine(xCoord, yCoord, xCoordMinute, yCoordMinute);
- //sekundy
- angle = ((M_PI / 2) - (((double)s)/60) * 2 * M_PI);
- xCoordSecond = xCoord + (int)(radius * cos(angle) * secondSize);
- yCoordSecond = yCoord - (int)(radius * sin(angle) * secondSize);
- LCD_DrawUniLine(xCoord, yCoord, xCoordSecond, yCoordSecond);
- oldS = s;
- oldM = m;
- oldH = h;
- }
- void clearClock()
- {
- //godziny
- angle = ((M_PI / 2) - ((double)oldH)/12 * 2 *M_PI);
- xCoordHour = xCoord + (int)(radius * cos(angle) * hourSize);
- yCoordHour = yCoord + (int)(radius * sin(angle) * hourSize);
- LCD_DrawUniLine(xCoord, yCoord, xCoordHour, yCoordHour);
- //minuty
- angle = ((M_PI / 2) - (((double)oldM)/60) * 2 * M_PI);
- xCoordMinute = xCoord + (int)(radius * cos(angle) * minuteSize);
- yCoordMinute = yCoord - (int)(radius * sin(angle) * minuteSize);
- LCD_DrawUniLine(xCoord, yCoord, xCoordMinute, yCoordMinute);
- //sekundy
- angle = ((M_PI / 2) - (((double)oldS)/60) * 2 * M_PI);
- xCoordSecond = xCoord + (int)(radius * cos(angle) * secondSize);
- yCoordSecond = yCoord - (int)(radius * sin(angle) * secondSize);
- LCD_DrawUniLine(xCoord, yCoord, xCoordSecond, yCoordSecond);
- }
- */
- int main(void)
- {
- STM_EVAL_LEDInit(LED1);
- STM_EVAL_LEDInit(LED2);
- STM_EVAL_LEDInit(LED3);
- STM_EVAL_LEDInit(LED4);
- USART_InitStructure.USART_BaudRate = 115200;
- USART_InitStructure.USART_WordLength = USART_WordLength_8b;
- USART_InitStructure.USART_StopBits = USART_StopBits_1;
- USART_InitStructure.USART_Parity = USART_Parity_No;
- USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
- USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
- STM_EVAL_COMInit(COM1, &USART_InitStructure);
- STM3210B_LCD_Init();
- LCD_Clear(LCD_COLOR_WHITE);
- LCD_SetBackColor(LCD_COLOR_BLUE);
- LCD_SetTextColor(LCD_COLOR_WHITE);
- //LCD_DisplayStringLine(LCD_LINE_0, (uint8_t *)MESSAGE1);
- //LCD_DisplayStringLine(LCD_LINE_1, (uint8_t *)MESSAGE2);
- //LCD_DisplayStringLine(LCD_LINE_2, (uint8_t *)MESSAGE3);
- STM_EVAL_LEDOn(LED1);
- STM_EVAL_LEDOn(LED2);
- STM_EVAL_LEDOn(LED3);
- STM_EVAL_LEDOn(LED4);
- /* Enable PWR and BKP clocks */
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
- /* Allow access to BKP Domain */
- PWR_BackupAccessCmd(ENABLE);
- /* Reset Backup Domain */
- BKP_DeInit();
- /* Enable the LSI OSC */
- RCC_LSICmd(ENABLE);
- /* Wait till LSI is ready */
- while (RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET){}
- /* Select the RTC Clock Source */
- RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
- /* Enable RTC Clock */
- RCC_RTCCLKCmd(ENABLE);
- /* Wait for RTC registers synchronization */
- RTC_WaitForSynchro();
- /* Wait until last write operation on RTC registers has finished */
- RTC_WaitForLastTask();
- /* Enable the RTC Second */
- RTC_ITConfig(RTC_IT_SEC, ENABLE);
- /* Wait until last write operation on RTC registers has finished */
- RTC_WaitForLastTask();
- /* Set RTC prescaler: set RTC period to 1sec */
- RTC_SetPrescaler(40000);
- /* Wait until last write operation on RTC registers has finished */
- RTC_WaitForLastTask();
- /* To output second signal on Tamper pin, the tamper functionality
- must be disabled (by default this functionality is disabled) */
- BKP_TamperPinCmd(DISABLE);
- /* Enable the RTC Second Output on Tamper Pin */
- BKP_RTCOutputConfig(BKP_RTCOutputSource_Second);
- /* Adjust the RTC prescaler value */
- RTC_SetPrescaler(32768 - 1);
- /* Wait until last write operation on RTC registers has finished */
- RTC_WaitForLastTask();
- /* Configure one bit for preemption priority */
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
- /* Enable the RTC Interrupt */
- NVIC_InitStructure.NVIC_IRQChannel = RTC_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- /* Infinite loop */
- while (1)
- {
- if(Trigger == 1)
- {
- Trigger = 0;
- //przekazywanie poprzednich wartosci by malowac wskazowki na kolor tla
- oldS = s;
- oldM = m;
- oldH = h;
- //inkrementacja czasowa
- s++;
- if(s==60)
- {
- s=0;
- m++;
- }
- if(m==60)
- {
- m=0;
- h++;
- }
- if(h==24)
- {
- h=0;
- }
- LCD_SetTextColor(LCD_COLOR_RED);
- LCD_DrawCircle(centerX,centerY,30);
- //zamalowanie wskazowek na bialo
- LCD_SetTextColor(LCD_COLOR_WHITE);
- if(oldH<12)
- {
- hr_x_coordinate= hr_x_coordinate_finder(oldH,10,30);
- hr_y_coordinate= hr_y_coordinate_finder(oldH,10,30);
- Draw_clock_hand(hr_x_coordinate,hr_y_coordinate);
- }
- else if(oldH >= 12)
- {
- hr_x_coordinate= hr_x_coordinate_finder( (oldH-12),10,30);
- hr_y_coordinate= hr_y_coordinate_finder( (oldH-12),10,30);
- Draw_clock_hand(hr_x_coordinate,hr_y_coordinate);
- }
- min_x_coordinate=min_x_coordinate_finder(oldM,30,6);
- min_y_coordinate=min_y_coordinate_finder(oldM,30,6);
- Draw_clock_hand(min_x_coordinate,min_y_coordinate);
- sec_x_coordinate=sec_x_coordinate_finder(oldS,20,6);
- sec_y_coordinate=sec_y_coordinate_finder(oldS,20,6);
- Draw_clock_hand(sec_x_coordinate,sec_y_coordinate);
- //rysowanie wskazowek
- LCD_SetTextColor(LCD_COLOR_GREEN); //kolor zielony
- if(h<12)
- {
- hr_x_coordinate= hr_x_coordinate_finder(h,10,30);
- hr_y_coordinate= hr_y_coordinate_finder(h,10,30);
- Draw_clock_hand(hr_x_coordinate,hr_y_coordinate);
- }
- else if(h >= 12)
- {
- hr_x_coordinate= hr_x_coordinate_finder( (h-12),10,30);
- hr_y_coordinate= hr_y_coordinate_finder( (h-12),10,30);
- Draw_clock_hand(hr_x_coordinate,hr_y_coordinate);
- }
- min_x_coordinate=min_x_coordinate_finder(m,30,6);
- min_y_coordinate=min_y_coordinate_finder(m,30,6);
- Draw_clock_hand(min_x_coordinate,min_y_coordinate);
- sec_x_coordinate=sec_x_coordinate_finder(s,20,6);
- sec_y_coordinate=sec_y_coordinate_finder(s,20,6);
- Draw_clock_hand(sec_x_coordinate,sec_y_coordinate);
- // LCD_SetTextColor(LCD_COLOR_WHITE);
- // clearClock();
- // LCD_SetTextColor(LCD_COLOR_RED);
- // drawClock();
- // LCD_SetTextColor(LCD_COLOR_WHITE);
- /* Add your application code here
- */
- }
- }
- }
- /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
Add Comment
Please, Sign In to add comment