Управляю контрастом и подсветкой, использую режим в котором данные записываются по 4 бита.
Если отрегулировать контраст, то просматривается заполненная верхняя строка, символы не выводит.
Проверил уже все что только мог придумать, подскажите где ошибка?
Вот код:
Код
...
#define D7_PORT PORTD
#define D7_BIT (4)
#define CLR_D7() CLR_PORT_BIT(D7_PORT, D7_BIT)
#define SET_D7() SET_PORT_BIT(D7_PORT, D7_BIT)
#define D6_PORT PORTD
#define D6_BIT (3)
#define CLR_D6() CLR_PORT_BIT(D6_PORT, D6_BIT)
#define SET_D6() SET_PORT_BIT(D6_PORT, D6_BIT)
#define D5_PORT PORTD
#define D5_BIT (2)
#define CLR_D5() CLR_PORT_BIT(D5_PORT, D5_BIT)
#define SET_D5() SET_PORT_BIT(D5_PORT, D5_BIT)
#define D4_PORT PORTD
#define D4_BIT (1)
#define CLR_D4() CLR_PORT_BIT(D4_PORT, D4_BIT)
#define SET_D4() SET_PORT_BIT(D4_PORT, D4_BIT)
#define RS_PORT PORTC
#define RS_BIT (4)
#define CLR_RS() CLR_PORT_BIT(RS_PORT, RS_BIT)
#define SET_RS() SET_PORT_BIT(RS_PORT, RS_BIT)
#define E_PORT PORTC
#define E_BIT (5)
#define CLR_E() CLR_PORT_BIT(E_PORT, E_BIT)
#define SET_E() SET_PORT_BIT(E_PORT, E_BIT)
...
#define LCD_CLEAR() LCD_Set(0x01)
#define LCD_RESET() LCD_Set(0x02)
#define LCD_AC_DEC_MODE() LCD_Set(0x04)
#define LCD_AC_INC_MODE() LCD_Set(0x06)
#define LCD_SHIFT_LEFT_MODE() LCD_Set(0x05)
#define LCD_SHIFT_RIGHT_MODE() LCD_Set(0x07)
#define LCD_DISPLAY_ON() LCD_Set(0x0C)
#define LCD_DISPLAY_OFF() LCD_Set(0x08)
#define LCD_CURSOR_ON() LCD_Set(0x0E)
#define LCD_CURSOR_OFF() LCD_Set(0x08)
#define LCD_BLANK_ON() LCD_Set(0x0D)
#define LCD_BLANK_OFF() LCD_Set(0x08)
#define LCD_SET_CURSOR_LEFT() LCD_Set(0x10)
#define LCD_SET_CURSOR_RIGHT() LCD_Set(0x14)
#define LCD_SET_DISPLAY_LEFT() LCD_Set(0x18)
#define LCD_SET_DISPLAY_RIGHT() LCD_Set(0x1C)
#define LCD_SET_CGR_ADDR(a) LCD_Set(0x40 | a)
#define LCD_SET_DDR_ADDR(a) LCD_Set(0x80 | a)
void LCD_Bus_Write(char data){
CLR_D7();
CLR_D6();
CLR_D5();
CLR_D4();
if (data & 0x80){SET_D7();}
if (data & 0x40){SET_D6();}
if (data & 0x20){SET_D5();}
if (data & 0x10){SET_D4();}
SET_E();
Delay_mSeconds(1);
CLR_E();
Delay_mSeconds(1);
CLR_D7();
CLR_D6();
CLR_D5();
CLR_D4();
if (data & 0x08){SET_D7();}
if (data & 0x04){SET_D6();}
if (data & 0x02){SET_D5();}
if (data & 0x01){SET_D4();}
SET_E();
Delay_mSeconds(1);
CLR_E();
Delay_mSeconds(1);
/*PORTD=(PORTD&0x0f)|(data&0xf0);
SET_E();
Delay_mSeconds(1);
CLR_E();
Delay_mSeconds(4);
data<<=4;
PORTD=(PORTD&0x0f)|(data&0xf0);
SET_E();
Delay_mSeconds(1);
CLR_E();
Delay_mSeconds(4);*/
}
void LCD_Set(char cmd){
LCD_Bus_Write(cmd);
}
void LCD_GOTO_XY(char x,char y){
if(y==1) {LCD_SET_DDR_ADDR(x);}
if(y==2) {LCD_SET_DDR_ADDR(x+64);}
}
void LCD_Init(void){
Delay_mSeconds(350);
LCD_Bus_Write(0x30);
Delay_mSeconds(5);
LCD_Bus_Write(0x30);
Delay_mSeconds(1);
LCD_Bus_Write(0x30);
LCD_Bus_Write(0x32);
LCD_Bus_Write(0x28);
LCD_Bus_Write(0x08);
LCD_Bus_Write(0x01);
LCD_Bus_Write(0x06);
LCD_DISPLAY_OFF();
LCD_RESET();
LCD_CLEAR();
LCD_DISPLAY_ON();
LCD_GOTO_XY(0,0);
}
void LCD_DisplayCharacter ( char Char){
SET_RS();
Delay_mSeconds(1);
LCD_Bus_Write (Char);
CLR_RS();
Delay_mSeconds(1);
}
void LCD_DisplayString (unsigned char *string){
while (*string)
LCD_DisplayCharacter (*string++);
}
void Init_Devices(){
...
LCD_Init();
...
}
...
main(void){
Init_Devices();
LCD_GOTO_XY(0,1);
LCD_DisplayString("Hello World!");
}
#define D7_PORT PORTD
#define D7_BIT (4)
#define CLR_D7() CLR_PORT_BIT(D7_PORT, D7_BIT)
#define SET_D7() SET_PORT_BIT(D7_PORT, D7_BIT)
#define D6_PORT PORTD
#define D6_BIT (3)
#define CLR_D6() CLR_PORT_BIT(D6_PORT, D6_BIT)
#define SET_D6() SET_PORT_BIT(D6_PORT, D6_BIT)
#define D5_PORT PORTD
#define D5_BIT (2)
#define CLR_D5() CLR_PORT_BIT(D5_PORT, D5_BIT)
#define SET_D5() SET_PORT_BIT(D5_PORT, D5_BIT)
#define D4_PORT PORTD
#define D4_BIT (1)
#define CLR_D4() CLR_PORT_BIT(D4_PORT, D4_BIT)
#define SET_D4() SET_PORT_BIT(D4_PORT, D4_BIT)
#define RS_PORT PORTC
#define RS_BIT (4)
#define CLR_RS() CLR_PORT_BIT(RS_PORT, RS_BIT)
#define SET_RS() SET_PORT_BIT(RS_PORT, RS_BIT)
#define E_PORT PORTC
#define E_BIT (5)
#define CLR_E() CLR_PORT_BIT(E_PORT, E_BIT)
#define SET_E() SET_PORT_BIT(E_PORT, E_BIT)
...
#define LCD_CLEAR() LCD_Set(0x01)
#define LCD_RESET() LCD_Set(0x02)
#define LCD_AC_DEC_MODE() LCD_Set(0x04)
#define LCD_AC_INC_MODE() LCD_Set(0x06)
#define LCD_SHIFT_LEFT_MODE() LCD_Set(0x05)
#define LCD_SHIFT_RIGHT_MODE() LCD_Set(0x07)
#define LCD_DISPLAY_ON() LCD_Set(0x0C)
#define LCD_DISPLAY_OFF() LCD_Set(0x08)
#define LCD_CURSOR_ON() LCD_Set(0x0E)
#define LCD_CURSOR_OFF() LCD_Set(0x08)
#define LCD_BLANK_ON() LCD_Set(0x0D)
#define LCD_BLANK_OFF() LCD_Set(0x08)
#define LCD_SET_CURSOR_LEFT() LCD_Set(0x10)
#define LCD_SET_CURSOR_RIGHT() LCD_Set(0x14)
#define LCD_SET_DISPLAY_LEFT() LCD_Set(0x18)
#define LCD_SET_DISPLAY_RIGHT() LCD_Set(0x1C)
#define LCD_SET_CGR_ADDR(a) LCD_Set(0x40 | a)
#define LCD_SET_DDR_ADDR(a) LCD_Set(0x80 | a)
void LCD_Bus_Write(char data){
CLR_D7();
CLR_D6();
CLR_D5();
CLR_D4();
if (data & 0x80){SET_D7();}
if (data & 0x40){SET_D6();}
if (data & 0x20){SET_D5();}
if (data & 0x10){SET_D4();}
SET_E();
Delay_mSeconds(1);
CLR_E();
Delay_mSeconds(1);
CLR_D7();
CLR_D6();
CLR_D5();
CLR_D4();
if (data & 0x08){SET_D7();}
if (data & 0x04){SET_D6();}
if (data & 0x02){SET_D5();}
if (data & 0x01){SET_D4();}
SET_E();
Delay_mSeconds(1);
CLR_E();
Delay_mSeconds(1);
/*PORTD=(PORTD&0x0f)|(data&0xf0);
SET_E();
Delay_mSeconds(1);
CLR_E();
Delay_mSeconds(4);
data<<=4;
PORTD=(PORTD&0x0f)|(data&0xf0);
SET_E();
Delay_mSeconds(1);
CLR_E();
Delay_mSeconds(4);*/
}
void LCD_Set(char cmd){
LCD_Bus_Write(cmd);
}
void LCD_GOTO_XY(char x,char y){
if(y==1) {LCD_SET_DDR_ADDR(x);}
if(y==2) {LCD_SET_DDR_ADDR(x+64);}
}
void LCD_Init(void){
Delay_mSeconds(350);
LCD_Bus_Write(0x30);
Delay_mSeconds(5);
LCD_Bus_Write(0x30);
Delay_mSeconds(1);
LCD_Bus_Write(0x30);
LCD_Bus_Write(0x32);
LCD_Bus_Write(0x28);
LCD_Bus_Write(0x08);
LCD_Bus_Write(0x01);
LCD_Bus_Write(0x06);
LCD_DISPLAY_OFF();
LCD_RESET();
LCD_CLEAR();
LCD_DISPLAY_ON();
LCD_GOTO_XY(0,0);
}
void LCD_DisplayCharacter ( char Char){
SET_RS();
Delay_mSeconds(1);
LCD_Bus_Write (Char);
CLR_RS();
Delay_mSeconds(1);
}
void LCD_DisplayString (unsigned char *string){
while (*string)
LCD_DisplayCharacter (*string++);
}
void Init_Devices(){
...
LCD_Init();
...
}
...
main(void){
Init_Devices();
LCD_GOTO_XY(0,1);
LCD_DisplayString("Hello World!");
}