Program compiled in Hi-Tech C for PIC16F877A, no result obtained

Discussion in 'Embedded Systems and Microcontrollers' started by archanak, Feb 22, 2013.

  1. archanak

    Thread Starter New Member

    Feb 22, 2013
    2
    0
    Hi,
    I've tried this simple embedded C Program using Hi-Tech C for PIC16F877A.
    The aim was to obtain a logic high as output on 3 pins (pins D7, D2, D3 of port D), if one input pin (pin B6, of Port B) is driven to logic 1. The program was built successfully but after burning it to the microcontroller I got no result.

    Program

    Code ( (Unknown Language)):
    1.  
    2. #include<htc.h>
    3. #define _XTAL_FREQ 20000000          //Clock frequecy=20Mhz
    4. main()
    5. {
    6.  TRISB=0b11111111;                         //Set Port B as input port
    7.  TRISD=0b00000000;                         //Set Port D as output port
    8.  while(1)                                          //forever loop
    9.      {if(RB6==1)                              //if pin B6 is high
    10.           {RD7=1;                          //set pin D7 as high
    11.           RD3=1;                            //set pin D3 as high
    12.           RD2=1;                            //set pin D2 as high
    13.         }
    14.       else                                         // if pin B6 is low
    15.            {RD7=0;                            //set pin D7 as low
    16.          RD3=0;                             //set pin D3 as low
    17.          RD2=0;                              //set pin D2 as low
    18.            }
    19.        
    20.     }
    21. }
    22.  
    Please tell me if there is any mistake in the code or the logic.

    Thanks
     
    Last edited by a moderator: Feb 22, 2013
  2. Brownout

    Well-Known Member

    Jan 10, 2012
    2,375
    998
    Nothing jumps out at me. What do you mean when you say "no result"?
     
    archanak likes this.
  3. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    Maybe the optimization was set to "super extreme"? :D

    Try looking in different directories for the .hex file, did you create a new project with directory, or just try to compile the standalone .c file above?

    The compiler usually shows what directory it is working it while it compiles, though it flashes by rather quickly. Try making it a project with a set directory, and see if you have the same problem.
     
    archanak likes this.
  4. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    To be clear, you do have a crystal attached, right? This device has no internal oscillator.

    Also, what are your configuration bits?
     
  5. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    As far as I can see have you have not set the configuration bits. In this case this is most likely error. In the manual serach for "Configuration Fuses" You will find the manual here "C:\Program Files\HI-TECH Software\PICC\9.83\docs" as an example
     
    archanak likes this.
  6. Ian Rogers

    Member

    Dec 12, 2012
    158
    29
    This guy has had the same answers back at ETO...

    I told him to include the line __CONFIG(0x37F2);
     
    archanak likes this.
  7. archanak

    Thread Starter New Member

    Feb 22, 2013
    2
    0
    I tried to set up the components on a Digital IC Trainer, using a logic switch as the input and LEDs as the output. By no result, I mean, the LEDs didn't light up when I turned the logic switch to High position.
     
  8. MrChips

    Moderator

    Oct 2, 2009
    12,449
    3,365
    You have to backup and try a simple program, for example, turn one LED on and another LED off.

    You have to check

    1) that the compiler works properly
    2) that the code is being transferred to the chip
    3) that the chip is configured properly
    4) that the code is correct
     
  9. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    I think we need a schematic here
     
  10. RRITESH KAKKAR

    Senior Member

    Jun 29, 2010
    2,831
    89
    I think __conf ???

    __CONFIG(LVP_OFF & BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_HS);
     
Loading...