- This topic has 0 replies, 1 voice, and was last updated 8 years, 9 months ago by .
Viewing 1 post (of 1 total)
Viewing 1 post (of 1 total)
- You must be logged in to reply to this topic.
|
Microcontroller › PIC › Send multiple analog signals with UART PIC16f877A
Hi
i am trying to get 2 analog signal from 2 sensors and send the data to a PC through a USB to UART bridge ….the code works with one analog signal but when i get it to 2 signals ,,,it doesnet work …. the 2 analog signals read the same signal some how …
can anyone help me? ,, thanx
unsigned int analogValX;
unsigned int analogValY;
char x[4];
char y[4];
void main()
{
CMCON = 7 ;
TRISA = 0XFF;
ADCON1 = 0XC0;
ADCON0 = 0X41;
// TRISB = 0X00;
//TRISD = 0X00;
UART1_Init(9600);
while (1)
{
ADCON0=0x41;
delay_us(50);
ADCON0.B2 = 1;
while (ADCON0.B2);
analogValX = ((unsigned int) ADRESH << |ADRESL;
IntToStr(analogValX,x); // Read A0
ADCON0=0x59;
delay_us(50);
ADCON0.B2 = 1;
while(ADCON0.B2);
analogValY = ((unsigned int) ADRESH << |ADRESL;
IntToStr(analogValY,y); //Read A1
UART1_Write_Text("AnalogX = ");
UART1_Write_Text(x);
UART1_Write_Text("$ ");
UART1_Write_Text("AnalogY = ");
UART1_Write_Text(y);
UART1_Write_Text("$");
UART1_Write(13);
strcpy(x,"");
strcpy(y,"");
//PORTB = ADRESL;
//PORTD = ADRESH;
}
}