|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
16f84 Switch counter to lcdHi all.
I am trying to make a switch counter that would put on the lcd screen how many times /50 the switch has been opened/closed. I purchased the Book PIC In Practice and have been successfull in building the LCD circuit 2x20 and able to put the words i need to the screen. (after spending hours trying to get it to work) What i need and am hopelessly lost at this point, is to count the switch on A0 and put the amount on to the screen. using the lcd Code in the above book. I beg you, this is not for any other purpose than to count the water gallon usage in my house using a hall effect switch on the meter. Can anyone help me with code/ suggestions etc Thanks in advance Paul -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist |
|
|
Re: 16f84 Switch counter to lcdHi Paul,
I still consider myself a newbie so treat my suggestions accordingly. The way I would tackle it is to use a flip-flop flag that toggles when A0 changes state. Then only update a counter when both the flag is clear and A0 is high. some thing like clrf counter bcf flag,0 Loop1: if (flag == 0 and A0 ==1) bsf flag,0 incf counter,f check for overflow and update a second counter and so on if needed else if(A0 ==0) bcf flag,0 end if end if do divide by 50 update lcd goto Loop1 hope this helps. If you got an lcd to work converting the rough pseudo code above should be straight forward. Interrupt on change may also be an option but I cant remember if '84 supports this. 2009/10/23 Paul & Lynn Tyrer <Paul@...> > Hi all. > I am trying to make a switch counter that would put on the lcd screen how > many times /50 the switch has been opened/closed. > > I purchased the Book PIC In Practice and have been successfull in building > the LCD circuit 2x20 and able to put the words i need to the screen. (after > spending hours trying to get it to work) > > What i need and am hopelessly lost at this point, is to count the switch on > A0 and put the amount on to the screen. using the lcd Code in the above > book. > > I beg you, this is not for any other purpose than to count the water gallon > usage in my house using a hall effect switch on the meter. > > Can anyone help me with code/ suggestions etc > > Thanks in advance > > Paul > > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist |
|
|
Re: 16f84 Switch counter to lcdPaul & Lynn Tyrer wrote:
> I am trying to make a switch counter that would put on the lcd screen > how many times /50 the switch has been opened/closed. > > ... > > What i need and am hopelessly lost at this point, is to count the > switch on A0 and put the amount on to the screen. So what part are you having problems with, counting the switch closures or displaying a number? They are two completely independent problems. ******************************************************************** Embed Inc, Littleton Massachusetts, http://www.embedinc.com/products (978) 742-9014. Gold level PIC consultants since 2000. -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist |
|
|
Re: 16f84 Switch counter to lcdPaul & Lynn Tyrer escreveu:
> Hi all. > I am trying to make a switch counter that would put on the lcd screen how > many times /50 the switch has been opened/closed. > > I purchased the Book PIC In Practice and have been successfull in building > the LCD circuit 2x20 and able to put the words i need to the screen. (after > spending hours trying to get it to work) > > What i need and am hopelessly lost at this point, is to count the switch on > A0 and put the amount on to the screen. using the lcd Code in the above > book. > > I beg you, this is not for any other purpose than to count the water gallon > usage in my house using a hall effect switch on the meter. > > Can anyone help me with code/ suggestions etc > > Thanks in advance > > Paul > Hello, I would suggest you to move to a newer PIC, such as 16F628A or 16F88. If you already managed to show a message on the LCD, then you went already 99% of the path. Just make an infinite loop and wait until some pin changes from low-to-high and high-to-low again (or vice-versa), then increase some counter (one byte variable). When your counter reaches 50, clear it to zero and increment another counter (possibly a two-byte variable) and update the value on the LCD. If you are using assembly, you will need to convert the counter value to a string to show on the LCD. If you are using C, then you just can use "printf", it is much easier. If you need further help, let me know. Best regards, Isaac __________________________________________________ Faça ligações para outros computadores com o novo Yahoo! Messenger http://br.beta.messenger.yahoo.com/ -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist |
|
|
Re: 16f84 Switch counter to lcdIsaac Marino Bavaresco wrote:
> Just make an infinite loop and wait until some pin changes from > low-to-high and high-to-low again (or vice-versa), then increase some > counter (one byte variable). It's not quite that easy. This is apparently a mechanical switch, so it will bounce. Important information the OP left out is what is the maximum frequency of switch closures, and what is the mininum duration of a closure. Since this is apparently a mechanical switch input, we can assume it can be sampled every 1mS. I would set up a periodic interrupt using timer 2 and sample and debounce the switch in the interrupt. The interrupt routine sets a flag on every debounced switch closure. The foreground code can then handle this as another event in the event loop. Dividing by 50 also doesn't sound like the right way. Is it really really 50.00? Probably not. One possibility is to add a small increment into a fixed point gallon accumulator with enough fraction bits. If you want to display whole gallons, you just use the integer bits. Another possibility is to accumulate raw switch closures, then multiply by the appropriate fixed point scale factor to make gallons when needed. Both these methods allow for tweaking the scale factor for calibration. ******************************************************************** Embed Inc, Littleton Massachusetts, http://www.embedinc.com/products (978) 742-9014. Gold level PIC consultants since 2000. -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist |
| Free embeddable forum powered by Nabble | Forum Help |