Program doesn't work after disconnect and connect power

hello; I create a program for test a led with my carte atmega328 and gsm800l V2. When I upload the program with USBasp everything works well, but when I disconnect and connect the power the program dosn't work correctly. and when I upload the program again everything works well.
for information I receive this message when I upload the program:
avrdude.exe: warning: cannot set sck period. please check for usbasp firmware update.

Please provide a wiring diagram of some kind as well as your code in codes tags </>.

thanks for your reply.
for diagram I use this schematic.


and I use a simple program to send a sms for activate and deactivate relay.

That drawing is no use for anything…
If you want good help, you need to make more effort.

Hello;
I think my problem has no relation with the schematic or the program, please can you read again my post:
When I upload the program with USBasp everything works well, but when I disconnect and connect the power the program dosn't work correctly. and when I upload the program again everything works well.

Possibly something to do with the code you haven't posted.
In between the code tags , of course <>.

That may be the case and it may not be. Either way this is an unproductive stance. If you want proper help you will need to provide all information requested of you. Then, people can help you find the problem.

Please provide your code as requested, using the code tag button </>.

Hello;

#include <SoftwareSerial.h>
SoftwareSerial mySerial(7,8);  // (Rx,Tx  > Tx,Rx) 

String incomingData;  
char incomingByte; 
String inputString;
int relay = 4; // Output for Relay Control

void setup() 
{
   inputString = "";
   pinMode(relay, OUTPUT);// initialize digital pin relay as an output.   
   digitalWrite(relay, LOW);// Initial state of the relay
   delay(100);
   mySerial.begin(9600); 
   while(!mySerial.available()){
        mySerial.println("AT");
        delay(1000); 
      }
   mySerial.println("AT+CMGF=1"); 
   delay(1000);  
   mySerial.println("AT+CNMI=1,2,0,0,0");
   delay(1000);
   mySerial.println("AT+CMGL=\"REC UNREAD\"");
}

void loop()
{  
  if(mySerial.available()){
      delay(100);
      while(mySerial.available()){
        incomingByte = mySerial.read();
        inputString += incomingByte; 
      }
   
        delay(10);      
      inputString.toUpperCase();

      //turn RELAY ON or OFF
      if (inputString.indexOf("START") > -1){
          digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on
          digitalWrite(relay, HIGH);   // turn the LED on
          SendMessage("PUMP ON");
       
      }
      if (inputString.indexOf("STOP") > -1){
          digitalWrite(LED_BUILTIN, LOW);   // turn the LED on
          digitalWrite(relay, LOW);   // turn the LED off
          SendMessage("PUMP OFF");
               
      }
       
        delay(50);

        //Delete Messages & Save Memory
        if (inputString.indexOf("OK") == -1){
        mySerial.println("AT+CMGDA=\"DEL ALL\"");
        delay(1000);}
        inputString = "";
  }
}

void SendMessage(String Text)
{
  mySerial.println("AT+CMGF=1");
  delay(1000);
  mySerial.println("AT+CMGS=\"+xxxxxxxxxxxxxx\"\r"); // Replace x with mobile number
  delay(1000);
  mySerial.println(Text);
  delay(100);
  mySerial.println((char)26);
  delay(1000);
}

 void RecieveMessage()
{
  incomingData = mySerial.read(); 
  delay(1000);
 }

What power source are you using for the 5V shown on your schematic?

Please can you read again:
When I upload the program with USBasp everything works well, but when I disconnect and connect the power the program dosn't work correctly. and when I upload the program again everything works well.
Then the USBasp is my source.

As in post #9 , what are powering the 5Volt supply with and HOW ??

I connect my PCB with USBASP to pc for upload program and after that I test the program and all works perfectly. but after that when I disconnect USBasp and use the other source (5VDC) or USBasp the program dosn't work. and when I upload the program again it's OK.

As a process of elimination , i can only suggest removing all the periferals , using only the basic CPU with a very basic "blink" or "Hello World" sketch and check the result.

ps. on closer exam of your circuit diagragm , the two 22pF caps in the crystal clock circuitry are Not shows to ground , is this the case or a typo?

Why are all the necessary ceramic capacitors missing in your circuit diagram, as well as the one electrolytic capacitor of at least 100 microfarads between + 5V and GND ??? Are these capacitors also missing in your structure?
And what does the program not work? what does it do and what does it not do?

The both 22 cps are connected to the GND;

Nevertheless, 100nF Ceramick capacitors are required directly at the connections VCC and GND as close as possible to the Atmega328, C12 will almost certainly be too far away from the Atmega. In addition, C12 is responsible for the voltage regulator, which cannot also do its job for the Atmega.
You don't need to be afraid of ceramic capacitors, they are neither evil nor do they try to usurp world domination. Note: it is better to build in one more than one too little.

OK; does the capacity affect the functioning of the program when I disconnect and connect the power.

The capacitor effects your power.
Are you starting it connected, then disconnecting it and expecting it to stay on?
Just trying to determine the sequence of events.

Thanks; but why when I upload the program by USBasp everything works well.