|
|
View previous topic :: View next topic |
Author |
Message |
engrmunir786
Joined: 25 Jul 2012 Posts: 20
|
Pic 16F877 Battery Symbol on LCD |
Posted: Thu Jul 26, 2012 11:02 pm |
|
|
Dear Experts
I am displaying Battery Symbol on LCD by using PIC16F877. My code is mention below.
Code: |
#include <16f877.h>
#fuses HS, NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,PUT
#use delay(clock = 16000000)
#byte PORTA = 0x05
#byte PORTB = 0x06
#byte PORTC = 0x07
#byte PORTD = 0x06
#byte TRISA = 0x85
#byte TRISB = 0x86
#byte TRISC = 0x87
#byte TRISD = 0x88
#include <flex_lcd.c>
void CPU_SETUP(void);
void batt_bar(void);
void main()
{
delay_ms(200);
CPU_SETUP();
lcd_init();
delay_ms(200);
while(1)
{
batt_bar();
}
}
void batt_bar()
{
lcd_send_byte(0, 0x40);
lcd_send_byte(1, 0x0E);
lcd_send_byte(1, 0x1B);
lcd_send_byte(1, 0x11);
lcd_send_byte(1, 0x11);
lcd_send_byte(1, 0x11);
lcd_send_byte(1, 0x11);
lcd_send_byte(1, 0x1F);
lcd_send_byte(1,0x00);
delay_ms(100);
lcd_send_byte(0, 0x40);
lcd_send_byte(1, 0x0E);
lcd_send_byte(1, 0x1B);
lcd_send_byte(1, 0x11);
lcd_send_byte(1, 0x11);
lcd_send_byte(1, 0x11);
lcd_send_byte(1, 0x11);
lcd_send_byte(1, 0x1F);
lcd_send_byte(1, 0x1F);
lcd_send_byte(1,0x00);
delay_ms(100);
lcd_send_byte(0, 0x40);
lcd_send_byte(1, 0x0E);
lcd_send_byte(1, 0x1B);
lcd_send_byte(1, 0x11);
lcd_send_byte(1, 0x11);
lcd_send_byte(1, 0x11);
lcd_send_byte(1, 0x1F);
lcd_send_byte(1, 0x1F);
lcd_send_byte(1, 0x1F);
lcd_send_byte(1,0x00);
delay_ms(100);
lcd_send_byte(0, 0x40);
lcd_send_byte(1, 0x0E);
lcd_send_byte(1, 0x1B);
lcd_send_byte(1, 0x11);
lcd_send_byte(1, 0x11);
lcd_send_byte(1, 0x1F);
lcd_send_byte(1, 0x1F);
lcd_send_byte(1, 0x1F);
lcd_send_byte(1, 0x1F);
lcd_send_byte(1,0x00);
delay_ms(100);
lcd_send_byte(0, 0x40);
lcd_send_byte(1, 0x0E);
lcd_send_byte(1, 0x1B);
lcd_send_byte(1, 0x11);
lcd_send_byte(1, 0x1F);
lcd_send_byte(1, 0x1F);
lcd_send_byte(1, 0x1F);
lcd_send_byte(1, 0x1F);
lcd_send_byte(1, 0x1F);
lcd_send_byte(1,0x00);
delay_ms(100);
lcd_send_byte(0, 0x40);
lcd_send_byte(1, 0x0E);
lcd_send_byte(1, 0x1B);
lcd_send_byte(1, 0x1F);
lcd_send_byte(1, 0x1F);
lcd_send_byte(1, 0x1F);
lcd_send_byte(1, 0x1F);
lcd_send_byte(1, 0x1F);
lcd_send_byte(1, 0x1F);
lcd_send_byte(1,0x00);
delay_ms(100);
lcd_send_byte(0, 0x40);
lcd_send_byte(1, 0x0E);
lcd_send_byte(1, 0x1F);
lcd_send_byte(1, 0x1F);
lcd_send_byte(1, 0x1F);
lcd_send_byte(1, 0x1F);
lcd_send_byte(1, 0x1F);
lcd_send_byte(1, 0x1F);
lcd_send_byte(1, 0x1F);
lcd_send_byte(1,0x00);
delay_ms(100);
}
|
The above mentioned code is working fine and display battery symbol exactly but when I add this line:
Code: |
lcd_gotoxy(1,6);
Printf(lcd_putc, "AC");
|
after batt_bar();
The battery symbol is again automatically displayed after that message. And if any new message is displayed then battery symbol is automatically displayed after that message. Can you tell me what is the problem ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Fri Jul 27, 2012 3:15 am |
|
|
Of course it is.....
Think:
Code: |
while(1) {
batt_bar();
lcd_gotoxy(1,6);
Printf(lcd_putc, "AC");
}
|
Is going to display the bar, then move to location 1,6, then display 'AC', then loop back, and display the bar again, etc. etc...
Best Wishes |
|
|
engrmunir786
Joined: 25 Jul 2012 Posts: 20
|
|
Posted: Sun Jul 29, 2012 11:50 pm |
|
|
Dear Ttelmah
But I do not want to display battery bar after any message, I only want to display at first line end location(1,16) and every time battery bar is display at that location. I am displaying different message at first line on different input signal but when any new signal comes and that message appear on lcd after that battery bar is automatically displayed. Can you tell me the procedure to display battery bar exactly at one location ? Not any other location on lcd, even if any message come on lcd. |
|
|
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Mon Jul 30, 2012 6:06 pm |
|
|
That was Ttelmah's point - if you look at your program flow, "while(1) is always true, so the series of statements within the brackets will execute repeatedly, not stop at the end like you seem to indicate you want.
The way your code is written, the instructions will execute as
batt_bar()
gotoxy
printf
batt_bar()
gotoxy
printf
... continuously because "while(1)" is always true.
mikey _________________ mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3 |
|
|
engrmunir786
Joined: 25 Jul 2012 Posts: 20
|
|
Posted: Tue Jul 31, 2012 10:03 pm |
|
|
Dear gpsmikey
Actually I want to display this battery bar at only one location on lcd and different other messages are also displaying on lcd on different inputs. So tell me the procedure how can I display this battery symbol exactly on same location again and again and battery symbol not display automatically anywhere on lcd ? This is my question. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Wed Aug 01, 2012 2:35 am |
|
|
First thing. Your define for the battery bar, seems to be 80% pointless. You are overwriting the same memory again and again.
The LCD, has a small area of RAM, for the character generator. This is addressed, by sending 0x40, _plus the address you want to talk to_. So sending '0x40 on it's own, talks to the first address in this RAM. Then data you write into this RAM, is displayable, just like any other character, but uses character 'zero' for the first 8 locations in this memory.
So the only part of you 'bar' definitions that actually does anything, is the last set of ten lines. All the previous ones are overwritten when you send this. You define the character, then display it just as any other character.
Then you have loads of wasted delays. The LCD function, waits till stuff is written already.
So:
Code: |
#include <16f877.h>
#fuses HS, NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,PUT
#use delay(clock = 16000000)
#byte PORTA = 0x05
#byte PORTB = 0x06
#byte PORTC = 0x07
#byte PORTD = 0x06
#byte TRISA = 0x85
#byte TRISB = 0x86
#byte TRISC = 0x87
#byte TRISD = 0x88
#include <flex_lcd.c>
void CPU_SETUP(void);
void define_bar(void);
#define display_bar() lcd_send_byte(1,0) //display character 0, which is the bar
void main(void) {
int n;
delay_ms(200);
CPU_SETUP();
lcd_init();
define_bar(); //This loads the 'bar' definition as character 0
while(TRUE) {
printf(lcd_putc,"\f"); //clear screen
lcd_gotoxy(1,1); //make sure at top corner
display_bar(); //display the bar character here
lcd_gotoxy(6,2);
printf(lcd_putc,"AC");
for (n=0;n<100;n++) {
//Now just as a demo, write a counter in front of the AC text
lcd_gotoxy(1,2);
printf(lcd_putc,"%03u",n);
delay_ms(250); //pause long enough for things to be seen
}
}
}
void define_bar(void) {
lcd_send_byte(0, 0x40);
lcd_send_byte(1, 0x0E);
lcd_send_byte(1, 0x1F);
lcd_send_byte(1, 0x1F);
lcd_send_byte(1, 0x1F);
lcd_send_byte(1, 0x1F);
lcd_send_byte(1, 0x1F);
lcd_send_byte(1, 0x1F);
lcd_send_byte(1, 0x1F);
lcd_send_byte(1,0x00);
}
|
There are several other little things going wrong. Your lcd_gotoxy(1,6) for example. Values for this, are x,y. Column, row. 6 would only be legal for a six line display.... In fact the code treats anything that is not '1' as equivalent to '2', but use the right values if you expect things to work as you want. A lot of other functions are _not_ so forgiving.....
Best Wishes |
|
|
engrmunir786
Joined: 25 Jul 2012 Posts: 20
|
|
Posted: Wed Aug 01, 2012 10:04 pm |
|
|
Dear Ttelmah
Thanks again for your detail response.
You say that my define battery bar is 80% pointless. Why? Yes I am overwriting same memory again and again because I want to display the battery bar charging status from bottom to top. So I must have to display it again and again so that battery charging status is displayed, for example in mobile battery charging symbol. When you plugged it in ac then battery bar is displaying that battery is charging and when you unplugged the ac then battery symbol is still at any point. You have displayed battery bar only once and do not display any other messages. It does not display battery charging status from bottom to top. You are getting my point or not? Tell me your email address. I will send you my complete code. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Thu Aug 02, 2012 2:33 am |
|
|
Ah. No.
Write the definitions one after the after the other:
Code: |
lcd_send_byte(0, 0x40);
lcd_send_byte(1, 0x0E);
lcd_send_byte(1, 0x1B);
lcd_send_byte(1, 0x11);
lcd_send_byte(1, 0x11);
lcd_send_byte(1, 0x11);
lcd_send_byte(1, 0x11);
lcd_send_byte(1, 0x1F);
lcd_send_byte(1,0x00);
//lcd_send_byte(0, 0x40); remove this line
lcd_send_byte(1, 0x0E);
lcd_send_byte(1, 0x1B);
lcd_send_byte(1, 0x11);
lcd_send_byte(1, 0x11);
lcd_send_byte(1, 0x11);
lcd_send_byte(1, 0x11);
lcd_send_byte(1, 0x1F);
lcd_send_byte(1, 0x1F);
lcd_send_byte(1,0x00);
//delay_ms(100); and remove the delays
|
Do this for the whole block of definitions
Then you have the seven different characters available to use.
So:
lcd_send_byte(1,0);
Will show the first bar, then
lcd_send_byte(1,1; the second, etc..
The point is you don't keep redefining the characters. You write _once_ the definitions for all the patterns you need, and display these when needed.
Code: |
#define display_bar(x) lcd_send_byte(1,x) //display character x, which are the bars
void main(void) {
int n;
int bno=0;
delay_ms(200);
CPU_SETUP();
lcd_init();
define_bar(); //This loads the 'bar' definitions as characters 0..6
while(TRUE) {
printf(lcd_putc,"\f"); //clear screen
lcd_gotoxy(1,1); //make sure at top corner
display_bar(bno++); //display the bar character here
if (bno==8) bno=0; //update to next bar
lcd_gotoxy(6,2);
printf(lcd_putc,"AC");
for (n=0;n<100;n++) {
//Now just as a demo, write a counter in front of the AC text
lcd_gotoxy(1,2);
printf(lcd_putc,"%03u",n);
delay_ms(250); //pause long enough for things to be seen
}
}
}
|
With the new full 7 character definitions, this will give the next battery bar after 100 counts.
Best Wishes |
|
|
engrmunir786
Joined: 25 Jul 2012 Posts: 20
|
|
Posted: Thu Aug 02, 2012 9:32 pm |
|
|
Dear Ttelmah
Thanks again for your detail response. did this show battery bar at one location and show charging status like mobile battery bar? i will program and checked it then reply you again.Dear can you tell me your email and skype address.
Regards
Muhammad Munir |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Aug 02, 2012 9:56 pm |
|
|
Let me tell you something about this forum. The people on it generally
only want to reply on the forum. They don't want to volunteer to be a
personal teacher of CCS. Most of the people who give answers have
full-time jobs and they answer questions during their breaks, or maybe
after-hours sometimes. They don't have any more time. They have to
do their work. So don't expect anyone to exchange email or skype
addresses. Just ask questions on the forum. That's the best way. |
|
|
engrmunir786
Joined: 25 Jul 2012 Posts: 20
|
|
Posted: Fri Aug 03, 2012 1:34 am |
|
|
Dear Ttelmah
Thanks in advance for my detail and quick help.
Code: |
lcd_send_byte(0, 0x40);
lcd_send_byte(1, 0x0E);
lcd_send_byte(1, 0x1B);
lcd_send_byte(1, 0x11);
lcd_send_byte(1, 0x11);
lcd_send_byte(1, 0x11);
lcd_send_byte(1, 0x11);
lcd_send_byte(1, 0x1F);
lcd_send_byte(1,0x00);
//lcd_send_byte(0, 0x40); remove this line
lcd_send_byte(1, 0x0E);
lcd_send_byte(1, 0x1B);
lcd_send_byte(1, 0x11);
lcd_send_byte(1, 0x11);
lcd_send_byte(1, 0x11);
lcd_send_byte(1, 0x11);
lcd_send_byte(1, 0x1F);
lcd_send_byte(1, 0x1F);
//lcd_send_byte(1,0x00); also remove this line then code is working fine.
//delay_ms(100); and remove the delays
|
Dear when i removed this line from above mention
Code: |
lcd_send_byte(1,0x00);
|
then your code is working fine. I think this line is only used in first location.
Now my lcd display is good and battery symbol now working well. Problem is solved with the help of Ttelmah. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|