richardlaishram
Member level 4
- Joined
- Jan 6, 2013
- Messages
- 77
- Helped
- 6
- Reputation
- 12
- Reaction score
- 6
- Trophy points
- 1,298
- Location
- Planet Earth
- Activity points
- 1,804
__CONFIG(FOSC_HS & WDTE_ON & PWRTE_ON & CP_OFF & BOREN_ON & LVP_OFF & CPD_OFF & DEBUG_OFF);
void ToggleEpinOfLCD(void)
{
LCD_E = 1; // Give a pulse on E pin
__delay_us(E_Delay); // so that LCD can latch the
LCD_E = 0; // data from data bus
__delay_us(E_Delay);
}
void WriteCommandToLCD(unsigned char Command)
{
LCD_RS = 0; // Command
__delay_ms(40);
PORTD &= 0x0F; // Make Data pins zero
PORTD |= (Command&0xF0); // Write Upper nibble of data
ToggleEpinOfLCD(); // Give pulse on E pin
PORTD &= 0x0F; // Make Data pins zero
PORTD |= ((Command<<4)&0xF0); // Write Lower nibble of data
ToggleEpinOfLCD(); // Give pulse on E pin
}
void WriteDataToLCD(char LCDChar)
{
LCD_RS = 1; // It is data
__delay_ms(40);
PORTD &= 0x0F; // Make Data pins zero
PORTD |= (LCDChar&0xF0); // Write Upper nibble of data
ToggleEpinOfLCD(); // Give pulse on E pin
PORTD &= 0x0F; // Make Data pins zero
PORTD |= ((LCDChar<<4)&0xF0); // Write Lower nibble of data
ToggleEpinOfLCD(); // Give pulse on E pin
}
void InitLCD(void)
{
// Firstly make all pins output
LCD_E = 0; // E = 0
LCD_RS = 0; // RS = 0
LCD_Data_Bus_D4 = 0; // Data bus = 0
LCD_Data_Bus_D5 = 0; // Data bus = 0
LCD_Data_Bus_D6 = 0; // Data bus = 0
LCD_Data_Bus_D7 = 0; // Data bus = 0
LCD_E_Dir = 0; // Make Output
LCD_RS_Dir = 0; // Make Output
LCD_Data_Bus_Dir_D4 = 0; // Make Output
LCD_Data_Bus_Dir_D5 = 0; // Make Output
LCD_Data_Bus_Dir_D6 = 0; // Make Output
LCD_Data_Bus_Dir_D7 = 0; // Make Output
__delay_ms(40);
PORTD &= 0x0F; // Make Data pins zero
PORTD |= 0x30; // Write 0x3 value on data bus
ToggleEpinOfLCD(); // Give pulse on E pin
__delay_ms(20);
PORTD &= 0x0F; // Make Data pins zero
PORTD |= 0x30; // Write 0x3 value on data bus
ToggleEpinOfLCD(); // Give pulse on E pin
__delay_ms(20);
PORTD &= 0x0F; // Make Data pins zero
PORTD |= 0x30; // Write 0x3 value on data bus
ToggleEpinOfLCD(); // Give pulse on E pin
__delay_ms(20);
PORTD &= 0x0F; // Make Data pins zero
PORTD |= 0x20; // Write 0x2 value on data bus
ToggleEpinOfLCD(); // Give pulse on E pin
__delay_ms(20);
WriteCommandToLCD(0x28); //function set
__delay_ms(20);
WriteCommandToLCD(0x0c); //display on,cursor off,blink off
__delay_ms(20);
WriteCommandToLCD(0x01); //clear display
__delay_ms(20);
WriteCommandToLCD(0x06); //entry mode, set increment
}
void WriteStringToLCD(const char *s)
{
while(*s)
WriteDataToLCD(*s++); // print first character on LCD
}
void ClearLCDScreen(void) // Clear the Screen and return cursor to zero position
{
WriteCommandToLCD(0x01); // Clear the screen
__delay_ms(20); // Delay for cursor to return at zero position
}
I tried with the WDTE_OFF and I'm not seeing anything in the LCD, not even some garbage character.but would say you need the Config WDTE = OFF and try BOREN = OFF
void main()
{
__delay_ms(100);
InitLCD();
WriteCommandToLCD(0x80);
WriteStringToLCD("Hello World!!");
__delay_ms(500);
ClearLCDScreen();
}
PORTD &= 0x0F; // Make Data pins zero
PORTD |= 0x30; // Write 0x3 value on data bus
ToggleEpinOfLCD(); // Give pulse on E pin
ADCON1=0x0E;
void InitLCD(void)
{
// Firstly make all pins output
LCD_E = 0; // E = 0
LCD_RS = 0; // RS = 0
LCD_Data_Bus_D4 = 0; // Data bus = 0
LCD_Data_Bus_D5 = 0; // Data bus = 0
LCD_Data_Bus_D6 = 0; // Data bus = 0
LCD_Data_Bus_D7 = 0; // Data bus = 0
LCD_E_Dir = 0; // Make Output
LCD_RS_Dir = 0; // Make Output
LCD_Data_Bus_Dir_D4 = 0; // Make Output
LCD_Data_Bus_Dir_D5 = 0; // Make Output
LCD_Data_Bus_Dir_D6 = 0; // Make Output
LCD_Data_Bus_Dir_D7 = 0; // Make Output
__delay_ms(40);
PORTD &= 0x0F; // Make Data pins zero
PORTD |= 0x30; // Write 0x3 value on data bus
ToggleEpinOfLCD(); // Give pulse on E pin
__delay_ms(20);
PORTD &= 0x0F; // Make Data pins zero
PORTD |= 0x30; // Write 0x3 value on data bus
ToggleEpinOfLCD(); // Give pulse on E pin
__delay_ms(20);
PORTD &= 0x0F; // Make Data pins zero
PORTD |= 0x30; // Write 0x3 value on data bus
ToggleEpinOfLCD(); // Give pulse on E pin
__delay_ms(20);
PORTD &= 0x0F; // Make Data pins zero
PORTD |= 0x20; // Write 0x2 value on data bus
ToggleEpinOfLCD(); // Give pulse on E pin
__delay_ms(20);
WriteCommandToLCD(0x28); //function set
// __delay_ms(20);
WriteCommandToLCD(0x0c); //display on,cursor off,blink off
// __delay_ms(20);
WriteCommandToLCD(0x01); //clear display
// __delay_ms(20);
WriteCommandToLCD(0x06); //entry mode, set increment
}
OPTION_REG &= 0x7F
void main()
{
unsigned int Mode=1,;
TRISB = 1;
PORTB = 0x00;
TRISA=1;
ADCON1=0x0E;
__delay_ms(50);
InitLCD();
WriteCommandToLCD(0x80);
WriteStringToLCD("Initializing...");
__delay_ms(500);
ClearLCDScreen();
while(1)
{
if(MSel == 1)
{
while(MSel == 1);
__delay_ms(20);
Mode = eeprom_read(0);
Mode++;
eeprom_write(0, Mode);
if(eeprom_read(0) == 6)
eeprom_write(0, 1);
WriteCommandToLCD(0x80);
WriteStringToLCD("Mode:");
WriteDataToLCD(eeprom_read(0)+0x30);
}
Yes, I have taken some sample codes from websites, I have done a little editing. The code is working perfectly fine in Proteus and also if I press the MCLR button once, it's working perfectly fine. The only problem is that the LCD is showing some garbage character on powering up for the first time. I'm worried whether my board is having some problem or do I need to define anything for the actual board to work.I think you are trying the example program from a website Don worry at last its going to be fine......
but the time matters try some other working program from this forum itself.........
Yes, once the MCLR button is pressed, it's working perfectly fine. Also I'm able to use the same code for both 16x2 and 20x4 LCD. For programming the PIC, I'm using MPLAB ICD 3 and PICDEM 2 Plus Demo Board. Previously I tried with the PIC16F877A which is a 40PIN PDIP, so I shifted to PIC16F876A which is a 28PIN PDIP. I'm facing the same problem in both the cases. The board is designed like in the Proteus Simulation and for 5V Supply I'm using the 7805 Voltage regulator. Crystal is connected along with two capacitances as mentioned. I have attached the whole project as zip. Please have a look. Thanks in advance.Are you sure your hardware is wired correctly ? has it ever displayed anything correctly ?
void InitLCD(void)
{
// Firstly make all pins output
[COLOR="#0000CD"] LCD_E_Dir = 0; // Make Output
LCD_RS_Dir = 0; // Make Output
LCD_Data_Bus_Dir_D4 = 0; // Make Output
LCD_Data_Bus_Dir_D5 = 0; // Make Output
LCD_Data_Bus_Dir_D6 = 0; // Make Output
LCD_Data_Bus_Dir_D7 = 0; // Make Output[/COLOR]
LCD_E = 0; // E = 0
LCD_RS = 0; // RS = 0
LCD_Data_Bus_D4 = 0; // Data bus = 0
LCD_Data_Bus_D5 = 0; // Data bus = 0
LCD_Data_Bus_D6 = 0; // Data bus = 0
LCD_Data_Bus_D7 = 0; // Data bus = 0
Code C - [expand] 1 2 __delay_ms(1000); __delay_ms(1000);
OMG!!! This was the problem. I'm so dumb. Thanks a ton. :idea: Thanks a lot to everyone. It's working!!hello
in InitLCD
initialize first the bit direction
Yes sir, I tried it. Sorry, but ii was in the wrong part. I removed the PORTD &= 0x0F; and used only PORTD |= 0x30; in the InitLCD function, again it was not working. I was not clear with what you have said earlier, else it would have been resolved much earlier :-(So what you learned is don worry for any problem there will be solution I told the same in #6, did you tried it??
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?