Setting Output in 89C52 in MikroC for 8051

Discussion in 'Embedded Systems and Microcontrollers' started by ssm14293, Dec 16, 2011.

  1. ssm14293

    Thread Starter Member

    Jul 14, 2011
    90
    1
    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
     
  2. ssm14293

    Thread Starter Member

    Jul 14, 2011
    90
    1
    can no one answer this?
     
  3. debjit625

    Well-Known Member

    Apr 17, 2010
    790
    186
    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 .
    Code ( (Unknown Language)):
    1.  
    2.         delay();//make a delay for 1sec
    3.         P1 = 0x00;
    4.         delay();//make a delay for 1sec
    5.         P1 = 0xFF;
    6.  
    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)
    Code ( (Unknown Language)):
    1.  
    2. main(){
    3.     P1_3 = 1 //Set P1.3 as input pin ,make it high
    4.     while(1){
    5.         if(P1_3 == 0){
    6.             P1_0 = 0 //Turn on the LED
    7.         }else{
    8.             P1_0 = 1 //Turn off the LED
    9.         }
    10.     }
    11. }
    12. }
    13.  
    Good Luck
     
  4. ssm14293

    Thread Starter Member

    Jul 14, 2011
    90
    1
    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?
     
  5. ssm14293

    Thread Starter Member

    Jul 14, 2011
    90
    1
    when i write P0_0 = 0 the compiler gives the error that "assigning non-lvalue to P0_0"
     
  6. debjit625

    Well-Known Member

    Apr 17, 2010
    790
    186
    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.

    Code ( (Unknown Language)):
    1. 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.
    Code ( (Unknown Language)):
    1. P1_1 = 1;
    In this code you are using only one bit i.e.. P1.1,you set that pin high.

    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
     
    ssm14293 likes this.
Loading...