[an error occurred while processing this directive]
Ответ: Вот кусок моего кода
(«Телесистемы»: Конференция «Микроконтроллеры и их применение»)

миниатюрный аудио-видеорекордер mAVR

Отправлено snowman 16 мая 2003 г. 21:24
В ответ на: ЖК не включается с первого раза (Извините за возможный дубликат, но первой месаги почемуто не нашел тут ) отправлено snowman 16 мая 2003 г. 00:42

Вот такая у меня ф-я инициализации(только сильно не пинайте это щас моя первая работа :) )
//некоторые нужные константы :)

#define LCD_ENTRY_INC_ 0x06 /* display shift off, inc cursor move dir */
#define LCD_ENTRY_MODE 2 /* DB2: set entry mode */
/* function set: set interface data length and number of display lines */
#define LCD_FUNCTION_4BIT_1LINE 0x20 /* 4-bit interface, single line, 5x7 dots */
#define LCD_FUNCTION_4BIT_2LINES 0x28 /* 4-bit interface, dual line, 5x7 dots */
#define LCD_FUNCTION_8BIT_1LINE 0x30 /* 8-bit interface, single line, 5x7 dots */
#define LCD_FUNCTION_8BIT_2LINES 0x38 /* 8-bit interface, dual line, 5x7 dots */
/* display on/off, cursor on/off, blinking char at cursor position */
#define LCD_DISP_OFF 0x08 /* display off */
#define LCD_DISP_ON 0x0C /* display on, cursor off */
#define LCD_DISP_ON_CURSOR_BLINK 0x0F /* display on, cursor on, blink char */

#define LCD_FUNCTION_DEFAULT LCD_FUNCTION_4BIT_2LINES
#define LCD_MODE_DEFAULT ((1<
void lcd_init(uint8_t dispAttr)
/* initialize display and select type of cursor */
/* dispAttr: LCD_DISP_OFF, LCD_DISP_ON, LCD_DISP_ON_CURSOR, LCD_DISP_CURSOR_BLINK */
{
/*------ Initialize lcd to 4 bit i/o mode -------*/

outp( 0xFF, LCD_DDR_PORT ); /* all port bits as output */
outp( 0xFF, DDRC); /* LCD_E_PORT = LCD_RS_PORT so one line is enoughf :-) */

delay(16000*2); /* wait 16ms or more after power-on */

/* initial write to lcd is 8bit */
outp(LCD_FUNCTION_8BIT_2LINES>>4,LCD_DATA_PORT);
lcd_e_toggle();
delay(4992*2); /* delay, busy flag can't be checked here */

outp(LCD_FUNCTION_8BIT_2LINES>>4,LCD_DATA_PORT);
lcd_e_toggle();
delay(64*2); /* delay, busy flag can't be checked here */

outp(LCD_FUNCTION_8BIT_2LINES>>4,LCD_DATA_PORT);
lcd_e_toggle();
delay(64*2); /* delay, busy flag can't be checked here */

outp(LCD_FUNCTION_4BIT_2LINES>>4,LCD_DATA_PORT); /* set IO mode to 4bit */
lcd_e_toggle();

/* from now the lcd only accepts 4 bit I/O, we can use lcd_command() */
lcd_command(LCD_FUNCTION_DEFAULT); /* function set: display lines */
lcd_command(LCD_DISP_OFF); /* display off */
lcd_clrscr(); /* display clear */
lcd_command(LCD_MODE_DEFAULT); /* set entry mode */
lcd_command(dispAttr); /* display/cursor control */

}/* lcd_init */

static void inline lcd_write(uint8_t data,uint8_t rs)
{
/* configure data pins as output */
outp(0xFF, LCD_DDR_PORT);
outp(0xFF, DDRC);
if (rs) { /* write data (RS=1, RW=0) */

/* output high nibble first */
sbi(LCD_RS_PORT,LCD_MY_RS);
outp( ((data)&0xF0)/*|(1< outp(data,LCD_DATA_PORT );
lcd_e_toggle();

/* output low nibble */
sbi(LCD_RS_PORT,LCD_MY_RS);
outp( ((data<<4)&0xF0)/*|(1< lcd_e_toggle();


} else { /* write instruction (RS=0, RW=0) */

/* output high nibble first */
cbi(LCD_RS_PORT,LCD_MY_RS);
outp( (data)&0xF0, LCD_DATA_PORT );
lcd_e_toggle();

/* output low nibble */
cbi(LCD_RS_PORT,LCD_MY_RS);
outp( (data<<4)&0xF0, LCD_DATA_PORT );
lcd_e_toggle();

}

cbi(LCD_RS_PORT,LCD_MY_RS);
cbi(LCD_E_PORT,LCD_MY_E);
/* all data pins high (inactive) */
outp(0xF0, LCD_DATA_PORT);
delay(100);
}


void lcd_command(uint8_t cmd)
/* send commando to LCD */
{
delay(80);
lcd_write(cmd,0);
}

а вот так её вызываю

lcd_init(LCD_DISP_ON_CURSOR_BLINK);
вызвваю я её 3 раз где-то после 3-5 сек после старта проги


Составить ответ  |||  Конференция  |||  Архив

Ответы



Перейти к списку ответов  |||  Конференция  |||  Архив  |||  Главная страница  |||  Содержание  |||  Без кадра

E-mail: info@telesys.ru