Set port1 pins as 0 or 1

Discussion in 'Embedded Systems and Microcontrollers' started by mrkrishnan, Feb 20, 2012.

  1. mrkrishnan

    Thread Starter New Member

    Feb 13, 2012
    4
    0
    Dear all,
    i am using P89V51RD2 (philips) 8051 micro-controller. i am doing some samples with NSK developemnt kit. In this i want to set the Port1 pint 0 to 7 as high/low continiously. I tried this by using the following lines,

    P1 = 0x00 ;
    delay(10000) ;
    P1 = 0xFF ;

    but still i am always getting around 5V on these pins. i searched lot of forums, but in that also they mentioned like this only. Kindly give your suggessions.......


    Thanks and Regards
    Radhakrishnan M
     
  2. be80be

    Senior Member

    Jul 5, 2008
    431
    57
    Your code needs to be some thing like this

    Code ( (Unknown Language)):
    1.  
    2. #include <REGX51.H>
    3. void msdelay(unsigned int );
    4. void main(){
    5. P1=0×00;  //all pin of PORT1 declared as output
    6. //infinite loop
    7. while(1){
    8. P1=0xFF;   //all pin high
    9. msdelay(1000);    //delay
    10. P1=0×00;   //all pin low
    11. msdelay(1000); //delay
    12. }
    13. }
    14. //delay function
    15. void msdelay(unsigned int value){
    16. unsigned int x,y;
    17. for(x=0;x<value;x++)
    18. for(y=0;y<1275;y++);
    19. }
    This is in C using Keil uVision4
     
    mrkrishnan likes this.
  3. mrkrishnan

    Thread Starter New Member

    Feb 13, 2012
    4
    0
    Thank you be80be. now it is working. Actually i missed the last delay.


    Thanks and Regards
    Radhakrishnan M
     
Loading...