Dual channel EEg system through PIC16F887

Discussion in 'Embedded Systems and Microcontrollers' started by @m@, Aug 20, 2011.

  1. @m@

    Thread Starter Member

    Mar 9, 2009

    I am working on multiple channel ADC to RS232 using PIC16F887
    Now the problem is that I want to build dual channel EEG systems which transmit data of both channel to the serial Comm (PC) simultaneously...
    Something like this ...

    For example: when I get output 8 bits for each channel, the Data bytes should take turns, i.e., I have to program the uC internally to send out the data like this. See below:

    EEG Channel A ->
    |-->uC / PIC--> Data A, Data B, Data A, Data B, -> uC Serial port
    EEG Channel B ->

    What i have tried so far is the code below...

    unsigned short temp_res;
    unsigned short temp_res1;
    char buf[7];
    char buf2[7];
    int i;
    void main() {
    ADCON1 = 0x80;
    TRISA = 0xFF;
    ANSEL = 0xFF; // Configure AN2 pin as analog
    C1ON_bit = 0; // Disable comparators
    C2ON_bit = 0;

    TRISA = 0x03; // PORTA is input
    TRISD = 0; // PORTC is output
    TRISB = 0; // PORTB is output

    do {
    temp_res = ADC_Read(1)>>2 ;
    PORTD = temp_res;
    temp_res1 = ADC_Read(0)>>2 ;
    PORTB = temp_res1; // Send lower 8 bits to PORTB

    for(i = 0; i < 7; i++)

    } while (1);

    The program above shows output on terminal like this 49341
    but it must be like this 94143 (because I applied 2.8V on AN0 and 1.85 on AN1)
    Sorry,, If I have done something really stupid in the code :p because I am very beginner for PIC programming so I really need help...
    If u ppl can guide me for my purpose in some more better way then I will be really thankful to all of u ...