PIC16F877A no output according to prgramming

Dear sir,

i am new to this PIC. I’m doing a wireless home alarm system. I’m able to decoder my data and i connect one of the data pin into port RB0. The voltage for the data is 5v. Here is my testing programming code using micro C:

//

void main()

{

portb=0x00;/* initializing all the ports used to be 0*/

portc=0x00;

trisb=0xff;/* initializing port b to be input and portc to be output*/

trisd=0x00;

while(1)

{

if(portb==0x01)

{

portd=0x01;

}

if(portb==0x02)

{

portd=0x02;

}

if(portb==0x03)

{

portd=0x04;

}

if(portb==0x04)

{

portd=0x08;

}

if(portb==0x05)

{

portd=0x10;

}

if(portb==0x06)

{

portd=0x20;

}

if(portb==0x07)

{

portd=0x40;

}

else

{

portd=0x00;

}

}

}

//

According to the program, i should get port RD0 as 1 (5v). But i only manage to get 0.01V at pin.

When i stimulate it using my design, it works well…

Plz help me… I really need assistance to solve this problem…

[/img][/code]

The reason for your problems is that you’re not using else if statements. Yourlogic will eventually hit this statement:

if(portb==0x07) 
{ 
portd=0x40; 
} 
else 
{ 
portd=0x00; 
}

If PORTB isn’t exactly equal to 0x07, then PORTD will be set to 0. If you want to keep your code as is, you should change all your if statments (except the first one) to else if.

Or, use switch-case.

Leon

Dear Sir,

thanks for replying…

Although i change my programming to if else, it still cant work…

then i change my programming to switch case…

void main()

{
portb=0x00;
trisb=0xff;
trisd=0x00;

do {
switch (PORTB)  // read PORTB and switch
{

case 0x01: portd = 0x03; break;
case 0xFF: portd = 0x00;

}   }
while (1);
}

Although i didn’t supply any input to PORT B, the pin number 25 (RC6/TX/CK) show 5V.

When i supply 5V to PORT B pin RB0, the voltage at pin number 25 is still 5V and there is no output at required pin at PORT D.

I dont know why there is a 5V at pin 25.

The voltage at pin 25 will be 0V when the reset button is pressed and once the reset button released the voltage become 5V again.

http://www.freeimagehosting.net/uploads/ea1612c258.jpg

this is a warning that i faced when i burn my hex file to my PIC chip. but i shows write OK. is this problem effect my output??

this is the programming and it shows compiled successfully…

http://www.freeimagehosting.net/uploads/906b2ca87e.jpg

Can anyone help me to get the output desired?

thanks you very much…

[/list]

The PIC’s USART (hardware serial port) transmiter is assigned to that pin. Disable it (SPEN = 0) and you will be able to use that pin as an input.