We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi, using C inside the Keil 7.0 Tools i have a strange behaviour. some defines / includes ... #include "mycpu.h" .. #define LCD_Port P2 #define RS P2_1 #define LOW = 0; ... void function1(unsigned char temp) { ... LCD_Port = temp; RS = LOW; // this two lines are not executed, using the debugger, the debugger jumps over these lines ... } void function2(unsigned char temp) { ... LCD_Port = temp; // this line is executed ... } Why? Thank you in advance Axel
#define LOW = 0;
Oops, and the '=' for that matter. The define should be:
#define LOW 0
"Remove the semicolon (;)." And the "="! Stefan
Hello, sorry, in the real program there is no ; and = at the specific positions in the define area, just a writing fault of me in this board ;-) Axel
Why? Impossible to tell from what you posted. You don't even show where these functions are called from. Note that the debugger jumping across a statement does not necessarily mean the statement is not executed --- it may have been moved around by the optimizer in ways the debugger doesn't understand. To be really sure, you'll have to step through the machine code, not the C source, and observe whether or not those registers are touched. Or observe the behaviour of the actual hardware. Just looking at the generated code in the debugger or int the listing file can clear things up a lot, too.
Hello, first thanks for all your answers. i use some of this functions to control a LCD (164A type) connected to Port2 of a Atmel T89C51CC01 mikrocontroller. These two functions are writing 2 nibbles to the dataport each, one for sending commands and one for sending characters I put the data using the LCDPort = command; on my outputport in one function, and during debugging i am watching the port watch of that port with the keil software. For sending commands this is ok, but for sending chars to the LCD i have also to set the RS pin to HIGH / or to low, not sure here, but to the opposite state of the port when entering the function). The debugger jumps over this two lines then and watching the outputport i also don t see my command working. Furthermore i tried it on my experimentation board, there i can see, that the LCD is correctly initialised, but no characters are send out, probably due to this behaviour. OK, there are some other ways to output the value to the port with only one command, but this should also work. (i.e. using or or and) for better understanding here are the whole functions the following functions is working good, i know, temp could be ommitted to save, but so it is easier to see for beginners like me void LCDSendCommand(unsigned char command) { unsigned char temp; temp=command; temp=temp & 0xF0; LCD_PORT=temp; // ok, output upper nibble LCDToggleEN(); LCDBusy(); temp=command; temp=temp<<4; LCD_PORT=temp; //ok, output lower nibble LCDToggleEN(); LCDBusy(); } this function is not outputting correct values void LCDSendData(unsigned char command) { unsigned char temp; temp=command; temp=temp & 0xF0; LCD_PORT=temp; // not ok LCD_RS = HIGH; // not ok LCDToggleEN(); LCDBusy(); temp=command; temp=temp<<4; LCD_PORT=temp; // not ok LCD_RS = HIGH; // not ok LCDToggleEN(); LCDBusy(); } last but not least the definitions,... #include <REG51CC01.H> #define HIGH 1 #define LOW 0 #define LCD_PORT P2 #define LCD_RS P2_3 #define LCD_RW P2_2 #define LCD_EN P2_1 #define LCD_DATA4 P2_4 #define LCD_DATA5 P2_5 #define LCD_DATA6 P2_6 #define LCD_DATA7 P2_7 (P2_0 is not used and not connected) just for interest the (working) subfunctions void LCDToggleEN(void) { LCD_EN = HIGH; LCDDelay(10); LCD_EN = LOW; } LCDBusy() is just a delay loop, because i am not using the really using the possibilitie of reading the busy flag. Thank you Axel
What does the assembly code generated look like for this? Is there any code generated for the statements that get skipped? Jon