LCD 1602A w/o library

I've been trying to interface my 16x2 lcd display, from arduino starter kit, without the LiquidCrystal library for a while... well.. I already made my own "library" and code for 4b interface, that I tried on ATMega2560 and it worked. But whenever I try to use it on my Arduino UNO, I can't even get past the initialization. I've tried a lot of things, even starting from scratch.

Could it be something with the ports? I have connected the LCD pins DB7-DB4 to digital pins 7-4, E to 3, RS to 2 (PortD according to arduino port manipulation page), which shouldn't be a problem (?). (Helloworld and all the other lcd example codes work)

Has anyone tried interfacing lcd with arduino uno without library and succeded? I know there are a lot of topics on this if you google for it, but none of them worked. I wrote the program from scratch several times.

And for anyone asking: No, i CAN'T use the LiquidCrystal library. It's something that I've been asked to do in C. Even though I can't use C properly...

#define DB7		7
#define DB6		6
#define DB5		5
#define DB4		4
#define Enable		3
#define RS		2
#define LCD_out	PORTD

		/* cbi sbi */
		
#define sbi(k,b) k|=(1<<b)
#define cbi(k,b) k&=~(1>>b)

void LCD_send (uint8_t lcd_reg);
void LCD_init_4b();
void LCD_char (char lcd_data);

uint8_t i;
char name[] ="name xyz";
char smth[] ="insert smth ";

int main(void) {
	DDRD = 0b11111100; // RX, TX 0
	LCD_init_4b;
	for (i=0; name[i]!=0; i++) {
		LCD_char(name[i]);
	}

	LCD_send(0xC0);	//2nd line
	_delay_ms(3);
	LCD_send(0);
	
	for (i=0; smth[i]!=0; i++) {
		LCD_char(smth[i]);
	}
}

void LCD_send(uint8_t lcd_reg) {
	LCD_out = lcd_reg;
	sbi(LCD_out,Enable);
	_delay_us(1);
	cbi(LCD_out,Enable);
	_delay_us(40);
}

		/* 4b interface init */
		
void LCD_init_4b() {
	for (uint8_t lcd_i=0; lcd_i<40; lcd_i++) {
		_delay_ms(16);
	}
	LCD_send(1<<DB5);	// First setup according to docs
	LCD_send(1<<DB5);	// Twice
	LCD_send(1<<DB7);	// 2line mode, 5x7
	_delay_us(60);
	LCD_send(0);		
	
	LCD_send((1<<DB7)|(1<<DB6)|(1<<DB5));	//Display,cursor,blink ON
	_delay_us(60);
	LCD_send(0);
	
	LCD_send(1<<DB4);
	_delay_ms(3);
	LCD_send(0);
	
	LCD_send((1<<DB6)|(1<<DB5));	// increment, shift off
	_delay_ms(3);
	LCD_send(0);
	
	LCD_send(0x80);	// first line
	_delay_ms(3);
	LCD_send(0);
}

		/* Char print */

void LCD_char (char lcd_data) {
	LCD_send(( (int) lcd_data & 0xF0) | (1<<RS));
	_delay_us(50);
	LCD_send((( (int) lcd_data << 4) & 0xF0) | (1<<RS));
	_delay_us(50);
}

This is my last program that I used (and worked on ATMega2560).. I tried to make it as simple as possible, yet it failed.
Some delays are unnecessary. It's been a month and I have no idea, what am I doing wrong.

Can you post the version of the code you say you are using successfully on the ATMega2560 ?
Your cbi macro looks odd to me. Are the chevrons correct ?
And maybe this: LCD_init_4b; should be this: LCD_init_4b() ;

Have you tried 'Googling' for the phrase "LCD Programming Examples". In the US the first hit takes you here.

I can vouch for the code, it has been working literally for decades.

Don

Agree with 6V6GT, cbi shift is wrong direction

AVR Libc Reference

6v6gt:
Can you post the version of the code you say you are using successfully on the ATMega2560 ?
Your cbi macro looks odd to me. Are the chevrons correct ?
And maybe this: LCD_init_4b; should be this: LCD_init_4b() ;

That is the version I've been using.. I just translated some words, so the code doesn't look like some random non-sense words to you. And yeah, I've had the (); after the function.. Not even compiler would take it without the (). Sorry, forgot to put it there while rewriting some of those words.
Also.. Fixed the macro. No idea how it worked on the ATMega

floresta:
Have you tried 'Googling' for the phrase "LCD Programming Examples". In the US the first hit takes you here.

I can vouch for the code, it has been working literally for decades.

Don

Been there, done that. Unforunately that code looks a little bit.. too complicated for what I need. (?) Maybe I've been trying to make the code too simple. Well. Guess I'll start from scratch again. Thanks

Weirdoh:
. . .
Been there, done that. Unforunately that code looks a little bit.. too complicated for what I need. (?) Maybe I've been trying to make the code too simple. Well. Guess I'll start from scratch again. Thanks

It is what is needed to make the device work, keep in mind that that code works and yours does not.

You might want to look at the LCD Initialization information at the same site.

Don