View previous topic :: View next topic |
Author |
Message |
HWGonly1
Joined: 02 Jul 2014 Posts: 15
|
Problem of single line of black squares on LCD 1602(16*2) |
Posted: Sun Jul 06, 2014 4:03 am |
|
|
Hi, experienced programmers, I come for help for the second time.
I'm working on PIC16F877 while the LCD only display a single line of black squares.
I've already add delay_ms(500) before and after lcd_init(),I'm wondering why it's still wrong.
It's all working on proteus and I've checked circuit for several times ,I think it's not the fault of wrong circuit.
Here is the flex_lcd.chttp://www.ccsinfo.com/forum/viewtopic.php?t=24661
and this is my code: Code: | #include"flex_lcd.c"
int32 RunMileage=0;
int mode=0;
int1 flag=TRUE;
int32 Price_calc()
{
int32 Price; //running with this at 100*
if(RunMileage<=2300)
Price=80000;
else if((RunMileage>2300)&&(RunMileage<=35000))
Price=80000+(RunMileage-2300)*26;
else if(RunMileage>35000)
Price=111200+(RunMileage-35000)*35;
return price;
}
void end()
{
lcd_putc('\f');
mode=0;
RunMileage=0;
}
#int_ext
void breakloop()
{
flag=1;
if (++mode==4)
mode=0;
}
void carrying()
{
setup_timer_1(T1_EXTERNAL_SYNC | T1_DIV_BY_1);
set_timer1(0);
}
void main()
{
int16 temp_timer;
int32 Price;
int count=0;
delay_ms(500);
lcd_init();
delay_ms(500);
ext_int_edge(H_TO_L);
clear_interrupt(INT_EXT);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
while(TRUE)
{
if (flag==TRUE)
{
//note where the flag test is...
flag=FALSE;
switch (MODE) {
case 0:
printf(lcd_putc,"\f\nVacant Car");
break;
case 1:
printf(lcd_putc,"\f\nWelcome");
delay_ms(1000);
carrying();
printf(lcd_putc,"\f\nFare");
mode=2; //automatically advance to 'running'
break;
}
}
temp_timer=get_timer1();
while(mode==2)
{
temp_timer=get_timer1();
RunMileage=temp_timer*30;
Price=Price_calc();
Price/=100;
printf(lcd_putc,"\f\nFare:");
printf(lcd_putc,"%5.2Lw",Price);
delay_ms(500);
}
if(mode==3)
{
}
}
}
|
I connect R/W to ground and comment out the defininition of USE_LCD_RW
And connect other pins just as in definition in lcd_flex.c.
And the '\n' doesn't work either,it never change to second line,but it doesn't really matter,but please tell me if you know why,thanks!
Last edited by HWGonly1 on Sun Jul 06, 2014 5:52 am; edited 1 time in total |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Sun Jul 06, 2014 5:10 am |
|
|
step number 1. Get rid of 99% of your code and ONLY code for the LCD module! Just create a simple 'Hello LCD' program. Confirm your LCD is properly connected,code uses the correct I/O pins,etc.
Show us that program and we can help...
cheers
jay |
|
|
HWGonly1
Joined: 02 Jul 2014 Posts: 15
|
Change to a simple one,but it still got the same error. |
Posted: Sun Jul 06, 2014 5:27 am |
|
|
temtronic wrote: | step number 1. Get rid of 99% of your code and ONLY code for the LCD module! Just create a simple 'Hello LCD' program. Confirm your LCD is properly connected,code uses the correct I/O pins,etc.
Show us that program and we can help...
cheers
jay |
#include"flex_lcd.c"
void main()
{
delay_ms(500);
lcd_init();
delay_ms(500);
printf(lcd_putc,"\f\nVacant Car");
} |
|
|
HWGonly1
Joined: 02 Jul 2014 Posts: 15
|
Change to a simple one,but it still got the same error. |
Posted: Sun Jul 06, 2014 5:28 am |
|
|
temtronic wrote: | step number 1. Get rid of 99% of your code and ONLY code for the LCD module! Just create a simple 'Hello LCD' program. Confirm your LCD is properly connected,code uses the correct I/O pins,etc.
Show us that program and we can help...
cheers
jay |
And I haven't connect trimpot to pin 15,16
And I'm using PICKIT3 to download to my PIC16F877,does it matter? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Sun Jul 06, 2014 6:35 am |
|
|
1) trimpot doesn't get connected to 15 and 16. that's 'usually' the LED backlighing connections....trimpot get connected to pin 3(contrast +-.5VDC)
2) I use the PICKit3 to program the 877 all the time
however, if using MPLAB be sure to set the 'build configuration' to 'release' and NOT 'debug'( the factory default).
hth
jay |
|
|
HWGonly1
Joined: 02 Jul 2014 Posts: 15
|
|
Posted: Sun Jul 06, 2014 6:41 am |
|
|
temtronic wrote: | 1) trimpot doesn't get connected to 15 and 16. that's 'usually' the LED backlighing connections....trimpot get connected to pin 3(contrast +-.5VDC)
2) I use the PICKit3 to program the 877 all the time
however, if using MPLAB be sure to set the 'build configuration' to 'release' and NOT 'debug'( the factory default).
hth
jay |
What build configuration?I'm new to CCS .
I clicked project--build configuration, the list only shows gray words"No Build Configurations"
But it build succeed and works well on proteus simulation, and so I don't know why.
Please help me |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Sun Jul 06, 2014 8:41 am |
|
|
OK...
Sounds like you have a bad installation of MPLAB.
You should have seen 'release' and 'debug' as the options for the 'build configuration' in the 'project' drop down window.
I'd remove and reinstall MPLAB and try again
Be sure to get the CCS 'plugin' form their website which allows you to use the compiler 'through' the MPLAB IDE.
hth
jay
also please note PROTEUS does NOT simulate a PIC properly.It is FULL of bugs, errors, and faulty DRCs !! Do NOT trust it !! |
|
|
HWGonly1
Joined: 02 Jul 2014 Posts: 15
|
Oh that's too bad!!!I shouldn't have trust proteus |
Posted: Sun Jul 06, 2014 8:50 am |
|
|
temtronic wrote: | OK...
Sounds like you have a bad installation of MPLAB.
You should have seen 'release' and 'debug' as the options for the 'build configuration' in the 'project' drop down window.
I'd remove and reinstall MPLAB and try again
Be sure to get the CCS 'plugin' form their website which allows you to use the compiler 'through' the MPLAB IDE.
hth
jay
also please note PROTEUS does NOT simulate a PIC properly.It is FULL of bugs, errors, and faulty DRCs !! Do NOT trust it !! |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jul 06, 2014 8:55 am |
|
|
HWGonly1,
Your schematic in your original thread shows no crystal oscillator
circuit external to the 16F877. Proteus doesn't care about this.
But in real hardware, this circuit is necessary. Your 16F877 won't do
anything without this circuit.
My advice is to get a different PIC, such as the 16F887, which has an
internal oscillator and doesn't need the crystal circuit. The 16F887 is a
much better PIC for a newbie.
Also, in all of your posted programs, you never show the #include line
for the PIC, the #fuses line, or the the #use delay() line. These lines
should be at the start of the program and are necessary for the PIC to
run correctly in real hardware. |
|
|
HWGonly1
Joined: 02 Jul 2014 Posts: 15
|
|
Posted: Sun Jul 06, 2014 10:35 am |
|
|
PCM programmer wrote: | HWGonly1,
Your schematic in your original thread shows no crystal oscillator
circuit external to the 16F877. Proteus doesn't care about this.
But in real hardware, this circuit is necessary. Your 16F877 won't do
anything without this circuit.
My advice is to get a different PIC, such as the 16F887, which has an
internal oscillator and doesn't need the crystal circuit. The 16F887 is a
much better PIC for a newbie.
Also, in all of your posted programs, you never show the #include line
for the PIC, the #fuses line, or the the #use delay() line. These lines
should be at the start of the program and are necessary for the PIC to
run correctly in real hardware. |
Thank you for advice,and I really want to accept your advice.
But what I'm working on is my task (I'm a college student),and we were given only 16F877 chip and so it's not what I chose.
So even if I'm newbie,I'm not fortunate to choose what I want to learn.
I still don't know what is oscillator and my RB0 is counting the pulse from NE555(if this is related to oscillator?).
Is the oscillator necessary for all circuit?I don't know about that cause I am very new to it.
I've done the pro-processing(my English is poor) in flex_lcd.c cause when I did in main code but in flex_lcd.c it makes error(such as #device* is needed)
this is my addition to flex_lcd.c Code: | #include"16F877.h"
#use delay(clock=4000000)
#use rs232(baud=9600,xmit=PIN_D7,rcv=PIN_D0)
#fuses HS, NOWDT, PUT
..... |
I don't know if it will cause some error, but really thank you for helping me. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19535
|
|
Posted: Sun Jul 06, 2014 10:49 am |
|
|
The oscillator is the 'heart' that makes the processor work.
Totally essential. The chip can't do anything at all without it.
Your 555, is _an_ oscillator, but is not really suitable, or fast enough to run the PIC. Once running there are circuits in the PIC, hat can 'count' signals from other sources, and it sounds as if this is what you are meant to be doing with the signal from the 555.
The PIC contains 90% of the circuitry needed to make it's oscillator. What it lacks it the bits to actually time the oscillation. Normally a crystal or ceramic resonator connected to it's 'oscillator pins'. As PCM programmer points out some other PIC's have everything included (though less accurate than the crystal).
You need an external crystal and load capacitances connected to the oscillator pins. The PIC data sheet (figure 12-1), shows what is needed. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jul 06, 2014 1:53 pm |
|
|
This schematic shows the crystal circuit that you need:
http://s21.postimg.org/gkrbc1cav/schema002.jpg
Crystal X1 can be a 4 MHz or 20 MHz crystal, whatever you have in stock.
The two capacitors should be 22 pf (picofarads). That capacitor value
will work fine with either a 4 or 20 MHz crystal.
And you will need a 10K pullup resistor to +5v on the MCLR pin
as shown in the schematic.
And you will need +5v connected to the PIC's Vdd pins, and Ground
connected to the Vss pins.
Proteus ignores all this, but you need it all to make your real hardware
work correctly. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19535
|
|
Posted: Sun Jul 06, 2014 2:28 pm |
|
|
and, a capacitor with a good high frequency performance (like perhaps a 0.1uF ceramic), _as close as possible to the supply pins on the PIC_. |
|
|
HWGonly1
Joined: 02 Jul 2014 Posts: 15
|
|
Posted: Sun Jul 06, 2014 6:54 pm |
|
|
PCM programmer wrote: | This schematic shows the crystal circuit that you need:
http://s21.postimg.org/gkrbc1cav/schema002.jpg
Crystal X1 can be a 4 MHz or 20 MHz crystal, whatever you have in stock.
The two capacitors should be 22 pf (picofarads). That capacitor value
will work fine with either a 4 or 20 MHz crystal.
And you will need a 10K pullup resistor to +5v on the MCLR pin
as shown in the schematic.
And you will need +5v connected to the PIC's Vdd pins, and Ground
connected to the Vss pins.
Proteus ignores all this, but you need it all to make your real hardware
work correctly. |
Thank you for advice and now I know there is oscillator on the base I plug PIC in.
I have got the CCS plugin for MPLAB IDE and the circuit still works improperly, just a single line of black squares. |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Sun Jul 06, 2014 7:16 pm |
|
|
Hi,
HWGonly1 wrote: |
Thank you for advice and now I know there is oscillator on the base I plug PIC in.
|
Who knows what this really means? I haven't a clue! If you are using some sort of a commercial development board, then post a link!
What you really need to do is connect an LED to an I/O pin of your PIC (thru a suitable current limiting resistor), and flash it at a known rate. Make a simple test program to do this, and tell us the results. Turn the LED On for 1 second and then Off for 1 second, and do this repeatedly. This test will tell you (1) if the PIC is actually running, and (2) if it's running at the desired speed. Seriously, don't do anything else until you can perform this test, and tell us the results. Otherwise this thread is going to go no where fast....
John |
|
|
|