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:
#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.
So I tried typing it with an extra bracket ")"
__CONFIG(0x37F2));
Now it was compiled successfully. I can't test if it works right now because I don't have the hardware or software required for burning the program into the microcontroller. But anyhow, isn't that a bit weird, one open bracket and 2 close brackets? :/
archana, its the same, the config bit of pic ( i'm more of an avr guy.. in avr config bits are called as fuse bits. ) refer page 146 of the PIC 16f877a datasheet for more info.
yeah both are the same but in pic datasheet there is no such thing as a fuse word. so to avoid confusion, I said so.. thanks Ian for the new info about fuse bits.
archana, its the same, the config bit of pic ( i'm more of an avr guy.. in avr config bits are called as fuse bits. ) refer page 146 of the PIC 16f877a datasheet for more info.
#include<htc.h>
#define _XTAL_FREQ 20000000 //Clock frequecy=20Mhz
__CONFIG(0x37F2); // Goes here...ish
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
}
}
}
The _CONFIG(); is in the headers... Once you use <htc.h> it is automatically defined so you can use it..