A simple alarm clock for the 1 day workshop presented by Skool and ARM Hungary in 2015.

Dependencies:   Skool_wkshp_lib2015 mbed

Committer:
lvagasi
Date:
Mon Sep 14 20:10:47 2015 +0000
Revision:
0:28b9efbdeffc
Child:
1:f76b625bd36e
Started to prepare it for the event. First commit.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lvagasi 0:28b9efbdeffc 1 #include "mbed.h"
lvagasi 0:28b9efbdeffc 2 #include "serial_lcd.h"
lvagasi 0:28b9efbdeffc 3
lvagasi 0:28b9efbdeffc 4 DigitalOut myled(LED1); // On-board LED
lvagasi 0:28b9efbdeffc 5 Serial pc(SERIAL_TX, SERIAL_RX); // UART to communicate with PC
lvagasi 0:28b9efbdeffc 6 DigitalOut R_LED(PA_10); // RED part of the RGB LED
lvagasi 0:28b9efbdeffc 7 DigitalOut G_LED(PB_5); // GREEN part of the RGB LED
lvagasi 0:28b9efbdeffc 8 DigitalOut B_LED(PA_9); // BLUE part of the RGB LED
lvagasi 0:28b9efbdeffc 9 DigitalOut LCD_RST(PB_10); // LCD RST
lvagasi 0:28b9efbdeffc 10 DigitalOut LCD_BL(PA_8); // LCD BackLight
lvagasi 0:28b9efbdeffc 11 PwmOut speaker(PB_4); // Speaker
lvagasi 0:28b9efbdeffc 12
lvagasi 0:28b9efbdeffc 13 I2C i2c1(I2C_SDA, I2C_SCL); // I2C interface for LCD display
lvagasi 0:28b9efbdeffc 14
lvagasi 0:28b9efbdeffc 15
lvagasi 0:28b9efbdeffc 16 // Define your own keypad values
lvagasi 0:28b9efbdeffc 17 const char Keytable[] = { '1', '2', '3', 'A', // r0
lvagasi 0:28b9efbdeffc 18 '4', '5', '6', 'B', // r1
lvagasi 0:28b9efbdeffc 19 '7', '8', '9', 'C', // r2
lvagasi 0:28b9efbdeffc 20 '*', '0', '#', 'D' // r3
lvagasi 0:28b9efbdeffc 21 };
lvagasi 0:28b9efbdeffc 22 // c0 c1 c2 c3
lvagasi 0:28b9efbdeffc 23 const uint16_t rows[4] = {GPIO_PIN_5, GPIO_PIN_6, GPIO_PIN_8, GPIO_PIN_9};
lvagasi 0:28b9efbdeffc 24 const uint16_t cols[4] = {GPIO_PIN_10, GPIO_PIN_11, GPIO_PIN_12, 0xFFFF};
lvagasi 0:28b9efbdeffc 25 //const int nrows = 4;
lvagasi 0:28b9efbdeffc 26 const int ncols = 3;
lvagasi 0:28b9efbdeffc 27 const char BCD2HEX[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
lvagasi 0:28b9efbdeffc 28
lvagasi 0:28b9efbdeffc 29 uint32_t Index = 0xFF;
lvagasi 0:28b9efbdeffc 30 uint32_t new_key = 0;
lvagasi 0:28b9efbdeffc 31 uint32_t Systck_cnt = 0;
lvagasi 0:28b9efbdeffc 32
lvagasi 0:28b9efbdeffc 33 void Error(int err) {
lvagasi 0:28b9efbdeffc 34 switch (err) {
lvagasi 0:28b9efbdeffc 35 case 0: pc.printf("\033[44m\033[37mI2C communication error!\033[00m\r\n");
lvagasi 0:28b9efbdeffc 36 break;
lvagasi 0:28b9efbdeffc 37 case 1: pc.printf("\033[44m\033[37mIncorrect calibration data error!\033[00m\r\n");
lvagasi 0:28b9efbdeffc 38 break;
lvagasi 0:28b9efbdeffc 39 default: pc.printf("\033[44m\033[37mUnknown error!\033[00m\r\n");
lvagasi 0:28b9efbdeffc 40 break;
lvagasi 0:28b9efbdeffc 41 }
lvagasi 0:28b9efbdeffc 42 while (1) {
lvagasi 0:28b9efbdeffc 43 myled = 1;
lvagasi 0:28b9efbdeffc 44 wait(0.1);
lvagasi 0:28b9efbdeffc 45 myled = !myled;
lvagasi 0:28b9efbdeffc 46 wait(0.1);
lvagasi 0:28b9efbdeffc 47 myled = !myled;
lvagasi 0:28b9efbdeffc 48 wait(0.1);
lvagasi 0:28b9efbdeffc 49 myled = !myled;
lvagasi 0:28b9efbdeffc 50 wait(2);
lvagasi 0:28b9efbdeffc 51 }
lvagasi 0:28b9efbdeffc 52 }
lvagasi 0:28b9efbdeffc 53
lvagasi 0:28b9efbdeffc 54 void EXTI9_5_IRQHandler(void) {
lvagasi 0:28b9efbdeffc 55 HAL_NVIC_DisableIRQ(EXTI9_5_IRQn);
lvagasi 0:28b9efbdeffc 56 if (__HAL_GPIO_EXTI_GET_IT(GPIO_PIN_5) != 0) {
lvagasi 0:28b9efbdeffc 57 __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_5);
lvagasi 0:28b9efbdeffc 58 HAL_GPIO_EXTI_Callback(0);
lvagasi 0:28b9efbdeffc 59 } else if (__HAL_GPIO_EXTI_GET_IT(GPIO_PIN_6) != 0) {
lvagasi 0:28b9efbdeffc 60 __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_6);
lvagasi 0:28b9efbdeffc 61 HAL_GPIO_EXTI_Callback(1);
lvagasi 0:28b9efbdeffc 62 } else if (__HAL_GPIO_EXTI_GET_IT(GPIO_PIN_7) != 0) {
lvagasi 0:28b9efbdeffc 63 __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_7);
lvagasi 0:28b9efbdeffc 64 HAL_GPIO_EXTI_Callback(4);
lvagasi 0:28b9efbdeffc 65 } else if (__HAL_GPIO_EXTI_GET_IT(GPIO_PIN_8) != 0) {
lvagasi 0:28b9efbdeffc 66 __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_8);
lvagasi 0:28b9efbdeffc 67 HAL_GPIO_EXTI_Callback(2);
lvagasi 0:28b9efbdeffc 68 } else if (__HAL_GPIO_EXTI_GET_IT(GPIO_PIN_9) != 0) {
lvagasi 0:28b9efbdeffc 69 __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_9);
lvagasi 0:28b9efbdeffc 70 HAL_GPIO_EXTI_Callback(3);
lvagasi 0:28b9efbdeffc 71 }
lvagasi 0:28b9efbdeffc 72 NVIC_ClearPendingIRQ(EXTI9_5_IRQn);
lvagasi 0:28b9efbdeffc 73 HAL_GPIO_WritePin(GPIOC, cols[0] | cols[1] | cols[2], GPIO_PIN_RESET); // All cols are driven Low for resume IRQ operation
lvagasi 0:28b9efbdeffc 74 }
lvagasi 0:28b9efbdeffc 75
lvagasi 0:28b9efbdeffc 76 void HAL_GPIO_EXTI_Callback(uint16_t pin) {
lvagasi 0:28b9efbdeffc 77 int col;
lvagasi 0:28b9efbdeffc 78 int temp;
lvagasi 0:28b9efbdeffc 79
lvagasi 0:28b9efbdeffc 80 for (col = 0; col < ncols; col++) {
lvagasi 0:28b9efbdeffc 81 HAL_GPIO_WritePin(GPIOC, cols[0] | cols[1] | cols[2], GPIO_PIN_SET); // All cols are driven High
lvagasi 0:28b9efbdeffc 82 HAL_GPIO_WritePin(GPIOC, cols[col], GPIO_PIN_RESET); // 1 col is driven Low
lvagasi 0:28b9efbdeffc 83 wait_ms(50);
lvagasi 0:28b9efbdeffc 84 temp = GPIOC->IDR;
lvagasi 0:28b9efbdeffc 85 temp = (temp & 0x0360);
lvagasi 0:28b9efbdeffc 86 switch (temp) {
lvagasi 0:28b9efbdeffc 87 case 0x0340: Index = col;
lvagasi 0:28b9efbdeffc 88 break;
lvagasi 0:28b9efbdeffc 89 case 0x0320: Index = 4 + col;
lvagasi 0:28b9efbdeffc 90 break;
lvagasi 0:28b9efbdeffc 91 case 0x0260: Index = 8 + col;
lvagasi 0:28b9efbdeffc 92 break;
lvagasi 0:28b9efbdeffc 93 case 0x0160: Index = 12 + col;
lvagasi 0:28b9efbdeffc 94 break;
lvagasi 0:28b9efbdeffc 95 default: Index = 0xFF;
lvagasi 0:28b9efbdeffc 96 break;
lvagasi 0:28b9efbdeffc 97 }
lvagasi 0:28b9efbdeffc 98 if (Index != 0xFF) {
lvagasi 0:28b9efbdeffc 99 break;
lvagasi 0:28b9efbdeffc 100 }
lvagasi 0:28b9efbdeffc 101 }
lvagasi 0:28b9efbdeffc 102 new_key++;
lvagasi 0:28b9efbdeffc 103 }
lvagasi 0:28b9efbdeffc 104 void SysTick_Handler(void) {
lvagasi 0:28b9efbdeffc 105 HAL_SYSTICK_Callback();
lvagasi 0:28b9efbdeffc 106 }
lvagasi 0:28b9efbdeffc 107
lvagasi 0:28b9efbdeffc 108 void HAL_SYSTICK_Callback(void) {
lvagasi 0:28b9efbdeffc 109 Systck_cnt++;
lvagasi 0:28b9efbdeffc 110 }
lvagasi 0:28b9efbdeffc 111
lvagasi 0:28b9efbdeffc 112 int write_ser_lcd(unsigned char data, bool mode) {
lvagasi 0:28b9efbdeffc 113 char wd[2];
lvagasi 0:28b9efbdeffc 114 int status;
lvagasi 0:28b9efbdeffc 115
lvagasi 0:28b9efbdeffc 116 wd[0] = ((mode) ? 0x40 : 0x00);
lvagasi 0:28b9efbdeffc 117 wd[1] = (char)data;
lvagasi 0:28b9efbdeffc 118 status = i2c1.write(ST7032I_ADDR, wd, 2, false);
lvagasi 0:28b9efbdeffc 119 return status;
lvagasi 0:28b9efbdeffc 120 }
lvagasi 0:28b9efbdeffc 121
lvagasi 0:28b9efbdeffc 122 void write_ser_text(unsigned char *text, uint32_t len) {
lvagasi 0:28b9efbdeffc 123 int i;
lvagasi 0:28b9efbdeffc 124 char wd[41];
lvagasi 0:28b9efbdeffc 125 int status;
lvagasi 0:28b9efbdeffc 126
lvagasi 0:28b9efbdeffc 127 wd[0] = 0x40;
lvagasi 0:28b9efbdeffc 128 for (i = 0; i < len; i++) {
lvagasi 0:28b9efbdeffc 129 wd[i + 1] = (char)text[i];
lvagasi 0:28b9efbdeffc 130 }
lvagasi 0:28b9efbdeffc 131 status = i2c1.write(ST7032I_ADDR, wd, len + 1, false);
lvagasi 0:28b9efbdeffc 132 if (status != 0) {
lvagasi 0:28b9efbdeffc 133 Error(0);
lvagasi 0:28b9efbdeffc 134 }
lvagasi 0:28b9efbdeffc 135 }
lvagasi 0:28b9efbdeffc 136
lvagasi 0:28b9efbdeffc 137 int init_ser_lcd(void) {
lvagasi 0:28b9efbdeffc 138 int status;
lvagasi 0:28b9efbdeffc 139
lvagasi 0:28b9efbdeffc 140 LCD_RST = 0x0; // Generating Reset pulse
lvagasi 0:28b9efbdeffc 141 LCD_BL = 0x0; // BackLight off
lvagasi 0:28b9efbdeffc 142 // BL_LCD = 0.0;
lvagasi 0:28b9efbdeffc 143 wait_us(200);
lvagasi 0:28b9efbdeffc 144 LCD_RST = 0x1;
lvagasi 0:28b9efbdeffc 145 wait_ms(40);
lvagasi 0:28b9efbdeffc 146 status = write_ser_lcd(0x38, false); // Function set with IS = 0
lvagasi 0:28b9efbdeffc 147 if (status != 0) {
lvagasi 0:28b9efbdeffc 148 Error(0);
lvagasi 0:28b9efbdeffc 149 }
lvagasi 0:28b9efbdeffc 150 wait_us(30);
lvagasi 0:28b9efbdeffc 151 status = write_ser_lcd(0x39, false); // Function set with IS = 1
lvagasi 0:28b9efbdeffc 152 if (status != 0) {
lvagasi 0:28b9efbdeffc 153 Error(0);
lvagasi 0:28b9efbdeffc 154 }
lvagasi 0:28b9efbdeffc 155 wait_us(30);
lvagasi 0:28b9efbdeffc 156 status = write_ser_lcd(0x14, false); // Internal OSC frequency adjustment
lvagasi 0:28b9efbdeffc 157 if (status != 0) {
lvagasi 0:28b9efbdeffc 158 Error(0);
lvagasi 0:28b9efbdeffc 159 }
lvagasi 0:28b9efbdeffc 160 wait_us(30);
lvagasi 0:28b9efbdeffc 161 status = write_ser_lcd(0x79, false); // Contrast set
lvagasi 0:28b9efbdeffc 162 if (status != 0) {
lvagasi 0:28b9efbdeffc 163 Error(0);
lvagasi 0:28b9efbdeffc 164 }
lvagasi 0:28b9efbdeffc 165 wait_us(30);
lvagasi 0:28b9efbdeffc 166 status = write_ser_lcd(0x5C, false); // Power/Icon/Contrast control
lvagasi 0:28b9efbdeffc 167 if (status != 0) {
lvagasi 0:28b9efbdeffc 168 Error(0);
lvagasi 0:28b9efbdeffc 169 }
lvagasi 0:28b9efbdeffc 170 wait_us(30);
lvagasi 0:28b9efbdeffc 171 status = write_ser_lcd(0x6E, false); // Follower control
lvagasi 0:28b9efbdeffc 172 if (status != 0) {
lvagasi 0:28b9efbdeffc 173 Error(0);
lvagasi 0:28b9efbdeffc 174 }
lvagasi 0:28b9efbdeffc 175 wait_ms(200);
lvagasi 0:28b9efbdeffc 176 // wait_us(30);
lvagasi 0:28b9efbdeffc 177 status = write_ser_lcd(0x0C, false); // Display ON
lvagasi 0:28b9efbdeffc 178 if (status != 0) {
lvagasi 0:28b9efbdeffc 179 Error(0);
lvagasi 0:28b9efbdeffc 180 }
lvagasi 0:28b9efbdeffc 181 wait_us(30);
lvagasi 0:28b9efbdeffc 182 status = write_ser_lcd(0x01, false); // Clear display
lvagasi 0:28b9efbdeffc 183 if (status != 0) {
lvagasi 0:28b9efbdeffc 184 Error(0);
lvagasi 0:28b9efbdeffc 185 }
lvagasi 0:28b9efbdeffc 186 wait_us(30);
lvagasi 0:28b9efbdeffc 187 status = write_ser_lcd(0x06, false); // Entry mode set
lvagasi 0:28b9efbdeffc 188 if (status != 0) {
lvagasi 0:28b9efbdeffc 189 Error(0);
lvagasi 0:28b9efbdeffc 190 }
lvagasi 0:28b9efbdeffc 191 wait_us(30);
lvagasi 0:28b9efbdeffc 192 status = write_ser_lcd(0x02, false); // Home
lvagasi 0:28b9efbdeffc 193 if (status != 0) {
lvagasi 0:28b9efbdeffc 194 Error(0);
lvagasi 0:28b9efbdeffc 195 }
lvagasi 0:28b9efbdeffc 196 wait_us(30);
lvagasi 0:28b9efbdeffc 197 LCD_BL = 0x1; // BackLight ON
lvagasi 0:28b9efbdeffc 198 // BL_LCD = 0.5;
lvagasi 0:28b9efbdeffc 199 return 0;
lvagasi 0:28b9efbdeffc 200 }
lvagasi 0:28b9efbdeffc 201
lvagasi 0:28b9efbdeffc 202 int main() {
lvagasi 0:28b9efbdeffc 203 uint32_t RGB_sel = 0;
lvagasi 0:28b9efbdeffc 204 uint32_t currentHclk;
lvagasi 0:28b9efbdeffc 205
lvagasi 0:28b9efbdeffc 206 GPIO_InitTypeDef keypadInit;
lvagasi 0:28b9efbdeffc 207
lvagasi 0:28b9efbdeffc 208 HAL_StatusTypeDef HAL_status;
lvagasi 0:28b9efbdeffc 209 HAL_LockTypeDef HAL_lock;
lvagasi 0:28b9efbdeffc 210 RTC_HandleTypeDef rtch;
lvagasi 0:28b9efbdeffc 211 HAL_RTCStateTypeDef rtc_state;
lvagasi 0:28b9efbdeffc 212 RTC_InitTypeDef rtc_init;
lvagasi 0:28b9efbdeffc 213 RTC_TimeTypeDef rtc_time;
lvagasi 0:28b9efbdeffc 214 RTC_DateTypeDef rtc_date;
lvagasi 0:28b9efbdeffc 215 RTC_AlarmTypeDef rtc_alarm;
lvagasi 0:28b9efbdeffc 216 int tmp_date, tmp_sec;
lvagasi 0:28b9efbdeffc 217
lvagasi 0:28b9efbdeffc 218 char tt[16];
lvagasi 0:28b9efbdeffc 219
lvagasi 0:28b9efbdeffc 220 R_LED = 1;
lvagasi 0:28b9efbdeffc 221 G_LED = 1;
lvagasi 0:28b9efbdeffc 222 B_LED = 1;
lvagasi 0:28b9efbdeffc 223
lvagasi 0:28b9efbdeffc 224 __GPIOC_CLK_ENABLE();
lvagasi 0:28b9efbdeffc 225 keypadInit.Pin = cols[0] | cols[1] | cols[2];
lvagasi 0:28b9efbdeffc 226 keypadInit.Mode = GPIO_MODE_OUTPUT_OD;
lvagasi 0:28b9efbdeffc 227 keypadInit.Pull = GPIO_NOPULL;
lvagasi 0:28b9efbdeffc 228 keypadInit.Speed = GPIO_SPEED_MEDIUM;
lvagasi 0:28b9efbdeffc 229 HAL_GPIO_Init(GPIOC, &keypadInit);
lvagasi 0:28b9efbdeffc 230
lvagasi 0:28b9efbdeffc 231 HAL_GPIO_WritePin(GPIOC, cols[0] | cols[1] | cols[2], GPIO_PIN_RESET);
lvagasi 0:28b9efbdeffc 232
lvagasi 0:28b9efbdeffc 233 keypadInit.Pin = rows[0] | rows[1] | rows[2] | rows[3];
lvagasi 0:28b9efbdeffc 234 keypadInit.Mode = GPIO_MODE_IT_FALLING;
lvagasi 0:28b9efbdeffc 235 keypadInit.Pull = GPIO_PULLUP;
lvagasi 0:28b9efbdeffc 236 HAL_GPIO_Init(GPIOC, &keypadInit);
lvagasi 0:28b9efbdeffc 237 NVIC_SetVector(EXTI9_5_IRQn, (uint32_t)EXTI9_5_IRQHandler);
lvagasi 0:28b9efbdeffc 238 HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
lvagasi 0:28b9efbdeffc 239
lvagasi 0:28b9efbdeffc 240 NVIC_SetVector(SysTick_IRQn, (uint32_t)SysTick_Handler);
lvagasi 0:28b9efbdeffc 241 HAL_SYSTICK_Config(14400000);
lvagasi 0:28b9efbdeffc 242
lvagasi 0:28b9efbdeffc 243 rtc_init.AsynchPrediv = 0x7F;
lvagasi 0:28b9efbdeffc 244 rtc_init.SynchPrediv = 0xFF;
lvagasi 0:28b9efbdeffc 245 rtc_init.HourFormat = RTC_HOURFORMAT_24;
lvagasi 0:28b9efbdeffc 246 rtc_init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
lvagasi 0:28b9efbdeffc 247 rtc_init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
lvagasi 0:28b9efbdeffc 248 rtc_init.OutPut = RTC_OUTPUT_DISABLE;
lvagasi 0:28b9efbdeffc 249
lvagasi 0:28b9efbdeffc 250 rtc_date.Date = 13;
lvagasi 0:28b9efbdeffc 251 rtc_date.Month = 9;
lvagasi 0:28b9efbdeffc 252 rtc_date.WeekDay = 7;
lvagasi 0:28b9efbdeffc 253 rtc_date.Year = 15;
lvagasi 0:28b9efbdeffc 254 tmp_date = 13;
lvagasi 0:28b9efbdeffc 255
lvagasi 0:28b9efbdeffc 256 rtc_time.DayLightSaving = RTC_DAYLIGHTSAVING_ADD1H;
lvagasi 0:28b9efbdeffc 257 rtc_time.Hours = 22;
lvagasi 0:28b9efbdeffc 258 rtc_time.Minutes = 37;
lvagasi 0:28b9efbdeffc 259 rtc_time.Seconds = 00;
lvagasi 0:28b9efbdeffc 260 rtc_time.StoreOperation =RTC_STOREOPERATION_SET;
lvagasi 0:28b9efbdeffc 261 tmp_sec = 0;
lvagasi 0:28b9efbdeffc 262
lvagasi 0:28b9efbdeffc 263 rtch.Instance = RTC;
lvagasi 0:28b9efbdeffc 264 rtch.Init = rtc_init;
lvagasi 0:28b9efbdeffc 265 rtch.Lock = HAL_lock;
lvagasi 0:28b9efbdeffc 266 rtch.State = rtc_state;
lvagasi 0:28b9efbdeffc 267
lvagasi 0:28b9efbdeffc 268
lvagasi 0:28b9efbdeffc 269 __PWR_CLK_ENABLE();
lvagasi 0:28b9efbdeffc 270 HAL_PWR_EnableBkUpAccess();
lvagasi 0:28b9efbdeffc 271 __HAL_RTC_WRITEPROTECTION_DISABLE(&rtch);
lvagasi 0:28b9efbdeffc 272 __HAL_RCC_LSE_CONFIG(RCC_LSE_ON);
lvagasi 0:28b9efbdeffc 273 __HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_LSE);
lvagasi 0:28b9efbdeffc 274 HAL_RTC_Init(&rtch);
lvagasi 0:28b9efbdeffc 275 HAL_RTC_SetDate(&rtch, &rtc_date, FORMAT_BIN);
lvagasi 0:28b9efbdeffc 276 HAL_RTC_SetTime(&rtch, &rtc_time, FORMAT_BIN);
lvagasi 0:28b9efbdeffc 277 __HAL_RCC_RTC_ENABLE();
lvagasi 0:28b9efbdeffc 278
lvagasi 0:28b9efbdeffc 279 __enable_irq();
lvagasi 0:28b9efbdeffc 280
lvagasi 0:28b9efbdeffc 281 pc.printf("\f\033[00m\033[33mmbed Clock with STM32F303RE NUCLEO board\033[00m\r\n");
lvagasi 0:28b9efbdeffc 282 currentHclk = HAL_RCC_GetHCLKFreq();
lvagasi 0:28b9efbdeffc 283 pc.printf("Current HCLK is: %d\r\n",currentHclk);
lvagasi 0:28b9efbdeffc 284 /* speaker.period(1.0/864.0);
lvagasi 0:28b9efbdeffc 285 speaker = 0.5;
lvagasi 0:28b9efbdeffc 286 wait(0.1);
lvagasi 0:28b9efbdeffc 287 speaker = 0.0;
lvagasi 0:28b9efbdeffc 288 */
lvagasi 0:28b9efbdeffc 289
lvagasi 0:28b9efbdeffc 290 init_ser_lcd();
lvagasi 0:28b9efbdeffc 291 write_ser_lcd(0x80, false); // set DDRAM addr to 0x00
lvagasi 0:28b9efbdeffc 292 write_ser_text((unsigned char *)"Hello", 5);
lvagasi 0:28b9efbdeffc 293 write_ser_lcd(0xC0, false); // set DDRAM addr to 0x40, beginning of 2nd line
lvagasi 0:28b9efbdeffc 294 write_ser_text((unsigned char *)"Teszt",5);
lvagasi 0:28b9efbdeffc 295
lvagasi 0:28b9efbdeffc 296 wait(2.0);
lvagasi 0:28b9efbdeffc 297
lvagasi 0:28b9efbdeffc 298 write_ser_lcd(0x01, false); // Clear display
lvagasi 0:28b9efbdeffc 299 wait_us(30);
lvagasi 0:28b9efbdeffc 300 write_ser_lcd(0x06, false); // Entry mode set
lvagasi 0:28b9efbdeffc 301 wait_us(30);
lvagasi 0:28b9efbdeffc 302 write_ser_lcd(0x80, false); // set DDRAM addr to 0x00, beginning of 1st line
lvagasi 0:28b9efbdeffc 303 wait_us(30);
lvagasi 0:28b9efbdeffc 304 write_ser_text((unsigned char *)"2015.09.12. Szo", 15);
lvagasi 0:28b9efbdeffc 305 write_ser_lcd(0xC0, false); // set DDRAM addr to 0x40, beginning of 2nd line
lvagasi 0:28b9efbdeffc 306 wait_us(30);
lvagasi 0:28b9efbdeffc 307 write_ser_text((unsigned char *)"23:24:56 23.2", 13);
lvagasi 0:28b9efbdeffc 308 write_ser_lcd(0xDF, true);
lvagasi 0:28b9efbdeffc 309
lvagasi 0:28b9efbdeffc 310 while (1) {
lvagasi 0:28b9efbdeffc 311 if (new_key != 0) {
lvagasi 0:28b9efbdeffc 312 if (Index < 0xFF) {
lvagasi 0:28b9efbdeffc 313 pc.printf("Key pressed: %c\r\n",Keytable[Index]);
lvagasi 0:28b9efbdeffc 314 write_ser_lcd(0xCF, false); // set DDRAM addr to 0x4F, end of 2nd line
lvagasi 0:28b9efbdeffc 315 write_ser_lcd(Keytable[Index], true);
lvagasi 0:28b9efbdeffc 316 } else {
lvagasi 0:28b9efbdeffc 317 pc.printf("Incorrect Index value!\r\n");
lvagasi 0:28b9efbdeffc 318 }
lvagasi 0:28b9efbdeffc 319 if (new_key > 1) {
lvagasi 0:28b9efbdeffc 320 pc.printf("There were missed keys: %d\r\n",new_key);
lvagasi 0:28b9efbdeffc 321 }
lvagasi 0:28b9efbdeffc 322 new_key = 0;
lvagasi 0:28b9efbdeffc 323 Index = 0xFF;
lvagasi 0:28b9efbdeffc 324 HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
lvagasi 0:28b9efbdeffc 325 }
lvagasi 0:28b9efbdeffc 326
lvagasi 0:28b9efbdeffc 327
lvagasi 0:28b9efbdeffc 328 HAL_RTC_GetTime(&rtch, &rtc_time, FORMAT_BCD);
lvagasi 0:28b9efbdeffc 329 if (rtc_time.Seconds != tmp_sec) {
lvagasi 0:28b9efbdeffc 330 tt[0] = BCD2HEX[((rtc_time.Hours & 0xF0) >> 4)];
lvagasi 0:28b9efbdeffc 331 tt[1] = BCD2HEX[(rtc_time.Hours & 0x0F)];
lvagasi 0:28b9efbdeffc 332 tt[2] = ':';
lvagasi 0:28b9efbdeffc 333 tt[3] = BCD2HEX[((rtc_time.Minutes & 0xF0) >> 4)];
lvagasi 0:28b9efbdeffc 334 tt[4] = BCD2HEX[(rtc_time.Minutes & 0x0F)];
lvagasi 0:28b9efbdeffc 335 tt[5] = ':';
lvagasi 0:28b9efbdeffc 336 tt[6] = BCD2HEX[((rtc_time.Seconds & 0xF0) >> 4)];
lvagasi 0:28b9efbdeffc 337 tt[7] = BCD2HEX[(rtc_time.Seconds & 0x0F)];
lvagasi 0:28b9efbdeffc 338 write_ser_lcd(0xC0, false);
lvagasi 0:28b9efbdeffc 339 write_ser_text((unsigned char *)tt, 8);
lvagasi 0:28b9efbdeffc 340
lvagasi 0:28b9efbdeffc 341 }
lvagasi 0:28b9efbdeffc 342
lvagasi 0:28b9efbdeffc 343 //HAL_RTC_GetDate(&rtch, &rtc_date, FORMAT_BIN);
lvagasi 0:28b9efbdeffc 344
lvagasi 0:28b9efbdeffc 345 if (Systck_cnt > 5) {
lvagasi 0:28b9efbdeffc 346 switch (RGB_sel % 3) {
lvagasi 0:28b9efbdeffc 347 case 0:
lvagasi 0:28b9efbdeffc 348 R_LED = 0;
lvagasi 0:28b9efbdeffc 349 G_LED = 1;
lvagasi 0:28b9efbdeffc 350 B_LED = 1;
lvagasi 0:28b9efbdeffc 351 break;
lvagasi 0:28b9efbdeffc 352 case 1:
lvagasi 0:28b9efbdeffc 353 R_LED = 1;
lvagasi 0:28b9efbdeffc 354 G_LED = 0;
lvagasi 0:28b9efbdeffc 355 B_LED = 1;
lvagasi 0:28b9efbdeffc 356 break;
lvagasi 0:28b9efbdeffc 357 case 2:
lvagasi 0:28b9efbdeffc 358 R_LED = 1;
lvagasi 0:28b9efbdeffc 359 G_LED = 1;
lvagasi 0:28b9efbdeffc 360 B_LED = 0;
lvagasi 0:28b9efbdeffc 361 break;
lvagasi 0:28b9efbdeffc 362 default:
lvagasi 0:28b9efbdeffc 363 R_LED = 1;
lvagasi 0:28b9efbdeffc 364 G_LED = 1;
lvagasi 0:28b9efbdeffc 365 B_LED = 1;
lvagasi 0:28b9efbdeffc 366 break;
lvagasi 0:28b9efbdeffc 367 }
lvagasi 0:28b9efbdeffc 368 RGB_sel++;
lvagasi 0:28b9efbdeffc 369 Systck_cnt = 0;
lvagasi 0:28b9efbdeffc 370 }
lvagasi 0:28b9efbdeffc 371 //HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
lvagasi 0:28b9efbdeffc 372 __WFI();
lvagasi 0:28b9efbdeffc 373 }
lvagasi 0:28b9efbdeffc 374 }