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 CCS Technical Support

Counter output to LCD

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



Joined: 26 Feb 2008
Posts: 6

View user's profile Send private message

Counter output to LCD
PostPosted: Thu Feb 28, 2008 2:13 pm     Reply with quote

Hi there,
I am working on my project and I am having problems with stopping a binary counter to a certain value.
I have two buttons connected to the inputs of the PIC. The count up button increments the counter by 1 and then display to the lcd, and the counter down button decrements the counter by 1 and display to the lcd.
I am counting in 10 bit and I would like to write a function that if I increment the counter to the maximum value 1023 then the count up button to stop working.
Then I use the countdown button to decrement minimum value 0 and stop working.
At the moment my function rolls over from 1023 – 0 an so on.
There is my code so far:
Code:

float iset;
int icount;

//Countup
if(!input(PIN_C2) )
  {
    //Increment COUNT
    //Calculation:
    iCOUNT = iCOUNT + 1;
    iset = (float)(icount * 5)/25.0;
 
    lcd_gotoxy(7,2);
    printf(lcd_putc, "\iset:%3.2f", iset);
   }

//Countdown
if( !input(PIN_C7) )
  {
    iCOUNT =  iCOUNT - 1 ;
    iset = (float)(icount * 5)/25.0;
    lcd_gotoxy(7,2);
    printf(lcd_putc, "\iset:%3.2f", iset);
  }
 

Any pointers would be really appreciated.
Ttelmah
Guest







PostPosted: Thu Feb 28, 2008 3:57 pm     Reply with quote

Code:

float iset;
int16 icount; //Note _must_ be int16, since you want more than 8bits...

//Countup
if(!input(PIN_C2) )
  {
    if (icount<1023) iCOUNT = iCOUNT + 1;
    iset = (float)(icount * 5)/25.0;
 
    lcd_gotoxy(7,2);
    printf(lcd_putc, "\iset:%3.2f", iset);
   }

//Countdown
if( !input(PIN_C7) )
  {
    if (icount>0) iCOUNT =  iCOUNT - 1 ;
    iset = (float)(icount * 5)/25.0;
    lcd_gotoxy(7,2);
    printf(lcd_putc, "\iset:%3.2f", iset);
  }


It should be fairly easy to work out the effect of the changes shown.

Best Wishes
marken1



Joined: 26 Feb 2008
Posts: 6

View user's profile Send private message

Problem solved
PostPosted: Wed Mar 05, 2008 3:19 am     Reply with quote

Many thanks. That's just what I was after.
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