Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
08/24/06 22:03
Read: times


 
#122973 - OK
Responding to: ???'s previous message
Andy Neil said:
Jon Ledbetter said:
So if I do:#define SW1 P_4;Then later in a proceedure or function I can do:Sw1 = 1; // turn on port
delay(20); // delay
SW1 = 0; // turn off portBut this doesn't work.

It doesn't work because it is not correct!

For a start, 'C' is case-sensitive - so SW1 and Sw1 are not equivalent!

When you use a #define, it works like this:#define Then, wherever the preprocessor sees , it simply replaces it with

In your code above,
is SW1
is P_4; - including the semicolon!


Thus, after preprocessing, your code becomes (assuming that you intended SW1 in both cases):P_4; = 1; // turn on port
delay(20); // delay
P_4; = 0; // turn off portand the error is immediately obvious!
See: http://www.8052.com/forum/read.phtml?id=29152

I have several references for C, but most use Keil code.

This is basic, plain vanilla, bog-standard 'C' - nothing to do with Keil, SDCC, or any other specific implementation!

As has already been mentioned, you need to learn the basic 'C' language first, before worrying about the extensions offered by Keil, SDCC, etc...



Ok first of all the Sw1 was a typo it should have been SW1.
Second, the reference to Keil code was the usage of Px^x vs Px_x
Third, the extensions is what makes it useful for a uC, right? That's why I'm giving a try, I don't want to program a PC. I understand I need to learn the basics first. It was just natural to put a ; at the end of the line.

Jon

List of 32 messages in thread
TopicAuthorDate
SDCC Nooby Question            01/01/70 00:00      
   Ok got it            01/01/70 00:00      
      it\'s ok in Keil            01/01/70 00:00      
         Yes...            01/01/70 00:00      
            The reason is...            01/01/70 00:00      
               C first            01/01/70 00:00      
                  Learning C            01/01/70 00:00      
                     if this is cut and paste then            01/01/70 00:00      
                        Semi-colon was it            01/01/70 00:00      
                           C is fidgety about error declaration            01/01/70 00:00      
                           Syntax error            01/01/70 00:00      
                              Going back and looking...            01/01/70 00:00      
                                 It means            01/01/70 00:00      
                                    Preprocessor output            01/01/70 00:00      
                                 explanation            01/01/70 00:00      
                        Semicolon            01/01/70 00:00      
                           yes, Andy you are absolutely correct            01/01/70 00:00      
                              Semicolon - example            01/01/70 00:00      
                           backwards            01/01/70 00:00      
                              HUH?            01/01/70 00:00      
                                 try this            01/01/70 00:00      
                     Dallas app notes            01/01/70 00:00      
                     False economy            01/01/70 00:00      
                        OK            01/01/70 00:00      
                     Learning from the tools            01/01/70 00:00      
                        #define and the preprocessor            01/01/70 00:00      
                           are you sure?            01/01/70 00:00      
                              Yes!            01/01/70 00:00      
                           Hmmm...            01/01/70 00:00      
   SDCC Manual            01/01/70 00:00      
      Err... ya think?            01/01/70 00:00      
         Looks clear enough to me            01/01/70 00:00      

Back to Subject List