![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
marken1
Joined: 26 Feb 2008 Posts: 6
|
Counter output to LCD |
Posted: Thu Feb 28, 2008 2:13 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Thu Feb 28, 2008 3:57 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
marken1
Joined: 26 Feb 2008 Posts: 6
|
Problem solved |
Posted: Wed Mar 05, 2008 3:19 am |
|
|
Many thanks. That's just what I was after. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|