Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC16F628A and 4 bit LCD programming question

Status
Not open for further replies.

Jman 31

Member level 2
Joined
Sep 18, 2009
Messages
49
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,675
Hi Guys,

I am working on the programming for this circuit. I decided to simplify it to the most basic form. Starting with getting the LCD working. I have done plenty with LCD's on the Arduino so I have a good idea of how they work.

I am having trouble getting the programming to work.

Here is the circuit:



and here is the simple program that I am trying to run:

Code:
/*
 * Project name:
     Lcd_Test (Simple demonstration of the LCD Library functions)
 * Copyright:
     (c) MikroElektronika, 2005-2008
 * Description:
     This is a simple demonstration of LCD library functions. LCD is first
     initialized, then some text is written at the first row.
 * Test configuration:
     MCU:             PIC16F628A
     Oscillator:      HS, 08.0000 MHz
     Ext. Modules:    LCD 2x16
     SW:              mikroC v8.0
 * NOTES:
     None.
*/

char *text = "mikroElektronika";

void main() {
  Lcd_Config(&PORTB, 5, 6, 0, 4, 3, 2, 1); // Lcd_Init_EP5, see Autocomplete

  LCD_Cmd(LCD_CLEAR);       // Clear display
  LCD_Cmd(LCD_CURSOR_OFF);  // Turn cursor off
  LCD_Out(1,1, text);       // Print text to LCD, 1st row, 1st column
  Delay_ms(1000);
  LCD_Out(2,6,"mikroE");    // Print text to LCD, 2nd row, 6th column
}

I have compiled it and it compiles fine. I used the default device flags that come with MikroC. I then programmed it with my PICKit2 and it programmed fine.

I am getting a row of white boxes across the top of the LCD which means that the LCD is not initializing. Does anyone have any idea what i could be doing wrong?

Thanks
J
 

There may be a function called 'LCD_Init' or something like that...which you may need to call before sending out any commands.
 

Hi

jumper is right
there' s a line missing and that's Lcd_Init();
and just add a while loop at the last line in the main routine
like the following

char *text = "mikroElektronika";

void main() {
Lcd_Config(&PORTB, 5, 6, 0, 4, 3, 2, 1); // Lcd_Init_EP5, see Autocomplete
Lcd_Init(); // newly added
LCD_Cmd(LCD_CLEAR); // Clear display
LCD_Cmd(LCD_CURSOR_OFF); // Turn cursor off
LCD_Out(1,1, text); // Print text to LCD, 1st row, 1st column
Delay_ms(1000);
LCD_Out(2,6,"mikroE"); // Print text to LCD, 2nd row, 6th column

while(1){
;
} // actually you don't need to use the braces
}

also adjust the contrast of the lcd
just connect the lcd pin15 to Vcc via a 1Kohm resistor
and the most IMPORTANT have you selected the fuse bits in proper way? i could not find any crystal connected to your circuit. the default setting in MicroC is HS that's external crystal. you must set is to INTernal Osc and do the other fuse settings. your system should work fin


regards


ml
 

Hi,
Code:
char *text = "mikroElektronika";

void main() {
  Lcd_Config(&PORTB, 5, 6, 0, 4, 3, 2, 1); // Lcd_Init_EP5, see Autocomplete

  LCD_Cmd(LCD_CLEAR);       // Clear display
  LCD_Cmd(LCD_CURSOR_OFF);  // Turn cursor off
  LCD_Out(1,1, text);       // Print text to LCD, 1st row, 1st column
  Delay_ms(1000);
  LCD_Out(2,6,"mikroE");    // Print text to LCD, 2nd row, 6th column
}
Change this to:
Code:
char *text = "mikroElektronika";

void main() {
  Lcd_Config(&PORTB, 5, 6, 0, 4, 3, 2, 1); // Lcd_Init_EP5, see Autocomplete
  //You can also write LCD_Init()
  //But LCD_Config allows you to set each LCD data and command pin according to your requirement

  LCD_Cmd(LCD_CLEAR);       // Clear display
  LCD_Cmd(LCD_CURSOR_OFF);  // Turn cursor off
  LCD_Out(1,1, text);       // Print text to LCD, 1st row, 1st column
  Delay_ms(1000);
  LCD_Out(2,6,"mikroE");    // Print text to LCD, 2nd row, 6th column
  while (1); //Endless loop
}

Hope this helps.
Tahmid.
 

Thanks guys. Sorry I posted this and then haven't posted back. I have been busy with my son's basketball team.

It was in the fuse settings. When I changed to the internal oscillator it took care of the problem!
 

also adjust the contrast of the lcd
just connect the lcd pin15 to Vcc via a 1Kohm resistor
and the most IMPORTANT have you selected the fuse bits in proper way? i could not find any crystal connected to your circuit. the default setting in MicroC is HS that's external crystal. you must set is to INTernal Osc and do the other fuse settings. your system should work fin

want to ask the what's ur mean by do other fuse settings? what is mean by fuse setting? isnt at the edit project there? and the oscillator should set to which one? clickout on RA6 or I/O on RA6?
 

Lcd_Config(&PORTB, 5, 6, 0, 4, 3, 2, 1); // Lcd_Init_EP5, see Autocomplete <----what does this do? When i insert into my coding,error found.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top