Estoy usando un PIC18F4685, segmento de 4 dígitos 7, RX de 433 MHz (super-het) y TX, Sensor de efecto Hall, HT12D y HT12E. Mi configuración es
lado de TX ... El sensor de efecto Hall está conectado a D11 (PIN12), 5V y GND. HT12E está utilizando un oscilador de 1 M ohmios (PIN15 y 16), TE (PIN14) está conectado a tierra y se usa AD11 (PIN13) TX a 433MHz con antena
Cuando el sensor se dispara, enviará una señal
lado RX ... El RX enviará la señal a HT12D Din (PIN14) HT12D está utilizando un oscilador de 51k ohms (PIN15 y 16), D11 (PIN13) hará que RB0 sea bajo cuando el sensor se active (según mi medidor). Cuando RB0 es bajo, incrementará el número.
// CONFIG1H
#pragma config OSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
#pragma config IESO = OFF // Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled)
// CONFIG2L
#pragma config PWRT = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = BOHW // Brown-out Reset Enable bits (Brown-out Reset enabled in hardware only (SBOREN is disabled))
#pragma config BORV = 3 // Brown-out Reset Voltage bits (VBOR set to 2.1V)
// CONFIG2H
#pragma config WDT = OFF // Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit))
#pragma config WDTPS = 32768 // Watchdog Timer Postscale Select bits (1:32768)
// CONFIG3H
#pragma config PBADEN = ON // PORTB A/D Enable bit (PORTB<4:0> pins are configured as analog input channels on Reset)
#pragma config LPT1OSC = OFF // Low-Power Timer 1 Oscillator Enable bit (Timer1 configured for higher power operation)
#pragma config MCLRE = ON // MCLR Pin Enable bit (MCLR pin enabled; RE3 input pin disabled)
// CONFIG4L
#pragma config STVREN = ON // Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)
#pragma config LVP = OFF // Single-Supply ICSP Enable bit (Single-Supply ICSP disabled)
#pragma config BBSIZ = 1024 // Boot Block Size Select bits (1K words (2K bytes) Boot Block)
#pragma config XINST = OFF // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode))
// CONFIG5L
#pragma config CP0 = OFF // Code Protection bit (Block 0 (000800-003FFFh) not code-protected)
#pragma config CP1 = OFF // Code Protection bit (Block 1 (004000-007FFFh) not code-protected)
#pragma config CP2 = OFF // Code Protection bit (Block 2 (008000-00BFFFh) not code-protected)
#pragma config CP3 = OFF // Code Protection bit (Block 3 (00C000-00FFFFh) not code-protected)
#pragma config CP4 = OFF // Code Protection bit (Block 4 (010000-013FFFh) not code-protected)
#pragma config CP5 = OFF // Code Protection bit (Block 5 (014000-017FFFh) not code-protected)
// CONFIG5H
#pragma config CPB = OFF // Boot Block Code Protection bit (Boot block (000000-0007FFh) not code-protected)
#pragma config CPD = OFF // Data EEPROM Code Protection bit (Data EEPROM not code-protected)
// CONFIG6L
#pragma config WRT0 = OFF // Write Protection bit (Block 0 (000800-003FFFh) not write-protected)
#pragma config WRT1 = OFF // Write Protection bit (Block 1 (004000-007FFFh) not write-protected)
#pragma config WRT2 = OFF // Write Protection bit (Block 2 (008000-00BFFFh) not write-protected)
#pragma config WRT3 = OFF // Write Protection bit (Block 3 (00C000-00FFFFh) not write-protected)
#pragma config WRT4 = OFF // Write Protection bit (Block 4 (010000-013FFFh) not write-protected)
#pragma config WRT5 = OFF // Write Protection bit (Block 5 (014000-017FFFh) not write-protected)
// CONFIG6H
#pragma config WRTC = OFF // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) not write-protected)
#pragma config WRTB = OFF // Boot Block Write Protection bit (Boot block (000000-0007FFh) not write-protected)
#pragma config WRTD = OFF // Data EEPROM Write Protection bit (Data EEPROM not write-protected)
// CONFIG7L
#pragma config EBTR0 = OFF // Table Read Protection bit (Block 0 (000800-003FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR1 = OFF // Table Read Protection bit (Block 1 (004000-007FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR2 = OFF // Table Read Protection bit (Block 2 (008000-00BFFFh) not protected from table reads executed in other blocks)
#pragma config EBTR3 = OFF // Table Read Protection bit (Block 3 (00C000-00FFFFh) not protected from table reads executed in other blocks)
#pragma config EBTR4 = OFF // Table Read Protection bit (Block 4 (010000-013FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR5 = OFF // Table Read Protection bit (Block 5 (014000-017FFFh) not protected from table reads executed in other blocks)
// CONFIG7H
#pragma config EBTRB = OFF // Boot Block Table Read Protection bit (Boot block (000000-0007FFh) not protected from table reads executed in other blocks)
// #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
#define S1 RC0 //RC0 for digit 1
#define S2 RC1 //RC1 for digit 2
#define S3 RC2 //RC2 for digit 3
#define S4 RC3 //RC3 for digit 4
void port_init() {
TRISB = 0xff; //Data from receiver->encoder->pin RB0
TRISC = 0x00; //All ports C and D are output
TRISD = 0x00;
PORTC = 0x00; //Initialize ports C and D to 0
PORTD = 0x00;
}
int main(int argc, char** argv) {
port_init();
int data = 0;
unsigned int num[] = {0xc0, //0
0xf9, //1
0xa4, //2
0xb0, //3
0x99, //4
0x92, //5
0x82, //6
0xf8, //7
0x80, //8
0x90}; //9
S4 = 1; //Turn on 4th digit (for testing)
while(1) {
if (PORTBbits.RB0 == 0) {
__delay_ms(100);
if (PORTBbits.RB0 == 0) {
data++; //Increment data
__delay_ms(100);
}
}
PORTD = num[data]; //Display the number corresponds to data
}
return (EXIT_SUCCESS);
}
La salida pasará de 0 a 9 dos veces, luego de un segmento aleatorio. Incluso sin disparar el sensor.
Idealmente, los datos solo se incrementarán, si el sensor se activa.
Básicamente es solo un contador por ahora. Solo estoy probando si el sensor puede transmitir una señal al PIC para que pueda mostrar una salida legible.
EDITAR: ¿Por qué el segmento 7 inicialmente cuenta hasta el infinito incluso sin ingresar la instrucción if? ¿O esperando que el sensor dispare la señal? La instrucción if será la que incremente el valor que se mostrará.
He probado el RX TX utilizando esta guía , y el RX TX puede comunicarse.
EDIT:
Lo siento, usé el interruptor DIP para el HT12E y el HT12D, y el bloque de terminales para RX y TX.