Cómo emitir datos desde el transmisor IR llevado con PIC16F628A

0

Lo que quiero hacer es emitir datos desde IR Led utilizando PIC16F28A ...

void main() {


 trisb.f0 = 1;
 trisb.f1 = 1;
 trisb.f3 = 1;
 trisb.f4 = 1;
 trisb.f5 = 1;
 trisb.f6 = 1;
 trisb.f7 = 1;
 porta = 0;

//I didn't set trisb.f2 as 1 because I used that pin as TX pin and connected it to + pin of IR LED


 UART1_Init(2400);

 while(1){
          if (portb.f0){
                    while(!UART1_Tx_Idle());
                    UART1_Write(1);
          }

 }

}

Sobre el circuito; 5.pin de PIC16F28A está conectado a GND y 14.pin está conectado a + 5V. Conecté 8.pin a + pin de IR Led. Hay un botón activo 1 que está conectado a RB0.

Lo que quiero es emitir datos '1', pero cuando obtengo los datos del Receptor IR que configuré en Arduino, vi datos aleatorios ... Quiero decir que el LED no emitía datos estables.

Quiero emitir el byte que está escrito en la función UART1_Write () como estable, pero creo que está emitiendo datos aleatorios de acuerdo con la electricidad que recibe.

El código que obtuve de enlace tampoco funcionó:

  #define address  0xff
  #define command_1 0xFF
  #define command_2 0x81
  #define command_3 0x42
  #define command_4 0xC3
  #define command_5 0x24
 unsigned int i=0,j=0;
 void repeat(){
 PWM1_Start();
 delay_us(8000);
 PWM1_Stop();
 delay_us(8000);
 }
  send_data_byte(unsigned char dattt){
   PWM1_init(36000);
 PWM1_Set_Duty(127);
  for(j=0;j<8;j++){
 PWM1_Start();
 delay_us(562);
 PWM1_Stop();
  if(dattt & 0x01){
  delay_us(1687);
  dattt=dattt>>1;
  }
 else
  {
  delay_us(562);
   dattt=dattt>>1;
  }
  }
 PWM1_Stop();
  }
  void send_data_command(unsigned char dat){
  PWM1_init(36000);
 PWM1_Set_Duty(127);
 PWM1_Start();
 delay_us(9000);
 PWM1_Stop();
 delay_us(4500);
  send_data_byte(dat);
  repeat();
  }
 void main() {
 CMCON=7;
 TRISA.F0=1;
 TRISA.F1=1;
 TRISA.F2=1;
 TRISA.F3=1;
 TRISB.F0 = 0;
 TRISB.F3=0;
 PORTB.F3=0;
 PORTB.F0 = 0;

 while(1){
  if(PORTA.F0==0){
  portb.f0 = 1;
 send_data_command(command_2);
 while(PORTA.F0==0){
 repeat();
 }
  }
  if(PORTA.F1==0){
 send_data_command(command_3);
 while(PORTA.F1==0){
 repeat();
 }
  }
   if(PORTA.F2==0){
 send_data_command(command_4);
 while(PORTA.F2==0){
 repeat();
 }
  }
    if(PORTA.F3==0){
 send_data_command(command_5);
 while(PORTA.F3==0){
 repeat();
 }
  }
 }
 }

¿Cómo puedo solucionar esto? Gracias ...

    
pregunta PIC16F84A

0 respuestas

Lea otras preguntas en las etiquetas