This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Mode Ports

Hi!
In Hello example for 8051 by MCB900 in main() there is:
P2M1=0;
P1M1=0;

Is it ok??
Im reading the datasheet of de microcontroller and i dont understand it, because to configurate the port is using PxM1 and PxM2. Then why is writed these (bold text)??
Thanks

  • "Im reading the datasheet ... is using PxM1 and PxM2"

    'x' here is used as a general notation to denote any port:

    P2M1 refers to Port-2;
    P1M1 refers to Port-1;

    In general:
    PxM1 refers to Port-x

  • 1) You haven't told us which chip you are using. MCB900 supports a lot of different chips.

    2) You haven't told us what datasheet you have been reading.

    3) You haven't told us what configuration you want.

    If you have a configuration register somewhere, the "right" value depends on what you want. If everyone wanted the same thing, then there would be no need for a configuration register in the first place...

    If you read the user manual for the P89LPC93x, there is a chapter "I/O Ports" that describes the port output configuration settings. It has a great description of these registers.

  • Well,
    - The chip is P89LCP936.
    - And only i want to see how can i switch on/off the led P2.
    In hello example: Write Hello in serial port this is the configuration:

    void main() {
      unsigned int j;
      P2M1 = 0;
      P1M1 = 0;
    
      SCON   = 0x52;                 /* initialize UART                            */
      BRGR0  = 0xF0;                 /* 9600 baud, 8 bit, no parity, 1 stop bit    */
      BRGR1  = 0x02;
    while (1) {
        for (j = 0x01; j <= 0x80; j <<= 1) { /* Blink LED 0,1,2,3,4,5,6 */
          P2 = j;                               /* Toggle port 2 pins each time we print */
          //printf ("Hello World\n");         /* Print "Hello World"                   */
              printf ("Hello \n");
          delay ();                         /* Delay about 0.2 seconds               */
        }
      }
    }
    

    Why :
    P2M1 = 0; P1M1 = 0;?????

    Thanks

  • Note that P2 is a PORT - not an LED.

    "Why: P2M1 = 0; P1M1 = 0;?"

    Why not?

    As Per suggested, have you actually looked in the Datasheet to see what effect writing zero to these registers will have?
    That should answer your question...

  • So look at the examples about the LEDs, then!

    Go to http://www.keil.com/download/list/c51.htm and see what LPC9xx examples are available...

  • Let's be a bit more specific: Have you read the chapter (I think it is chapter 5) in the user manual, where the individual bits of the port mode registers are described?

    That chapter tells explicitly what mode the I/O pin will use for any bit combination in P1M1/P1M2 and P2M1/P2M2.

    Note that the code only writes to P1M1/P2M1 and not to P1M2/P2M2 so they are keeping their defaults.

    Now it should be quite easy to:
    1) Figure out what the default values are for P1M2 and P2M2.
    2) Figure out what a 0 in P1M1/P2M1 means together with the value of P1M2/P2M2.
    3) Decide if that pin mode is suitable for the specific hardware you run on.

    The schematics for the board is also available on this web site.

    Please come back with specific questions when you have looked through that chapter, looked at the initial value for the 'different SFR and looked at the schematics.