Need Help!

Thread Starter

Viann

Joined Jun 16, 2009
5
I've been cracking my head for hours, and I couldn't come up with a solution.

PIC I am using is PIC16F877A

Alright, I'm supposed to receive a value from the ADC and convert it to its appropriate value and output it to an LCD.

Attached is the code I did... but the problem is the values that come out are garbage and after that, I am getting "Hardware Stack Overflow". I tested it using PIC Simulator IDE.

Could someone help me debug the code?


Based on the Source Code, this is how I output the value:
  • Add whatever value in the memory labelled First with b'00110000' in order to get the appropriate value.
  • After that, I send out a '.', a dot signifying the next two values being decimal places.
  • Then, I add whatever value in the memory labelled Second with b'00110000' in order to get the appropriate value.
  • After that, I add whatever value in the memory labelled Third with b'00110000' in order to get the appropriate value.

And then the code goes back to the beginning to check for the ADC value again, and outputs a newer value when changed.

I know the code is long, but I sincerely hope you guys can help me out.
The problem starts here: OUTPUT CURRENT READING
 

Attachments

beenthere

Joined Apr 20, 2004
15,819
When you add the converted number to 30h, the purpose is to make it into an ASCII character for the display.

The A to D converter is 10 bits - that is a decimal value of 1024. You are using three digits, so I will guess that you want to display 0 - 999.

You may have an initial problem in that the converted value is binary, and will have to be changed to a decimal equivalent before the change to an ASCII value for display. For instance, the maximum conversion value is 11 1111 1111 (3Fh), which is 1023d.
 

millwood

Joined Dec 31, 1969
0
it would have been so much easier to do it in C.

I would break the code in to two pieces: lcd and adc. and make sure that each section works properly before combining them together.
 
I have started programming in assembly for the Z80 and later for the 80x86.
I did learn PICs using the assembly, just to have a better hardware feeling...

...but definitely C is much better. It let you think closer to your language and reduce bugs.
...the time I could forget about changing banks it was a good time.

I do follow these basic rules:

  • Use assembly just for optimizations
  • Optimize just what you must optimize
  • Document the battle neck with timing tests (to make sure that the optimization let really save you time)
...otherwise just write the most clear software...
...without any optimizations.

The brilliance of optimizations normally let the software being less readable.

Ciao,

Mauro
 
Top