Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8638477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:44:17+00:00 2026-06-12T10:44:17+00:00

I am trying to execute some commands using USART communication and reading some values

  • 0

I am trying to execute some commands using USART communication and reading some values using ATmega32-A. have a look at my code . My problem is i am trying to add some cases (nested switch case) but i am not getting what i want. I hope i am giving all most all information required to solve my problem.

void uniCom(void) {
switch (Command) {
/* ... */
case (muxsel):
  printf(muxselection);
  switch (c) {
    case 1:
      printf("this is mux chaneel1");
      DDRB = 0b10111111;
      PORTB = 0b00000000;
      printf("adc Value", ReadAdc());
      Command = 0;
      break;
    case 2:
      /*-------------------*/
      break;
  }
  Command = 0;
break;
/* ... */
default:
    Command = 0;
    break;
}

}
The problem is undefined c. And I don’t see any declaration of muxselection, maybe missing “” ? Now the second approach.

void selcase(void) {
unsigned char c;
printf("muxselection");
while (rx_counter0) {
 c = getchar();
switch (c) {
  case 1:
    printf("this is mux chaneel1");
    DDRB = 0b10111111;
    PORTB = 0b00000000;
    printf("adc Value", ReadAdc());
    Command = 0;
    break;
  case 2:
    /*-------------------*/
    break;
}
}
}
void uniCom(void) {
switch (Command) {
/* ... */
case (muxsel):
  printf(muxselection);
  selcase();
  Command = 0;
  break;
/* ... */
default:
    Command = 0;
    break;
}
}

My problem is i am executing all the commands as i declared but i want to select some more cases in one of the main switch case command “muxsel”. for that i wrote nested switch case. if i select “muxsel” command on hyperteminal then it is printing like “muxselection” then if i enter 1 to select “case ‘1’”in second switch, nothing is printing. it is printing “command not found”. what is the problem. I want execute nested switch but i am not able to do that using above code I have tried like this also.

void selcase(void) {
         unsigned char c;
         printf("muxselection");
         while (rx_counter0) {
         c = getchar();

         switch (c) {
                  case '1':
                    printf("this is mux chaneel1");
                    DDRB = 0b10111111;
                    PORTB = 0b00000000;
                    printf("adc Value", ReadAdc());
                    c= 0;
                    break;
                  case '2':
                  /*-------------------*/
                  break;
                 default;
                  break;
               }
            }
          }

creating one function for nested switch case and calling in main switch case as shown below.

  void uniCom(void) {
      switch (Command) {
                 /* ... */
                   case (muxsel):
                          printf(muxselection);
                          selcase();
                          Command = 0;
                          break;
                     /* ... */
                     default:
                       Command = 0;
                       break;
         }
       }

this way also not working please suggest me how to overcome this problem. i want to select one of the command in main switch case such as “muxsel” after that i have select mux channels using case statement. any help appreciated.

Thanks in advance.

I have solved this problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T10:44:18+00:00Added an answer on June 12, 2026 at 10:44 am

    OK… the code isn’t terribly clear, but I think I see your problem.
    You tried to modify the code like this:

    case (muxsel):
     printf(muxselection);
      switch (c) {
         case 1:
             printf("this is mux chaneel1");
             DDRB = 0b10111111;
             PORTB = 0b00000000;
             printf("adc Value", ReadAdc());
             Command = 0;
             break;
         case 2: 
    

    First, you don’t have c declared in the scope of the uniCom() function. So that would not compile. Because you didn’t give full code I assume you know that and probably really did something like this:

    void uniCom(void) {
    
        unsigned char c;
        c = getchar();  
    
        switch (Command) {
          case (no_com):
              Command = 0;
        ....
          case (muxsel):
              printf("muxselection\n"); //Need quotes here and maybe a \n?
              switch (c) {
                 case 1:
                  ...
    

    Which leads to the next problem. You’re asking for a char c but your cases are built on an int. For example, if the user enters 3, what you’re getting is the character ‘3’ or the int 51. Check the ASCII Table

    So your cases are for start of header (SOH), start of text (STX), etc right now… that’s not going to work the way you wanted it to. You need to either do this:

              switch (c) {
                 case 51:     // This is ASCII '1'
                  ...
                  break;
                 case 52:     // This is ASCII '2'
    

    Or do this:

              switch (c) {
                 case '1':
                  ...
                  break;
                 case '2':
    

    Since you didn’t give your input, or how c was defined, I could be wrong… but I’m going to wager that’s your problem. By the way, make sure you have a default case at the end with a message like “bad input”, it makes this type of thing easier to catch.

    EDIT:
    Modify the code as follows and share the result:

    void runCom(void){
          unsigned char c;
          c = getchar();
          printf("%c %d\n", c, c);   //<-- add this line here
          switch(Command){ 
    

    and

    void selcase(void) {
        unsigned char c;
        printf("muxselection");
        while (rx_counter0) {
            c = getchar();
            printf("%c %d\n", c, c); //<-- and this line here
            switch (c) {  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to execute some Linux commands from Java using redirection (>&) and
Problem: I am trying to write an app that executes some code when the
Trying to execute powershell script in my C# code. Using .NET Framework v. 4.0.30319
I'm very new at MySQL and I'm trying to execute some commands, wait a
I'm trying to run some commands in paralel, in background, using bash. Here's what
i am just trying to create a link which execute some JavaScript in stead
I'm trying to use cx_Oracle to connect to an Oracle instance and execute some
Im trying to execute a .bat file remotely in a powershell script. The code
I`m trying to execute linux commant 'cat' from java code, but it does not
I'm trying to execute command prompt commands and read the output in C#. This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.