16f877a push button and led

Find out how to setup your programmer's software and how to solve many common problems.

Moderator: phalanx

Post Reply
yikwei
Posts: 1
Joined: Mon Jun 02, 2014 9:13 pm

16f877a push button and led

Post by yikwei » Mon Jun 02, 2014 9:19 pm

Code: Select all

/* Main.c file generated by New Project wizard
 *
 * Created:   Tue Jun 3 2014
 * Processor: PIC16F877A
 * Compiler:  HI-TECH C for PIC10/12/16
 */

#include <htc.h>
#define _XTAL_FREQ 20000000

void main(void)
 {
{
TRISB0=1;
TRISB1=1;
TRISD0=0;
TRISD1=0;

do
{
	if(RB0==1)
	{
	__delay_ms(100);
		if(RB0==1)
		{
		RD0=1;
		__delay_ms(2000);
		RD0=0;
		}
	}
}while(1);

do
{
	if(RB1==1)
	{
	__delay_ms(100);
		if(RB1==1)
		{
		RD1=1;
		__delay_ms(2000);
		RD1=0;
		}
	}
}while(1);
 }
Image

any idea why the led not on?

waltr
Support Volunteer
Posts: 2823
Joined: Tue Sep 08, 2009 12:07 pm
Location: Philadelphia, USA

Re: 16f877a push button and led

Post by waltr » Wed Jun 04, 2014 1:35 pm

Where are the CONFIG bits set?
Try stepping through your code in the MPLAB Simulator.
Try just setting the LED on without reading an input first.
Does port B & D have any other features (analog) that you must disable, enable Digital IO.

Post Reply