Continue to Site

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.

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

Need help on PIC16F877 microcontroller (Amazing Problem)

Status
Not open for further replies.

nilupul21

New Member
Following are two hitech C codes for a main program

1st one

Code:
#include <pic.h>
#include "delay.h"

void main()
{
	TRISD = 0x00;
	while(1) 
	{
		PORTD = 0x01;
		DelayMs(255);
		PORTD = 0x00;
		DelayMs(255);
	}
}

2nd one

Code:
#include <pic.h>
#include "delay.h"

void main()
{
	TRISD = 0x00;
	TRISB = 0x00;
	PORTB = 0xFF;
	while(1) 
	{
		PORTD = 0x01;
		DelayMs(255);
		PORTD = 0x00;
		DelayMs(255);
	}
}


Can Anybody kindly explain why 2nd cord is not working on the PCB while 1st code is working? thanx in advance!
 
I can't see anything fundamentally wrong with the code. I would start looking at your hardware set up. What is PORT B connected to? Are you sure you're not drawing too much current from the PIC? That data sheet says the max current PORTA, B, and E combined can source is 200 mA. Maybe if you draw too much current, it could make the PIC not work properly. I'm not sure but that's where I'd start looking.
 
Thank you for replying

I could find a design fault on PCB. Even though program was written to use port B as an output, I have designed it to use as an input. I have connected 2.2k resistors between ground and port B terminals in order to input 0 at at default. As vne147 says it may take more current out from portB. After I corrected it, it worked fine. Thank you!

I have enabled LVP in configuration settings. How LVP can make an effect on that?
 
How LVP can make an effect on that?
Is LVP is enabled, then taking the PGM pin high (or letting it float high if open circuit) will put the PIC into programming mode.

The PGM pin is on PORTB, which might or might not explain the difference in the two programs.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top