Jump to content

Recommended Posts

Hello kind Sourcebost developers

 

last two days I'm getting mad about my LCD driver that I written, cause I can't really make it work and don't know where the problem can be (tried on real device and also in the paid plugin of yours). These are the main functions, the delays are just as in the example for the LCD plugin (asm nop's):

void sendDataToLCD_delay (char data, char rs) {

	RS = rs;
	LCD_SetupDelay();
	LCD = data >> 4; 	// sending left nibble
	E = 1;			// perhaps a little delay will be needed before and after 
	LCD_EnablePulseDelay();
	E = 0;			// pulse Enable H/L to send the data
	LCD_HoldupDelay();
	LCD_CycleMakeupDelay();
	
	RS = rs;
	LCD_SetupDelay();
	LCD = data & 0x0F;	// sending right nibble
	E = 1;			// perhaps a little delay will be needed before and after
	LCD_EnablePulseDelay();
	E = 0;				// pulse Enable H/L to send the data
	LCD_HoldupDelay();
	LCD_CycleMakeupDelay();
}

// Clears the LCD display
void clearLCD (void) {
	sendDataToLCD_delay(clear_lcd, 0);
	delay_ms(2);
}


// initializes the LCD display
void initLCD (void) {
	char a;
	
	//delay_ms(20); // delay_ms(20) before
	delay_ms(16); // delay_ms(20) before
	

	sendDataToLCD_delay(system_set_reset_4bit, 0);
	delay_ms(5);
	sendDataToLCD_delay(system_set_reset_4bit, 0);
	delay_10us(100); // min delay here of 100us
	sendDataToLCD_delay(system_set_reset_4bit, 0);
	delay_10us( 5 ); // standard command delay time
	
	sendDataToLCD_delay(system_set_4_bit, 0);
	delay_10us( 5 ); // standard command delay time
	sendDataToLCD_delay(entry_mode, 0);
	sendDataToLCD_delay(display_on, 0);
	//sendDataToLCD_delay(set_dd_ram, 0);
}

// Sends a string to certain position of the display
void sendStringToLCD (char *s, char pos) {
	int ptr = 0;
	
	sendDataToLCD_delay(set_dd_ram+pos, 0);
	while (s[ptr] != 0)
		sendDataToLCD_delay(s[ptr++], 1);
}

The configuration is for PORTB - PORTB.RB5=E, PORTB.RB4=RS, PORTB.RB0-RB3 - DATA (D4-D7), RW=GND, I think the problem lies in the config, but I can't see it clearly. Could you give me a slight hint, am I missing some operation or do I send the data in a wrong way?

 

Thanks for your help!

 

Midin

Share this post


Link to post
Share on other sites

Hi Midin,

 

I see you have the control and data on the same port. This will cause a few problems if not taken care of properly.

 

When you write the 4 bits of data you are writing all 8 bits therefore over-writing any controls bit you have set previously

such as the RS bit. Which will be reset to a 0 if set before writting the data.

 

Depending upon the type of PIC you are using, you may also suffer from the "read-before-write" gotcha.

 

Try using a port shadow register. When writing new data AND out the old and OR in the new.

Write the shadow register to the port.

 

A few more lines of code but should solve your problems.

 

Cheers

 

Reynard

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

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.

Loading...

×
×
  • Create New...