Dimitar Marinov
/
Nucleo_4_encoders_w_Nokia5110
4 Rotary encoders with 5110 LCD display. For Nucleo boards
Diff: main.cpp
- Revision:
- 5:0daf19d95cc7
- Parent:
- 4:cd50b7dfaf27
- Child:
- 6:920bfbc7a7a1
--- a/main.cpp Wed Sep 21 14:37:29 2016 +0000 +++ b/main.cpp Sat Oct 22 17:01:11 2016 +0000 @@ -1,24 +1,17 @@ #include "mbed.h" #include "N5110.h" #include "REnc.h" -//https://developer.mbed.org/users/mbed_official/code/mbed-src/file/c9b73cd93427/targets/hal/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F411RE/PeripheralPins.c + //DigitalOut red(LED1); //DigitalOut blue(LED2); //DigitalOut green(LED3); - int i; // VCC,SCE, RST, D/C, MOSI,SCLK,LED N5110 lcd(PB_8,PA_4,PA_0,PA_1,PA_7,PA_5,PB_9); //PA_4 and PA_6 not used REnc encoder(PC_3, PC_2); -//PwmOut led(PA_3); -//PwmOut green(LED1); int temperature = 50; -TIM_HandleTypeDef tim_init; - -// Function declarations -void enable_tim(void); void CCW_Handle(void) { @@ -36,21 +29,6 @@ lcd.init(); encoder.setHandleCCW(CCW_Handle); encoder.setHandleCC(CW_Handle); - - HAL_TIM_Base_MspInit(&tim_init); // initialize the TIM basic - enable_tim(); - - // led.period_us(100); - // led = 20; - // green = 0.5; -// green.period_us(10000); -// while(1) { -// green = green + 0.01; -// wait(0.2); -// if(green == 1.0) { -// green = 0; -// } -// } // while(1) { // for (i=1; i<7; i++) { @@ -61,8 +39,6 @@ // } // } while(1) { - - HAL_TIM_Base_Start(&tim_init); // starts the timer // these are default settings so not strictly needed lcd.normalMode(); // normal colour mode @@ -77,8 +53,8 @@ // int temperature = encoder.getVal(); int length = sprintf(buffer,"T = %2d C",temperature); // print formatted data to buffer // it is important the format specifier ensures the length will fit in the buffer - if (length <= 14) // if string will fit on display - lcd.printString(buffer,0,1); // display on screen + // if (length <= 14) // if string will fit on display + // lcd.printString(buffer,0,1); // display on screen float pressure = 1012.3; // same idea with floats length = sprintf(buffer,"P = %.2f mb",pressure); @@ -109,57 +85,3 @@ } } - -void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) { - if(htim->Instance == TIM1){ - // if(curr_sec == usec){ -// HAL_TIM_Base_Stop(&tim_init); // stop the timer it has been 15 useconds -// // print the level of the signal to the console -// curr_sec = 0; -// } -// else -// curr_sec++; - } -} - -/* - * Configures the timer to pin PA3. - */ -void enable_tim(void){ - tim_init.Instance = TIM1; - tim_init.Init.CounterMode = TIM_COUNTERMODE_UP; - tim_init.Init.Prescaler = 16 - 1; // 1,000,000 Hz -> 1/1,000,000 seconds - tim_init.Init.Period = 0; - tim_init.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; // for now... - //tim_init.Init.RepetitionCounter = 0; - __TIM1_CLK_ENABLE(); // pin PA8 - PA10 - // configure the GPIO PA3 - __GPIOA_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pin = GPIO_PIN_8; // TIM1_CH1 - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF1_TIM1; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - GPIO_InitStruct.Pin = GPIO_PIN_9; // TIM1_CH2 - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - GPIO_InitStruct.Pin = GPIO_PIN_10; // TIM1_CH3 - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = GPIO_PIN_13; // TIM1_CH1N - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - GPIO_InitStruct.Pin = GPIO_PIN_14; // TIM1_CH2N - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - GPIO_InitStruct.Pin = GPIO_PIN_15; // TIM1_CH3N - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - HAL_NVIC_SetPriority(TIM1_UP_TIM10_IRQn, 0, 0); //Enable the peripheral IRQ - HAL_NVIC_EnableIRQ(TIM1_UP_TIM10_IRQn); - HAL_TIM_Base_Init(&tim_init); - //HAL_TIM_Base_Start_IT(&tim_init); //Start the timer -} - -void TIM1_IRQHandler(void) { - HAL_TIM_IRQHandler(&tim_init); -}