CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Exit ADC

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
art



Joined: 21 May 2015
Posts: 181

View user's profile Send private message

Exit ADC
PostPosted: Tue Sep 15, 2015 11:49 pm     Reply with quote

Hi, I'm trying to make a code that user can select to check ADC voltage or send Output to port D by typing "Z" or "z". The main problem here is how to modify it to make it able to exit from ADC which is in B: to A: .

Here is my code:
Code:

#include <18F4550.h>
#DEVICE ADC=10
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)
#include <string.h>
#include <input.c>
#include <stdio.h>
#include <stdlib.h>

void main()
{
   int i;
   float min, value, max;
   int8 binary_string[10];
 

A:

   printf("Enter "Z" for ADC or "z" for binary number : \n");
        get_string(binary_string,9);



        if(binary_string=="Z")
     {goto B; }

   if(binary_string=="z")
     {goto C; }



B:

    setup_port_a(ALL_ANALOG);
    setup_adc(ADC_CLOCK_INTERNAL);
    set_adc_channel(0);

    do  {
            min=1023;
            max=0;
            for(i=0; i<=1; ++i)
                {
                  delay_ms(5);
                  value = Read_ADC();
           
                   If( value<=min);
                       min=value*5/1023;
                   If( value>=min);
                       max=value;       
                 }
             printf(" Voltage : %2.3f V   NO: %3.0f ", min, max);
            }while(TRUE);




C:   


   while(true)
             {       
               printf("Enter 8 binary number : \n");
               get_string(binary_string,9);

      if(binary_string=="A")
             {goto A; }

               output_D((int8)strtoul(binary_string,0,2));


             }


}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Sep 16, 2015 1:01 am     Reply with quote

Normally, if you want something to "exit", you make it into a routine,
and you call it, and then it exits and returns to your main code.
Also, we don't normally use goto's. We would use either a switch-case
that called a routine in each case, or we would use if-else statements.
You need to get a book on the C language.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group