|
|
View previous topic :: View next topic |
Author |
Message |
art
Joined: 21 May 2015 Posts: 181
|
Exit ADC |
Posted: Tue Sep 15, 2015 11:49 pm |
|
|
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
|
|
Posted: Wed Sep 16, 2015 1:01 am |
|
|
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. |
|
|
|
|
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
|