/*
void sendCoefThroughUART(void) {
signed int AC1, AC2, AC3, AC4, AC5, AC6, B1, B2, MB, MC, MD;

     AC1 = coefficients(BMP085_CAL_AC1);
     IntToStr(AC1, data_);
     UART1_Write_Text(data_);
     UART1_Write(' ');
     
     AC2 = coefficients(BMP085_CAL_AC2);
     IntToStr(AC2, data_);
     UART1_Write_Text(data_);
     UART1_Write(' ');

     return;
}
*/
void main() {

     genericInit();
     I2C1_Init(100000);      // Initiate I2C @ 100 kHz
     initMPU6050();
     //CallibrateMPU6050raw(); // Measures the offset values of both accelerometer and gyroscope
     initHMC5883L();
/*
     initTimer0();
     startTimer0();
     Delay_ms(1000);         // Maximum allowable time
     stopTimer0();
*/

     Delay_ms(100);                   // Wait for UART module to stabilize
     
     while(1) {
        do {} while(UART1_Read() != 's'); // Wait until start signal is received
        do {
           readAccMPU6050();
           readGyrMPU6050();
           readTmpMPU6050();
           readUTBMP085();
           readUPBMP085();
           readHMC5883Lraw();
           sendThroughUARTtoMSVS();
           //Delay_ms(1000);
        } while(UART1_Read() != 'e'); // Do until end signal is received
     }//while

     return;
}
Esempio n. 2
0
void EmptySerialBuffer(void)
{
    char recieveChar;
    while (UART1_Data_Ready() == 1) {
        recieveChar = UART1_Read();
    }
}
Esempio n. 3
0
void main()
{
int i;



trisb=0;
portb=0;
     Lcd_Init();                        // Initialize LCD

UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize
while (1)       // Endless loop
{
if (UART1_Data_Ready())    // If data is received,
{
 for(i=0;i<100;i++)
 {
 uart_rd[i]= UART1_Read();
}
for(i=0;i<100;i++)
{
  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
  Lcd_Out(1,1,uart_rd[i]);
  delay_ms(10000);
}
}
}
}
Esempio n. 4
0
void Proceso(void){
 // Lectura del Voutput del sensor LM35
 // Mostrando Voutput y su conversion a °C
 char val[15];
 float volts;
 float grados;
 char centigrados[15];
 
 adc_value = ADC1_Get_Sample(10);
 grados = adc_value/cuentas;
 FloatToStr(grados,centigrados);
 UART1_Write_Text(centigrados);
 UART1_Write(13);
 UART1_Write(10);
 Lcd_Out(1, 1, centigrados);
 Lcd_Out(1, 8, "\xDFc");
 
 volts = adc_value;
 FloatToStr(volts,val);
 Lcd_Out(2, 15, "V");
 Lcd_Out(2, 1, val);
 delay(0xFFFFF);
 Lcd_Cmd(_LCD_CLEAR);
 
if (UART1_Data_Ready()) {     // If data is received
 uart_rd = UART1_Read();     // read the received data
 if (uart_rd == '1'){
  LAMPARA = ~LAMPARA;
 }
 else if (uart_rd == '2')
 {
  VENTILADOR = ~VENTILADOR;
 }
}
}
Esempio n. 5
0
static void ProcessInput(void)
{
  for( ; ; )
  { uint8_t Byte; int Err=UART1_Read(Byte); if(Err<=0) break; // get byte from console, if none: exit the loop
    if(Byte==0x03) ProcessCtrlC();                            // if Ctrl-C received
    NMEA.ProcessByte(Byte);                                   // pass the byte through the NMEA processor
    if(NMEA.isComplete())                                     // if complete NMEA:
    { /* if(NMEA.isChecked()) */ ProcessNMEA();               // and if CRC is good: interpret the NMEA
      NMEA.Clear(); }                                         // clear the NMEA processor for the next sentence
  }
}
Esempio n. 6
0
void WaitForRecieveChar(char delimiterChar)
{
    char recieveChar = 0;
    while (1)
    {
        if (UART1_Data_Ready() > 0) {
            recieveChar = UART1_Read();
            //UART1_Write(recieveChar);
        }
        if (recieveChar == delimiterChar) break;
    }
}
Esempio n. 7
0
 /* 
    Nombre: qtama
    Descripcion: establece el tamaño de la porcion de comida servida.
    Parametros: ninguno
    Retorna: entero sin signo
 */
unsigned short qtama () {
 unsigned short kp;
  qtama:

   do {
      kp = Keypad_Key_Click();             // Store key code in kp variable
      if (UART1_Data_Ready()){
         kp = UART1_Read();
         goto    bluetooth1;
         }
      }while (!kp);
    kp = teclado(kp);
    
    bluetooth1:

    if(kp == 'A' ||kp== 'B' ||kp== 'C'||kp== 'D'){
          Lcd_chr(2, 5, kp);

    do {
      kp = Keypad_Key_Click();             // Store key code in kp variable
      if (UART1_Data_Ready()){
         kp = UART1_Read();
         goto    bluetooth2;
         }
      }while (!kp);
      
    kp = teclado(kp);
    bluetooth2:
    
    if(kp == '#'){
    goto qtama;
    }
   }
  else {
  goto qtama;
  }
  return (kp);
 }
Esempio n. 8
0
unsigned short qtama () {
  unsigned short kp;
  qtama:
  
    do {
      kp = Keypad_Key_Click();
      if (UART1_Data_Ready()){
         kp = UART1_Read();
         goto    bluetooth1;
         }
    }while (!kp);
    kp = teclado(kp);
   
    bluetooth1:
    if(kp == 'A' ||kp== 'B' ||kp== 'C'||kp== 'D'){
      Lcd_chr(2, 4, kp);
      do {
        kp = Keypad_Key_Click();             // Store key code in kp variable
        if (UART1_Data_Ready()){
          kp = UART1_Read();
          goto    bluetooth2;
        }
      }while (!kp);
      kp = teclado(kp);
      
      bluetooth2:
      if(kp == '#'){
        goto qtama;
      }
      if(kp == '*'){
        Lcd_Chr (2,6,'G'); Lcd_Chr (2,7,'u'); Lcd_Chr (2,8,'a'); Lcd_Chr (2,9,'r');Lcd_Chr (2,10,'d');Lcd_Chr (2,11,'a'); Lcd_Chr (2,12,'d'); Lcd_Chr (2,13,'o');
      }
   }else {
     goto qtama;
   }
   return (kp);
 }
Esempio n. 9
0
void main() {
      configure();

      UART1_Write_Text(ConnectionEstablished);
      setPID();

      //testPIC();

      debugText = "          Starting..  ";
      UART1_Write_Text(debugText);

      delay_ms(1000);
      debugText = "Test Sensors   ";
      UART1_Write_Text(debugText);

      for(count=0; count<1; count++){
            receiveCommand = UART1_Read();
            sendSensorStatus();
            delay_ms(1000);
      }                                                  //while( receiveCommand != 'A' && receiveCommand != 'a' );

      debugText = "Start Line follow..   ";
      UART1_Write_Text(debugText);
      //lineFollowNormal();
      //lineFollow();
      lineFollowPID();
      
      testPIC();
      
      while(1){

      debugText = " Rotate Clockwise ";
      UART1_Write_Text(debugText);
      rotateClockwise(255);
      delay_ms(220);
      stop();

      delay_ms(2000);

      debugText = " Rotate Anti Clockwise ";
      UART1_Write_Text(debugText);
      rotateAntiClockwise(255);
      delay_ms(220);
      stop();

      delay_ms(2000);

      }
}
Esempio n. 10
0
void interrupt(){
     if(PIR1.RCIF) {
        PORTD.F6 = 0;
            while(UART1_Data_Ready() == 1){
                 str[count] = UART1_Read();
                 count++;
                 if(count == 13){
                    PORTD.F6 = 0;
                    flag = 1;
                 }else{
                    PORTD.F6 = 1;
                 }
           }
      }
}
Esempio n. 11
0
void UART1_Read_Line (char *Output, unsigned int length)
{

    for ( int j = 0; j < length; j++ ) {
        Output[j] = 0;
    }
    int i=0;
    for ( ; i < length; i++ ) {
        char c = UART1_Read();
        if ( c == '\r' ) break;
        Output[i] = c;
    }
    if ( i == length ) {  // at end of output, filled with characters
        Output[i-1] = 0;  // zero terminate.
    }
}
Esempio n. 12
0
unsigned int UART1_ReadBuffer( uint8_t *buffer, const unsigned int bufLen)
{
    unsigned int numBytesRead = 0 ;
    while ( numBytesRead < ( bufLen ))
    {
        if( uart1_obj.rxStatus.s.empty)
        {
            break;
        }
        else
        {
            buffer[numBytesRead++] = UART1_Read () ;
        }
    }

    return numBytesRead ;
}
Esempio n. 13
0
void WaitForRecieveCharAndBlink(char delimiterChar)
{
    char recieveChar = 0;
    while (1)
    {
        LED_Blink(1);
        if (UART1_Data_Ready() > 0) {
            recieveChar = UART1_Read();
            //UART1_Write(recieveChar);
        }
        if (recieveChar == delimiterChar)
        {
            LED_Off();
            break;
        }
    }
}
Esempio n. 14
0
interrupt()
{
rr = UART1_Read();
switch(rr)
{
case '$':
   {
    v=1;
    i=0;
    break;
    }

  case 'G':
   {
   if(v<6)
   {
    v++;
    break;
   }
   }
case 'P':
   {
    if(v==2)
    v=3;
    break;
   }

case 'A':
    {
    if(v==5)
    v=6;
    break;
    }
case 150:
    {
     mode=1;
     break;
    }
}
if (v==6){
 i++;
rec[i] = rr;
}

 }
Esempio n. 15
0
unsigned short obtenerNumero (unsigned short numMax) {
  unsigned short dig, numero, kp;
  volverObtenerNumero:
  dig = 0;
  numero=0;
  
  leerNum:
  do {
      kp = Keypad_Key_Click();
      if (UART1_Data_Ready()){
        kp = UART1_Read();
        goto    bluetoothRead;
      }
    }while (!kp);
    kp = teclado(kp);
    
    bluetoothRead:
    if(kp == 'A' || kp== 'B' || kp == 'C' ||kp == 'D'){
      goto leerNum;
    }else if (kp != '#' && kp != '*'){
      dig++;
      numero =  numero*10  +  kp -48;
      //Lcd_Chr(2, 7+dig, kp);
    }
  
  //}while (numero > numMax && kp != '*'  && kp != '#');
  
  if(kp == '#'){               //si presiona numeral se borra el numero
    goto volverObtenerNumero;
  }else if (kp == '*' && numero > 0){
    //Lcd_Chr(2, 7, (numero+48));
    Lcd_Out(2, 1, "Valor guardado");
    delay();
  }else if (numero > numMax){
    Lcd_Cmd(_LCD_CLEAR);
    Lcd_Out(2, 1, "Se paso de valor maximo");
    delay();
    goto volverObtenerNumero;
  } else{
    goto leerNum;
  }

  return (numero);
}
Esempio n. 16
0
unsigned short obtenerNumero (unsigned short numeroMax) {
  unsigned short dig,numero,kp;
  volverObtenerNumero:
  dig = 0;
  numero=0;
  Lcd_chr(2, 5, ' '); Lcd_chr(2, 4, ' '); Lcd_chr(2, 3, ' '); Lcd_chr(2, 2, ' '); Lcd_chr(2, 1, ' ');
  
  leerNumero:
  do {
    kp = Keypad_Key_Click();             // Store key code in kp variable
    if (UART1_Data_Ready()){
      kp = UART1_Read();
      goto    bluetooth4;
    }
  }while (!kp);
  kp = teclado(kp);
  
  bluetooth4:
  if(kp == 'A' || kp== 'B' || kp == 'C' ||kp == 'D'){
    goto leerNumero;
  }else if (kp>=48 && kp<=57) {
    dig++;
    Lcd_chr_Cp(kp);
    numero = (kp-48)+(10*numero);
  }
  
  if(kp == '#'){
    goto volverObtenerNumero;
  }else if (kp == '*' ){
    Lcd_Chr (2,6,'G'); Lcd_Chr (2,7,'u'); Lcd_Chr (2,8,'a'); Lcd_Chr (2,9,'r');Lcd_Chr (2,10,'d');Lcd_Chr (2,11,'a'); Lcd_Chr (2,12,'d'); Lcd_Chr (2,13,'o');
    delay();
  }else if (numero >= numeroMax){
    //Lcd_Cmd(_LCD_CLEAR);
    Lcd_chr(2, 1,'M'); Lcd_chr(2, 2,'a'); Lcd_chr(2, 3,'x'); Lcd_chr(2, 5,'t');
    delay();
    delay();
    goto volverObtenerNumero;
  }else{
      goto leerNumero;
   }

   return (numero);
}
void main() {

  TRISA = 0b00000000; // set PORTA -> salidas
  TRISB = 0b01000000; // set PORTB -> salida menos el pin 6.
  ANSEL  = 0;              // Configure AN2 pin as analog
  ANSELH = 0;
  C1ON_bit = 0;                      // Disable comparators
  C2ON_bit = 0;
  INTCON = 0b10100000; // INTERRUPCION POR TIMER0 Y GIE ACTIVADOS.
  /* INTCON.T0IE = 1;                 /\* Activado interrupcion por timer0 *\/ */
  OPTION_REG = 0b10000111; //  TMR0 temporizado:  RBPU, TOCS= INTERNAL INSTRUCTION CLOCK= 0 PSA =0   1:256
  TRISC = 0b10000000;                          // PUERTOC COMO SALIDA exepto pin 7
  PORTC = 0;                          // LIMPIAR PUERTOC
  setupTimer1();
  Delay_us(10);                 /* wait for acquisition time*/
  Lcd_Init();                        // Initialize LCD

  /* Programa principal */
  Lcd_Out(2,0,txtDefault);                 // Write text in second row
  UART1_Init(9600);                         // initialize UART1 module
  Delay_ms(100);                  // Wait for UART module to stabilize
  moverEnAutomatico();
  while (1) {
    waitSignal();
    if (UART1_Data_Ready()) {     // If data is received,
      uart_rd = UART1_Read();     // leer el dato recibido del celular
      waitSignal();
      switch (uart_rd) {
      case 'A': {               /* Modo automático */
        Lcd_Out(2,6,txtAutomatic);
        moverEnAutomatico();
        break;
      }
      case 'M': {
        moverManual();
        break;
      }
      default:
        break;
      }
    }
  }
}
interrupt()
{
rr = UART1_Read();
switch(rr)
{
case 'k':
   {
    for(i=0;i<20;i++)
   {
s1=1;s2=1;s3=1;br1=1;
delay_us(1500);
s1=0;s2=0;s3=0;br1=0;
delay_us(18500);
   }
    break;
    }

  case 'x':
   {
    for(i=0;i<20;i++)
   {
s1=1;s2=1;s3=1;br1=1;
delay_us(2350);
s1=0;s2=0;s3=0;br1=0;
delay_us(17650);
   }

    break;
   }
   case 'o':
   {
    for(i=0;i<20;i++)
     {
s1=1;s2=1;s3=1;br1=1;
delay_us(650);
s1=0;s2=0;s3=0;br1=0;
delay_us(19350);
    }

    break;
   }  }
x=1;
  }
Esempio n. 19
0
/**
 * Relays data from USB to Radio
 */
void relayFromUSB()
{
    /* UART1 - FTDI USB
     * UART2 - Bluetooth
     * UART3 - Radio        */

    if(!UART1_ReceiveBufferIsEmpty())
    {
        unsigned char rx = UART1_Read(); //Reads data from UART1 and
        InjectLoop(rx); //sends to injector

        //check for BTB_LAND packet from Mission Planner
        CheckLandingDirection(rx);
    }

    //Lets see if there is some data available to send to radio
    if(!CircularBufferIsEmpty(&(inject.outBuff)))
        UART3_Write(CircularBufferDeque(&(inject.outBuff)));

}
Esempio n. 20
0
void lerProtocolo(void) { //função que lê o protocolo e chama sua execução

  if(UART1_Data_Ready()) {

    lido = UART1_Read(); // lê o byte de inicio do protocolo

    if(lido == '[') { // se for '[' indica que o protocolo eh de identificação do módulo
      UART1_Read_Text(ID, "]", 4);
      executarProtocolo();
    }

    else if(lido == '{') { // se for '{' indica que o protocolo eh de envio ao ME
      UART1_Read_Text(ME, "}", 11);
      executarProtocolo();
    }

    else if(lido == '+') { // ser for '+' indica que o protocolo eh de resposta
      UART1_Read_Text(RE, "+", 4);
      executarProtocolo();
    }
  }
}
void cargarDato(){
if (UART1_Data_Ready())     // If data is received,
  uart_rd_temp = UART1_Read();     // leer el dato recibido del celular

}
Esempio n. 22
0
//FIN CONVERSION
void main() {
char receive;
ANSEL=ANSELH=0;///CONFIGURAMOS PINES COMO DIGITALTES
PORTA=0;
TRISA=0B1111;
TRISD=0;
PORTD=0;
UART1_Init(115200);
Delay_ms(100);
ANSEL = 0;
ANSELH = 0;
i= 0;

TRISD = 0x00;
PORTD = 0;     //VALOR INICIAL

TRISC.B7 = 0x01;               //RX
PORTC.B7 = 0; //VALOR INICIAL 0

TRISC.B0 = 0x00;
TRISC.B1 = 0x00;             //PINC.B0,B1 COMO SALIDAS DIGITALTES
PORTC.B0 = 0x00;
PORTC.B1 = 0x00;

while(1){

PORTC.B0 = CS1_DAC;
PORTC.B1 = WR_DAC;

if (UART1_Data_Ready() == 1) {
 receive = UART1_Read();
  //dessincriptacion
  switch(receive){
      case 'G' :{
      
            if (UART1_Data_Ready() == 1) {
             receive = UART1_Read();
                  //nible bajo
                       switch(receive){
                             case '0' :{
                              p1=0;
                             break;
                             }
                             case '1' :{
                             p1=1;
                             break;
                             }
                             case '2' :{
                             p1=2;
                             break;
                             }
                             case '3' :{
                             p1=3;
                             break;
                             }
                             case '4' :{
                             p1=4;
                             break;
                             }
                             case '5' :{
                             p1=5;
                             break;
                             }
                             case '6' :{
                             p1=6;
                             break;
                             }
                             case '7' :{
                             p1=7;
                             break;
                             }
                             case '8' :{
                             p1=8;
                             break;
                             }
                             case '9' :{
                             p1=9;
                             break;
                             }
                             case 'A' :{
                             p1=10;
                             break;
                             }
                             case 'B' :{
                             p1=11;
                             break;
                             }
                             case 'C' :{
                             p1=12;
                             break;
                             }
                             case 'D' :{
                             p1=13;
                             break;
                             }
                             case 'E' :{
                             p1=14;
                             break;
                             }
                             case 'F' :{
                             p1=15;
                             break;
                             }
                          }
                             if (UART1_Data_Ready() == 1) {
                                  receive = UART1_Read();
                                   //suma nible alto
                                    switch(receive){
                                          case '0' :{
                                          p1=p1+0*16;
                                          break;
                                          }
                                          case '1' :{
                                          p1=p1+1*16;
                                          break;
                                          }
                                          case '2' :{
                                          p1=p1+2*16;
                                          break;
                                          }
                                          case '3' :{
                                          p1=p1+3*16;
                                          break;
                                          }
                                          case '4' :{
                                          p1=p1+4*16;
                                          break;
                                          }
                                          case '5' :{
                                          p1=p1+5*16;
                                          break;
                                          }
                                          case '6' :{
                                          p1=p1+6*16;
                                          break;
                                          }
                                          case '7' :{
                                          p1=p1+7*16;
                                          break;
                                          }
                                          case '8' :{
                                          p1=p1+8*16;
                                          break;
                                          }
                                          case '9' :{
                                          p1=p1+9*16;
                                          break;
                                          }
                                          case 'A' :{
                                          p1=p1+10*16;
                                          break;
                                          }
                                          case 'B' :{
                                          p1=p1+11*16;
                                          break;
                                          }
                                          case 'C' :{
                                          p1=p1+12*16;
                                          break;
                                          }
                                          case 'D' :{
                                          p1=p1+13*16;
                                          break;
                                          }
                                          case 'E' :{
                                          p1=p1+14*16;
                                          break;
                                          }
                                          case 'F' :{
                                          p1=p1+15*16;
                                          break;
                                          }
                                          }
                                       }
             }
      break;

      }//FIN CANAL 1
      
            case 'H' :{//CANAL 2

            if (UART1_Data_Ready() == 1) {
             receive = UART1_Read();
                  //nible bajo
                       switch(receive){
                             case '0' :{
                              p2=0;
                             break;
                             }
                             case '1' :{
                             p2=1;
                             break;
                             }
                             case '2' :{
                             p2=2;
                             break;
                             }
                             case '3' :{
                             p2=3;
                             break;
                             }
                             case '4' :{
                             p2=4;
                             break;
                             }
                             case '5' :{
                             p2=5;
                             break;
                             }
                             case '6' :{
                             p2=6;
                             break;
                             }
                             case '7' :{
                             p2=7;
                             break;
                             }
                             case '8' :{
                             p2=8;
                             break;
                             }
                             case '9' :{
                             p2=9;
                             break;
                             }
                             case 'A' :{
                             p2=10;
                             break;
                             }
                             case 'B' :{
                             p2=11;
                             break;
                             }
                             case 'C' :{
                             p2=12;
                             break;
                             }
                             case 'D' :{
                             p2=13;
                             break;
                             }
                             case 'E' :{
                             p2=14;
                             break;
                             }
                             case 'F' :{
                             p2=15;
                             break;
                             }
                          }
                             if (UART1_Data_Ready() == 1) {
                                  receive = UART1_Read();
                                   //suma nible alto
                                    switch(receive){
                                          case '0' :{
                                          p2=p2+0*16;
                                          break;
                                          }
                                          case '1' :{
                                          p2=p2+1*16;
                                          break;
                                          }
                                          case '2' :{
                                          p2=p2+2*16;
                                          break;
                                          }
                                          case '3' :{
                                          p2=p2+3*16;
                                          break;
                                          }
                                          case '4' :{
                                          p2=p2+4*16;
                                          break;
                                          }
                                          case '5' :{
                                          p2=p2+5*16;
                                          break;
                                          }
                                          case '6' :{
                                          p2=p2+6*16;
                                          break;
                                          }
                                          case '7' :{
                                          p2=p2+7*16;
                                          break;
                                          }
                                          case '8' :{
                                          p2=p2+8*16;
                                          break;
                                          }
                                          case '9' :{
                                          p2=p2+9*16;
                                          break;
                                          }
                                          case 'A' :{
                                          p2=p2+10*16;
                                          break;
                                          }
                                          case 'B' :{
                                          p2=p2+11*16;
                                          break;
                                          }
                                          case 'C' :{
                                          p2=p2+12*16;
                                          break;
                                          }
                                          case 'D' :{
                                          p2=p2+13*16;
                                          break;
                                          }
                                          case 'E' :{
                                          p2=p2+14*16;
                                          break;
                                          }
                                          case 'F' :{
                                          p2=p2+15*16;
                                          break;
                                          }
                                          }
                                       }
             }
      break;
      }//FIN CANAL 2
      
      
            case 'I' :{//EMPIEZA CANAL 3

            if (UART1_Data_Ready() == 1) {
             receive = UART1_Read();
                  //nible bajo
                       switch(receive){
                             case '0' :{
                              p3=0;
                             break;
                             }
                             case '1' :{
                             p3=1;
                             break;
                             }
                             case '2' :{
                             p3=2;
                             break;
                             }
                             case '3' :{
                             p3=3;
                             break;
                             }
                             case '4' :{
                             p3=4;
                             break;
                             }
                             case '5' :{
                             p3=5;
                             break;
                             }
                             case '6' :{
                             p3=6;
                             break;
                             }
                             case '7' :{
                             p3=7;
                             break;
                             }
                             case '8' :{
                             p3=8;
                             break;
                             }
                             case '9' :{
                             p3=9;
                             break;
                             }
                             case 'A' :{
                             p3=10;
                             break;
                             }
                             case 'B' :{
                             p3=11;
                             break;
                             }
                             case 'C' :{
                             p3=12;
                             break;
                             }
                             case 'D' :{
                             p3=13;
                             break;
                             }
                             case 'E' :{
                             p3=14;
                             break;
                             }
                             case 'F' :{
                             p3=15;
                             break;
                             }
                          }
                             if (UART1_Data_Ready() == 1) {
                                  receive = UART1_Read();
                                   //suma nible alto
                                    switch(receive){
                                          case '0' :{
                                          p3=p3+0*16;
                                          break;
                                          }
                                          case '1' :{
                                          p3=p3+1*16;
                                          break;
                                          }
                                          case '2' :{
                                          p3=p3+2*16;
                                          break;
                                          }
                                          case '3' :{
                                          p3=p3+3*16;
                                          break;
                                          }
                                          case '4' :{
                                          p3=p3+4*16;
                                          break;
                                          }
                                          case '5' :{
                                          p3=p3+5*16;
                                          break;
                                          }
                                          case '6' :{
                                          p3=p3+6*16;
                                          break;
                                          }
                                          case '7' :{
                                          p3=p3+7*16;
                                          break;
                                          }
                                          case '8' :{
                                          p3=p3+8*16;
                                          break;
                                          }
                                          case '9' :{
                                          p3=p3+9*16;
                                          break;
                                          }
                                          case 'A' :{
                                          p3=p3+10*16;
                                          break;
                                          }
                                          case 'B' :{
                                          p3=p3+11*16;
                                          break;
                                          }
                                          case 'C' :{
                                          p3=p3+12*16;
                                          break;
                                          }
                                          case 'D' :{
                                          p3=p3+13*16;
                                          break;
                                          }
                                          case 'E' :{
                                          p3=p3+14*16;
                                          break;
                                          }
                                          case 'F' :{
                                          p3=p3+15*16;
                                          break;
                                          }
                                          }
                                       }
             }
      break;
      }//FIN CANAL 3
      
      case 'G' :{

            if (UART1_Data_Ready() == 1) {
             receive = UART1_Read();
                  //nible bajo
                       switch(receive){
                             case '0' :{
                              p4=0;
                             break;
                             }
                             case '1' :{
                             p4=1;
                             break;
                             }
                             case '2' :{
                             p4=2;
                             break;
                             }
                             case '3' :{
                             p4=3;
                             break;
                             }
                             case '4' :{
                             p4=4;
                             break;
                             }
                             case '5' :{
                             p4=5;
                             break;
                             }
                             case '6' :{
                             p4=6;
                             break;
                             }
                             case '7' :{
                             p4=7;
                             break;
                             }
                             case '8' :{
                             p4=8;
                             break;
                             }
                             case '9' :{
                             p4=9;
                             break;
                             }
                             case 'A' :{
                             p4=10;
                             break;
                             }
                             case 'B' :{
                             p4=11;
                             break;
                             }
                             case 'C' :{
                             p4=12;
                             break;
                             }
                             case 'D' :{
                             p4=13;
                             break;
                             }
                             case 'E' :{
                             p4=14;
                             break;
                             }
                             case 'F' :{
                             p4=15;
                             break;
                             }
                          }
                             if (UART1_Data_Ready() == 1) {
                                  receive = UART1_Read();
                                   //suma nible alto
                                    switch(receive){
                                          case '0' :{
                                          p4=p4+0*16;
                                          break;
                                          }
                                          case '1' :{
                                          p4=p4+1*16;
                                          break;
                                          }
                                          case '2' :{
                                          p4=p4+2*16;
                                          break;
                                          }
                                          case '3' :{
                                          p4=p4+3*16;
                                          break;
                                          }
                                          case '4' :{
                                          p4=p4+4*16;
                                          break;
                                          }
                                          case '5' :{
                                          p4=p4+5*16;
                                          break;
                                          }
                                          case '6' :{
                                          p4=p4+6*16;
                                          break;
                                          }
                                          case '7' :{
                                          p4=p4+7*16;
                                          break;
                                          }
                                          case '8' :{
                                          p4=p4+8*16;
                                          break;
                                          }
                                          case '9' :{
                                          p4=p4+9*16;
                                          break;
                                          }
                                          case 'A' :{
                                          p4=p4+10*16;
                                          break;
                                          }
                                          case 'B' :{
                                          p4=p4+11*16;
                                          break;
                                          }
                                          case 'C' :{
                                          p4=p4+12*16;
                                          break;
                                          }
                                          case 'D' :{
                                          p4=p4+13*16;
                                          break;
                                          }
                                          case 'E' :{
                                          p4=p4+14*16;
                                          break;
                                          }
                                          case 'F' :{
                                          p4=p4+15*16;
                                          break;
                                          }
                                          }
                                       }
             }
      break;

      }//FIN CANAL 4
      }

 }//FIN DE RECUPERACION DE DATOS =)
 
// SELECCION DE CANAL A MOSTRAR
if(porta.b0==1){
portd=p1;
}
if(porta.b1==1){
portd=p2;
}
if(porta.b2==1){
portd=p3;
}
if(porta.b3==1){
portd=p4;
}
//fin del programon juju =)

}
}
Esempio n. 23
0
main(){
int i;
trisb=0;
portb=0;

UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize
while (1) { // Endless loop
if (UART1_Data_Ready())    // If data is received,
{
 for(i=0;i<100;i++)
 uart_rd[i]= UART1_Read();
 UART1_Write(uart_rd);
}
/*if (uart_rd == ‘a’){
i=21;
PWM1_Set_Duty(i);
PWM1_Start();
}
if (uart_rd == ‘b’){
i=42;
PWM1_Set_Duty(i);
PWM1_Start();
}
if (uart_rd == ‘c’){
i=63;
PWM1_Set_Duty(i);
PWM1_Start();
}
if (uart_rd == ‘d’){
portb=0b00000010;
}if (uart_rd == ‘e’){
i=165;
PWM1_Set_Duty(i);
PWM1_Start();
}
if (uart_rd == ‘f’){
i=187;
PWM1_Set_Duty(i);
PWM1_Start();
}
if (uart_rd == ‘g’){
i=207;
PWM1_Set_Duty(i);
PWM1_Start();
}
if (uart_rd == ‘h’){
portb=0b00000000;}
if (uart_rd == ‘R’){
i=255;
PWM1_Set_Duty(i);
PWM1_Start();
}
if (uart_rd == ‘L’){
i=0;
PWM1_Set_Duty(i);
PWM1_Start();
}
if (uart_rd == ‘C’){
portb=0b00000001;
delay_ms(10);
portb=0b00000000;
PWM1_Start();
} */
}
}
Esempio n. 24
0
// Interrupciones
void interrupt() {
  // UART
  if(PIR1.RCIF) {
    uart_rx = UART1_Read();
    if(uart_rx == STX)
      indice = 1;
    else switch(indice) {
      case 0:
        break;
      case 1:
        if(uart_rx == id || uart_rx == network_broadcast_id)
          indice = 2;
        else
          indice = 0;
        break;
      case 2:
        uart_valvula = uart_rx.B0;
        indice = 3;
        break;
      case 3:
        uart_rojo = uart_rx;
        indice = 4;
        break;
      case 4:
        uart_verde = uart_rx;
        indice = 5;
        break;
      case 5:
        uart_azul = uart_rx;
        indice = 6;
        break;
      default:
        indice = 0;
        if(uart_rx == ETX) {
          valvula = uart_valvula;
          transicion = 0b111;
          INTCON.TMR0IE = 1;
        }
    }
  }

  // TIMER0
  if(INTCON.TMR0IF) {
    INTCON.TMR0IF = 0;
    if(transicion) {
      if(color_rojo == uart_rojo)
        transicion.B0 = 0;
      else if(color_rojo < uart_rojo)
        color_rojo++;
      else
        color_rojo--;
      if(color_verde == uart_verde)
        transicion.B1 = 0;
      else if(color_verde < uart_verde)
        color_verde++;
      else
        color_verde--;
      if(color_azul == uart_azul)
        transicion.B2 = 0;
      else if(color_azul < uart_azul)
        color_azul++;
      else
        color_azul--;
    } else INTCON.TMR0IE = 0;
  }
}
Esempio n. 25
0
//MAIN
void main()
{
    char currentByte, previousByte;
    char header, payload[NUMDATABYTES], checksum;
    char i; //Keeps track of data index
    unsigned int rxChecksumErrorCnt, rxInvalidHeaderCnt;
    enum state currentState;
    int direction;
    char openFlag;
    int closeCounter;

    // Initialize
    Initialize();
    // Initialize Serial Comm
    currentByte = previousByte = 0;
    currentState = waitForStartBytes;
    rxChecksumErrorCnt = 0;
    rxInvalidHeaderCnt = 0;
    openFlag = 0;
    closeCounter = 0;

    while (1)
    {

        if (UART1_Data_Ready())
        {
            previousByte = currentByte;
            currentByte = UART1_Read();

            if ((previousByte == STARTBYTE1) && (currentByte == STARTBYTE2))
            {
                currentState = getHeader;
                checksum = previousByte + currentByte;
            }
            else
            {
                switch (currentState)
                {
                    case waitForStartBytes:
                        //Do nothing wait for if statement above to succeed
                        break;

                    case getHeader:
                        checksum += header = currentByte;
                        i = 0;
                        currentState = getData;
                        break;

                    case getData:
                        checksum += payload[i] = currentByte;
                        i++;
                        if (i >= NUMDATABYTES)  // was >=
                        {
                            currentState = processChecksum;
                        }
                        break;

                    case processChecksum:
                        if (checksum == currentByte) //Valid message received
                        {
                            switch (header) //Switch on header to supported messages
                            {
                                case ping:
                                    FPing();
                                    break;

                                case setMotorAddress:
                                    FSetMotorAddress(payload);
                                    break;
									
								case setServoOutputs:
                                    FSetServoOutputs(payload);
                                    break;
									
								case reportMotorStatus:
                                    FReportMotorStatus(payload);
                                    break;

                                case reportMCUId:
                                    FReportMCUId();
                                    break;

                                default:
                                    rxInvalidHeaderCnt++;
                                    //Do something if count exceeds some value
                                    break;
                            }
                        }
                        else //Checksum failed, throw out message
                        {
                            rxChecksumErrorCnt++;
                            //Do something if error count exceeds some value
                        }

                        currentState = waitForStartBytes;
                        break;

                    default:
                        currentState = waitForStartBytes;
                        break;
                }
            }
        }
        else
        {
         // Nothing
        }
    }
}
Esempio n. 26
0
void UART1_Read_Text (char *Output, unsigned int length)
{
    for(int i=0; i<length;i++)
        Output[i] = UART1_Read(); //Reads a desired length of text continuously
}
Esempio n. 27
0
/**
   uint8_t DRV_UART1_Read ( void )
*/
uint8_t DRV_UART1_Read (void)
{
   return(UART1_Read());
}
Esempio n. 28
0
void main() {
  unsigned char i,tmp;
  unsigned int tout;

  CMCON=0x07; 
  TRISA=0x30;
  TRISB=0xE7;
  
  PORTA=0;
  PORTB=0;

  lcd_init();

  UART1_Init(9600);

//teste serial
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(codetxt_to_ramtxt("Teste Serial TX"));
  lcd_cmd(L_L2+2);
  lcd_str(codetxt_to_ramtxt("9600 8N1"));

  UART1_Write_Text(codetxt_to_ramtxt("\r\n Picsimlab\r\n Teste Serial TX\r\n"));

  for(i=0;i<4;i++)
  {
    UART1_Write(i+0x30);
    UART1_Write_Text(codetxt_to_ramtxt(" PicsimLab\r\n"));
  }
  delay_ms(1000);

  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(codetxt_to_ramtxt("Teste Serial RX"));
  UART1_Write_Text(codetxt_to_ramtxt(" Digite!\r\n"));
  for(i=0;i<32;i++)
  {
    if(!(i%16))
    {
       lcd_cmd(L_L2);
       UART1_Write_Text(codetxt_to_ramtxt("\r\n"));
    }

  tout=0;
  while(!UART1_Data_Ready() && (tout < 2000))
  {
    tout++;
    delay_ms(1);
  }
    
  if (UART1_Data_Ready() == 1) {
   tmp = UART1_Read();
  }
  else
  {
    tmp='-';
  }

    
    lcd_dat(tmp);
    UART1_Write(tmp);
  }
  delay_ms(100);

  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(codetxt_to_ramtxt("Teste Teclado TX"));
  UART1_Write_Text(codetxt_to_ramtxt("\r\n Aguarde!\r\n"));
  for(i=0;i<32;i++)
  {
    if(!(i%16))
    {
      lcd_cmd(L_L2);
      UART1_Write_Text(codetxt_to_ramtxt("\r\n"));
    }
    tmp=tc_tecla(2000)+0x30;
    lcd_dat(tmp);
    UART1_Write(tmp);
  }
  delay_ms(100);


//fim teste 
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1+4);
  lcd_str(codetxt_to_ramtxt("Fim"));
  lcd_cmd(L_L2+1);
  lcd_str(codetxt_to_ramtxt("Pressione RST"));

  UART1_Write_Text(codetxt_to_ramtxt("\r\n FIM!\r\n"));

  while(1);


}