Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
09/21/11 03:19
Read: times


 
#183820 - LCD DV16210 interfacing
SiLabs c8051f314 and LCD DV16210 (16x2)
I'm new to programming (C) so used ready initialization code. Unfortunately C code Examples for 4 bit interface for silabs MCU i have not found. I had to adapt the code for the SiLabs c8051f314.
I have tried many different versions of this code but lcd still don't work.

Can somebody help to find what's wrong in this code?

with best regards,
vlad


(Keil uVision4)
#include <C8051F310.H>

// Pin Declarations
//----------------------
#define lcdport P3 // data port (P3^1;P3^2;P3^3;P3^4)


sbit LCD_RS = P1^3;
sbit LCD_EN = P1^4;


volatile unsigned long tmpCnt;

//-----------------------------------------------------------------------------
// Function Prototypes
//-----------------------------------------------------------------------------
void lcd_init(void); //LCD init
void OSCILLATOR_Init (void); 
void PORT_Init (void);

//lcd fuctions
void lcd_write(unsigned char);
void lcd_clear(void);
void lcd_puts(unsigned char * );
void lcd_putch(unsigned char );
void lcd_goto1(unsigned char );

void Delay (unsigned int); 





//-----------------------------------------------------------------------------
// main() Routine
//-----------------------------------------------------------------------------

void main (void)
{
						
OSCILLATOR_Init (); 
PORT_Init ();


lcd_init(); //initialize lcd
lcd_goto1(1); // line1 + 1st place for character

lcd_putch('H');// display ONE character

}



// OSCILLATOR_Init
//-----------------------------------------------------------------------------
void OSCILLATOR_Init (void)
{
OSCICN |= 0x03; // Configure internal oscillator for
// its maximum frequency (24.5 Mhz)
}

// PORT_Init
void PORT_Init (void)
{


P1MDOUT = 0x18; //P1.4, P1.3

P3MDOUT = 0x1E; // P3.1, P3.2, P3.3, P3.4
XBR1 = 0x40; // Enable crossbar and enable

}


void Delay (unsigned int ms)
{
unsigned long tmp;
tmp = ((unsigned long) ms) * 5;
for (tmpCnt = 0; tmpCnt<tmp; tmpCnt++);
}

/////////////////////////////////////
////////////////LCD//////////////////
////////////////////////////////////

/* write a byte to the LCD in 4 bit mode */

void lcd_write(unsigned char c)
{
 P3MDOUT = 0x1E;
lcdport = (c & 0x0F) << 4; //send lower-order nibble
LCD_EN = 1;
Delay(50);//200microseconds
LCD_EN = 0; //LCD_STROBE;
lcdport = (c & 0xF0); // send higher-order nibble
LCD_EN = 1;
Delay(50);//200microseconds
LCD_EN = 0;//LCD_STROBE;

}

/* write one character to the LCD */

void lcd_putch(unsigned char c)
{
LCD_RS =1;	// write characters

lcd_write(c);
}


/*
* Go to the specified position in line 1
*/

void lcd_goto1(unsigned char pos)
{
LCD_RS = 0;

lcd_write(0x80 + pos);
}




/* initialise the LCD - put into 4 bit mode */

void lcd_init(void)
{

PCA0MD &= ~0x40; //watchdog
OSCILLATOR_Init (); 
PORT_Init ();



LCD_RS = 0;	// write control bytes



Delay(3675);// power on delay 15ms

lcd_write(0x03);
Delay(1250);//5ms
lcd_write(0x03);
Delay(1250);//5ms
lcd_write(0x03);
Delay(1250);//5ms

lcd_write(0x02);
Delay(50);//200microseconds
lcd_write(0x01);
Delay(1250);//5ms
lcd_write(0x06);
Delay(50);//200microseconds
lcd_write(0x0E);
Delay(50); //200microseconds
}
 



List of 4 messages in thread
TopicAuthorDate
LCD DV16210 interfacing            01/01/70 00:00      
   I have tried many different versions            01/01/70 00:00      
      testing and debugging            01/01/70 00:00      
   two comments            01/01/70 00:00      

Back to Subject List