A novice question on ST Microcontroller programming with Blue Pill board
I am trying to step into ST Microcontrollers. I have been able to blink LED of Blue Pill. My next attempt to interface 16x2 LCD with Blue Pill. An example code is being studied. In MikroC PIC Compiler control first goes to main() function from where other functions are called. In STM Cube IDE, I cannot understand where control goes first. Also what is the significance of "void delay (unit16_t us)" and "HAL_Delay()". The code is attached. Please help this
#include "LCD.h"
#include "stm32f1xx_hal.h"
/*********** Define the LCD PINS below ****************/
#define RS_Pin GPIO_PIN_1
#define RS_GPIO_Port GPIOA
#define RW_Pin GPIO_PIN_2
#define RW_GPIO_Port GPIOA
#define EN_Pin GPIO_PIN_3
#define EN_GPIO_Port GPIOA
#define D4_Pin GPIO_PIN_4
#define D4_GPIO_Port GPIOA
#define D5_Pin GPIO_PIN_5
#define D5_GPIO_Port GPIOA
#define D6_Pin GPIO_PIN_6
#define D6_GPIO_Port GPIOA
#define D7_Pin GPIO_PIN_7
#define D7_GPIO_Port GPIOA
void delay (uint16_t us)
{
int oo = 0;
while (oo < us) {
oo++;
}
}
/****************************************************************************************************************************************************************/
void send_to_lcd (char data, int rs)
{
HAL_GPIO_WritePin(RS_GPIO_Port, RS_Pin, rs); // rs = 1 for data, rs=0 for command
/* write the data to the respective pin */
HAL_GPIO_WritePin(D7_GPIO_Port, D7_Pin, ((data>>3)&0x01));
HAL_GPIO_WritePin(D6_GPIO_Port, D6_Pin, ((data>>2)&0x01));
HAL_GPIO_WritePin(D5_GPIO_Port, D5_Pin, ((data>>1)&0x01));
HAL_GPIO_WritePin(D4_GPIO_Port, D4_Pin, ((data>>0)&0x01));
HAL_GPIO_WritePin(EN_GPIO_Port, EN_Pin, 1);
HAL_Delay(10);
HAL_GPIO_WritePin(EN_GPIO_Port, EN_Pin, 0);
HAL_Delay(10);
}
void lcd_send_cmd (char cmd)
{
char datatosend;
/* send upper nibble first */
datatosend = ((cmd>>4)&0x0f);
send_to_lcd(datatosend,0); // RS must be 0 while sending command
/* send Lower Nibble */
datatosend = ((cmd)&0x0f);
send_to_lcd(datatosend, 0);
}
void lcd_send_data (char data)
{
char datatosend;
/* send higher nibble */
datatosend = ((data>>4)&0x0f);
send_to_lcd(datatosend, 1); // rs =1 for sending data
/* send Lower nibble */
datatosend = ((data)&0x0f);
send_to_lcd(datatosend, 1);
}
void lcd_clear (void)
{
lcd_send_cmd(0x01);
HAL_Delay(2);
}
void lcd_put_cur(int row, int col)
{
switch (row)
{
case 0:
col |= 0x80;
break;
case 1:
col |= 0xC0;
break;
}
lcd_send_cmd (col);
}
void lcd_init (void)
{
HAL_Delay(10);
lcd_send_cmd (0x02);
lcd_send_cmd (0x28); // Function set --> DL=0 (4 bit mode), N = 1 (2 line display) F = 0 (5x8 characters)
lcd_send_cmd (0x08); //Display on/off control --> D=0,C=0, B=0 ---> display off
lcd_send_cmd (0x01); // clear display
lcd_send_cmd (0x06); //Entry mode set --> I/D = 1 (increment cursor) & S = 0 (no shift)
lcd_send_cmd (0x0C); //Display on/off control --> D = 1, C and B = 0. (Cursor and blink, last two bits)
}
void lcd_send_string (char *str)
{
while (*str) lcd_send_data (*str++);
}
newbie.
