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. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,869
    Likes:
    144
    Location:
    morristown,tn
    That's the brain dead part
    That board that's in the video is a LPC demo board the leds are on PORTC Do YOU GET that
    IT's BLINKING DO YOU GET THAT the chip has just 3 PORTS PORTA PORTB PORTC
    IT has ADC on PORTC
    I don't need a hex I never had any broking blinky hex my blinky blinks fine
    RA4 can sink only on the 16f877A DO YOU GET THAT in the data sheet maybe you missed that to.
    RA4/T0CKI
    pin is a Schmitt Trigger input and an open-drain output.
     
    Last edited: Jun 30, 2009
  2. millwood

    millwood Banned

    Joined:
    Jun 17, 2009
    Messages:
    191
    Likes:
    2
    sorry, be80be, I didn't mean to upset you so much.

    But which chip are you having trouble blinking? the sooner you tell us, the sooner we can help you.

    Thanks.
     
  3. millwood

    millwood Banned

    Joined:
    Jun 17, 2009
    Messages:
    191
    Likes:
    2
    is that before or after your proposed the following "fix" that didn't quite fix anything?

     
  4. dave

    Dave New Member

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


     
  5. millwood

    millwood Banned

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

    now, going to back to the comments about incorrectly configuring the port. here is a quick run that blinks the LEDs on Port A configured as analog input.

    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;        //turn off adc;
        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=0b01010101;
            delay(500);
            LED=0b10101010;
            //TODO Auto-generated main function
        }
    }

     
    as you can see, because analog pins are read as zero, LED=~LED; does not work anymore. But that's not the fault of the code, it is the fault of the programmer not reading the datasheet, not understanding the datasheet and failing to set up the port correct (analog vs digital).

    this has nothing to do with multiplexing but has everything to do with incompetent programmer.
     

    Attached Files:

    Last edited: Jul 1, 2009
  6. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,869
    Likes:
    144
    Location:
    morristown,tn
    Millwood the only reson the code I posted didn't work was he didn't set the osc right
    for his chip he had ADC turn off
    ADCON1=0x06; see
    Code (text):

    void main(void){
    ADCON1 =0x06 ; // Changes PORTA to digital
    CMCON = 0x07 ; // Disable analog comparators
    PORTA = 0x00 ;
     
     
  7. millwood

    millwood Banned

    Joined:
    Jun 17, 2009
    Messages:
    191
    Likes:
    2
    how could he have set the osc right?

    ? is he NOT supposed to do that?
     
  8. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,869
    Likes:
    144
    Location:
    morristown,tn
    This is what you keep going on about
    He had the setting for it right if you look at his code you can see that he set it right
    Now he didn't post what he changed for the osc but if you read he said after he change
    the osc setting it worked.

    here you some thing to try in you sim
    Code (text):
    main(void)
    {
        unsigned char   i, j;

        TRISB = 0;      /* all bits output */
        j = 0;
        for(;;) {
            PORTB = 0x00;       /* turn all on */
            for(i = 100 ; --i ;)
                continue;
            PORTB = ~j;     /* output value of j */
            for(i = 100 ; --i ;)
                continue;
            if(BUTTON == 0)     /* if switch pressed, increment */
                j++;
        }
    }
     
     
    Last edited: Jul 1, 2009
  9. millwood

    millwood Banned

    Joined:
    Jun 17, 2009
    Messages:
    191
    Likes:
    2
    so are you saying he should or shouldn't turn the adc off? which position, not positins, are you taking on here?

    and how does all this have anything to do with your inability to tell us on which chip you had trouble blinking the LEDs with X=~X?

    just wanted to help, you know.
     
  10. millwood

    millwood Banned

    Joined:
    Jun 17, 2009
    Messages:
    191
    Likes:
    2
    please just let say that if I had written something like that, I would have been so embarrassed that I have to kill myself.
     
  11. aredhel_vlsi

    aredhel_vlsi New Member

    Joined:
    Dec 15, 2011
    Messages:
    2
    Likes:
    0
    Thank you so much for your help guys ! I 've been trying for two weeks and didn't work.
    I use a 18F43331 and HITECH Compiler C .

    Micro571, can you please explain why you include these?

    #include <conio.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <ctype.h>

    I never used these header files.
    All my ports blink, except some PWM ports. My configuration Bits are not set by code.
    Also this command CMCON = 0x07 ; // Disable analog comparators didn't work for me, I made it a comment and managed to build it. But it works again regarding the leds.

    Could you please recommend any good site with tutorials about step by step programming in HITECH C for PICs? How did you write this code? Please give me some hints !

    thank you very much !
     
  12. adhnan

    adhnan New Member

    Joined:
    Feb 26, 2012
    Messages:
    2
    Likes:
    0
    i want the code for configuration of oscillator of PIC 18F2455 using HI-tech C.
    is this configured by using __COFIG();
    the how???
    can you pls send??
     
  13. aredhel_vlsi

    aredhel_vlsi New Member

    Joined:
    Dec 15, 2011
    Messages:
    2
    Likes:
    0
    Hi, you may check if _CONFIG works for you. For example, in my case, I should write PROG_CONFIG to be able to run. Additionally, you should prefer to set the Configuration bits from the menu, and not by code. This way is easier and you minimize the chance of having mistake. To begin, try to set the first (OSCILLATOR ) to HS if you use a >=4 MHz oscilator. The last ones should be not protected. I don't remember the rest right now, I have to check my pc. Let us know if you are ok and it works or anyway.
     
  14. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,869
    Likes:
    144
    Location:
    morristown,tn
    You can export them In MPLAB
     

Share This Page