Jump to content
43oh

Initiliazing LCD for Stellaris Board.


Recommended Posts

I am having some problems initializing the LCD .
µC I am using is LM3s6965. 

It has to be initialized in 4 bit mode, since 4 pins are only accesible.

these are the ports 

 

PA6/I2CSCL   -  LCD_RW 
PA7/I2CSDA   - LCD_RS 
PB2/I2C0SCL - LCD_D4_KEYB_F 
PB3/I2CSDA   - LCD_D5_KEYB_E 
PB4/C0           - LCD_D6_KEYB_D 
PB5/C1           -  LCD_D7
PB6/C0+         -  LCD_E 
 

This problem is a big pain in the ass..  I would be very gratefull if anyone could find the error on why it is not working. I am of certain it just a minor thing, but i have my doubts.. 

LCD init code (1).zip

Link to post
Share on other sites

Have you checked the data sheet on how long the enable pin needs to be set (or cleared)?

The code and comments are inconsistent about whether enable is active high or active low - so check that.  

("When the code and the documentation do not agree, both are probably wrong.")

 

Assume you validated the while loop timing (that counting that long at current clock speed gives delay stated in comments).

Might consider encapsulating the enable pin behavior in a procedure to make the code easier to work on.

 

There are examples of libraries for this display on this web site, you might take a peek at them if doing so is compatible with assignment instructions.

Link to post
Share on other sites

Thanks for the response

 

My timings is correct, or maybe too long, my for loop take about 1 min to complete on section , this should more than plenty of time. I've made a function which operate the enable pin.  

I am really lost on what should have gone wrong here. 

The one i've used is this one http://web.alfredstate.edu/weimandn/lcd/lcd_initialization/lcd_initialization_index.html

it seems the method is common for all LCD..

Link to post
Share on other sites

Hey Yosef,

some hints:

1) in your systick.c file FPCU define is missing a zero. Your FCPU is 5Mhz but should be 50MHz.

2) You have to pull RS low before writing a instruction, so that the instruction register is selected.

RS Low --> Put Instruction Data on 4 Data Pins --> Enable High --> Wait >42us --> Enable Low --> Wait >42us

Your Enable Pulse is just some Instruction cycles long, on 50Mhz these are just a few nanoseconds. That's way too short.

Link to post
Share on other sites

Since i haven't activated DEN for the RS_PIN I just figured it automatically would be low. 

So would it be fine to keep it low all the time or?

 

I've changed it so my enable_pin is low inside my for loop..

for(i=0,i<1000000;i++)

{

enable_pin(OFF)

}

for(i=0,i<1000000;i++)

{

enable_pin(ON)

}

 

Something like this you were thinking??

 

It is still not working.. 

Link to post
Share on other sites

well... right now i've just ignored the pins on port A...So I am only using PortB

 

Since i haven't activated DEN for the RS_PIN I just figured it automatically would be low.

 

Have you checked that this is the case?  

Often if you do nothing with a pin it will behave similar to an open circuit (i.e. not high, not low, just floating).

(i.e. not a fair assumption unless you have external pulldown resistors, or specific information about the controller in question, etc.)

If I recall the init document you are using said that RS and R/W have to be held low.

Which was why I was looking for where you defined RS and R/W (both on port A) as outputs, and set them to whatever they are supposed to be.

If you are pulling them to desired value with external circuitry that is okay too.

Link to post
Share on other sites

I've changed my GPIO to include Port A. 

 

void init_gpio(void)
{
	  INT8S dummy;

	  // Enable the GPIO port that is used for the on-board LED.
	  SYSCTL_RCGC2_R = SYSCTL_RCGC2_GPIOF | SYSCTL_RCGC2_GPIOG | SYSCTL_RCGC2_GPIOD | SYSCTL_RCGC2_GPIOB |SYSCTL_RCGC2_GPIOA;

	  // Do a dummy read to insert a few cycles after enabling the peripheral.
	  dummy = SYSCTL_RCGC2_R;


	  // Enable the GPIO pins for digital function (PD6, PF0, FP1, PG0 and PG1).
	  GPIO_PORTD_DEN_R |= 0b01000000;			 // Red
	  GPIO_PORTF_DEN_R |= 0b00000001;			 // Select LED
	  GPIO_PORTG_DEN_R |= 0b00000011;			 // Yellow og Green LED
	  GPIO_PORTA_DEN_R |= 0b11000000;    		 // screen   RS = PA7 /RW = PA6
	  GPIO_PORTB_DEN_R |= 0b01000000;	         // Screen	  - enable

	  // Set the direction as output (PF0+PG0+PG1+PD6).
	  GPIO_PORTF_DIR_R |= 0b00000001;   // Select LED
	  GPIO_PORTG_DIR_R |= 0b00000011;   // yellow and Green LED
	  GPIO_PORTD_DIR_R |= 0b01000000;   // Red

	 // GPIO_PORTA_DIR_R |= 0b11000000; // screen
	 GPIO_PORTB_DIR_R |= 0x7E;          // Screen




	 // GPIO_PORTG_DEN_R = 0x03;

	  // Enable internal pull-up (PF1).
	  //GPIO_PORTF_PUR_R = 0x02;
}


And  i Activate RS and RW using my function

void RS_PIN(int a)
{
	if (a)
	{
		GPIO_PORTA_DATA_R &= ~(0b10000000); // Enables  "RS" pin
	}

	else{
		GPIO_PORTA_DATA_R |= (0b10000000); //Disables "RS" pin
	}

}

void RW_pin (int a)
{
	if (a)
		{
			GPIO_PORTA_DATA_R &= ~(0b01000000); // Enables  "RW" pin
		}

		else{
			GPIO_PORTA_DATA_R |= (0b01000000); //Disables "RW "pin
		}

}

So my Screen init look like this 

void screen_init( void )
{
	 //POwer on
	 //MILLISEC(100);
	RW_pin(OFF);
	RS_PIN(OFF);
	yellowLed(ON);
	for(i=0; i<10000000; i++)
	{
		enable_pin(OFF);
	}
	yellowLed(OFF);
	redLed(ON);
	 // Special case Function set
//----------------------------------------------------------------//

	// MILLISEC(1);				// 1 ms delay
	nibble_value(0b00000011); 	// DB5 = 1, DB4 = 1
	for(i=0; i<10000000; i++)
		{
			enable_pin(ON); 			// enable pin on
		}

	for(i=0; i<10000000; i++)
		{
			enable_pin(OFF);
		}
	// MILLISEC(15); 				// 5 ms delay
	GPIO_PORTF_DATA_R ^= 0x01;

	// MILLISEC(1);				// 1 ms delay
    nibble_value(0b00000011);	// DB5 = 1, DB4 = 1
	for(i=0; i<10000000; i++)
	 	{
	 		enable_pin(ON); 			// enable pin on
	 	}

	 for(i=0; i<10000000; i++)
	 	{
	 			enable_pin(OFF);
	 	}
	GPIO_PORTF_DATA_R ^= 0x01;

	// MILLISEC(1);				// 1 ms delay
	 nibble_value(0b00000011);			// DB5 = 1, DB4 = 1
	 for(i=0; i<10000000; i++)
	 	 {
		 	 enable_pin(ON); 			// enable pin on
	 	 }

	 for(i=0; i<10000000; i++)
	 	 {
		 	 enable_pin(OFF);
	 	 }
	GPIO_PORTF_DATA_R ^= 0x01;

//-----------------------------------------------------------------//
	 //initial Function set
//-----------------------------------------------------------------//
	// MILLISEC(1);				// 1 ms delay
	 nibble_value(0b00000010);			// 0x02 = 0b00000010 => DB5 = 1
	 for(i=0; i<10000000; i++)
	 	 {
		 	 enable_pin(ON); 			// enable pin on
	 	 }
	 for(i=0; i<10000000; i++)
	 	 {
		 	 enable_pin(OFF);
	 	 }
	 GPIO_PORTF_DATA_R ^= 0x01;

//----------------------------------------------------------------//
	 //Function set
//----------------------------------------------------------------//
	// MILLISEC(1);				// 1 ms delay
	 nibble_value(0b00000010);			// 0x02 = 0b00000010 => DB5 = 1
	 for(i=0; i<10000000; i++)
	 	 {
		 	 enable_pin(ON); 			// enable pin on
	 	 }

	 for(i=0; i<10000000; i++)
	 	{
		 	 enable_pin(OFF);
	 	}
	GPIO_PORTF_DATA_R ^= 0x01;

	// MILLISEC(1);				// 1 ms delay
	 nibble_value(0b00001000);	// 0x8 = 0b00001000 n = 1 and f = 0 => DB7 = 1
	 for(i=0; i<10000000; i++)
	 	 {
		 	 enable_pin(ON); 			// enable pin on
	 	 }

	 for(i=0; i<10000000; i++)
	 	 {
		 	 enable_pin(OFF);
	 	 }
	GPIO_PORTF_DATA_R ^= 0x01;

//----------------------------------------------------------------//
	 //Display On/Off
//----------------------------------------------------------------//
	// MILLISEC(1);				// delay = 1 ms
	 nibble_value(0b00000000);		// ZERO
	 for(i=0; i<10000000; i++)
	 	{
	 		enable_pin(ON); 			// enable pin on
	 	}

	 for(i=0; i<10000000; i++)
	 	{
			enable_pin(OFF);
	 	}
	 GPIO_PORTF_DATA_R ^= 0x01;

	// MILLISEC(1); 				// delay = 1 ms
	 nibble_value(0b00001000); 		// DB7  = 1 => display off
	 for(i=0; i<10000000; i++)
	 	{
	 		enable_pin(ON); 			// enable pin on
	 	}

	for(i=0; i<10000000; i++)
	 	{
 			enable_pin(OFF);
	 	}
	GPIO_PORTF_DATA_R ^= 0x01;

//---------------------------------------------------------------//
	 //Clear Display
//---------------------------------------------------------------//
	// MILLISEC(1); 				// delay = 1 ms
	 nibble_value(0b00000000); 	// Zero
	 for(i=0; i<10000000; i++)
	 	{
	 		enable_pin(ON); 			// enable pin on
	 	}

   	for(i=0; i<10000000; i++)
	 	{
	 			enable_pin(OFF);
	 	}
	GPIO_PORTF_DATA_R ^= 0x01;

	// MILLISEC(1); 				// delay = 1 ms
	 nibble_value(0b00000001); 	// No configurable bits, CLEAR Display
	 for(i=0; i<10000000; i++)
	 	{
	 		enable_pin(ON); 			// enable pin on
	 	}

	 for(i=0; i<10000000; i++)
	 	{
	 			enable_pin(OFF);
	 	}
	GPIO_PORTF_DATA_R ^= 0x01;

//---------------------------------------------------------------//
	 //Entry Mode set
//---------------------------------------------------------------//
	// MILLISEC(1); 				// delay = 1 ms
	 nibble_value(0b00000000); 	// Zero
	 for(i=0; i<10000000; i++)
	 	{
	 		enable_pin(ON); 			// enable pin on
	 	}

	 for(i=0; i<10000000; i++)
	 	{
	 			enable_pin(OFF);
	 	}
	GPIO_PORTF_DATA_R ^= 0x01;

	// MILLISEC(1); 				// delay = 1 ms
	 nibble_value(0b0000110); 		// DB6 = 1, DB5 = 1 (increment by 1) , DB4 = 0 (No shift)
	 for(i=0; i<10000000; i++)
	 	{
	 		enable_pin(ON); 			// enable pin on
	 	}

	 for(i=0; i<10000000; i++)
	 	{
	 			enable_pin(OFF);
	 	}
	GPIO_PORTF_DATA_R ^= 0x01;

//---------------------------------------------------------------//

//---------------------------------------------------------------//
		 //Instruction
//---------------------------------------------------------------//
		// MILLISEC(1); 				// delay = 1 ms
    nibble_value(0b00000000); 	// Zero
	for(i=0; i<10000000; i++)
		{
				enable_pin(ON); 			// enable pin on
		}

	for(i=0; i<10000000; i++)
	   {
		 	    enable_pin(OFF);
	   }
	GPIO_PORTF_DATA_R ^= 0x01;

		// MILLISEC(1); 				// delay = 1 ms
	nibble_value(0b0001100); 		// DB6 = 1, DB5 = 1 (increment by 1) , DB4 = 0 (No shift)
	for(i=0; i<10000000; i++)
		{
				enable_pin(ON); 			// enable pin on
		}

	for(i=0; i<10000000; i++)
	    {
	 			enable_pin(OFF);
		}
	GPIO_PORTF_DATA_R ^= 0x01;

//---------------------------------------------------------------//

}

Screen init is only runned once. 

Cause it is not working.. :S

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...