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. (aft= er > 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 gall= on > 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 #include 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 =3D 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 =3D 0; // put the code to initialize the MCU and I/Os here; LCDInit(); while( 1 ) { clrscr(); printf( "Value: %5u", Count ); while( SENSOR =3D=3D 0 ) CLRWDT(); delay_ms( 1 ); while( SENSOR !=3D 0 ) CLRWDT(); delay_ms( 1 ); Count++; } } __________________________________________________ Fa=E7a liga=E7=F5es 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