[SOLVED] Problem with MPLAB Programming

Status
Not open for further replies.

baby_1

Advanced Member level 1
Joined
Dec 3, 2010
Messages
415
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,298
Activity points
4,277
hello my friends
i wrote this program


#include <p18f452.h>
#pragma config WDT=OFF
#pragma config OSC=HS
#define baby1 PORTBbits.RB5

int baby;
void main(void)
{
TRISD=0;
TRISBbits.RB5=1;
PORTD=255;
while(1)
{

if(baby1==0)
{
PORTD=~PORTD;
for(baby=0;baby<=30000;baby++);
}

}
}


it has some problems that i can't understand:
when i power up my circuit PORTD=0 it against of that i set the PORTD=255 , why?
i put a swicth button on RB5 and ground another pins of switch putton and i pull up the RB5 with a 4.7Kohm resistor ,when i press it the statues of portd set to 1 but it leaves its status when i unpress it.why?

excuse if my english is poor

---------- Post added at 18:01 ---------- Previous post was at 17:37 ----------

it works in Proteus but in reality doesn't work
 

i change and write a new program
schematic:


program:
#include <p18f452.h>
#pragma config WDT=OFF
#pragma config OSC=HS
int baby;
void main(void)
{
TRISD=0;
TRISB=1;
while(1){

PORTDbits.RD3=1;
PORTDbits.RD2=1;
for(baby=0;baby<30000;baby++);
PORTDbits.RD3=0;
PORTDbits.RD2=1;
for(baby=0;baby<30000;baby++);
PORTDbits.RD3=1;
PORTDbits.RD2=0;
for(baby=0;baby<30000;baby++);
PORTDbits.RD3=0;
PORTDbits.RD2=0;
for(baby=0;baby<30000;baby++);


}
}

when i press the button the circuit works well ! why? and how can i solve it?

---------- Post added at 23:00 ---------- Previous post was at 22:08 ----------

problem solved with adding this code(disable LVP)
#pragma config LVP=OFF
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…