0
\$\begingroup\$

in this code :

//at89s52 processor 16.000Mhz oscillator
#include<REG52.h>

sbit IN1 = P1^0;
sbit IN2 = P1^1;
sbit IN3 = P1^2;
sbit IN4 = P1^3;

sbit north = P0^0;
sbit south = P0^1;
sbit east = P0^2;
sbit west = P0^3;

sbit northE = P0^4;
sbit northW = P0^5;
sbit southE = P0^6;
sbit southW = P0^7;
sbit pump = P3^3;
 sbit led = P1^0;
void delay(int a)
{
    int i;
    for(i = 0; i<a;i++)
    {
TH0 = 0xFA;
        TL0 = 0xCA;
        TR0 = 1;
        while(TF0 == 1)
        {
            TF0 = 0;
            TR0 = 0;
        }
    }
}
        void SerialBegin()
        {
            TMOD = 0x21; // timer 0 mode 1 & timer 1 mode 2
            SCON = 0x50;
            TH1 = 0xF7;  //4800bit per second
            TR1 = 1;
        }
        void SerialLetter(char t)
        {   
    SBUF = t; 
            while(!TI);
            TI = 0;
            //send ASCII letter
        }
        void SerialPrint(char *q)
        {
            while(*q)
            {
                SerialLetter(*q++);
            }
        } //send entire string
        int SerialRead(void)
        {
            while(!RI);
            RI = 0;
            return(SBUF);
        } // value of reading Serial
        int dat;
        int count = 0;
        
        void main()
        {
            SerialBegin();
            SerialPrint("Made by Kiro Using AT89S52 \n");
            P1 = 0x00;
            P2 = 0x00;  
            P0 = 0xFF;
            pump = 0x00;
IE = 0x81;
IT0 = 0;        


            while(1)
            {
                dat = SerialRead();     
                switch(dat)
                {
                    case 'F':
                    SerialPrint("Forward");
                    IN1 = 1;
                    IN2 = 0;
                    IN3 = 1;
                    IN4 = 0;
                    break;
                    
                    case 'B':
                    SerialPrint("Backward");
                    IN1 = 0;
                    IN2 = 1;
                    IN3 = 0;
                    IN4 = 1;
                  break;
                    
                    case 'R':   
                    SerialPrint("Turning Right");
                    IN1 = 0;
                    IN2 = 0;
                    IN3 = 1;
                    IN4 = 0;
                  break;
                    
                    case 'L':
                    SerialPrint("Turning Left");
                    IN1 = 1;
                    IN2 = 0;
                    IN3 = 0;
                    IN4 = 0;
                  break;
                    
                    case 'S':
                    SerialPrint("Stopped");
                    IN1 = 0;
                    IN2 = 0;
                    IN3 = 0;
                    IN4 = 0;
          break;
}
}               
}
        void ISR() interrupt 0
        {
            if(south == 1)
            {
                pump = 1;
            SerialPrint("*SR255G0B0*");
            delay(5);
                pump = 0;
                SerialPrint("*SR0G0B0*");
            }
            if(north == 1)
            {
                pump = 1;
            SerialPrint("*NR255G0B0*");
            delay(5);
                pump = 0;
                SerialPrint("*NR0G0B0*");
            }
            if(east == 1)
            {
                pump = 1;
            SerialPrint("*ER255G0B0*");
            delay(5);
                pump = 0;
                SerialPrint("*ER0G0B0*");
            }
        }

The pump is working properly in Proteus simulator
enter image description here
After uploading the code to the MCU , the pump didn't work like what happened in Proteus.
What should I do to make the pump work ?

\$\endgroup\$
10
  • 4
    \$\begingroup\$ Learn debugging. (Also : ISRs are supposed to be short and fast. That means, no serial I/O in ISRs : set flags to tell the main loop what to print) \$\endgroup\$ – user_1818839 Jan 4 at 22:29
  • \$\begingroup\$ @BrianDrummond I want to turn the motor on during ISR can you answer that question ? \$\endgroup\$ – Kiroloes Amir Jan 4 at 22:32
  • 3
    \$\begingroup\$ Turning a port bit on or off in an ISR should be fine, but you want to connect Q1 as a low side switch not an emitter follower. (and don't forget the flyback suppressor diode! You may have killed Q1 already) \$\endgroup\$ – user_1818839 Jan 4 at 22:36
  • 2
    \$\begingroup\$ That's not where the flyback suppression diode goes. (also, Vcesat is ENORMOUS for that device. What voltage is the pump rated for? Will it even start at 3V?) \$\endgroup\$ – user_1818839 Jan 4 at 22:42
  • 1
    \$\begingroup\$ There is a difference between turning on and your use of SerialPrint. Your ISR is bad! \$\endgroup\$ – StainlessSteelRat Jan 5 at 0:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.