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

Hi-Tech C Compiler: What am I doing wrong?

Discussion in 'Microcontrollers' started by micro571, Jun 28, 2009.

  1. millwood

    millwood Banned

    Joined:
    Jun 17, 2009
    Messages:
    191
    Likes:
    2
    no reason to jump up and down declaring your intent: we don't question the least bit of your intent to help the others. and you shouldn't either.

    and in my very first post on this very thread, I said that "I assume the port configurations are right" - I simply didn't have time to check it out, and I took that as rudimentary for anyone with any experience programming any mcu.

    if you had tried his code and then realized that the port settings are wrong, ...
     
  2. millwood

    millwood Banned

    Joined:
    Jun 17, 2009
    Messages:
    191
    Likes:
    2
    this whole thing really gets me intrigued about this chip.

    here is the block diagram and it shows adc on PORTA, and pwm/spi/i2c/uart on PORTC.

    if ever we ever had the problem with incorrectly configuring an "analog" port and not being able to set it low, shouldn't that problem show up on PORTA instead?

    what am I missing?

    now, I would really love to see how be80be did it on PORTC but managed to get PORTA to defy the datasheet.
     

    Attached Files:

  3. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,019
    Likes:
    317
    Location:
    Brisbane Australia
    However, you have bloated a thread with irrelevant arguments because you didn't read the data sheet or, if you did read it, you didn't understand it. If you do now understand it then your arrogance has stopped you admitting it.

    I hope that in future I am able to differentiate between newbies that want to learn and those that want to waste everyones time.

    Mike.
     
  4. dave

    Dave New Member

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


     
  5. millwood

    millwood Banned

    Joined:
    Jun 17, 2009
    Messages:
    191
    Likes:
    2

    you are mad because you didn't understand what was going wrong with the program.

    the reason PORTC isn't working is that upon power-on, TRISC is set to 0xff. That means all PORTC pins are in DIGITAL INPUT.

    it has nothing to do with being "analog mode" - that could have been the right argument for PORTA which does have the adc on.

    all of that are in the datasheet, which you clearly haven't read, or couldn't comprehend.
     
  6. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,807
    Likes:
    135
    Location:
    morristown,tn
    Let's get this strait the poster has a 16f877a I did read the data sheet. I tried his code on
    the chip i was using but my chip has adc on portC so I fixed the code so it would run On my chip. 3v0 posted about lata 16f don't have a latch. Now I no the code will run it has to be like Mike said and it was number 5 on his list
     
    Last edited: Jun 30, 2009
  7. millwood

    millwood Banned

    Joined:
    Jun 17, 2009
    Messages:
    191
    Likes:
    2
    I was so curious that I tried this on my own computer.

    16f877, picc-lite, hi-tide ide.

    Code (text):

    #include <htc.h>

    //hardware configuration
    #define LEDC    PORTC
    //end hardware configuration

    //configuration bits

    __CONFIG( XT & WDTDIS & PWRTDIS & BORDIS & LVPDIS & WRTEN & DEBUGDIS & UNPROTECT );


    void init_mcu(void);
    void delay(int dly);

    void init_mcu(void) {
       
    //up on power-on, porta set to analog input.
       
        TRISC=0b00000000;   //set all pins on port C as output.
       
    }

    void delay(int dly) {
        for(;dly>0; dly--)
            ;
    }


    void
    main(void)
    {

        init_mcu();
        LEDC=0b10101010;
        while (1){
            delay(500);
            LEDC=~LEDC;
            //TODO Auto-generated main function
        }
    }

     
    here is what it shows in simulation. as you can see, the LEDs did blink, and the logic analyzer agrees too, :).
     

    Attached Files:

  8. millwood

    millwood Banned

    Joined:
    Jun 17, 2009
    Messages:
    191
    Likes:
    2
    bingo!

    the big give-away is how he set the adcon/cmcon registers for port a.

    But either way, that has no impact on port C, which is where you guys thought his problem was.
     
  9. millwood

    millwood Banned

    Joined:
    Jun 17, 2009
    Messages:
    191
    Likes:
    2
    here is the same code running on port C of 16f877A.

    those blinkies are really nice, :)
     

    Attached Files:

    Last edited: Jun 30, 2009
  10. millwood

    millwood Banned

    Joined:
    Jun 17, 2009
    Messages:
    191
    Likes:
    2
    is Mike god or something? :)

    yeah, if it has to be like Mike said and let Mike lay it out for us how it runs. I am sure he will up the challenge.
     
  11. millwood

    millwood Banned

    Joined:
    Jun 17, 2009
    Messages:
    191
    Likes:
    2
    btw, if you guys need the .hex files, please let me know.
     
  12. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,807
    Likes:
    135
    Location:
    morristown,tn
    Millwood you can program Ok but You haven't even read what the poster has posted he didn't have any leds on portc when he first posted it looks like he was going to use all 32 I/O but here is where he said how he set up the chip.
     
  13. millwood

    millwood Banned

    Joined:
    Jun 17, 2009
    Messages:
    191
    Likes:
    2
    I thought you guys said that X=~X would work on ANY port, and you specifically said it didn't work for you on port C (of a different chip, you later clarified).

    I am happy to run it on port C of your chip if you care to tell me what chip you failed to blink the leds on.
     
  14. micro571

    micro571 New Member

    Joined:
    Nov 30, 2003
    Messages:
    62
    Likes:
    0
    Yep, I only had 2 LEDs.

    I was toggling all PORTs so that I could see something happen even if I put the led in the wrong spot.

    This code works for me for toggling:
    <code>
    while(1){
    DelayMs(500);
    PORTA = ~PORTA;
    PORTB = ~PORTB;
    PORTC = ~PORTC;
    PORTD = ~PORTD;
    PORTE = ~PORTE;
    }
    </code>
     
  15. millwood

    millwood Banned

    Joined:
    Jun 17, 2009
    Messages:
    191
    Likes:
    2
    you want to blink port D?

    you get your freaking blinking port D, :).

    I didn't want to change it too much but you can see that some bits of port D is on and others off.
     

    Attached Files:

  16. millwood

    millwood Banned

    Joined:
    Jun 17, 2009
    Messages:
    191
    Likes:
    2
    how about blinky some port A? :)

    Code (text):

    #include <htc.h>

    //hardware configuration
    #define LED     PORTA
    //end hardware configuration

    //configuration bits

    __CONFIG( XT & WDTDIS & PWRTDIS & BORDIS & LVPDIS & WRTEN & DEBUGDIS & UNPROTECT );


    void init_mcu(void);
    void delay(int dly);

    void init_mcu(void) {
       
    //up on power-on, porta set to analog input.
       
        ADCON1=0x06;
        TRISA=0b00000000;   //set all pins on port C as output.
       
    }

    void delay(int dly) {
        for(;dly>0; dly--)
            ;
    }


    void
    main(void)
    {

        init_mcu();
        LED=0b10101010;
        while (1){
            delay(500);
            LED=~LED;
            //TODO Auto-generated main function
        }
    }

     
    and simulation with updated traces on the logic analyzer.
     

    Attached Files:

  17. millwood

    millwood Banned

    Joined:
    Jun 17, 2009
    Messages:
    191
    Likes:
    2
    My offer to you continues: as long as you tell me which chip's port C you have trouble blinking, I am happy to write a piece of code to blink it to you, and send you the .hex file.

    all for free, :)

    how's that for our friendship.

    that offer applies to prommie too.
     
  18. millwood

    millwood Banned

    Joined:
    Jun 17, 2009
    Messages:
    191
    Likes:
    2
    be80be, I will let you figure out why RA4 isn't blinking. :)
     
  19. millwood

    millwood Banned

    Joined:
    Jun 17, 2009
    Messages:
    191
    Likes:
    2
    I believe you problem lies somewhere else, not in this piece of code.

    have you tried to trace it in hi-tide to see if the ports actually change values?
     
    Last edited: Jun 30, 2009
  20. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,807
    Likes:
    135
    Location:
    morristown,tn
    Are you brain dead or what it was setup not the code and do you think your the first to
    Code (text):

    portc =~portc
     
    that's the first thing I said when i read the man post why all the
    Code (text):

    while(1){
    PORTA = 0XFF ;
    PORTB = 0XFF ;
    PORTC = 0XFF ;
    PORTD = 0XFF ;
    PORTE = 0Xff ;
    DelayMs(500);
    PORTA = 0X00 ;
    PORTB = 0X00 ;
    PORTC = 0X00 ;
    PORTD = 0X00 ;
    PORTE = 0X00 ;
    DelayMs(500);
    }
    }
     
    I don't need a hex and I posted the code for this
    Code (text):

    void main (){
    ANSEL = 0;                  // makes PORTC digital
    PORTC = 0;                 // Initialize PORTC
    TRISC = 0;                 // Configure PORTC as output
    while(1){
      Delay_Ms(100);
      PORTC = ~PORTC;
     }
    }
     
    here you can watch it blink
    [embed]http://www.youtube.com/v/SCpjRvNJtVQ&hl=en&fs=1&[/embed]
    maybe you can figure what chip has adc on PORTC from the video have fun
    Oh I forgot some thing
     
    Last edited: Jun 30, 2009
  21. millwood

    millwood Banned

    Joined:
    Jun 17, 2009
    Messages:
    191
    Likes:
    2
    is that what you do when you are losing a discussion?

    why are you so afraid of telling us the chippie so we can help you?

    this is a place for us to help each other, as you said earlier, right?
     

Share This Page