hello guys
as you know RC-switch is a good library for 355 and 433mhz Frequency. Before I saw it "RC-switch", I wrote simple code for 433mhz...
My code in Proteus was Ok. But in practice, it had many problems.
and my question is, no way to convert RC-switch for PIC microcontroller?
XC8 MPLBX
/*
* File: main.c
* Author: iBnav
*
* Created on February 18, 2022 4:51 PM
*/
// PIC12F1822 Configuration Bit Settings
// 'C' source line config statements
// CONFIG1
#pragma config FOSC = INTOSC // Oscillator Selection (INTOSC oscillator: I/O function on CLKIN pin)
#pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled)
#pragma config PWRTE = ON // Power-up Timer Enable (PWRT enabled)
#pragma config MCLRE = OFF // MCLR Pin Function Select (MCLR/VPP pin function is digital input)
#pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled)
#pragma config CPD = OFF // Data Memory Code Protection (Data memory code protection is disabled)
#pragma config BOREN = ON // Brown-out Reset Enable (Brown-out Reset enabled)
#pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
#pragma config IESO = OFF // Internal/External Switchover (Internal/External Switchover mode is disabled)
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is disabled)
// CONFIG2
#pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off)
#pragma config PLLEN = ON // PLL Enable (4x PLL enabled)
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
#pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config LVP = OFF // Low-Voltage Programming Enable (High-voltage on MCLR/VPP must be used for programming)
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
#include <xc.h>
#define _XTAL_FREQ 8000000
void PIN_MANAGER_Initialize(void) {
LATA = 0x00;
TRISA = 0b00000011;
ANSELA = 0x00;
}
#define RF_DATA PORTAbits.RA0
#define K_LEARN PORTAbits.RA1
#define LED_REC LATAbits.LATA2
char chekbit() {
unsigned char i = 0;
char b = 0;
while (1) {
if (i > 150) {
if (RF_DATA) b = 1;
break;
}
__delay_us(10);
i++;
}
while (RF_DATA);
return b;
}
void remote_code() {
unsigned char inbits[24], shift;
unsigned char i = 0;
Rsw = Rcode[0] = Rcode[1] = Rcode[2] = 0;
while (!((RF_DATA) && i >= 8)) {
if (RF_DATA) i = 0;
__delay_ms(1);
i++;
}
i = 0;
while (i < 24) {
while (!(RF_DATA));
inbits[i] = chekbit();
i++;
}
shift = 3;
for (i = 0; i < 4; i++) {
Rcode[0] |= inbits[i] << shift;
shift--;
}
shift = 7;
for (i = 4; i < 12; i++) {
Rcode[1] |= inbits[i] << shift;
shift--;
}
shift = 7;
for (i = 12; i < 20; i++) {
Rcode[2] |= inbits[i] << shift;
shift--;
}
shift = 3;
for (i = 19; i < 24; i++) {
Rsw |= inbits[i] << shift;
shift--;
}
}