السلام عليكم :
انا اعمل دائرة ارسال واستقبال بستخدام RF 433MHZ بين متحكمين وجربت اكثر من كود وبأستخدام اكثر من طريقة مثل EUSART وقرأة انه Manchester Code ما ينفع برضوا وعملت برامج بطريقة عادية ما نفع كمان ممكن حد يدلني على طرييقة شغالة 100% ؟ وكمان مشكلة ال noise كيف اتخلص منها ؟ وشكراااااااا .
*المتحكم رقم PIC16LF1783 يشتغل على 3.3 فولت والكود بالمترجم MPLAB X IDE v3.26 و اذا في مشكلة بالمترجم بالنسة لك, عادي اذا بال MicroC ينفع انا احوله .
كود:
/**
Generated Main Source File
Company:
Microchip Technology Inc.
File Name:
main.c
Summary:
This is the main file generated using MPLAB(c) Code Configurator
Description:
This header file provides implementations for driver APIs for all modules selected in the GUI.
Generation Information :
Product Revision : MPLAB(c) Code Configurator - 3.15.0
Device : PIC16LF1783
Driver Version : 2.00
The generated drivers are tested against the following:
Compiler : XC8 1.35
MPLAB : MPLAB X 3.20
*/
#include "mcc_generated_files/mcc.h"
#include <string.h>
#define relay_up PORTBbits.RB7
#define relay_down PORTBbits.RB6
#define led PORTCbits.RC3
#define rf_rx PORTCbits.RC4
/* function declaration */
unsigned int retint,i,nothing; // general purpose integer
unsigned char ir_byte,count,bouton;
unsigned char ir_result;
unsigned int temp_ir;
//********************************************
void ISR_interrupt()
{
count++;
INTCONbits.TMR0IF=0; // Timer0 Overflow Interrupt Flag bit
TMR0=0;
}
//********************************************
unsigned int bit_start(){
TMR0= 0; count=0;
for(;!rf_rx;){}
retint=2*(TMR0+(count*256));
return retint;
}
//********************************************
unsigned int get_space(){
TMR0= 0; count=0;
for(;rf_rx;){}
retint=2*(TMR0+(count*256));
return retint;
}
//********************************************
unsigned char get_sony_byte(char nbits){
char n;
ir_byte = 0; // initialise
while(rf_rx);
for(n=0 ; n<nbits ; n++){
temp_ir = bit_start();
nothing = get_space(); // expect ~510uS
ir_byte >>= 1; // 650uS = 0, 1.2uS = 1
if ((temp_ir > 1000)&&(temp_ir < 1500)) {
ir_byte += 0x80;
}
}
ir_byte >>= 8-nbits;
return ir_byte;
}
//********************************************
void main(void)
{
// initialize the device
SYSTEM_Initialize();
for(i=0;i<5;i++)
{
led=1;
__delay_ms(100);
led=0;
__delay_ms(100);
}
/*bit7: Weak Pull-Up disable & & bit5: Timer0 Clock Source from Internal instruction cycle clock (FOSC/4) & &
bit3: Prescaler is assigned to the Timer0 module && bit(2&1&0): Prescaler Rate 1:2 */
OPTION_REG=0b10000000;
INTCONbits.GIE=1; //Enables all active interrupts
INTCONbits.TMR0IE=1; //Timer0 Overflow Interrupt Enables
TMR0 = 0;
while(1){
ir_result = 0; // return 0, 0 if glitch
while(rf_rx); // wait for IR to go low
temp_ir = bit_start();
if((temp_ir>2000)&&(temp_ir<3000)) { // expect 2.4mS mark
ir_result = get_sony_byte(7); // 7 bit command
__delay_ms(5);} // wait for repeat messages to clear
//**********************************************
switch (ir_result){
case 1: relay_up = 1;
__delay_ms(250);
break; // button TV '0'
case 3: relay_down = 1;
__delay_ms(250);
break; // button TV '1'
default:break;
}
relay_up=relay_down=0;
}
}
/**
End of File
*/
__________________________________________________ _____________
كود:
/**
Generated Main Source File
Company:
Microchip Technology Inc.
File Name:
main.c
Summary:
This is the main file generated using MPLAB(c) Code Configurator
Description:
This header file provides implementations for driver APIs for all modules selected in the GUI.
Generation Information :
Product Revision : MPLAB(c) Code Configurator - 3.15.0
Device : PIC16LF1783
Driver Version : 2.00
The generated drivers are tested against the following:
Compiler : XC8 1.35
MPLAB : MPLAB X 3.20
*/
#include "mcc_generated_files/mcc.h"
#define one_high 1200
#define one_low 600
#define zero_high 600
#define zero_low 600
#define start_pulse 2400
#define start_pulse_low 600
#define space_between_start_pulse 27500
volatile unsigned short i,x,y,dbit=0;
#define sw_up PORTBbits.RB7
#define sw_down PORTBbits.RB6
#define rf_tx PORTCbits.RC4
#define led PORTBbits.RB5
/* function declaration */
void send_start_pulse(void);
void send_1(void);
void send_0(void);
void main(void)
{
// initialize the device
SYSTEM_Initialize();
for(i=0;i<5;i++)
{
led=1;
__delay_ms(100);
led=0;
__delay_ms(100);
}
while (1)
{
rf_tx=1;
__delay_ms(50);
rf_tx=0;
__delay_ms(50);
if(sw_up == 0)
{
for(i=0;i<2;i++)
{
led =1;
__delay_ms(55);
led =0;
__delay_ms(50);
}
for(y=0;y<2;y++)
{
send_start_pulse();
send_1();
for(x=0;x<6;x++){send_0();}
send_1();
__delay_ms(20);
}
}
else if(sw_down == 0)
{
for(i=0;i<2;i++)
{
led=1;
__delay_ms(55);
led=0;
__delay_ms(50);
}
for(y=0;y<2;y++)
{
send_start_pulse();
send_1();
send_1();
for(x=0;x<5;x++){send_0();}
send_1();
__delay_ms(20);
}
}
}
}
void send_start_pulse()
{
rf_tx=1; __delay_us(start_pulse);
rf_tx=0; __delay_us(start_pulse_low);
}
void send_1()
{
rf_tx=1; __delay_us(one_high);
rf_tx=0; __delay_us(one_low);
}
void send_0()
{
rf_tx=1; __delay_us(zero_high);
rf_tx=0; __delay_us(zero_low);
}
واذا ممكن المساعده بتطوير الكود بكون متشكرا جدااا ^^