I am trying to print the word hello on the LCD screen, but it is not working and I don't know why, although I am copying the code from a book for Nucleo board. i know it is a silly question, but I have just started :)
#include <stdio.h>
#include <stdint.h>
#include "stm32f4xx.h"
void delayMs(int n);
void LCD_init(void);
void PORTS_init(void);
void LCD_DATA(char DATA);
void LCD_commands(unsigned char commands);
int main(void){
LCD_init();
LCD_DATA('l');
LCD_DATA('o');
delayMs(1000);
while(1) {
/* Write "hello" on LCD */ LCD_DATA('h');
LCD_DATA('e');
LCD_DATA('l');
/* clear LCD display */ LCD_commands(1);
delayMs(500);
}}
void LCD_init(void){
PORTS_init();
delayMs(30); /* initialization sequence */ LCD_commands(0x30);
delayMs(10);
LCD_commands(0x30);
delayMs(1);
LCD_commands(0x30);
LCD_commands(0x38); /* set 8-bit data, 2-line, 5x7 font */
LCD_commands(0x06); /* move cursor right after each char */
LCD_commands(0x01); /* clear screen, move cursor to home */
LCD_commands(0x0F);
}
void PORTS_init(){
RCC->AHB1ENR |=0x06;
GPIOC->MODER &=!(0x0000FFFF);
GPIOC->MODER |= 0x00005555;
GPIOB->MODER &=!(0x0000FC00);
GPIOB->MODER |= (0x00005400);
GPIOB->BSRR = 0x00C00000;
}
void LCD_commands(unsigned char commands){
GPIOB->BSRR |=(0x60 << 16);
GPIOC->ODR |=commands;
GPIOB->BSRR |=0x80;
delayMs(0);
GPIOB->BSRR |=0x80 << 16;
if (commands < 4)
delayMs(2); /* commands 1 and 2 needs up to 1.64ms */
else
delayMs(1);
}
void LCD_DATA(char DATA){
GPIOB->BSRR |= (0x20);
GPIOB->BSRR |= (0x40 <<16);
GPIOC->ODR |=DATA;
GPIOB->BSRR |=0x80;
delayMs(0);
GPIOB->BSRR |=0x80 << 16;
}
void delayMs(int n) {
int i;
for (; n > 0; n--)
for (i = 0; i < 3195; i++) ;
}