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

How to communicate between RS232 VB6.0 & 8051 keil C

I want to have some leds in P2.0~2.3 and show off the "ON" lamp in VB6.0 program though RS232 during the sensors are +5V output to P1.0~1.3 89S52 MCU. But it appears many errors and doesn't work in PC. Please advise me the comments for the following code. Thanks a lot!!

Parents
  • Sorry!

    void delayms(unsigned int time);
    
    main()
    {
      TMOD=0x20;
      TH1=230;
      TL1=230;
      TR1=1;
    
      SCON=0x70;
      RI=0;
      TI=0;
      ES=1;
      EA=1;
      while(1)
        {
         while(P3==0xff);
             switch(P3)
               {
                case 0xfb:
                   {
                         P1_0=0;
                 SBUF=P1;
                             break;
                       }
    
                case 0xf7:
                   {
                         P1_0=1;
                 SBUF=P1;
                             break;
                       }
    
                case 0xef:
                   {
                         P1_1=0;
                 SBUF=P1;
                             break;
                       }
    
                case 0xdf:
                   {
                         P1_1=1;
                 SBUF=P1;
                             break;
                       }
           }
    
              delayms(100);
              while(P3!=0xff);
            }
    }
    
    void scon_int (void) interrupt 4
    {
     if(RI==1)
        {
         RI=0;
         switch(SBUF)
              {
               case 0xfb:
                  {
                        P1_0=0;
                SBUF=P1;
                            break;
                      }
    
               case 0xf7:
                  {
                        P1_0=1;
                SBUF=P1;
                            break;
                      }
    
               case 0xef:
                  {
                        P1_1=0;
                SBUF=P1;
                            break;
                      }
    
               case 0xdf:
                  {
                        P1_1=1;
                SBUF=P1;
                            break;
                      }
          }
    
        }
      else TI=0 ;
    }
    
    void delayms(unsigned int time)
    {
      unsigned int n;
      while(time>0)
       {
         n=120;
         while(n>0)  n--;
         time--;
       }
    }
    

Reply
  • Sorry!

    void delayms(unsigned int time);
    
    main()
    {
      TMOD=0x20;
      TH1=230;
      TL1=230;
      TR1=1;
    
      SCON=0x70;
      RI=0;
      TI=0;
      ES=1;
      EA=1;
      while(1)
        {
         while(P3==0xff);
             switch(P3)
               {
                case 0xfb:
                   {
                         P1_0=0;
                 SBUF=P1;
                             break;
                       }
    
                case 0xf7:
                   {
                         P1_0=1;
                 SBUF=P1;
                             break;
                       }
    
                case 0xef:
                   {
                         P1_1=0;
                 SBUF=P1;
                             break;
                       }
    
                case 0xdf:
                   {
                         P1_1=1;
                 SBUF=P1;
                             break;
                       }
           }
    
              delayms(100);
              while(P3!=0xff);
            }
    }
    
    void scon_int (void) interrupt 4
    {
     if(RI==1)
        {
         RI=0;
         switch(SBUF)
              {
               case 0xfb:
                  {
                        P1_0=0;
                SBUF=P1;
                            break;
                      }
    
               case 0xf7:
                  {
                        P1_0=1;
                SBUF=P1;
                            break;
                      }
    
               case 0xef:
                  {
                        P1_1=0;
                SBUF=P1;
                            break;
                      }
    
               case 0xdf:
                  {
                        P1_1=1;
                SBUF=P1;
                            break;
                      }
          }
    
        }
      else TI=0 ;
    }
    
    void delayms(unsigned int time)
    {
      unsigned int n;
      while(time>0)
       {
         n=120;
         while(n>0)  n--;
         time--;
       }
    }
    

Children