I am using NEX Robotics board for LPC2148. I find very strange problem with below lines of code.
//Prototypes void diaplayInRow1WithPosition(unsigned char* data, unsigned char position); void diaplayInRow2WithPosition(unsigned char* data, unsigned char position); unsigned char convertHigherNibbleToASCIIValue(unsigned char data); unsigned char convertLowerNibbleToASCIIValue(unsigned char data); int main (void) { unsigned char temp2; unsigned int PLLStatus; initializeAll(); PLLStatus = PLL0STAT; temp2 = convertLowerNibbleToASCIIValue(PLLStatus); diaplayInRow1WithPosition(&temp2,15); temp2 = convertHigherNibbleToASCIIValue(PLLStatus); diaplayInRow1WithPosition(&temp2,14); temp2 = PLLStatus>>8; temp2 = convertLowerNibbleToASCIIValue(PLLStatus); diaplayInRow1WithPosition(&temp2,13); return(0); } When this code is executed, I see a blank display. I noticed that the problem is with last convertLowerNibbleToASCIIValue function call. It should have been:
temp2 = convertLowerNibbleToASCIIValue(temp2 ); But because of this one line error, why entire display is blank? Only last function diaplayInRow1WithPosition should have given trouble right? Even after changing with above line, I am getting blank display. So I replaced that line containing last convertLowerNibbleToASCIIValue as
temp2 = convertLowerNibbleToASCIIValue(PLLStatus>>8); And finally I got correct display.
Unable to digest the problem. Anyone can help? Main answer I need is if at all there is a problem in one line, why previous lines are not getting executed correctly? I am using Keil compiler and any compiler dependencies? There is no compilation error. If there is a problem with types etc, will entire program get corrupted? Also I noticed that adding extra dummy line such as temp=10; changes the behavior even though temp variable is not utilized.
You haven't responded to the note that you should not exit main().
There are no operating system that will return you to a command line prompt or to a GUI if the program exits. Exiting main() in an embedded device like this results in undefined behaviour. The program may restart again, and again, and again. Or it may find some random instructions to run. And the current state of the processor registers, or the size of the program, or contents from the previous version of the program may affect what will happen. That's the "nice" thing about something being undefined - you can't be expected to know what will happen. So you just should not exit main() but add an infinite loop at the end.
By the way - why do you use magic constants like 0x30 and 0x37?
Isn't it much better to add '0' if you want to get the ASCII value for 0..9? And you can add 'A'-10, if you want upper-case characters A..F or 'a'-10 to get lower-case characters.
Did you notice one more thing - you still haven't picked up on how to post source code, making it look like:
void mul_by_two(int a) { return a*2; }
The information is clearly there, if you just take the time to look.
Thanks for feedback on posting the code. Yeah, I did not notice
and <\pre>. I tried removing return from main. Even then behavior is not consistent.
Exiting main(), yes bad idea there, where do you think that goes?
int main(void) { //....your code while(1); //infinite loop for not existing main }