AnsweredAssumed Answered

have problem with the lcd code (aducm360 in keil)

Question asked by me987 on Mar 21, 2018
Latest reply on Mar 23, 2018 by ABuda

eval_aducm360  aducm360  @ADUCM360 _ADUCM360

lcd4bits _LCD4BIT CODE

 

Hi i am new to this microcontroller.

i am finding problem with the LCD code below

the main problem is with the stability if i press reset of the micro controller odd number of times it works fine and pressing reset even number of time i get rubbish characters

 

#include <stdio.h>
#include <string.h>
#include <ADuCM360.h>
#include <aducm360.h>

#include <..\common\ClkLib.h>
#include <..\common\IntLib.h>
#include <..\common\DioLib.h>
#include <..\common\WdtLib.h>
#include <..\common\WutLib.h>
#include <..\common\GptLib.h>
#include <..\common\DioLib.h>
#include <..\common\PwmLib.h>
#include <..\common\AdcLib.h>
#include <..\common\DacLib.h>

#define LCDRS BIT0
#define LCDRW BIT1
#define LCDEN BIT2
#define PORT_START 4
#define LCD_DATA_MASK (BIT4|BIT5|BIT6|BIT7)
#define MAX_CHAR_IN_ONE_LINE 16

void set_lcd_port_output(void);
void init_lcd(void);

void test_cmd(void);
void lcd_putstring(char line1, char pos1,char *string1,
char line2, char pos2,char *string2);
void lcd_clear(void);
void lcd_backlight_on(void);
int lcd_gotoxy(unsigned int x, unsigned int y);
void lcd_putchar(char c);
void delay1(int count);
void Msdelay(int count);
void lcd_data_write(unsigned char ch);
void lcd_command_write(unsigned char c);
void delay(long int);

void delay (long int length)
{
while (length >0)
length--;
}

void delay1(int count)
{
for(;count>0;count--);
}

void lcd_command_write( unsigned char command )
{
unsigned char temp=0;
unsigned int temp1=0;

temp=command;
temp=(temp>>4)&0x0F;
temp1=(temp<<PORT_START)&LCD_DATA_MASK;

DioClr(pADI_GP2,LCDRS); //CLEAR p0.0
delay1(20);
DioSet(pADI_GP2,LCDEN); //SET p0.1
delay1(20);
DioClr(pADI_GP1,LCD_DATA_MASK); //((mask p1.4 to p1.7))
delay1(20);
DioSet(pADI_GP1,temp1);
delay1(10000);
DioClr(pADI_GP2,LCDEN); //CLEAR p0.1
delay1(100);
temp=command;
temp&=0x0F;
temp1=(temp<<PORT_START)&LCD_DATA_MASK;
delay1(100*2);

DioClr(pADI_GP2,LCDRS);
delay1(20);
DioSet(pADI_GP2,LCDEN);
delay1(20);
DioClr(pADI_GP1,LCD_DATA_MASK);
delay1(20);
DioSet(pADI_GP1,temp1); // CHECK WHETHER ITS GP0 OR GP1
delay1(10000);
DioClr(pADI_GP2,LCDEN); // or else DioClr(pADI_GP0,LCDEN);
delay1(100);
//wait_lcd();
}

void set_lcd_port_output(void)
{
DioOen(pADI_GP2,(LCDEN | LCDRS | LCDRW)); //((OR))(OPTION IS USING DioOenpin(pADI_GP0,PIN0,1); DioOenpin(pADI_GP0,PIN1,1); DioOenpin(pADI_GP0,PIN2,1);
DioClr(pADI_GP2,(LCDEN | LCDRS | LCDRW));
DioOen(pADI_GP1,LCD_DATA_MASK);
DioClr(pADI_GP1,LCD_DATA_MASK);
}

void lcd_clear( void)
{
lcd_command_write( 0x00 );
lcd_command_write( 0x01 );
delay1(100);
}

int lcd_gotoxy( unsigned int x, unsigned int y)
{
int retval = 0;

if( (x > 1) && (y > 15) )
{
retval = -1;
}

else
{

if( x == 0 )
{
lcd_command_write( 0x80 + y ); /* command - position cursor at 0x00 (0x80 + 0x00 ) */
}
else if( x == 1 )
{
lcd_command_write( 0xC0 + y ); /* command - position cursor at 0x40 (0x80 + 0x00 ) */
}
else if( x == 2 )
{
lcd_command_write( 0x94 + y ); /* command - position cursor at 0x40 (0x80 + 0x00 ) */
}
else if( x == 3 )
{
lcd_command_write( 0xD4 + y ); /* command - position cursor at 0x40 (0x80 + 0x00 ) */
}
}
return retval;
}

void lcd_data_write( unsigned char data )
{
unsigned char temp=0;
unsigned int temp1=0;

temp=data;
temp=(temp>>4)&0x0F;
temp1=(temp<<PORT_START)&LCD_DATA_MASK;

DioSet(pADI_GP2,(LCDEN|LCDRS));
delay1(20);
DioClr(pADI_GP1,LCD_DATA_MASK);
delay1(20);
DioSet(pADI_GP1,temp1);
delay1(10000);
DioClr(pADI_GP2,LCDEN);
delay1(100);
temp=data;
temp&=0x0F;
temp1=(temp<<PORT_START)&LCD_DATA_MASK;

DioSet(pADI_GP2,(LCDEN|LCDRS));
delay1(20);
DioClr(pADI_GP1,LCD_DATA_MASK);
delay1(20);
DioSet(pADI_GP1,temp1);
delay1(10000);
DioClr(pADI_GP2,LCDEN);
delay1(100);

// wait_lcd();
}

void init_lcd( void )
{
DioOen(pADI_GP1,(BIT4|BIT5|BIT6|BIT7)); // by default all pins are inputs so COMMENTED THE INSTRUCION..
DioOen(pADI_GP2,(LCDRS|LCDRW|LCDEN));
delay1(20);
}


void test_cmd(void)
{
lcd_command_write(0x28); // Interface length 8-bit 2 line
lcd_command_write(0x0C); //Display on cursor off
lcd_command_write(0x06); //Move cursor right by 1 char
lcd_command_write(0x01); //Clear display
}

void delay(long int);

int main (void)
{
WdtCfg(T3CON_PRE_DIV1,T3CON_IRQ_EN,T3CON_PD_DIS); // Disable Watchdog timer resets
ClkDis(CLKDIS_DISSPI0CLK|CLKDIS_DISSPI1CLK|CLKDIS_DISI2CCLK|CLKDIS_DISDMACLK);
ClkCfg(CLK_CD0,CLK_HF,CLKSYSDIV_DIV2EN_DIS,CLK_UCLKCG); // Select CD0 for CPU clock - 16Mhz clock

 

// init_lcd();
set_lcd_port_output();
test_cmd();

lcd_data_write('t');
delay1(9000000);

lcd_clear();

lcd_data_write('m');
delay1(9000000);

lcd_clear();

}

}

 

 

//and i dint use goto function because that too dint work properly.

kindly findly out the mistake if possible and revert back.

thank you

kindly find the attachment of the code too...

Attachments

Outcomes