hey guys,
thank you for reading my thread, i am creating a program where a stepper motor does 1 step and reads sensor values, however, to read the sensor values i have to always do the following code:
char adc []= "ADC value=";
char *temp = "0000";
int a=0;
unsigned int adc_value;
ADCON0 = 0b10010000; //AN2 analog channel selected
ADCON1 = 0b01001001; //PORT configuratoin to AN2
TRISA = 0b00000100; //RA2 analogue input
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,adc);
do {
adc_value = ADC_Read(2); //read from channel 1
temp [0] = adc_value/1000 +48 ; //add 48 to get the ascii value
temp [1] = (adc_value/100) %10 +48 ;
temp [2] = (adc_value/10) %10 +48;
temp [3] = (adc_value/1)%10 +48;
Lcd_Out(1,11,temp);
Delay_ms(100);
if (adc_value>=900){
Lcd_Out(2,1,"Too hard ");
the above is quite long as i have to copy and paste the highlighted part again and again in the main code, i have tried doing it in a separate function, however, as i try to read the adc_value in the main function, it says that the function is undeclared (i know i have to copy the declaration but that would be the same thing all over), any suggestions would be appreciated, of if theres a better way...Thanks guys
i just want to save the time of copying all that again and again and saving the hedache of checking incase there is a fault or change needed in the future
thank you for reading my thread, i am creating a program where a stepper motor does 1 step and reads sensor values, however, to read the sensor values i have to always do the following code:
char adc []= "ADC value=";
char *temp = "0000";
int a=0;
unsigned int adc_value;
ADCON0 = 0b10010000; //AN2 analog channel selected
ADCON1 = 0b01001001; //PORT configuratoin to AN2
TRISA = 0b00000100; //RA2 analogue input
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,adc);
do {
adc_value = ADC_Read(2); //read from channel 1
temp [0] = adc_value/1000 +48 ; //add 48 to get the ascii value
temp [1] = (adc_value/100) %10 +48 ;
temp [2] = (adc_value/10) %10 +48;
temp [3] = (adc_value/1)%10 +48;
Lcd_Out(1,11,temp);
Delay_ms(100);
if (adc_value>=900){
Lcd_Out(2,1,"Too hard ");
the above is quite long as i have to copy and paste the highlighted part again and again in the main code, i have tried doing it in a separate function, however, as i try to read the adc_value in the main function, it says that the function is undeclared (i know i have to copy the declaration but that would be the same thing all over), any suggestions would be appreciated, of if theres a better way...Thanks guys