cancel
Showing results for 
Search instead for 
Did you mean: 

Trouble getting correct data and position of data on 16x2 HD44780 LCD

AVINASH PATHAK
Associate II

Hi,

I have made a code in keil using CMSIS for 16x2 LCD.I am not able to get corresponding data according to data send on the data port.I was unable to identify the problem.

I have checked the data the GPIO port is getting is correct,but LCD shows some other data.

Can somebody help to identify the problem?

Code:-

#include "stm32l4xx.h"

/*

PA0 --->PA7 PORT FOR DATA

RS--->PC0

EN--->PC2

RW--->PC1

*/

void lcdcmd( uint8_t);

void lcddata(uint8_t);

long int i;

int x=0x80;

RCC_TypeDef *clock;

GPIO_TypeDef *GPIO;

GPIO_TypeDef *GPIO1;

//clock=RCC;

//GPIO=GPIOA;

int main(){

/*RCC_TypeDef *clock;

GPIO_TypeDef *GPIO;*/

clock=RCC;

GPIO=GPIOA;

GPIO1=GPIOC;

clock->CR &=0x00000000;

clock->CR |=(1<<16);

while(!((clock->CR)&(1<<17)));

clock->CFGR &=0x00000000;

clock->CFGR|=0x0A0;

clock->AHB2ENR&=0x00000000;

clock->AHB2ENR|=0x05;

GPIO->MODER &=0xABFFFFFF;

GPIO->MODER &=0xABFF5555;

GPIO1->MODER &=0xFFFFFFFF;

GPIO1->MODER &=0xFFFFF15;

GPIO->OTYPER &=0x00000000;

GPIO1->OTYPER &=0x00000000;

GPIO->OSPEEDR|=0x0C000000;

GPIO1->OSPEEDR|=0x00000000;

GPIO->ODR &=0x00000000;

GPIO1->ODR =0x00000000;

lcdcmd(0x38);

for(uint32_t i=0;i<15001;i++);//wait for 15 ms

lcdcmd(0x38);

for(uint32_t i=0;i<5001;i++);

lcdcmd(0x38);

for(uint32_t i=0;i<51;i++);

lcdcmd(0x0F);

lcdcmd(0x01);

lcdcmd(0x80);

lcddata('a');

while(1){

}

}

void lcdcmd(

uint8_t cmd)

{

GPIO1->ODR &= ~((1U<<0)|(1U<<1));//RS OFF

GPIO1->ODR |= (1U<<2);//EN ON

for( i=0;i<11;i++)__ASM("NOP");

GPIO->ODR=cmd;

GPIO1->ODR &=~( (1U<<0)|(1U<<1)|(1U<<2));//EN OFF

for( i=0;i<11;i++)__ASM("NOP");

}

void lcddata( uint8_t data)

{

GPIO1->ODR |= (1U<<0);//RS ON

GPIO1->ODR &= ~(1U<<1);//PC2 OFF OR RW OFF

GPIO1->ODR |= (1U<<2);//EN ON

for( i=0;i<11;i++)__ASM("NOP");

GPIO->ODR=data;

GPIO1->ODR &= ~((1U<<2)|(1U<<1));//EN OFF

for( i=0;i<11;i++)__ASM("NOP");

}

0 REPLIES 0