16f84 Switch counter to lcd

View: New views
6 Messages — Rating Filter:   Alert me  

16f84 Switch counter to lcd

by Paul & Lynn Tyrer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Just to update, I am hopelessly new and lost. I was a VB basic guy years ago
and remember a little of what I need to do but not a lot.
I know I will need a place to store the count, and will have a call list up
to 50 so when the count equals 10 I will have a call to put 1+0 on the
screen.
How do I :
Create a place to store the count.
Increment 1 to this count when the state changes
compare the stored count so when it equals 50 I increment the lcd by 1

I was hoping to find a piece of code out there in Google land to help me but
as of yet I have not been successful. However I do feel a sense of
achievement coming this far.

Any help is of course appreciated.

Thanks

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 successful 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 lcd

by Olin Lathrop :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Paul & Lynn Tyrer wrote:
> How do I :
> Create a place to store the count.

count    res     1           ;individual events counter

You'll need this later too:

gallon   res     4           ;32 bit total gallons
         global  gallon

> Increment 1 to this count when the state changes

         banksel count
         incf    count       ;count one more event

> compare the stored count so when it equals 50 I increment the lcd by 1

         movf    count, w    ;get the raw count
         sublw   49          ;compare to threshold
         skip_wgt            ;got another whole gallon ?
         jump    done_gallon ;no
         ;
         ;   One more whole gallon detected.
         ;
         clrf    count       ;reset counts until next gallon
         movlw   1           ;count one more gallon
         addwf   gallon+0
         skip_ncarr
         addwf   gallon+1
         skip_ncarr
         addwf   gallon+2
         skip_ncarr
         addwf   gallon+3
         gcall   disp_gallon ;display the new gallons value
done_gallon

SKIP_WGT, SKIP_NCARR, and GCALL are wrapper macros I use to make the code
the code more readable, less tedious, and less error prone.  You can
probably guess from context what they do.


********************************************************************
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 lcd

by Bob Blick-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, 23 Oct 2009 10:00:39 -0500, "Paul & Lynn Tyrer"
<Paul@...> said:

> Just to update, I am hopelessly new and lost. I was a VB basic guy years
> ago
> and remember a little of what I need to do but not a lot.
> I know I will need a place to store the count, and will have a call list
> up
> to 50 so when the count equals 10 I will have a call to put 1+0 on the
> screen.
> How do I :
> Create a place to store the count.
> Increment 1 to this count when the state changes
> compare the stored count so when it equals 50 I increment the lcd by 1
>
> I was hoping to find a piece of code out there in Google land to help me
> but
> as of yet I have not been successful. However I do feel a sense of
> achievement coming this far.

Hi Paul,

It sounds like you are doing this in assembly language. At this point
you have learned a bit about PICs and assembly language. I would suggest
deciding what the purpose of the exercise is now, and by the way,
congratulations you've gotten this far. If you want to become more
proficient at assembly language, continue on the path you are on. But if
you want to get your project done, I'd suggest looking into programming
in C or even Basic. It gets the job done and for many people(myself
included) assembly language is something you use for a subroutine once
in a while, not your whole program.

On the other hand, you are very close to being done with the program as
it is. I don't know the book you've been using, style in programming
PICs changed at a certain point because Microchip's tools improved. Most
books I've seen use the old style where the program chunks were
delineated by "org" and variables were in "cblock". Is that how your
program is put together?

Cheerful regards,

Bob

--
http://www.fastmail.fm - Same, same, but different...

--
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 lcd

by Isaac Marino Bavaresco :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Paul & Lynn Tyrer escreveu:

> Just to update, I am hopelessly new and lost. I was a VB basic guy years ago
> and remember a little of what I need to do but not a lot.
> I know I will need a place to store the count, and will have a call list up
> to 50 so when the count equals 10 I will have a call to put 1+0 on the
> screen.
> How do I :
> Create a place to store the count.
> Increment 1 to this count when the state changes
> compare the stored count so when it equals 50 I increment the lcd by 1
>
> I was hoping to find a piece of code out there in Google land to help me but
> as of yet I have not been successful. However I do feel a sense of
> achievement coming this far.
>
> Any help is of course appreciated.
>
> Thanks
>
> 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 successful 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
>  

It would be better if you start by telling what language you are using.

I know there are some BASIC compilers for PIC. If you are struggling
with assembly, I would suggest you to switch to BASIC or C.


Best regards,

Isaac


PS.: The code below (in Hi-Tech C) should do what you need. There are
free versions of the Hi-Tech PICC available.
If you need any help, please say so.

#include <pic.h>
#include <stdio.h>

void LCDInit( void )
{
// put your LCD initialization code here
}

void putch( char c )
{
// put your code to show one character on LCD here
}

void clrscr( void )
{
// put your code to clear the LCD here
}

void delay_ms( unsigned short t )
{
    unsigned short i;

    for( ; t; t-- )
    {
        for( i = 100; i; i-- )
        {
        // put code to waste slightly less than 10us here.
        // You could test in the simulator and modify until each
iteration of
        // the outer loop takes the closest possible time to 1ms.
        }
    }
}

#define SENSOR RB0 /* or whatever other pin you want to use */

void main( void )
{
    unsigned short Count = 0;

    // put the code to initialize the MCU and I/Os here;

    LCDInit();

    while( 1 )
    {
        clrscr();
        printf( "Value: %5u", Count );
        while( SENSOR == 0 )
            CLRWDT();
        delay_ms( 1 );
        while( SENSOR != 0 )
            CLRWDT();
        delay_ms( 1 );
        Count++;
    }
}
__________________________________________________
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 lcd

by CDB-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



:: 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.

Paul,

I have code for a water meter that you can download from my website.

It is written in 'C', uses a turbine flow meter, but as this just has
a Hall effect switch internally, you should with minimal reworking be
able to use it, or play about with the code until you are satisfied.

Colin

--
cdb, colin@... on 10/24/2009
 
Web presence: www.btech-online.co.uk  
 
Hosted by:  www.1and1.co.uk/?k_id=7988359
 

 
 
 
 

--
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 lcd

by ivp :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Paul, there are conversion routines here

http://www.piclist.com/techref/microchip/math/radix/index.htm

to convert the counter contents to ASCII for the LCD

For a single byte you might try a simple /10 + remainder

         movf    counter,w ;copy
         movwf   temp
         clrf    dg_lo     ;clear destination
         clrf    dg_hi

loop     movlw   0x0a
         subwf   temp      ;subtract 10
         incf    dg_hi     ;increment 10's
         bc      loop      ;loop if temp > FF (-1)

         decf    dg_hi     ;else reduce 10's count
         addwf   temp,w    ;add back the 10
         movwf   dg_lo     ;store remainder (units)

         movlw   0x30      ;convert to ASCII
         iorwf   dg_lo
         iorwf   dg_hi

--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist