varunme
Advanced Member level 3
The following code does not works ,
i want to control a stepper motor with the values send by rs232 and get the feedback from the pot, but to check the values of adc and uart , i just used dummy values in the below code
i want to control a stepper motor with the values send by rs232 and get the feedback from the pot, but to check the values of adc and uart , i just used dummy values in the below code
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 unsigned char ch; // unsigned int adc_rd; // Declare variables char *text; // long tlong,ulong; char output[7]; int i,rot; float ufloat,tfloat; int uint; void main() { CMCON |= 7; ADCON1 = 0X04; ADCON1 = 0; TRISA = 0x04; ADCON1 = 0x80; TRISB =0; // PORTB=0x00; while (1) { adc_rd = ADC_Read(2); // A/D conversion. Pin RA2 is an input. Lcd_Out(2,1,text); // Write result in the second line tlong = (long)adc_rd * 5000; // Convert the result in millivolts tlong = tlong / 1023; // 0..1023 -> 0-5000mV ch = tlong / 1000; // Extract volts (thousands of millivolts) // from result UART1_Init(9600); // Initialize UART1 module at 9600 bps Delay_ms(100); // Wait for UART 1module to stabilize UART1_Write_Text("Start"); UART1_Write(13); UART1_Write(10); while (!UART1_Data_Ready()); // wait for UART character in buffer // Initialize string with all '\0' for(i=0; i<7; i++){ output[i] = '\0'; } UART1_Read_Text(output, "m", 255); // read input from uart ulong = atol(output); while(1) { if ( ulong =! tlong ) { if (ulong > tlong ) { PORTB.f1=1; UART1_Write_Text("1"); break; } else //(ulong < tlong ) {PORTB.f1=0; PORTB.f2=1; UART1_Write_Text("2"); break; } } if ( ulong == tlong ) { PORTB.f3=1; UART1_Write_Text("3"); PORTB.f1=0; PORTB.f2=1; break; } } } }