Setting up HD44780 on STM32F103R6
Hello everyone,
I am trying to make an LM020L work in Proteus. I am using Eclipse to code.
I am trying to follow the datasheet for the initialization of the LCD and set the cursor at the beginning. This is where I found info: https://web.alfredstate.edu/faculty/weimandn/lcd/lcd_initialization/lcd_initialization_index.html
I want to use 4-bit mode.
Here is my current code:
void resetlcd(void){
GPIOB->BSRR &= ~(GPIO_BSRR_BS9); //RS
GPIOB->BSRR &= ~(GPIO_BSRR_BS10); //RW
GPIOB->BSRR &= ~(GPIO_BSRR_BS11); //E
GPIOB->BSRR &= ~(GPIO_BSRR_BS12); //D4
GPIOB->BSRR &= ~(GPIO_BSRR_BS13); //D5
GPIOB->BSRR &= ~(GPIO_BSRR_BS14); //D6
GPIOB->BSRR &= ~(GPIO_BSRR_BS15); //D7
GPIOB->BSRR |= (GPIO_BSRR_BR9);
GPIOB->BSRR |= (GPIO_BSRR_BR10);
GPIOB->BSRR |= (GPIO_BSRR_BR11);
GPIOB->BSRR |= (GPIO_BSRR_BR12);
GPIOB->BSRR |= (GPIO_BSRR_BR13);
GPIOB->BSRR |= (GPIO_BSRR_BR14);
GPIOB->BSRR |= (GPIO_BSRR_BR15);
}
void LCD_Init(void){
// Ukljuciti takt za dati Port -> Enable the peripheral clock of GPIO Port X
RCC->APB2ENR |= RCC_APB2ENR_IOPBEN; // Enable the peripheral clock of GPIO Port C
GPIOB->CRH &= ~(GPIO_CRH_MODE9 | GPIO_CRH_CNF9); // delete settings for PB9
GPIOB->CRH |= (GPIO_CRH_MODE9_1 | GPIO_CRH_CNF9_0); //GPO Push-pull
GPIOB->CRH &= ~(GPIO_CRH_MODE10 | GPIO_CRH_CNF10); // delete settings for PB10
GPIOB->CRH |= (GPIO_CRH_MODE10_1 | GPIO_CRH_CNF10_0); //GPO Push-pull
GPIOB->CRH &= ~(GPIO_CRH_MODE11 | GPIO_CRH_CNF11); // delete settings for PB11
GPIOB->CRH |= (GPIO_CRH_MODE11_1 | GPIO_CRH_CNF11_0); //GPO Push-pull
GPIOB->CRH &= ~(GPIO_CRH_MODE12 | GPIO_CRH_CNF12); //delete settings for PB12
GPIOB->CRH |= (GPIO_CRH_MODE12_1 | GPIO_CRH_CNF12_0); //GPO Push-pull
GPIOB->CRH &= ~(GPIO_CRH_MODE13 | GPIO_CRH_CNF13); // brisemo podesavanja za PB13
GPIOB->CRH |= (GPIO_CRH_MODE13_1 | GPIO_CRH_CNF13_0); //GPO Push-pull
GPIOB->CRH &= ~(GPIO_CRH_MODE14 | GPIO_CRH_CNF14); // brisemo podesavanja za PB14
GPIOB->CRH |= (GPIO_CRH_MODE14_1 | GPIO_CRH_CNF14_0); //GPO Push-pull
GPIOB->CRH &= ~(GPIO_CRH_MODE15 | GPIO_CRH_CNF15); // delete settings for PB15
GPIOB->CRH |= (GPIO_CRH_MODE15_1 | GPIO_CRH_CNF15_0); //GPO Push-pull
delay(20000); // turning on
resetlcd();
delay(10000);
GPIOB->BSRR |= (GPIO_BSRR_BS11); // enable
delay(30000);
GPIOB->BSRR |= (GPIO_BSRR_BS12);
GPIOB->BSRR |= (GPIO_BSRR_BS13);
GPIOB->BSRR &= ~(GPIO_BSRR_BR11); // disable
delay(10000);
resetlcd();
GPIOB->BSRR |= (GPIO_BSRR_BS11); // enable
delay(10000);
GPIOB->BSRR |= (GPIO_BSRR_BS12);
GPIOB->BSRR |= (GPIO_BSRR_BS13);
GPIOB->BSRR &= ~(GPIO_BSRR_BR11); // disable
delay(10000);
resetlcd();
GPIOB->BSRR |= (GPIO_BSRR_BS11); // enable
delay(10000);
GPIOB->BSRR |= (GPIO_BSRR_BS12); //DB4
GPIOB->BSRR |= (GPIO_BSRR_BS13); //DB5
GPIOB->BSRR &= ~(GPIO_BSRR_BR11); // disable
delay(10000);
resetlcd();
GPIOB->BSRR |= (GPIO_BSRR_BS11); // enable
delay(10000);
GPIOB->BSRR |= (GPIO_BSRR_BS13); //DB5
GPIOB->BSRR &= ~(GPIO_BSRR_BR11); // disable
delay(10000);
resetlcd();
GPIOB->BSRR |= (GPIO_BSRR_BS11); // enable
delay(10000);
GPIOB->BSRR |= (GPIO_BSRR_BS13); //DB5
GPIOB->BSRR &= ~(GPIO_BSRR_BR11); // disable
delay(10000);
resetlcd();
GPIOB->BSRR |= (GPIO_BSRR_BS11); // enable
delay(10000);
GPIOB->BSRR &= ~(GPIO_BSRR_BR11); // disable
delay(10000);
//dsp off
resetlcd();
GPIOB->BSRR |= (GPIO_BSRR_BS11); // enable
delay(10000);
GPIOB->BSRR &= ~(GPIO_BSRR_BR11); // disable
delay(10000);
GPIOB->BSRR |= (GPIO_BSRR_BS11); // enable
delay(10000);
GPIOB->BSRR |= (GPIO_BSRR_BS15); //DB7
GPIOB->BSRR &= ~(GPIO_BSRR_BR11); // disable
delay(10000);
//dsp on
resetlcd();
GPIOB->BSRR |= (GPIO_BSRR_BS11); // enable
delay(10000);
GPIOB->BSRR &= ~(GPIO_BSRR_BR11); // disable
delay(10000);
GPIOB->BSRR |= (GPIO_BSRR_BS11); // enable
GPIOB->BSRR |= (GPIO_BSRR_BS12); //DB4
GPIOB->BSRR &= ~(GPIO_BSRR_BR11); // disable
delay(10000);
//entry mode set
resetlcd();
delay(10000);
GPIOB->BSRR |= (GPIO_BSRR_BS11); // enable
delay(10000);
GPIOB->BSRR &= ~(GPIO_BSRR_BR11); // disable
resetlcd();
delay(10000);
GPIOB->BSRR |= (GPIO_BSRR_BS11); // enable
delay(10000);
GPIOB->BSRR |= (GPIO_BSRR_BS12); //DB4
GPIOB->BSRR |= (GPIO_BSRR_BS13); //DB5
GPIOB->BSRR |= (GPIO_BSRR_BS14); //DB6
GPIOB->BSRR &= ~(GPIO_BSRR_BR11); // disable
delay(100000);
resetlcd();
}Can anybody tell what went wrong? Also, I would appreciate it if someone can help me to write a simple "Hello world" message, that is my goal but I am currently stuck on the initialization.
