Bonjour à tous
je désire commander un moteur à l'aide d'une télécommande en variant juste potentiomètre, ce dernier est lié à un pic 16F887 .
la même chose pour la réception, il y a aussi un pic 16F887.
le problème c'est que toujours le rapport cyclique est fixe!! indépendant du potentiomètre !!
pourriez vous m'aider??
merci d'avance
Code://TX // Manchester module connections //sbit MANRXPIN at RC0_bit; //sbit MANRXPIN_Direction at TRISC0_bit; sbit MANTXPIN at RC0_bit; sbit MANTXPIN_Direction at TRISC0_bit; // End Manchester module connections void main() { int val; int i; ansel=0x04; anselh=0; TRISA=0XFF; ANSEL = 0; // Configure AN pins as digital I/O ANSELH = 0; C1ON_bit = 0; // Disable comparators C2ON_bit = 0; TRISC.F2 = 0; TRISC.F3 = 0; PORTC.F2 = 0; PORTC.F3 = 0; Man_Send_Init(); // Initialize transmitter while (1) { val=ADC_Read(2); val=(int)((val*5)/1023); if(val==0) i= 0; if(val==1) i= 1; if(val==2) i=2; if(val==3) i=3; if(val==4) i=4; /*if (60<val && val<80) UART1_Write(4+48); if (80<val && val <100) UART1_Write(5+48);*/ switch(i) { case 0:Man_Send(0x30);break; case 1:Man_Send(0x31);break; case 2:Man_Send(0x32);break; case 3:Man_Send(0x33);break; case 4:Man_Send(0x34);break; } } }Code://RX // Manchester module connections Start sbit MANRXPIN at RC0_bit; sbit MANRXPIN_Direction at TRISC0_bit; sbit MANTXPIN at RC1_bit; sbit MANTXPIN_Direction at TRISC1_bit; unsigned char error = 0, ErrorCount = 0, temp = 0; void main() { int val; TRISC.F2 = 0; // Set as output used for Start bit found indicator TRISC.F3 = 0; // Set as output used for Update UART indicator PORTC.F5 = 0; TRISC.F5 = 0; UART1_Init(19200); Man_Receive_Init(); // Initialize Receiver do{ // Rx Routine forever loop GET_BYTE: temp = Man_Receive(&error); // Attempt byte receive if (error) goto GET_BYTE; // if comm's error goto error handler goto START_BYTE; // if good byte Received goto start handler START_BYTE: switch (temp) { case 0x30:{ val=100; break; } case 0x31:{ val=200; break; } case 0x32: { val=400; break; } case 0x33: { val=600; break; } case 0x34: { val=255; break; } } pwm1_set_duty(val); delay_ms(100); RE_SYNC: // UART1_Write_Text("Synchronizing\n\r"); // Display Activity on 2nd Row delay_ms(50); temp = Man_Synchro(); // Try to synchronize again //Man_Receive_Init(); // Alternative, try to Initialize Receiver again ErrorCount = 0; // Reset error counter if (temp == 0xFF) goto RE_SYNC; // Sync failed try again goto GET_BYTE; // Sync complete start over again }while(1); }
-----