Help in ports configuration

Thread Starter

FZA

Joined Jul 31, 2007
5
Hi i am using C8051F226 to program a 8x2 LCD in C language... I am using Port 3.0-3.7 to DB0-DB7 (Data Bus pins),Port 2.5 for RS ( Register Select pin),Port 2.6 for RW (Read/Write pin) and Port 2.7 for E (Enable pin)...I need help in configuring the ports..My LCD keep on displaying "rows of square dots" even though i had already initialize it...Below is how i configure the ports...I am just wondering whether I am configuring the ports correctly? It would be grateful if you guys can tell me.
Thanks.


// Configure the PRTnMX Registers
PRT0MX = 0x00; // PRT0MX: Initial Reset Value
PRT1MX = 0x00; // PRT1MX: Initial Reset Value
PRT2MX = 0x00; // PRT2MX: Initial Reset Value

// Port configuration (1 = Push Pull Output)
PRT0CF = 0x00; // Output configuration for P0
PRT1CF = 0x00; // Output configuration for P1
PRT2CF = 0x00; // Output configuration for P2
PRT3CF = 0xFF; // Output configuration for P3

P0MODE = 0xFF; // Input configuration for P0
P1MODE = 0xFF; // Input configuration for P1
P2MODE = 0xFF; // Input configuration for P2
P3MODE = 0xFF; // Input configuration for P3
 

Thread Starter

FZA

Joined Jul 31, 2007
5
I don't really have a schematic of my hook ups from my ports... Below i have pdf files on the attachments of the pin assignment of the LCD and you can find the schematic of the C8051F226 target board in the C8051F2xx-DK.pdf ... The way I connected the LCD to the 8051 is something like in the picture that I had attached...I am using PC0802-A LCD from Powertip.
 

Attachments

hgmjr

Joined Jan 28, 2005
9,027
Here is a good link to LCD INFO that may be helpful...

One thing that can cause the dark squares is that the contrast setting is misadjusted. You may want to try turning the contrast control down.

hgmjr
 

Thread Starter

FZA

Joined Jul 31, 2007
5
Here is a good link to LCD INFO that may be helpful...

One thing that can cause the dark squares is that the contrast setting is misadjusted. You may want to try turning the contrast control down.

hgmjr
Ok i have already turned down the contrast down and the LCD did display but not the things that i want...Sometimes my LCD will not display anything and sometimes it will display something but it may take some time to display... Also it will display things like for eg. i wanted to display 'hi" on my LCD instead it display some letters,spreading all over the LCD...
 

Thread Starter

FZA

Joined Jul 31, 2007
5
@FZA can i see your program? i mean complete program..
These are my program:

Rich (BB code):
//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------
#include <c8051F200.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
//-----------------------------------------------------------------------------
// Global CONSTANTS
//-----------------------------------------------------------------------------
	unsigned int q;

	sbit RS = P2^5; 	// RS (Register Select) for Port 2.5
	sbit RW = P2^6; 	// RW for Port 2.6
	sbit E = P2^7; 		// Enable for Port 2.7

	sbit DB0 = P3^0;	//DB = Data bus 
	sbit DB1 = P3^1;
	sbit DB2 = P3^2;
	sbit DB3 = P3^3;
	sbit DB4 = P3^4;
	sbit DB5 = P3^5;
	sbit DB6 = P3^6;
	sbit DB7 = P3^7;

//-----------------------------------------------------------------------------
// Function PROTOTYPES
//-----------------------------------------------------------------------------
void config(void);
void delay (unsigned int duration);
void enable();
void lcdinit (void);
void command(unsigned char m);
void print(unsigned char k);
void hi();

//------------------------------------------------------------------------------------
// Generating Delay
//------------------------------------------------------------------------------------
void delay (unsigned int duration)
{
   while (duration--!=0);
}

//------------------------------------------------------------------------------------
// Enable
//------------------------------------------------------------------------------------
void enable()
{
	E = 1;
	delay(100);
	E = 0;
	delay(100);
}

//------------------------------------------------------------------------------------
// Initialize LCD
//------------------------------------------------------------------------------------
void lcdinit(void)
{

		E = 0;
  		RS = 0;
  		RW = 0;

  P3 = 0x38;		 //Function Set (8 bits,2 lines,5x7 fonts)
  enable();     
  P3 = 0x08; 	//Off Display 
  enable();	
  P3 = 0x06; 	//Entry Mode (increment cursor,no shift display)                                          
  enable(); 	
  P3 = 0x01; 	// Clear Display
  enable(); 
  P3 = 0x0C;	//Display On
  enable();
}

//------------------------------------------------------------------------------------
// Command Character to LCD 
//------------------------------------------------------------------------------------
void command(unsigned char m)
{
	P3 = m;
	RS = 0;
	RW = 0;
	enable();
}

//------------------------------------------------------------------------------------
// Print Character to LCD
//------------------------------------------------------------------------------------
void print(unsigned char k) 	
{
	P3 = k;
	RS = 1;
	RW = 0;
	enable();	
}

//------------------------------------------------------------------------------------
// Array for printing "HI"
//------------------------------------------------------------------------------------
void hi()
{
	unsigned char words[] = "hi";
	for(q=0;q<3;q++)	//3 character stored
	{
		print(words[q]);
	}
}


//-----------------------------------------------------------------------------
// MAIN Routine
//-----------------------------------------------------------------------------

void main()
{
  config();

  lcdinit();	//Initialize LCD
  command(0x80);
  hi();
  delay(500000);
}
 

nanovate

Joined May 7, 2007
666
Quasi-bidirectional is alll you get chum
Do you mean quasi-bidirectional as in there is a weak pull-up always enabled?


That is true of the older 8051s but Silabs (and others) have push-pull outputs available (along with many other enhancements).

please see:

8051 "bible"
http://www.nxp.com/acrobat_download/various/80C51_FAM_HARDWARE_1.pdf

and

OP's device datasheet
http://www.silabs.com/public/documents/tpub_doc/dsheet/Microcontrollers/Small_Form_Factor/en/C8051F2xx.pdf

You'll probably agree they've come a long way :)

John
 
Top