CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

glcd_rect

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
MegatroniC



Joined: 08 Dec 2009
Posts: 35

View user's profile Send private message ICQ Number

glcd_rect
PostPosted: Mon May 14, 2012 7:13 am     Reply with quote

Hi, I need some help.

I use graphic display with KS0108 (and pic18f4620 8MHz). I try to do such a scale:




using GRAPHICS.C and function :

Code:

///****************************************************************************//
// Purpose:       Draw a rectangle on a graphic LCD                           //
// Inputs:        (x1, y1) - the start coordinate                             //
//                (x2, y2) - the end coordinate      (diagonals)              //
//                fill  - YES or NO                                           //
//                color - ON or OFF                                           //
// Dependencies:  glcd_pixel(), glcd_line()                                   //   
//****************************************************************************//
#ifdef LARGE_LCD
void glcd_rect(unsigned int16 x1, unsigned int16 y1, unsigned int16 x2, unsigned int16 y2, int1 fill, int1 color)
#else
void glcd_rect(unsigned int8 x1, unsigned int8 y1, unsigned int8 x2, unsigned int8 y2, int1 fill, int1 color)
#endif
.............


Мy code:

Code:

if(power!=old_power){
    old_power=power;
    switch(power){
       case 0: power_bar(0,0,0,0,0,0,0,0);
         break;
       case 1:
       case 2: power_bar(1,0,0,0,0,0,0,0);
         break;
       case 3:
       case 4: power_bar(1,1,0,0,0,0,0,0);
         break;
       case 5:
       case 6: power_bar(1,1,1,0,0,0,0,0);
         break;
       case 7:
       case 8: power_bar(1,1,1,1,0,0,0,0);
         break;
       case 9:
       case 10: power_bar(1,1,1,1,1,0,0,0);
         break;
       case 11:
       case 12: power_bar(1,1,1,1,1,1,0,0);
         break;
       case 13:
       case 14: power_bar(1,1,1,1,1,1,1,0);
         break;
       case 15: power_bar(1,1,1,1,1,1,1,1);
         break;
    }
 }


void power_bar(int1 a, int1 b, int1 c, int1 d, int1 e, int1 f, int1 g, int1 h)
{
 glcd_rect(120,58,127,62,1,Off);   
 glcd_rect(118,52,127,56,1,Off);                 
 glcd_rect(116,46,127,50,1,Off);                 
 glcd_rect(114,40,127,44,1,Off);                 
 glcd_rect(112,34,127,38,1,Off);                 
 glcd_rect(110,28,127,32,1,Off);                 
 glcd_rect(108,22,127,26,1,Off);                 
 glcd_rect(106,16,127,20,1,Off);               
 
 glcd_rect(120,58,127,62,a,ON);   
 glcd_rect(118,52,127,56,b,ON);                 
 glcd_rect(116,46,127,50,c,ON);                 
 glcd_rect(114,40,127,44,d,ON);                 
 glcd_rect(112,34,127,38,e,ON);                 
 glcd_rect(110,28,127,32,f,ON);                 
 glcd_rect(108,22,127,26,g,ON);                 
 glcd_rect(106,16,127,20,h,ON);                 
}


by increasing or reducing in value, image flicker.
How to avoid flicker? Embarassed

Тhanks
regards
Ttelmah



Joined: 11 Mar 2010
Posts: 19358

View user's profile Send private message

PostPosted: Mon May 14, 2012 8:38 am     Reply with quote

Write less.....
Your current code is like a person writing the bar on a blackboard, who when asked to add one bar, or remove one bar, instead of just erasing, or filling that single bar on the board, rubs out the whole board, then is surprised at how long it takes!.
So, store the values in static variables in the power_bar function, and if the new is > than old, just draw the new bar (don't bother to erase the old), and also if == old, don't change anything for that rectangle. Reduce the actual writing to the minimum.

Best Wishes
MegatroniC



Joined: 08 Dec 2009
Posts: 35

View user's profile Send private message ICQ Number

PostPosted: Mon May 14, 2012 11:55 pm     Reply with quote

Thanks for the reply. Smile

When the value increases, no problem because the new bar is drawn over the old.
When the value decreases, I have to remove only the filling, then delete the old bar, in order to draw new without filling.

This bar is flicker, but this is less of a problem.
Reduction is smooth, one by one, but if you need to delete all at once then you get bad flashing.

I will consider other options. Smile

Have a nice day.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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