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

what do you think about my code??

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



Joined: 24 Jun 2005
Posts: 206

View user's profile Send private message Send e-mail

what do you think about my code??
PostPosted: Thu Mar 23, 2006 4:35 am     Reply with quote

Hi All, the following code works OK, but i just want your input in case i am doing somthing the wrong way. It is a menu system where a arrow moves down the page using a switch. If i press another switch, the state will change between off, on and auto. The state will be displayed on the screen. Is there anything that i could do in a better way??

Code:

#include <16f877a.h>
#fuses NOWDT, HS, NOPROTECT, BROWNOUT, NOPUT, NODEBUG, NOLVP
#use delay(clock=20000000)
#use i2c(MASTER, SDA=PIN_C4, SCL=PIN_C3)
#use rs232(baud=57600,parity=N,bits=8,xmit=PIN_C6,rcv=PIN_C7)

#define downarrow         PIN_C1
#define   select            PIN_C2
   
#include <ds1307.c>
#include <HDM64GS12.c>
#include <graphics.c>

char lcddata[20];

int sec, min, hrs, day, mth, year, dow;
int outputforce[8];
int p, arrowstate;

void drawstates()
   {
      int forcestat;
      int ypos = 0;
      for(p=0;p<8;p++)
         {
            forcestat = outputforce[p];                              //move force state to var
            
            if (arrowstate == p)                                 //check if arrow position state is on the same line as we are printing too.
               {
                  sprintf(lcddata,"<<");
                  glcd_text57(115,ypos,lcddata,1,on);
               }
            else
               {
                  glcd_rect(115, ypos, 128, ypos + 8, yes, off);         //clears all other positions
               }

            switch (forcestat)
               {
                  case 0:                                 //force is off
                     sprintf(lcddata,"Off");
                     glcd_text57(85,ypos,lcddata,1,on);
                     break;
                  
                  case 1:                                 //force is On
                     sprintf(lcddata,"On");
                     glcd_text57(85,ypos,lcddata,1,on);
                     break;

                  case 2:                                 //force is off
                     sprintf(lcddata,"Auto");
                     glcd_text57(85,ypos,lcddata,1,on);
                     break;
               }
            ypos = ypos + 8;
         }
   }   
void main()
   {

      
      glcd_init(ON);                                           //turn of LCD


      arrowstate = 0;
sprintf(lcddata,"Light Bank 1");                     //setup non-changing data
            glcd_text57(1,0,lcddata,1,on);
            sprintf(lcddata,"Light Bank 2");
            glcd_text57(1,8,lcddata,1,on);
            sprintf(lcddata,"Light Bank 3");
            glcd_text57(1,16,lcddata,1,on);
            sprintf(lcddata,"Light Bank 4");
            glcd_text57(1,24,lcddata,1,on);   
            sprintf(lcddata,"Light Bank 5");
            glcd_text57(1,32,lcddata,1,on);   
            sprintf(lcddata,"Heaters");
            glcd_text57(1,40,lcddata,1,on);
            sprintf(lcddata,"PH Valve");
            glcd_text57(1,48,lcddata,1,on);
            sprintf(lcddata,"Hood Fan");
            glcd_text57(1,56,lcddata,1,on);

      while(1)
         {


            
         
            drawstates();
         
            if (input(downarrow))                              //down switch
               {
                  if (arrowstate >= 7)
                     {
                        arrowstate = 0;
                     }
                  else
                     {
                        arrowstate ++;
                     }
               }   
            
               if (input(select))                              //select switch, set forcestate if pushed
               {
                  if (outputforce[arrowstate] >= 2)
                     {
                        outputforce[arrowstate] = 0;
                        glcd_rect(85, arrowstate * 8, 112, arrowstate * 8 + 8, yes, off);
                     }
                  else
                     {
                        outputforce[arrowstate] ++;
                        glcd_rect(85, arrowstate * 8, 112, arrowstate * 8 + 8, yes, off);
                     }
               }   
            
            
         }
   
     }



Thanks for you input

Mark
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