Пример #1
0
void enviarProtocolo(char r1, char r2, char r3, char r4, char r5) {

  /*
  char checksum;

  UART1_Write(0x7E);
  UART1_Write(0x00);
  UART1_Write(0x13);
  UART1_Write(0x10);
  UART1_Write(0x01);
  UART1_Write(0x00);
  UART1_Write(0x00);
  UART1_Write(0x00);
  UART1_Write(0x00);
  UART1_Write(0x00);
  UART1_Write(0x00);
  UART1_Write(0xFF);
  UART1_Write(0xFF);
  UART1_Write(0xFF);
  UART1_Write(0xFE);
  UART1_Write(0x00);
  UART1_Write(0x00);
  */
  UART1_Write(r1);
  UART1_Write(r2);
  UART1_Write(r3);
  UART1_Write(r4);
  UART1_Write(r5);
  /*
  checksum = (0xFF - ((0x10 + 0x01 + 0xFF + 0xFF + 0xFF + 0xFE + r1 + r2 + r3 + r4 + r5) & 0xFF));
  UART1_Write(checksum);
  */
}
Пример #2
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;
 }
}
}
Пример #3
0
void wifi_write(unsigned long total)
{
    char write[4];
    write[3] = total >> 24;
    write[2] = total >> 16;
    write[1] = total >> 8;
    write[0] = total;

    UART1_Write(&write, 4);
    char newline = '\n';
    UART1_Write(newline, 1);

}
Пример #4
0
void OutPut(double right, double left)
{
  int tmp;

  UART1_Write(0);
  UART1_Write((right >= 0.0) ? 0 : 1); //+ : 0 - : 1
  tmp = (int)(abs(right) * 10.0);
  UART1_Write(tmp);

  Soft_UART_Write(0);
  Soft_UART_Write((left >= 0.0) ? 0 : 1);
  tmp = (int)(abs(left) * 10.0);
  Soft_UART_Write(tmp);
}
Пример #5
0
void main() {
  int i=0;
  int j=0;
  int iu=0;

DDRB = 0xFF;

  UART1_Init(9600);               // Initialize UART module at 9600 bps
  Delay_ms(100);                  // Wait for UART module to stabilize
  
  while (1) {
    if (UART1_Data_Ready() == 1) {          // if data is received
    UART1_Read_Text(packet, " ", 10);    // reads text until 'OK' is found
    
    if ((packet[0] == 0x11)&&(packet[1] == 0x01)
    &&(packet[2] == 0x00)&&(packet[3] == 0x55) ) {
      packet[0]  = 0x11;
      packet[1]  = 0x01;
      packet[2]  = 0x04;
      packet[3]  = 0x00;
      packet[4]  = 0x00;
      packet[5]  = 0x01;
      packet[6]  = 0x23;
      packet[7]  = 0x59;
      packet[8]  = 0xaa;
      UART1_Write(packet[0]);
      UART1_Write(packet[1]);
      UART1_Write(packet[2]);
      UART1_Write(packet[3]);
      UART1_Write(packet[4]);
      UART1_Write(packet[5]);
      UART1_Write(packet[6]);
      UART1_Write(packet[7]);
      UART1_Write(packet[8]);
    }
 }

}

   
//   while  (UART1_Data_Ready())  {
//      packet[i] = UART1_Read();
//      i++;
//   }
//   Delay_ms(100);
//   j=0;
//   while (i>0) {
//    UART1_Write(packet[j]);
//    j++;
//    i--;
//   }
   

  }
void LCDPrint(char *fmt, ...)
{

    char buffer[80];
    char *a=buffer;
    int cnt;


    va_list argptr;
    va_start(argptr, fmt);
    cnt = vsprintf(buffer,(char *)fmt, argptr);
    va_end(argptr);

   	strupr(buffer);
	
		 strcat(buffer,"\n");
		UART1_Write(buffer, strlen(buffer));
	/*
	BAR0_ON;
  BAR1_ON;
  BAR2_ON;
  BAR3_ON;	
	*/
	for(i=0;i<6;i++)
	   tab[i]=buffer[i];
	
	
  LCD_GLASS_DisplayStrDeci(tab);
}
Пример #7
0
void UART1_Write_Text_Constant(const char *txt)
{
    while (*txt!=0)
    {
        UART1_Write(*txt);
        txt++;
    }
}
Пример #8
0
void TxPacket(char buffer[])
{
    int i;
    for (i=0; i<PACKETLENGTH; i++)
    {
        UART1_Write(buffer[i]);
    }
}
Пример #9
0
void SendSMS(const char message[])   // Send SMS to danish number
{
    GSM_PowerOn();
    LED_On(); // Turn on LED
    GSM_Initialize(0);
    UART1_Write_Text_Constant("AT+CMGF=1");
    UART1_Write(13); //Carriage return (new line)
    Delay_ms(10);
    WaitForRecieveChar(0x0D);
    EmptySerialBuffer();
    CancelAlarmOnClick(); // Check if # is held - if true, disable the alarm and buzzer

    UART1_Write_Text_Constant("AT+CSCS=");
    UART1_Write(34); // "
    UART1_Write_Text_Constant("GSM");
    UART1_Write(34); // "
    UART1_Write(13); //Carriage return (new line)
    Delay_ms(10);
    WaitForRecieveChar(0x0D);
    EmptySerialBuffer();
    CancelAlarmOnClick(); // Check if # is held - if true, disable the alarm and buzzer

    // Set mobile number
    UART1_Write_Text_Constant("AT+CMGS=");
    UART1_Write(34); // "
    UART1_Write_Text_Constant("45"); // Country code (Denmark)
    UART1_Write_Text(MobileNumber);
    UART1_Write(34); // "
    UART1_Write(13); //Carriage return (new line)
    Delay_ms(500);
    WaitForRecieveChar(0x0A);

    // Write message
    i = 0;
    while (message[i] != 0)
    {
        UART1_Write(message[i]);
        i++;
    }
    UART1_Write(26); // Substitution (CTRL+Z)
    WaitForRecieveCharAndBlink(0x0A);
    EmptySerialBuffer();
    CancelAlarmOnClick(); // Check if # is held - if true, disable the alarm and buzzer

    Delay_ms(1000); // Give time to send the message
    GSM_PowerOff();
}
Пример #10
0
void sendThroughUARTtoProcessing(void) {

     IntToStr(AccX, data_);
     UART1_Write_Text(data_);
     UART1_Write(0x0A);
     IntToStr(AccY, data_);
     UART1_Write_Text(data_);
     UART1_Write(0x0A);
     IntToStr(AccZ, data_);
     UART1_Write_Text(data_);
     UART1_Write(0x0A);

     IntToStr(Xmag, data_);
     UART1_Write_Text(data_);
     UART1_Write(0x0A);
     IntToStr(Ymag, data_);
     UART1_Write_Text(data_);
     UART1_Write(0x0A);

     return;
}
Пример #11
0
void SetNewNumber(void)
{
    char i;
    char PressedKey;
    for(i = 0; i < 8; i++)
    {
#ifdef DEBUG
        UART1_Write_Text_Constant("Waiting for press");
        UART1_Write(13); //Carriage return (new line)
#endif
        do
        {
            PressedKey = GetKeyPad();
        } while (PressedKey == 0); // Wait for press
        MobileNumber[i] = PressedKey;
        Buzzer_Beep(1);
#ifdef DEBUG
        UART1_Write(MobileNumber[i]);
        UART1_Write_Text_Constant(" pressed. ");
        UART1_Write(i+48);
        UART1_Write('=');
        UART1_Write(MobileNumber[i]);
        UART1_Write_Text_Constant(" - Waiting for release");
        UART1_Write(13); //Carriage return (new line)
#endif
        while(GetKeyPad() != 0); // Wait for release
    }
    MobileNumber[8] = 0;

#ifdef DEBUG
    UART1_Write_Text(MobileNumber);
#endif
}
Пример #12
0
void main() {

  char valor[8];
  UART1_Init(9600);               // Initialize UART module at 9600 bps
  DDRB.B2=1;
  
  while(1){
  val = ADC_Read(3);       // obtener valor Análogo de canal 3
  IntToStr(val, valor);
  for (i = 0; i <7 ; i++ )UART1_Write(valor[i]);
  UART1_Write_Text(" ");
  delay_ms(100);
  }
  }
Пример #13
0
unsigned int UART1_WriteBuffer( const uint8_t *buffer , const unsigned int bufLen )
{
    unsigned int numBytesWritten = 0 ;

    while ( numBytesWritten < ( bufLen ))
    {
        if((uart1_obj.txStatus.s.full))
        {
            break;
        }
        else
        {
            UART1_Write (buffer[numBytesWritten++] ) ;
        }
    }

    return numBytesWritten ;

}
Пример #14
0
void GSM_Initialize(const char firstInit)
{
    UART1_Write_Text_Constant("AT");
    UART1_Write(13); //Carriage return (new line)
    Delay_ms(500);
    UART1_Write_Text_Constant("AT");
    UART1_Write(13); //Carriage return (new line)
    WaitForRecieveChar(0x0A);
    EmptySerialBuffer();
    CancelAlarmOnClick(); // Check if # is held - if true, disable the alarm and buzzer
    if (firstInit == 1) BeepAndBlink(1);

    UART1_Write_Text_Constant("AT+CPIN=");
    // Write PIN Code
    i = 0;
    while (SIMPin[i] != 0)
    {
        UART1_Write(SIMPin[i]);
        i++;
    }
    UART1_Write(13);
    WaitForRecieveChar(0x0A);
    EmptySerialBuffer();
    if (firstInit == 1) BeepAndBlink(1);

    WaitForRecieveMessage("Call Ready");
    EmptySerialBuffer();
    CancelAlarmOnClick(); // Check if # is held - if true, disable the alarm and buzzer
    if (firstInit == 1) BeepAndBlink(1);

    UART1_Write_Text_Constant("AT+CREG?");
    UART1_Write(13); //Carriage return (new line)
    WaitForRecieveChar(0x0D);
    EmptySerialBuffer();
    CancelAlarmOnClick(); // Check if # is held - if true, disable the alarm and buzzer
    if (firstInit == 1) BeepAndBlink(1);

#ifndef DEBUG
    Delay_ms(10000); // Wait for the GSM module to connect to the GSM network (Response +CREG: 0,1)
    UART1_Write_Text_Constant("AT+CREG?");
    UART1_Write(13);
    WaitForRecieveChar(0x0D);
    EmptySerialBuffer();
    CancelAlarmOnClick(); // Check if # is held - if true, disable the alarm and buzzer
    if (firstInit == 1) BeepAndBlink(1);
#endif

}
Пример #15
0
void main() {
  int i,j;

  UART1_Init(57600);              
  Delay_ms(100);                  

  UART1_Write_Text("Start\n");
  UART1_Write(13);
  UART1_Write(10);
  timer_setup();
  UART1_Write_Text("timer started");
  UART1_Write(13);
  UART1_Write(10);

for( i = STOP; i > state_e; state_e++ )  // every state is being executed 1000 times except GRAPHICS, it is done 10 times
  {
    for( j = 0; j < 10000; j++ )
    {
      switch( state_e )
      {
        case DHRYSTONE:
          dhrystone_benchmark();    // after executing, record the time passed
          record_time();
          reset_time();
        break;
        case FFT:
          fft_benchmark();
          record_time();
          reset_time();
          break;
        case WHETSTONE:
          whetstone_benchmark();
          record_time();
          reset_time();
          timer_setup();
        break;
        case GRAPHICS:
        {  uint8_t temp;
          if ( j % 100 == 0)
          {
            for (temp = 0; temp <10; temp++)
            {
              graphics_benchmark();
              record_time();
              reset_time();
             }
          }
         }
        break;
      }
    }
  }

  // print out the time passed

  UART1_Write_Text("Drhystone: ");
  IntToStr(dhrystone_time, txt);
  UART1_Write_Text(txt);
  UART1_Write(13);
  UART1_Write(10);

  UART1_Write_Text("FFT: ");
  IntToStr(fft_time, txt);
  UART1_Write_Text(txt);
  UART1_Write(13);
  UART1_Write(10);

  UART1_Write_Text("whetstone: ");
  IntToStr(whetstone_time, txt);
  UART1_Write_Text(txt);
  UART1_Write(13);
  UART1_Write(10);

  UART1_Write_Text("graphics: ");
  IntToStr(graphics_time, txt);
  UART1_Write_Text(txt);
  UART1_Write(13);
  UART1_Write(10);



}
Пример #16
0
void sendThroughUARTtoMSVS(void) {

     IntToStr(AccX, data_);
     UART1_Write_Text(data_);
     UART1_Write(' ');
     IntToStr(AccY, data_);
     UART1_Write_Text(data_);
     UART1_Write(' ');
     IntToStr(AccZ, data_);
     UART1_Write_Text(data_);
     UART1_Write(' ');
     IntToStr(GyrX, data_);
     UART1_Write_Text(data_);
     UART1_Write(' ');
     IntToStr(GyrY, data_);
     UART1_Write_Text(data_);
     UART1_Write(' ');
     IntToStr(GyrZ, data_);
     UART1_Write_Text(data_);
     UART1_Write(' ');
     IntToStr(Tmp, data_);
     UART1_Write_Text(data_);
     UART1_Write(' ');
     
     IntToStr(UT, data_);
     UART1_Write_Text(data_);
     UART1_Write(' ');
     LongWordToStr(UP, data_);
     LTrim(data_);
     UART1_Write_Text(data_);

     IntToStr(Xmag, data_);
     UART1_Write_Text(data_);
     UART1_Write(' ');
     IntToStr(Ymag, data_);
     UART1_Write_Text(data_);
     UART1_Write(' ');
     IntToStr(Zmag, data_);
     UART1_Write_Text(data_);
     UART1_Write(' ');
     
//     UART1_Write(13);//CR
     UART1_Write(31);//US

     return;
}
Пример #17
0
/**
 * Relays data from Radio to USB/Bluetooth
 */
void relayFromRadio()
{
    /* UART1 - FTDI USB
     * UART2 - Bluetooth
     * UART3 - Radio        */

    if(!UART3_ReceiveBufferIsEmpty())       //New data on UART3 (Radio)
    {
        uint8_t rxByte = UART3_Read(); //Read byte from U3

        if(relayUSBConneted())
        {
           // if(!UART1_TransmitBufferIsFull())   //There is free space in U1 tx buffer //commented this out to avoid random loss of connection -D Cironi 2015-05-11
           // {              
                UART1_Write(rxByte);           //Send to U1
           // }
        }
        else
        {
            if(!UART2_TransmitBufferIsFull())   //There is free space in U2 tx buffer
            {
                UART2_Write(rxByte);     //Read byte from U3 and send to U2
            }
        }

        
        LandChannel = CheckRCLoop(rxByte); //check to see if data from radio is RC_Channel info

        if(LandChannel != 0 && LandChannel < 1500 && MissionInjectStage == 0 && LandInjected == 0)    //Valid reading and the mode we want for landing
        {
            MissionInjectStage = 1;
        }
        else if (LandChannel != 0 && LandChannel > 1500) //valid reading but not the mode we want
        {
            MissionInjectStage = 0;
            LandInjected = 0;
            Nop();
        }

        switch(MissionInjectStage) //inject a packet on each cycle
        {
            case 0:
                //do nothing
                break;
            case 1:
                InjectCount(4);
                break;
            case 2:
                InjectWaypoint('h');
                break;
            case 3:
                InjectWaypoint('1');
                break;
            case 4:
                InjectWaypoint('2');
                break;
            case 5:
                InjectWaypoint('3');
                break;
            case 6:
                InjectAcknowledge();
                break;
        }
    }
}
Пример #18
0
/**
   void DRV_UART1_Write( const uint8_t byte)
*/
void DRV_UART1_Write( const uint8_t byte)
{
    UART1_Write(  byte);
}
Пример #19
0
int main(void)
{
	int i;
	
	
	RCC_Configuration();	                           //?????????????	        
	
	NVIC_Configuration();    
	LED_Config();
	TIM7_Configuration(10) ;
 
  RCC_Config();



 ADC_initial();
 UART1_Init();
 UART1_Config(9600);
 UART1_Cmd(ENABLE);
 UART1_Write("stm start",9);
 LCD_GLASS_Configure_GPIO();
 LCD_GLASS_Init();
      
	

 while (1)
 {
	  int wdt=0;
		int adc_wdt=0;
	  double adc=0;
	 //// solution 2 working String
	   i=0;
	 
     memcpy(buff2,buff, strlen(buff)); // ? buff ??? buff2
     memset(buff, 0, strlen(buff)); // ?? buff ???????  
						
	   while(1)
		 {
			  if(USART_GetFlagStatus(USART1,USART_FLAG_RXNE) != RESET)
				{
						char c = USART_ReceiveData(USART1); 
						i=i+1;				
						if(c == '\r')
							break;
						else 
						if (c == '\n')
							break;
						else
							 sprintf (buff, "%s%c", buff,c);
						
				}else
				{	
				    wdt++;
					  adc_wdt++;
					  if(adc_wdt%100==0)
						{
							 adc=(adc*99.0+GetADC())/100.0;	
						}
					  if(adc_wdt>10000)
						{
							 adc_wdt=0;
							 LCDPrint(" %0.1f ",adc);
						
						}
						if(wdt==50)
						{
								 wdt=0;
								
								 for(i=0;i<4;i++)
								 {
									 if(flag[i]==0)
									 {
											LED[i]++;
											if(LED[i]>300)
											{
													flag[i]=1;
											}
									 }else
									 {
											 LED[i]--;
											if(LED[i]==0)
											{
													flag[i]=0;
											} 
									 }
									}
								
							}
					}
				}
			/*	strcat(buff,"\n");
				UART1_Write(buff, strlen(buff));
				Lcd_print(buff);
*/				//	UART1_Write(")",1);
				USART_ClearFlag(USART1, USART_FLAG_RXNE);
			
			}
}
Пример #20
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);


}
Пример #21
0
void main(){

  //TRISD = 0x00;
  //PORTD = 0b00000000;
//  CMCON| = 7;
  UART1_Init(9600);              // Initialize UART module at 9600 bps

  //TRISA = 0xFF; //PORTA as input
ADCON1 = 0b00001001; // Set AN0 channel pin as analog
CMCON |= 7; // Disable comparators
  //X=0;
  ADC_init();
  //UART1_Init(9600);
  //Lcd_Init();
  /*

  Lcd_Cmd(_LCD_CLEAR);
  Lcd_Cmd(_LCD_CURSOR_OFF);
  Lcd_Out(1,1,"W");
  delay1();
  Lcd_Out(1,2,"E");
  delay1();
  Lcd_Out(1,3,"L");
  delay1();
  Lcd_Out(1,4,"C");
  delay1();
  Lcd_Out(1,5,"O");
  delay1();
  Lcd_Out(1,6,"M");
  delay1();
  Lcd_Out(1,7,"E");
  delay1();
  delay1();
  Lcd_Out(2,1,"I");
  delay2();
  Lcd_out(2,2,"N");
  delay2();
  Lcd_Out(2,3,"I");
  delay2();
  Lcd_Out(2,4,"T");
  delay2();
  Lcd_Out(2,5,"I");
  delay2();
  Lcd_Out(2,6,"A");
  delay2();
  Lcd_Out(2,7,"L");
  delay2();
  Lcd_Out(2,8,"I");
  delay2();
  Lcd_Out(2,9,"Z");
  delay2();
  Lcd_Out(2,10,"I");
  delay2();
  Lcd_Out(2,11,"N");
  delay2();
  Lcd_Out(2,12,"G");
  delay2();
  Lcd_Out(2,13,".");
  delay2();
  Lcd_Out(2,14,".");
  delay2();
  Lcd_Out(2,15,".");
  delay2();
  delay1();
  delay1();
  delay_ms(350);
  lcd_cmd(_LCD_CLEAR);

  Lcd_Out(1,1, "Input char:");
  */
  while(1) {

hold0 = adc_read(0)*0.4886; //0.406
delay_ms(12);
hold1 = adc_read(1)*0.4886;
delay_ms(12);
hold2 = adc_read(2)*0.4886;
delay_ms(12);
hold3 = adc_read(3)*0.4886;
delay_ms(12);
hold4 = adc_read(4)*0.4886;
delay_ms(12);
hold5 = adc_read(5)*0.4886;
delay_ms(12);

intToStr(hold0, data1);
LTRIM(data1);
intToStr(hold1, data2);
LTRIM(data2);
intToStr(hold2, data3);
LTRIM(data3);
intToStr(hold3, data4);
LTRIM(data4);
intToStr(hold4, data5);
LTRIM(data5);
intToStr(hold5, data6);
LTRIM(data6);

//delay_us(10);
//LCD_Chr(1,1,5*hold/1024+48);
//LCD_Chr(1,2,46);
//LCD_Chr(1,1,(50*hold/1024)%10+48);
//LCD_Chr(1,2,(20*hold/41)%10+48); //20/41 =~ 500/1024
//LCD_Chr(1,3,0xdf);
//LCD_out(1,4,"C");
//LCD_Out(2,1,"RAW ADC =");

//Lcd_Out(2,1,txt);
//LTRIM(txt);
//RTRIM(txt);

//sprintf(txt,0.1f,hold);

UART1_Write_text("Data1");
UART1_Write_text("  ");
UART1_Write_text(data1);
UART1_Write(0x0D);
UART1_Write(0x0A);

//delay_ms(1);

UART1_Write_text("Data2");
UART1_Write_text("  ");
UART1_Write_text(data2);
UART1_Write(0x0D);
UART1_Write(0x0A);

//delay_ms(1);

UART1_Write_text("Data3");
UART1_Write_text("  ");
UART1_Write_text(data3);
UART1_Write(0x0D);
UART1_Write(0x0A);

UART1_Write_text("Data4");
UART1_Write_text("  ");
UART1_Write_text(data4);
UART1_Write(0x0D);
UART1_Write(0x0A);

//delay_ms(1);

UART1_Write_text("Data5");
UART1_Write_text("  ");
UART1_Write_text(data5);
UART1_Write(0x0D);
UART1_Write(0x0A);


//delay_ms(1);

UART1_Write_text("Data6");
UART1_Write_text("  ");
UART1_Write_text(data6);
UART1_Write(0x0D);
UART1_Write(0x0A);
UART1_Write(0x0D);
UART1_Write(0x0A);


Wait();
X=0;
//delay_ms(4000);

      /*
      if (UART1_Data_Ready() == 1) {
      uart_rd = UART1_Read();
      //UART1_Write(uart_rd);


      temp = uart_rd;

      switch (temp)
          {
          case 'a':portd=0b00000010;
      delay_ms(450);
      portd=0b00000000;
          break;

          case 's':portd=0b00000100;
      delay_ms(450);
      portd=0b00000000;
          break;

          case 'd':portd=0b00001000;
      delay_ms(450);
      portd=0b00000000;
          break;

          case 'f':portd=0b00010000;
      delay_ms(450);
      portd=0b00000000;
          break;

          case 'k':for (X=0;X<=5;X++)
          aku();
          break;
          }


}
*/
}
}
Пример #22
0
//-----------------------------------------------------------------------
//Name:  - Senior Design Project of Counting the Crowd entering the
//	   Jamaraat area during the Hajj.
//       - PIC16F628a#3 is uesd as a storage unit to store and sent the
//         calculated echo pulses of Ultrasonic sensor to the Arduino
//         Uno R3.
//       - Assuming a room temp of 25 degrees centigrade.
//Autor:   Ahmed Abdulaziz Abualsaud
//Version: v 1.0
//Date:    Dec, 2, 2015
//-----------------------------------------------------------------------
void main()
{
     //Declare teh Global Variable
     int a;       //Variable to store the echo pulses
     int i = 1;   //Counter to know which sensor is selected
     char txt[7]; //Char String is used to send the distance to the Arduino
     char txtD[7];//Char String is used to send the selected sensor to the Arduino

     //Configure all pin as digital by disable the comparators
     CMCON = 0b00000111;

     //Configure the TIMER1 to work beasd on the internal oscilator speed 4MHz
     T1CON = 0b00000000;

     //Configure each digital bins as In/Out ports
     //Pin Name  - 0/1        - Pin Lable    - Pin Number
     TRISA.F0    = 0;//       = exP3         - 17
     TRISA.F1    = 0;//       = stP3         - 18
     TRISA.F4    = 1;//       = done         - 3
     TRISB.F0    = 1;//       = enP3(A1)     - 6
     TRISB.F1    = 1;//       = Read3        - 7
     TRISB.F2    = 0;//       = MX3          - 8
     TRISB.F4    = 1;//       = C            - 10
     TRISB.F5    = 1;//       = D            - 11


     UART1_Init(9600);// Initialize UART module at 9600 bps
     Delay_ms(50);    // Wait for UART module to stabilize

     while (1)
     {
           //Clear the TIMER1 registers
           TMR1H = 0;
           TMR1L = 0;
           PORTA.F0 = 0;               //Disable exP3 signal
           PORTA.F1 = 0;               //Disable stP3 signal

           while(!PORTB.F1);           //Wait the echo (Read3 signal) to become 1
           T1CON.F0 = 1;               //Enable the TIMER1
           while(PORTB.F1);
           T1CON.F0 = 0;

           a = (TMR1L | (TMR1H << 8)) / 29.1 / 2;
           IntToStr(a,txt);
           Ltrim(txt);
           IntToStr(i,txtD);
           Ltrim(txtD);

           //Wait the control Signal from Arduino to start sending the data
           while(PORTB.F5 != 1 && PORTB.F4 != 0);//D&C
           while(PORTB.F0 == 0);       //Wait for enP3 signal comming from Arduino
           
           PORTA.F1 = 1;               //Enable stP3 signal

           // Start sending data via UART
           UART1_Write_Text("GG3_");
           UART1_Write_Text(txtD);
           UART1_Write_Text(": ");
           UART1_Write_Text(txt);
           UART1_Write_Text(" cm");
           UART1_Write_Text("!");
           UART1_Write(13);            //The Carriage Return

           PORTA.F0 = 1;               //Enable the exP3 signal

           ++i;                        //Increment the sensor iterator
           if (i == 5){i = 1;}         //Reset the sensor iterator
           while(PORTA.F4 == 0);       //Wait for the done signal coming from Arduino
     }//End while loop
}//End void main
Пример #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();
} */
}
}