1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

compiler for c

Discussion in 'Microcontrollers' started by Dr_Doggy, Dec 28, 2011.

  1. DerStrom8

    DerStrom8 Super Moderator Most Helpful Member

    Joined:
    Aug 9, 2010
    Messages:
    5,484
    Likes:
    503
    Location:
    Vermont (GMT-5:00)
    That is why I prefer to use the method I described earlier to set up and call the functions. It is much easier to understand. Your prototype would set up the value types and the code for that function in the prototype. That way, when you're in main and want to call the function, you only need to type the function name and put in the right values. I.E. int myFunction(int, int, int, int), and call it later by saying myFunction(CSA,SECTOR,BLOCK,PAGE); That way, you can pass the variables up into the function, and have it execute the code up there, and then come back down to main.
     
  2. Dr_Doggy

    Dr_Doggy Well-Known Member

    Joined:
    Aug 11, 2007
    Messages:
    1,715
    Likes:
    37
    ya, just another learning curve, the code is coming together nicely though, and ima bracket everything just to be safe,

    actually idk if it matters but that error didnt show till i got up to line 600something, AND im sure i will pick this all up, but just my "c for dummies" didnt get in to the ports and stuff, and iv never seen: "|" that line thingy on the keyboard before!, at first i actually had to punch it off of the ascii chart!!, also i kno this code is flawed; because im importing it from basic; first a crude translation, then ima smooth out the buggs.

    I do need to admit this is over my head, in fact iv never seen a RGB cube with my features(not that there isnt), i was this" close to finishing in basic, but im loosing whole pages in my serial comm, and i cant find prob(nor doogle) and i cant track the variables, im hoping that since c is more robust in adjusting details, plus this step-by-step debugging, wwaayyy betterrrrr, GCGB was trial and error the whole way, getting to the code i have now. sometimes taking 2 minutes to compile,.

    BESIDES I have such amazing profs in here, better than any school, and full confidence, I graduated as an Electronics Technician @ george brown and came out wondering *** id ever do with a transistor. since last year(maybe 2or3) when you guys showed me what a uC was it opened soo many doors for me, and circuit designs became wayyy simpler too~!, a million times i would like to thank you all once again, I may never do this professionally, but at least i can,



    I LUV ELECTRICITY !!!!!!!
     
    Last edited by a moderator: Jan 14, 2012
  3. Dr_Doggy

    Dr_Doggy Well-Known Member

    Joined:
    Aug 11, 2007
    Messages:
    1,715
    Likes:
    37
    ACK! so it seems to be coming together nicely already the registers and multiplex is running great! HOWEVER while using the breakpoints, i seem to have somehow set an advanced breakpoint on a line but now i cant find how to delete it? (not those red dots)



    NM i got it, it went away just as mysteriously as it appeared?>!
     
    Last edited: Jan 14, 2012
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. DerStrom8

    DerStrom8 Super Moderator Most Helpful Member

    Joined:
    Aug 9, 2010
    Messages:
    5,484
    Likes:
    503
    Location:
    Vermont (GMT-5:00)

    It sounds like you just set a breakpoint that couldn't be resolved. This usually happens if you put it on a bracket or empty line. Breakpoints must be set on lines that actually have executable instructions. If the breakpoint on your code showed up as only the red outline, that's probably what it was. To get rid of them, just double-click in the line it's set on. This is how you remove breakpoints.

    Regards
     
  6. Dr_Doggy

    Dr_Doggy Well-Known Member

    Joined:
    Aug 11, 2007
    Messages:
    1,715
    Likes:
    37
    ya, iv seen those! it wasnt that thou, it was listed under: ADV B, right next to the "reestablish pickit" and "read eeprom" buttons, but i couldn't delete it there, and it was not showing anything(dots) on the line breaking...
    anyway it resolved with a software reset,


    BUT NOW i think i am having problems with the clock timing everything is running very slow(in fast play(not stepmode) and in program mode) although i have set up my clk to INTIO67(properly) i think i need to include the clock speed(8Mhz), I am reading around, but there is not much, I also referred to my datasheet and it says it should default to the 8Mhz, it also says something about:
    IRCF2:IRCF0=111
    but it is not recognized when i put it in (my main, or in #pragma)
     
  7. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA
    These are OSCON register bits. Set them as you would any bits in any register using your compiler.

    You always need to refer to the data sheet to see what bits to set then look at the processor header file to see what names to use when setting them.
    In C18
    OSCONbits.IRCF0=1;
    OSCONbits.IRCF1=1;
    OSCONbits.IRCF2=1;

    or
    OSCON = x111xxxx;
    where x's are set to required values.
     
    Last edited: Jan 14, 2012
  8. Dr_Doggy

    Dr_Doggy Well-Known Member

    Joined:
    Aug 11, 2007
    Messages:
    1,715
    Likes:
    37
    OSCON np/ there it is, this is sooo cool going over this sheet im starting to see the LATABITS and such and how all the bits fit, so
    OSCCON = 01111111;
    that speeds it up a bit but it is still 100x slower than it was in cow@8mhz?

    but something about the clock again, OSC=INTI067; RIGHT? but the datasheet says something about either INT01 or INTO2, but INTIO67 is the one that works? datasheet just calls it register 1H,
     
  9. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA
    INTIO67 means INTernal osc IO on pins RA6 and RA7. This sets bits in the config memory.

    Do not confuse the above with OSCON which is a register aka Special Function Register aka SFR.

    HTH
     
    Last edited: Jan 14, 2012
  10. Dr_Doggy

    Dr_Doggy Well-Known Member

    Joined:
    Aug 11, 2007
    Messages:
    1,715
    Likes:
    37
    HMM well it is working, and i can see the speed changes when i change it up, but even with OSCON at 0111xxxx, i am still getting a substantial lag, is there maybe something else im overlooking,?? ID swear its only running at 32khz

    also i think it says that with OSCCON @ 01111001 will enable the pll and boost it up to 32MHz, that would be cool to do that...
     
    Last edited: Jan 14, 2012
  11. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA
    Bits 0 and 1 of OSCCON maybe the problem

    the key here is you want bit 1 to be 1
     
  12. Dr_Doggy

    Dr_Doggy Well-Known Member

    Joined:
    Aug 11, 2007
    Messages:
    1,715
    Likes:
    37
    thats how i had it originally, i just read that the last bits need to be 1000 or 1001 to use the f-devider

    both do the same though, also am i suppost to use 0b before the OSCON value since it binary?

    I have a feeling that its my main clock config, how do i specify a clock speed? is there an instruction to make sure its at 8 MHZ
     
  13. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA
    yes 0b for binary

    I am not sure which chip you are using but it may look like this

    0bxxxxxxx1x will set the system to use the internal clock
    0bx111xxxx will set the freq selector (mux) to use 8MHz

    0b01110010 setting all the x's to zero

    This value along with the INTIO67 in the #pragma config should give you 8 MHz

    maybe time to post your current code.
     
    Last edited: Jan 14, 2012
  14. Dr_Doggy

    Dr_Doggy Well-Known Member

    Joined:
    Aug 11, 2007
    Messages:
    1,715
    Likes:
    37
    um,k, but first pls be aware that alot of the subs in there are still mostly inactive, the main ones i am using are:

    READYCHIP
    SHIFTOUT
    MUX
    INSTRUCT

    now there is a bigger loop in shiftout but that is why i need the fast clk, to keep the output rotation fast enough to blend the LED array, and the always true if statement is just a bypass bit so its not reading the eeprom

    but the whole thing seems to be working fine besides the speed of it all, usually it can go fast enough, so that there is only a trace of a weak flikker, but now you really see the phase loops, id say on a factor of 10x - 100x
     

    Attached Files:

    • first1.c
      File size:
      13.8 KB
      Views:
      187
  15. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA
    Looks like it should be running at 8MHz to me. Maybe someone else can spot a problem.
     
  16. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,008
    Likes:
    316
    Location:
    Brisbane Australia
    Looks like it should run at 8MHz to me too.

    I just checked a project I did that ran at 32MHz and this is the relevant bit,
    Code (text):

    #pragma config WDT = OFF, LVP = OFF, OSC = INTIO67

    void main(void){
    unsigned char i,Buffer[20];
        OSCCON=0x70;            //8MHz please
        OSCTUNEbits.PLLEN=1;    //*4 = 32MHz
        ADCON1=0x07;            //no ADC
        CMCON=0x07;
     
    Note, bit 1 of OSCCON doesn't need to be set.

    Mike.
     
  17. Dr_Doggy

    Dr_Doggy Well-Known Member

    Joined:
    Aug 11, 2007
    Messages:
    1,715
    Likes:
    37
    excelent, that worked good, except i deleted:unsigned char i,Buffer[20];

    but who cares, it works!!!
     
  18. Dr_Doggy

    Dr_Doggy Well-Known Member

    Joined:
    Aug 11, 2007
    Messages:
    1,715
    Likes:
    37
    thnx again guys for all the paitence, but now i am having problems reading ports, i set it up in TRIS

    TRISB = 0b01000101; // B0 B2 AND B6 ARE INPUTS


    LATDATA == PORTBbits.RB2;
    if (LATDATA = 1) {INVALU = 3;}

    but invalu always = 3, however i have the port shorted to ground! (or vcc, doesnt change to value), i have also tried LATBbits.LATB2
     
  19. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA
    To start with you have mixed up = (the assignment operator) and == (the comparison for equality).
     
  20. Dr_Doggy

    Dr_Doggy Well-Known Member

    Joined:
    Aug 11, 2007
    Messages:
    1,715
    Likes:
    37
    ah yes there we go, but i dont get it, i shouldnt need == if all my values are integers(int)?



    OOOH... comparison
     
    Last edited: Jan 15, 2012
  21. DerStrom8

    DerStrom8 Super Moderator Most Helpful Member

    Joined:
    Aug 9, 2010
    Messages:
    5,484
    Likes:
    503
    Location:
    Vermont (GMT-5:00)
    Not sure if that last line means you understand, so I'm just going to specify. You can set bits and variables using '=', but if you want to compare values you have to use '=='.
     

Share This Page