programming advice


Are you just looking for general advice, or is there something specific that you want your code to do, that it isn't doing?

Not able to Display the Value, and looking for help on what can i do on my code.

I don’t understand why you’re directly calling what appears to be an ISR in “loop()”.

Try breaking down the problem using code that is already debugged - use the serial monitor to print results and debug info (but not in ISRs!), and build up your sketch - don’t try the whole lot at once because you have no idea what works and what doesn’t.

Can you use the auto-format tool and repost, please?
Your indentation hurts my eyes.

I second what AWOL said about using auto-format on your code. It's basically un-readable as it is, without any indentation or anything.

When you say you are not able to display the value, do you mean that you cannot make the LCD show characters? Or that the LCD shows characters, but they are the wrong ones (i.e. your conversion from number to ASCII is broken)? If the former, I suggest trying to make the program work using Serial.print() instead of LCD. Once it is working properly over Serial, transition to the LCD.

Do not call the ISR EXT_INT0() from within your loop(). Only the interrupt should call the ISR. Assuming your code compiles and everything, your loop() is incrementing t_overflow_count constantly, thousands of times a second, making its value meaningless.

You have way too much code inside ISR(TIMER1_OVF). An ISR should do as little as possible. An ISR should hardly ever need to update a display, or do complex calculations. Ideally, the ISR should set a flag that is then checked from within loop() and if the flag is set, then loop() performs the display update and so forth.

  energy_KWH =0;
  display =0;

Pointless; the compiler/crt0 has already done this for you.

total_tvalue= (unsigned long)(t_overflow_count*65535+TCNT1);

65535 is not representable as a 16 bit "int"; try "65535L" instead.