Mini64SE R6 realtime clock RTC and connecting LCD Nokia 5510
Hello, today we will be engaged in connecting LCD Nokia 5510 to the board Mini64SE R6, and will establish a real time clock.
Main.c The principle of work, the screen displays the time, the inscription “Mini64SER6”, circle and square. By pressing first become hour+1, by pressing seconnd become minute+1, by pressing third reset seconds.
#include "stm32f10x.h" #include "stm32f10x_rcc.h" #include "stm32f10x_rtc.h" #include "stm32f10x_gpio.h" #include "stm32f10x_tim.h" #include "main.h" #include "lcd5510.h" #define TIMER_PRESCALER 720 #define EXT_TIM_PULSE 150 #define TIM_PULSE 50 GPIO_InitTypeDef GPIO_InitStructure; extern unsigned char lcd8544_buff[84*6]; //buffer lcd int ci,i; int SysTickDelay; int IncDelay=100; char ch=0; unsigned char bars[5] = {1, 2, 3, 4, 5}; /* Structure to save time parameters */ typedef struct { unsigned char hour; //Hour unsigned char min; //minutes unsigned char sec; //seconds } RTC_Time; RTC_Time Time; //framework for work to "time" uint32_t tmp; //auxiliary variable void SysTick_Handler(void) { if (SysTickDelay != 0) { SysTickDelay--; } } void Delay( unsigned int Val) { SysTickDelay = Val; while (SysTickDelay != 0) {}; } //******************************************************************************************** //function interrupt is generated by RTC // //******************************************************************************************** void RTC_IRQHandler(void) { //cause interruption - overflow input divider (new second) if(RTC->CRL & RTC_CRL_SECF) { RTC->CRL &= ~RTC_CRL_SECF; //reset flag (Required!) //perform some action } //cause interruption - coincidence calculation and signal register if(RTC->CRL & RTC_CRL_ALRF) { RTC->CRL &= ~RTC_CRL_ALRF; //reset flag (Required!) //perform some action } //cause interruption - overflow counting register if(RTC->CRL & RTC_CRL_OWF) { RTC->CRL &= ~RTC_CRL_OWF; //reset flag (Required!) //perform some action } /* if(GPIOC->IDR & GPIO_BSRR_BS8) { //Toggle every sec LED3 GPIOC->BRR=GPIO_BSRR_BS8; } else { GPIOC->BSRR=GPIO_BSRR_BS8; }*/ } //******************************************************************************************** //function init RTC // //argument none // //result 1 - initialization is performed, 0 - the clock has been initialized // //******************************************************************************************** unsigned char RtcInit (void) { //timing modules enable power management and backup management domain RCC->APB1ENR |= RCC_APB1ENR_PWREN | RCC_APB1ENR_BKPEN; //allow access to the area of backup data PWR->CR |= PWR_CR_DBP; //If the clock is turned off - initialize them if ((RCC->BDCR & RCC_BDCR_RTCEN) != RCC_BDCR_RTCEN) { //reset region backup data RCC->BDCR |= RCC_BDCR_BDRST; RCC->BDCR &= ~RCC_BDCR_BDRST; //select the clock source external quartz 32768 and submit timing RCC->BDCR |= RCC_BDCR_RTCEN | RCC_BDCR_RTCSEL_LSE; RTC->CRL |= RTC_CRL_CNF; RTC->PRLL = 0x7FFF; //register dividing by 32768 RTC->CRL &= ~RTC_CRL_CNF; //set the permission bits of work and wait for the installation bits readiness RCC->BDCR |= RCC_BDCR_LSEON; while ((RCC->BDCR & RCC_BDCR_LSEON) != RCC_BDCR_LSEON){} RTC->CRL &= (uint16_t)~RTC_CRL_RSF; while((RTC->CRL & RTC_CRL_RSF) != RTC_CRL_RSF){} return 1; } return 0; } //******************************************************************************************** //function converts "time" in seconds (in case 0->00:00:00) // //argument a pointer to a structure that keeps time to convert // //result час у форматі "секунди" // //******************************************************************************************** uint32_t TimeToRtc(RTC_Time *time ) { uint32_t result; result = (uint32_t)time->hour * 3600; //hours result += (uint32_t)time->min * 60; //minutes result += time->sec; //seconds return result; } //******************************************************************************************** //functionconverts "time" in seconds (in case 0->00:00:00) // //argument counter value, a pointer to a structure of "Time" // //result none // //******************************************************************************************** void RtcToTime( uint32_t cnt, RTC_Time *time ) { time->sec = cnt % 60; cnt /= 60; time->min = cnt % 60; cnt /= 60; time->hour = cnt % 24; } void PortInit(void) { GPIO_InitTypeDef GPIO_InitStructure; // Enable PORTB Periph clock RCC_APB2PeriphClockCmd(LedBluePortRcc, ENABLE); RCC_APB2PeriphClockCmd(LedYellowPortRcc, ENABLE); RCC_APB2PeriphClockCmd(ButtonPortRcc, ENABLE); GPIO_InitStructure.GPIO_Pin = (Button1Pin|Button2Pin|Button3Pin); // buttons GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init(ButtonPort, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = LedBluePin; // Blue LED GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(LedBluePort, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = LedYellowPin; // Yellow LED GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(LedYellowPort, &GPIO_InitStructure); } int main(void) { PortInit(); SysTick_Config(SystemCoreClock /1000);//1ms RtcInit (); //RTC->CRL |= RTC_CRL_CNF; //enable RTC configuration registers RTC->CRH = RTC_CRH_SECIE;//enable interrupt pulses of second //RTC->CRH = RTC_CRH_ALRIE;//enable interrupt the coincidence counting and signal register //RTC->CRH = RTC_CRH_OWIE; //enable interrupt overflow counting register //RTC->CRL &= ~RTC_CRL_CNF; //exit the configuration NVIC_EnableIRQ (RTC_IRQn); //Download to structure the right time Time.hour= 12; Time.min = 00; Time.sec = 00; tmp = TimeToRtc(&Time); //convert time into the "clear" for RTC RTC_SetCounter(tmp); //record time counting register RTC LcdInit(); while(1) { /* GPIO_SetBits(LedYellowPort, LedYellowPin); Delay(1000); GPIO_ResetBits(LedYellowPort, LedYellowPin); Delay( 1000); */ tmp = RTC_GetCounter(); //read time from RTC RtcToTime(tmp,&Time); //turn into "human" format if (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_0)==0) { Time.hour++;//Hours +1 tmp = TimeToRtc(&Time); //convert time into the "clear" for RTC RTC_SetCounter(tmp); //record time counting register RTC } if (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_1)==0) { Time.min++;//minutes +1 tmp = TimeToRtc(&Time); //convert time into the "clear" for RTC RTC_SetCounter(tmp); //record time counting register RTC } if (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_2)==0) { Time.sec=0;//Seconds=0 tmp = TimeToRtc(&Time); //convert time into the "clear" for RTC RTC_SetCounter(tmp); //record time counting register RTC } LcdDec(Time.hour, 2, 0, 0, 0);//Hours to LCD LcdPutChar(14,1,':', 0); LcdDec(Time.min, 2, 20, 0, 0);//minutes to LCD LcdPutChar(32,1,':', 0); LcdDec(Time.sec, 2, 38, 0, 0);//Seconds to LCD LcdPutStr(0,10,"MINI64SER6",0);//derive inscription LcdRect(20,20,45,45,1);//Rectangle LcdCircle(32,32,8);//circle LcdRefresh(); Delay(1000); LcdClearBuff(); } }
To work with the pin LCD
we need to edit the file lcd5510.h shall init the pins board Mini64SE R6 to control LCD
#define LCD_PIN_ENABLE #define LCD_PIN_ENABLE GPIO_Pin_8 #define LCD_PIN_RESET GPIO_Pin_9 #define LCD_PIN_COMMAND GPIO_Pin_5 #define LCD_PIN_DATA GPIO_Pin_6 #define LCD_PIN_CLOCK GPIO_Pin_7 #define LCDPort GPIOB #define LCDRcc RCC_APB2Periph_GPIOB
That’s all here attach project Keil (I’m learning it now )
No Comments