art
Joined: 21 May 2015 Posts: 181
|
Entering ADC while loop |
Posted: Mon Sep 28, 2015 5:18 pm |
|
|
Hi, i'm using 'ENTER' key on keyboard to exit ADC while loop for the first time. It can exit the loop and and display "Enter 'Z' for ADC or 'z' for RELAY :". But the main problem here is when I enter 'Z' once again, it cannot enter the ADC loop and keep repeating "Enter 'Z' for ADC or 'z' for RELAY :".
What is wrong with my code.
Code: |
#include <18F4550.h>
#DEVICE ADC=10
#fuses HS,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#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>
main()
{
char ch;
unsigned char key;
float value, min;
int8 binary_string[10];
while(true)
{
printf("\n\n");
printf("Enter 'Z' for ADC or 'z' for RELAY : \n");
ch=getc();
if(ch=='Z')
{
while (key!=13)
{
setup_port_a( ALL_ANALOG );
setup_adc( ADC_CLOCK_INTERNAL );
set_adc_channel( 0 );
if(kbhit())
{key=getch();}
value = Read_ADC();
min=value*5/1023 ;
printf("\r%2.3f",min);
delay_ms(1000);
}
}
if(ch=='z')
{
while (1)
{
printf("Enter Relay Number : \n");
get_string(binary_string,9);
output_B((int8)strtoul(binary_string,0,2));
}
}
}
} |
|
|