USART

hi im trying to send data from RX on arduino to a pic having trouble sending

#include <SoftwareSerial.h>
SoftwareSerial mySerial(0, 1);


unsigned char PIR = 1;
unsigned char MIC = 1;
unsigned char REED = 1;
unsigned char ALARM = 1;

void setup(){
  //Serial1.pinMode (1, OUTPUT);
  Serial.begin(9600);
  mySerial.begin(9600);
  
}

void loop()
{
    PIR = 0;
    MIC = 0;
    REED = 0;
    ALARM = 0;
   mySerial.write(mySerial.write(7));
    
    if (PIR&MIC&REED&ALARM) {
        mySerial.write(mySerial.write(0b0111));
    }
    else if (MIC&REED&ALARM) {
        mySerial.write(mySerial.write(0b0110));
    }
    else if (PIR&REED&ALARM) {
        mySerial.write(mySerial.write(0b0101));
    }
   else if (PIR&MIC&ALARM) {
        mySerial.write(mySerial.write(0b0100));
    }
    else if (PIR) {
        mySerial.write(mySerial.write(0b0001));
    }
    else if (MIC) {
        mySerial.write(mySerial.write(0b0010));
    }
    else if (REED) {
        mySerial.write(mySerial.write(0b0011));
    }
    delay(500); //wait for 500ms
}

Which arduino?. Pins 0+1 are Serial (hardware serial) and not SoftSerial on most.

Mark

   mySerial.write(mySerial.write(7));

What exactly do you expect from this line of code? You have a bunch of them in your code and I'm almost sure your expectations are wrong.
BTW: your code won't ever do anything reasonable. You might have to tell us what you think it should do.

hi im trying to send information to a pic18F1220 to turn leds on, ive re wrote the code to this
ive checked pin 11 its defintely sending the problem is the pic aint receiving

#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11);

unsigned char PIR = 0;
unsigned char MIC = 0;
unsigned char REED = 0;
unsigned char ALARM = 0;

void setup(){
    Serial.begin(9600);
}

void loop()
{
    PIR = 0;
    MIC = 0;
    REED = 0;
    ALARM = 0;
    
  mySerial.write(0b0110);

    if (PIR&MIC&REED&ALARM) {
        mySerial.write(0b0111);
    }
    else if (MIC&REED&ALARM) {
        mySerial.write(0b0110);
    }
    else if (PIR&REED&ALARM) {
        mySerial.write(0b0101);
    }
    else if (PIR&MIC&ALARM) {
        mySerial.write(0b0100);
    }
    else if (PIR) {
        mySerial.write(0b0001);
    }
    else if (MIC) {
        mySerial.write(0b0010);
    }
    else if (REED) {
        mySerial.write(0b0011);
    }
    delay(500); //wait for 500ms
}

PIC CODE

#include <htc.h>
#include <pic18.h>
#pragama config WDT=OFF, OSC=INTIO2,PWRT=ON, LVP=OFF, MCLRE=OFF
#include <plib/usart.h>
#include <delays.h>

int main(void) {
        //Open Serial Port for Read Communication
    OpenUSART(USART_RX_INT_OFF&
              USART_TX_INT_OFF&
              USART_ASYNCH_MODE&
              USART_EIGHT_BIT&
              USART_CONT_RX&
              USART_BRGH_HIGH, 51);
    CREN = 1;
    ADCON1= 0x7F;
    TRISA = 0x00; // set PortA to Output

      //while(1)  {
        PORTAbits.RA0 = 1;
        PORTAbits.RA1 = 1;
        PORTAbits.RA2 = 1;
        PORTAbits.RA3 = 1;
        Delay100TCYx(78);
        PORTAbits.RA0 = 0;
        PORTAbits.RA1 = 0;
        PORTAbits.RA2 = 0;
        PORTAbits.RA3 = 0;
        Delay100TCYx(78);
      
    while(1){
        while(!DataRdyUSART()); //wait until data is availiable on the USART
        switch(ReadUSART()) { //Read from USART and test against table
            case(0b0001): //
                PORTAbits.RA0 = 1;
                break;
            case(0b0010):
                PORTAbits.RA1 = 1;
                break;
            case(0b0011):
                PORTAbits.RA2 = 1;
                break;
            case(0b0100):
                PORTAbits.RA0 = 1;
                PORTAbits.RA1 = 1;
                PORTAbits.RA3 = 1;
                break;
            case(0b0101):
                PORTAbits.RA0 = 1;
                PORTAbits.RA2 = 1;
                PORTAbits.RA3 = 1;
                break;
            case(0b0110):
                PORTAbits.RA1 = 1;
                PORTAbits.RA2 = 1;
                PORTAbits.RA3 = 1;
                break;
            case(0b0111):
                PORTAbits.RA0 = 1;
                PORTAbits.RA1 = 1;
                PORTAbits.RA2 = 1;
                PORTAbits.RA3 = 1;
                break;
        default:PORTA = 0;
        }
        //Delays10KTCYx(10); //wait for 500ms
        LATA = 0; //Turn LEDs off
    }
}

Since PIR, MIC, REED and ALARM are set to zero and never changed, the if's will never be true. The only mySerial.write() that is executed is the first one.

yeah the arduino isnt sending

Are you sure you want bitwise and (a single &) and not logical and (&&)?.

Mark

PS are your ground connected!.

Mark

i know its group project the PIR REED MIC And ALARM isnt my bit of code, thats is done enought bit of code im simpley trying to get the arduino to send data to the pic, that first line was to check after i got that to work i would have change the others

so && is actually digital & yeah i beleive thats the one i need, but its still doesnt help that the arduino aint sending any data have hooked up to an oscilloscope and getting nothing

What happend to your mySerial.begin() in setup?

Mark

Have you checked both pin 10 and 11?