problem related c programming

Status
Not open for further replies.

jay_3189

Banned
Joined
Sep 19, 2013
Messages
104
Helped
0
Reputation
0
Reaction score
0
Trophy points
16
Location
Ahmedabad
Activity points
0
Hello everyone,

I have written simple c program for led blink. and in that program I have written P2=0X00 but still I am getting few voltage (i.e., 3 or 4 volts) through pin 3rd and 2nd. any one can help me to solve this.

I am using at89c51 and keil IDE.
 

I think putting 0x00 into port2 will on the leds. as pull-up's are enabled. write 0xff it will of the led's

So your program should be

while(1)
{
p2=0x00;
delay
p2=0xff;
}
 

Post your code and circuit.

That is more useful to solve your problem.
 

Try this if possible:



My code has logic inverted!!!
 

Attachments

  • AT89C51 - LED Blink.rar
    24 KB · Views: 73

This is another example. There is in Keil\C51\Examples\BLINKY

Code:
/* BLINKY.C - LED Flasher for the Keil MCBx51 Evaluation Board with 80C51 device*/
                
#include<reg51.h> // changed


// When you have enabled the option Stop Program Execution with Serial
// Interrupt, the Monitor-51 uses the serial interrupt of the UART.
// It is therefore required to reserve the memory locations for the interrupt
// vector.  You can do this by adding one of the following code lines:

// char code reserve [3] _at_ 0x23;   // when using on-chip UART for communication
// char code reserve [3] _at_  0x3;   // when using off-chip UART for communication

void wait (void)  {                   /* wait function */
  ;                                   /* only to delay for LED flashes */
}

void main (void)  {
  unsigned int i;                     /* Delay var */
  unsigned char j;                    /* LED var */
  P0=0;
  P1=0;
  P2=0;
  P3=0;

  while (1) {                         /* Loop forever */
    for (j=0x01; j< 0x80; j<<=1)  {   /* Blink LED 0, 1, 2, 3, 4, 5, 6 */
      P2 = j;                         /* Output to LED Port */
      for (i = 0; i < 10000; i++)  {  /* Delay for 10000 Counts */
       wait ();                       /* call wait function */
      }
    }

    for (j=0x80; j> 0x01; j>>=1)  {   /* Blink LED 6, 5, 4, 3, 2, 1 */
      P2 = j;                         /* Output to LED Port */
      for (i = 0; i < 10000; i++)  {  /* Delay for 10000 Counts */
       wait ();                       /* call wait function */
      }
    }
  }
}
 
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…