Joined Sep 9, 2011
69
Is there a common ground between your breadboard and the MCU board?

How are you powering your MCU board?

What frequency is your external Oscillator?

Tim S.

ya.there is a common ground between my breadboard and my MCU.my MCU is powered from the 5V of the regulator.my oscillator there got 4.000 it belong to 4mhz or 4khz?

Last edited:

Joined Sep 9, 2011
69
wanna test whether my board can work probably but till now the LED still cannot function well cannot go further to my real final year project stuck at this most basic testing!

#### t06afre

Joined May 11, 2009
5,934
I tested my simple blink code and it worked as it should. No problem in that department at all. However not on a your chip. But that should not mean anything at all. And I used 4 MHz as CPU clock. Before we go any further. Have you build a project in MPLAB from start. And then tested my blink code in it. If not you should do that. Go to project in the toolbar. And select the project wizard. Also you have a teacher. Why not ask him/her for help. Your teacher is there to help you. You may perhaps also ask other education staff. I you prepare a list of what you have done so far. And why and how you struggle. You want loose any face asking question.
Are you also able to verify that your code is correct programmed into the chip.
I googled your programmer. And it seems to be a PICKIT clone. And that is good.
Could you also tell us what this magical number is
Rich (BB code):
__CONFIG(0x3F39);
I have no idea at all, and I have no plans to download the 16f877 datasheet to find out. If you had written in this style
Rich (BB code):
__CONFIG(INTIO & WDTDIS &PWRTDIS & BORDIS & MCLRDIS & FCMEN  & IESODIS & UNPROTECT);//NOTE ver 9.80 style
I would in a second spotted if it was something wrong in respect to your setup. I am in fact puzzled by the fact. That you are quite stubborn. You ask for help. But seems to follow the advice only if it suits you.

Joined Sep 9, 2011
69
I tested my simple blink code and it worked as it should. No problem in that department at all. However not on a your chip. But that should not mean anything at all. And I used 4 MHz as CPU clock. Before we go any further. Have you build a project in MPLAB from start. And then tested my blink code in it. If not you should do that. Go to project in the toolbar. And select the project wizard. Also you have a teacher. Why not ask him/her for help. Your teacher is there to help you. You may perhaps also ask other education staff. I you prepare a list of what you have done so far. And why and how you struggle. You want loose any face asking question.
Are you also able to verify that your code is correct programmed into the chip.
I googled your programmer. And it seems to be a PICKIT clone. And that is good.
Could you also tell us what this magical number is
Rich (BB code):
__CONFIG(0x3F39);
I have no idea at all, and I have no plans to download the 16f877 datasheet to find out. If you had written in this style
Rich (BB code):
__CONFIG(INTIO & WDTDIS &PWRTDIS & BORDIS & MCLRDIS & FCMEN  & IESODIS & UNPROTECT);//NOTE ver 9.80 style
I would in a second spotted if it was something wrong in respect to your setup. I am in fact puzzled by the fact. That you are quite stubborn. You ask for help. But seems to follow the advice only if it suits you.

Ya,I have created the project file.
the __CONFIG(0x3F39) is actually from here:
http://1.bp.blogspot.com/-RgoUeac409s/Tmyprg1gaRI/AAAAAAAAAHM/_nqzwC_v2tc/s1600/Untitled.png
my teacher dont know about high tech c.he **** throw me a project tiltle and never guide me anythg.everythg i find from forum ask ppl.my teacher said dont get spoon feed by him everythg do by myself and my senior told me my teacher dont know about programming he alway mc and when we wana consult him he said "do yourself dont ask me".i never touch high tech c b4 i only learn the assembly code of mplab.but hope to learn it as it's easier than assembly code.Really sorry i do know that actually this is the simple thg but just panic why i cannot make it work!i'll try to figure out.million thanks to u!

#### t06afre

Joined May 11, 2009
5,934
Any engineer must be able to navigate in unknown water. And that include be able to read and digest new information. From say data sheets and documentation. And in this case. I think perhaps your teacher will give an exercise in this. In this project. However seeking information like you have done by asking in this forum. Is also perfectly OK. Seek information at the source.
I have looked at your __config word. Now as it is not magic number. And as far as I can see it looks OK. So the next question how do you program your PIC. Do you do it via MPLAB or are you using the PICKIT 2 app? Do you get any error messages during programming. And are you also able to verify that the code in your chip. Is what you think you have programmed. Also try to erase your PIC and then do a blank check. Then reprogram it. Since you use an external power. Do not turn on "VDD" from PICKIT 2/MPLAB. Also if not done select MRCLR off.
Just one thing. You are sure your hex file is up to date. After changing something in your code. You MUST do a rebuild (CTRL+F10) in order to generate a new hex file. And then program your chip

Last edited:

Joined Sep 9, 2011
69
I've tried all the important things you said.but still failed.you know what when i perform this coding

Rich (BB code):
#include <htc.h>
//device configuration bit
__CONFIG(0x3F3A);
//define
#define LED1 RB7
#define LED2 RB6
//function prototype
//main function
//================================================== ==============
void main(void)
{
//device peripheral configuration
TRISB7=0; //set RB7 as output
TRISB6=0; //set RB6 as output

//infinity loop
while(1)
{

}
}
//function to blink LED1 for n times
{
//loop for n times
for(n+=1;n>0;n-=1)
{
//set LED1 to 1
LED1=1;

//short delay
for(unsigned int i=0;i<20000;i+=1); //max value is 65535

//set LED1 to 1
LED1=0;

//short delay
for(unsigned int i=0;i<20000;i+=1); //max value is 65535
}
}
//function to blink LED2 for n times
{
//loop for n times
for(n+=1;n>0;n-=1)
{
//set LED2 to 1
LED2=1;

//short delay
for(unsigned int i=0;i<20000;i+=1); //max value is 65535

//set LED2 to 1
LED2=0;

//short delay
for(unsigned int i=0;i<20000;i+=1); //max value is 65535
}
}

the LEDs can blink but the coding is blink for 3 times and turn to another LED to blink for 3 times.but my LED perform 4 times of blinking for each.SHOCK!!!!!the simple coding provided by u can be built successful but in cannot work in my circuit.too bad!mayb i need to buy a new circuit or pic to try!

Last edited:

#### cheezewizz

Joined Apr 16, 2009
82
you need to get into the habit of using code tags to make it a bit more readable for people looking through it for you. and what's with the for loops being used for the delay? where'd __delay_ms() vanish to? I feel like we're going backwards here... forget about blinking one 3 times then the other 3 times. blink 1 led at a steady frequency then move onto more complicated matters...

#### t06afre

Joined May 11, 2009
5,934
Here is code tags explained.
Ok so you can burn and run the code(inside the pic) that you posted in your last post. I have noted you have changed the __config() value from x3F39 to 0x3F3A what is it in this change. What does the magic number 0x3F3A mean?
Rich (BB code):
for(n+=1;n>0;n-=1)
You can write
Rich (BB code):
for(;n>0;n-=1)
Just google C For Loop Statement for more info. And you also get one extra loop since you type for(n+=1;n>0;n-=1)

Joined Sep 9, 2011
69
Here is code tags explained.
Ok so you can burn and run the code(inside the pic) that you posted in your last post. I have noted you have changed the __config() value from x3F39 to 0x3F3A what is it in this change. What does the magic number 0x3F3A mean?
Rich (BB code):
for(n+=1;n>0;n-=1)
You can write
Rich (BB code):
for(;n>0;n-=1)
Just google C For Loop Statement for more info. And you also get one extra loop since you type for(n+=1;n>0;n-=1)

the 3F3A is explained here:
http://1.bp.blogspot.com/-C605a0NI3rQ/Tm2COduFZQI/AAAAAAAAAHU/gOQ3v7H2nlc/s1600/Untitled.png

sorry i dont know that but now i know how to use code tag.thanks!i will try the for loop u suggested.

#### t06afre

Joined May 11, 2009
5,934
The protype card(the card with the PIC16F877 on) you have. Is profesional made. Use google to if you can find some documentation and program examples about it.

#### u5Al3

Joined Dec 24, 2010
21
TRISD = 0 // must be output configuration of PORTD.....
then don't use NOP() function in for loop ......
take for loop empty like
for(i=0;i<33000;i++)
{}
if you get nothing ....then build your program and check the excet delay value...
as i mention earlier your PORTD must be output configured....

Joined Sep 9, 2011
69
@t06afre:

can i see your circuit board how you use the simple code to let ur LED blink as i try using my frd circuit but failed too.i like the code you provide as i can know the delay timing more accurately without using the coding i posted that using for loop.

#### t06afre

Joined May 11, 2009
5,934
You have to trust me on this one. And it would not help very much to see my circuit board. I use a different chip that you do, with an internal osc. But it is 16F series chip. And I test burned the code into the chip. However since my PIC did not have port D. I used port C. But this is not important since my simple sample code can be run at any 16F series PIC. As long as the port used are proper configurated. And can work as output port.
Do you do it via MPLAB or are you using the PICKIT 2 app? Do you get any error messages during programming. And are you also able to verify that the code in your chip. Is what you think you have programmed. Also try to erase your PIC and then do a blank check. Then reprogram it. Since you use an external power. Do not turn on "VDD" from PICKIT 2/MPLAB. Also if not done select MRCLR off.
Just one thing. You are sure your hex file is up to date. After changing something in your code. You MUST do a rebuild (CTRL+F10) in order to generate a new hex file. And then program your chip

Joined Sep 9, 2011
69
I tried both i had done by using mplab and also pickit2.verification and programming are succeeded.what made me think of i have programmed is the words programming successful verification successful or pickit is ready.
i have tried also to erase and do blank checked and then reprogrammed.i never turn on the VDD.and never set MCLR.
i alway press "rebuild"when i change or correct my code so that i'm very sure that the hex file is up tp date as the details showing the new time when i updated.

I have done all the things you told me.sorry i juz answer i hv done everythg u said but not in details in the provious post but this time answer one by one.hope u can understand what i said.

#### stahta01

Joined Jun 9, 2011
133

Note: A voltage regulator requires power to work; your photo showed no power source.

Tim S.

#### t06afre

Joined May 11, 2009
5,934
What I can think about is that your CPU clock somehow is not running properly. If you put a scope on the osc2 pin. You should be able to see 4 MHz if the MCU clock is running properly, as you use 4 MHz. Your setup seams to be OK since you can program and verify your code. So I am quite sure your setup correct. I also tested your code in post #26 And it was not a problem running it. I used a PICKIT 2 to program it. And set the MCU clock to 4 MHz. No problem at all But I had to use config word adapted to my PIC. Did this code work for you?