Setting Output in 89C52 in MikroC for 8051

Thread Starter

ssm14293

Joined Jul 14, 2011
90
Hi
I am confused about how to make a Port input and output in MikroC for 8051 for 89C52. and also how to give outputs on a certain pin.
i have used PICs before but im newbie at this.

Thanks in advance.

PS: Compiler: MikroC for 8051
Micro controller: 89C52
 

debjit625

Joined Apr 17, 2010
790
I am confused about how to make a Port input and output in MikroC for 8051 for 89C52
I think you are asking about how to configure the pins of 89C52.First of all its not PIC so its different it have no TRIS register to configure port pins,its architecture is different ,you have to go through the datasheet first.Anyway in 89C52 we have two register Latch register (ex PORT0 LATCH)and another is Port register (ex PORT0 DRIVER) ,any value written to port pins are written to latch register and any value read from port pins are read from port register.But their is one more thing ,every pin have their own pull up resistors, so to make a pin input you have to write 1 on that pin and then you can start using that pin as input pin.
For example ,using PORT1's pins as output to toggel the pins .
Rich (BB code):
        delay();//make a delay for 1sec
        P1 = 0x00;
        delay();//make a delay for 1sec
        P1 = 0xFF;
Using P1.3 as input (connect a switch between that pin and GND),and turning on / off P1.1 (connect a LED with 470 ohms resistor from P1.1 to 5V)
Rich (BB code):
main(){
    P1_3 = 1 //Set P1.3 as input pin ,make it high
    while(1){
        if(P1_3 == 0){
            P1_0 = 0 //Turn on the LED 
        }else{
            P1_0 = 1 //Turn off the LED 
        } 
    }
} 
}
Good Luck
 

Thread Starter

ssm14293

Joined Jul 14, 2011
90
thanx man!!
but still confused on one thing...
if i want to give 1 on P1_0 then how to set the pins? like
P1 = 0x00:
and later P1_0 = 1?
 

debjit625

Joined Apr 17, 2010
790
if i want to give 1 on P1_0 then how to set the pins?
I didn't understood what you ment by "set the pins" here.If you write 1 to P1_0 you make the pin high as output and also you can use that pin as input pin,it depends on you.

Rich (BB code):
P1 = 0x00;
In this code you are using the full port or full byte i.e.. from pins P1.0 to P1.7,you set them all low.
Rich (BB code):
P1_1 = 1;
In this code you are using only one bit i.e.. P1.1,you set that pin high.

when i write P0_0 = 0 the compiler gives the error that "assigning non-lvalue to P0_0"
Not sure much as I use Keil uVision with c51 as compiler.And as per c51 the code is all right.But in C this kind of error happens when the left side of assignment operator is not lvalue i.e.. something to which you can't assign value or not ment for lvalue.

Good Luck
 
Top