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

Thread Starter

archanak

Joined Feb 22, 2013
2
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

Rich (BB code):
#include<htc.h>
#define _XTAL_FREQ 20000000          //Clock frequecy=20Mhz
main()
{
 TRISB=0b11111111;                         //Set Port B as input port
 TRISD=0b00000000;                         //Set Port D as output port
 while(1)                                          //forever loop
     {if(RB6==1)                              //if pin B6 is high
          {RD7=1;                          //set pin D7 as high
          RD3=1;                            //set pin D3 as high
          RD2=1;                            //set pin D2 as high
        }
      else                                         // if pin B6 is low
           {RD7=0;                            //set pin D7 as low
         RD3=0;                             //set pin D3 as low
         RD2=0;                              //set pin D2 as low
           }
        
    }
}
Please tell me if there is any mistake in the code or the logic.

Thanks
 
Last edited by a moderator:

thatoneguy

Joined Feb 19, 2009
6,359
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.
 

tshuck

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

Also, what are your configuration bits?
 

t06afre

Joined May 11, 2009
5,934
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
 

Thread Starter

archanak

Joined Feb 22, 2013
2
Nothing jumps out at me. What do you mean when you say "no result"?
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.
 

MrChips

Joined Oct 2, 2009
21,041
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
 
Top