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

LCD12864

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



Joined: 18 Nov 2008
Posts: 274
Location: Athens, Greece.

View user's profile Send private message

LCD12864
PostPosted: Wed May 02, 2018 2:27 am     Reply with quote

Hello,

I am making my custom library to set/clear pixel on a 128*64 LCD with ST7920.

I got it working but I have this in my code:

Code:

   if       (px==0 || px==8  || px==16 || px==24 || px==32 || px==40 || px==48 || px==56 || px==64 || px==72 || px==80 || px==88 || px==96 || px==104 || px==112 || px==120) Pix=128;
   else if (px==1 || px==9  || px==17 || px==25 || px==33 || px==41 || px==49 || px==57 || px==65 || px==73 || px==81 || px==89 || px==97 || px==105 || px==113 || px==121) Pix=64;
   else if (px==2 || px==10 || px==18 || px==26 || px==34 || px==42 || px==50 || px==58 || px==66 || px==74 || px==82 || px==90 || px==98 || px==106 || px==114 || px==122) Pix=32;
   else if (px==3 || px==11 || px==19 || px==27 || px==35 || px==43 || px==51 || px==59 || px==67 || px==75 || px==73 || px==91 || px==99 || px==107 || px==115 || px==123) Pix=16;
   else if (px==4 || px==12 || px==20 || px==28 || px==36 || px==44 || px==52 || px==60 || px==68 || px==76 || px==84 || px==92 || px==100 || px==108 || px==116 || px==124) Pix=8;
   else if (px==5 || px==13 || px==21 || px==29 || px==37 || px==45 || px==53 || px==61 || px==69 || px==77 || px==85 || px==93 || px==101 || px==109 || px==117 || px==125) Pix=4;
   else if (px==6 || px==14 || px==22 || px==30 || px==38 || px==46 || px==54 || px==62 || px==70 || px==78 || px==86 || px==94 || px==102 || px==110 || px==118 || px==126) Pix=2;
   else if (px==7 || px==15 || px==23 || px==31 || px==39 || px==47 || px==55 || px==63 || px==71 || px==79 || px==87 || px==95 || px==103 || px==111 || px==119 || px==127) Pix=1;


Is there a better/more efficient way to do this?

Thanks!
_________________
George.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Wed May 02, 2018 2:42 am     Reply with quote

Code:

   int8 temp;
   const pxval[]={128,64,32,16,8,4,2,1};

   temp=px%8;
   Pix=pxval[temp];


I think that should give the right values.
georpo



Joined: 18 Nov 2008
Posts: 274
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Wed May 02, 2018 3:18 am     Reply with quote

It works Shocked

I have no idea how but it works!

thanks a lot Ttelmah!

Just noticed that your trick saved me 14% of ROM Neutral
_________________
George.


Last edited by georpo on Wed May 02, 2018 3:31 am; edited 1 time in total
georpo



Joined: 18 Nov 2008
Posts: 274
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Wed May 02, 2018 3:25 am     Reply with quote

BTW, in some other part of my "setpixel" code:

Code:

   if(px<8) X=0;                  //0-7            
   else if((px>7) && (px<16)) X=1;      //8-15
   else if((px>15) && (px<24)) X=2;   //16-23
   else if((px>23) && (px<32)) X=3;   //24-31
   else if((px>31) && (px<40)) X=4;   //32-39
   else if((px>39) && (px<48)) X=5;   //40-47
   else if((px>47) && (px<56)) X=6;   //48-55
   else if((px>55) && (px<64)) X=7;   //56-63   
   else if((px>63) && (px<72)) X=8;   //64-71
   else if((px>71) && (px<80)) X=9;   //72-79
   else if((px>79) && (px<88)) X=10;   //80-87
   else if((px>87) && (px<96)) X=11;   //88-95
   else if((px>95) && (px<104)) X=12;   //96-103
   else if((px>103) && (px<112)) X=13;   //104-111
   else if((px>111) && (px<120)) X=14;   //112-119
   else if((px>119) && (px<128)) X=15;   //120-127


The above decides in which X offset the pixel belongs to.
Is there any magic here? Rolling Eyes
_________________
George.
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed May 02, 2018 4:55 am     Reply with quote

It's early for me but
this...
else if((px>7) && (px<16)) X=1; //8-15

could be simplified to
else if(px<16)) X=1; //8-15

providing the IFs are in the correct order
something like this...
if(px<8) X=0; //0-7
else if(px<16)) X=1; //8-15
else if(px<24)) X=2; //16-23
else if(px<32)) X=3; //24-31
...
should work fine
when I look at it is says
if px<8 x becomes 0 and leave else then if px<16 x become 2.....

The other option would be to use the 'SWITCH...' statement. Actually you should code both and see what compiles,dump the listing(programname.lst file) to see It may be the SWITCH method produces smaller,faster code which means less ROM space and faster execution.
georpo



Joined: 18 Nov 2008
Posts: 274
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Wed May 02, 2018 5:15 am     Reply with quote

I get the point.

Thanks a million!
_________________
George.
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed May 02, 2018 5:37 am     Reply with quote

great cause I'm still sleepy over here in canada......
always amazes me the WORLDWIDE appeal of PICs !
ohpa
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Wed May 02, 2018 7:03 am     Reply with quote

georpo wrote:
It works Shocked

I have no idea how but it works!

thanks a lot Ttelmah!

Just noticed that your trick saved me 14% of ROM Neutral


OK lets go through it....

Code:


   int8 temp;
   const pxval[]={128,64,32,16,8,4,2,1};

   temp=px%8;
//Now this gives the remainder from dividing by 8. so just 1 to 7
//'1' for the first line of your tests, '2' for the next, etc. etc..

   Pix=pxval[temp];
//This gives '128' for '1', '64' for '2' etc..

Smile
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