title: UART between pic and matlab gui
body: <p>I have a trouble with interfacing pic microcontroller with pc using MATLAB GUI 
  Matlab gives me this error "Warning: A timeout occurred before the Terminator was reached "</p>
  
  <p>Here is the mikroc code:</p>
  
  <pre><code>void main() 
  {
      char x,send;
      TRISD = 0x00;
      TRISB = 1;
      while(1)
      {
          if (PORTB.f0==1)
          {
              UART1_Init(9600);
              Delay_ms(100);
              UART_Write('s');
              x = 0;
              while(x==0)
              {
                  x = UART1_Read();
                  if (x=='y')
                  {
                      PORTD.f0=1; Delay_ms(1000); PORTD.f0=0;  
                  }
                  else if (x=='n')
                  { 
                      PORTD.f1 = 1;  
                      Delay_ms(1000);  
                      PORTD.f1 = 0;
                  }
              } 
         }
    }
  </code></pre>
  
  <p>}</p>
  
  <p>and here is the matlab code :</p>
  
  <pre><code>function pushno_Callback(hObject, eventdata, handles)
  
  delete(instrfind);
  s = serial('COM4');
  set(s,'BaudRate',9600,'DataBits', 8, 'Parity', 'none','StopBits', 1, 'FlowControl',   none','Terminator','CR');
  
  s.BytesAvailableFcnCount = 1;
  s.BytesAvailableFcnMode = 'byte';
  s.BytesAvailableFcn=@mycallback;
  handles.pushno=s;
  fopen(s);
  
  function mycallback(hObject, event, handles)
  s=handles.pushno;
  out=fscanf(s);
  if (out=='s')
  pause(1);
  fprintf(s,'y');
  end 
  fclose(s);
  delete(s);
  clear s;
  </code></pre>