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 20:39
Read: times


 
#122956 - Learning C
Responding to: ???'s previous message
Maarten Brock said:
Jon,

You need to learn C first.


You're right. Once upon a time I took a C class some 15 years ago, unfortunatly I don't remember much of it and it was for PC. For a few years now I've been tempted to pick it up again for my 8052 stuff. It just seems so much more complicated to get the desired results than from assembler.

The whole idea of using SDCC (for me) is that it's free, so likewise I'm not going to go out and buy a book to learn it, I'm using internet resources for that. I have several references for C, but most use Keil code.


The preprocessor will turn this
#define SW1 = P2_4
SW1=1;
into this
= P2_4=1;
Which is not correct C code.

Then, what's right in Keil does not need to be right in SDCC. SDCC is not Keil compatible for non-ANSI extensions. So
sbit SW1 = 0xA4;
tells SDCC there is some special function bit variable and it is initialized to 1 (0xA4 != 0).

Your first define was closest to the right solution:
#define SW1 P2_4

Maarten



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 port


But this doesn't work.

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