|
|
View previous topic :: View next topic |
Author |
Message |
ze.vana
Joined: 11 Jun 2011 Posts: 15
|
HT6P20 how to decode it. |
Posted: Sat Dec 08, 2012 2:25 pm |
|
|
hello people
Does anybody know the HT6P20, or have already done a project to decode it's pulses? This is a Holtek transmitter RF Encoder.
I am trying make a Receptor that decode it, for a long time without success.
Please help me!
Here is the code but it doesn't work right.
Receptor:
Code: | #include <18f4520.h>
#fuses HS,NOWDT,NOLVP
#use delay(clock=20M)
#include "flex_lcd_semRW.c"
#bit TMR0IF=0xff2.2 //INTCON BIT 2
int8 change_edge;
int16 pulse[4];
int16 time[5];
//the signal out from Receptor 434 is conected on pins B0 and C1
//B0:int external / C1:Timer1 external
#int_ext
void funcion_ext_int(){
if(change_edge==0) {
set_timer1(0);
set_timer0(0);
change_edge=1;
}//these next three bloks are the same,they're just to change edge.
if(TMR0IF && change_edge==1) { //overflow timer0
pulse[change_edge]=get_timer1();//get pulses from timer1
time[change_edge]=get_timer0();//get the time from timer0
ext_int_edge(H_TO_L);
change_edge=2;
set_timer1(0);
set_timer0(0);
TMR0IF=0;
}
if(TMR0IF && change_edge==2) {//overflow timer0 --__
pulse[change_edge]=get_timer1();//get pulses from timer1
time[change_edge]=get_timer0();//get the time from timer0
ext_int_edge(L_TO_H);
change_edge=3;
set_timer0(0);
set_timer1(0);
TMR0IF=0;
}
if(TMR0IF && change_edge==3) {
pulse[change_edge]=get_timer1();//get the time from timer0
time[3]=get_timer0(); //get the time from timer0
change_edge=4;
ext_int_edge(H_TO_L);
set_timer0(0);
set_timer1(0);
TMR0IF=0;
}
if(TMR0IF && change_edge==4) { //overflow timer0
pulse[change_edge]=get_timer1();//captura os pulsos do timer1
time[4]=get_timer0();
change_edge=0;//reestart again
ext_int_edge(L_TO_H);
set_timer0(0);
set_timer1(0);
TMR0IF=0;
}
}
void main(){
set_tris_a(0xff);
set_tris_b(0b00000001);
set_tris_c(0b10111111);//xmit=PIN_c6:out
//----------------------------------------TIMER0
SETUP_TIMER_0(RTCC_INTERNAL|RTCC_DIV_16);// pin B0
set_timer0(0);
SETUP_TIMER_1(T1_EXTERNAL | T1_DIV_BY_1 );//pin C1
set_timer1(0);
ext_int_edge(0,L_TO_H);
enable_interrupts(int_ext); //Habilitación interrupción RB0
enable_interrupts(global);
lcd_init();
delay_ms(100);
while(true)
{
lcd_gotoxy(1, 1);
printf(LCD_PUTC, "\%Lu %Lu %Lu ",pulse[1],pulse[2],time[1] );
lcd_gotoxy(1, 2);
printf(LCD_PUTC, "\%Lu %Lu %Lu ",time[2],time[3],time[4]);
}
}
|
|
|
|
Arsenic
Joined: 23 Sep 2016 Posts: 13
|
|
Posted: Thu Oct 06, 2016 5:07 am |
|
|
I did, but with a different PIC. Just I made it to decode, but you can modify it as you want. Here, try it:
Code: |
#include <16f628a.h>
#fuses INTRC_IO, NOWDT, BROWNOUT, NOPROTECT, MCLR
#use delay (internal = 4M)
#use fast_io (B)
#define Margen (int16)40
#define RX PIN_B4
#define LCD_RS_PIN PIN_A7 ////
#define LCD_RW_PIN PIN_A4 ////
#define LCD_ENABLE_PIN PIN_A6 ////
#define LCD_DATA4 PIN_A0 ////
#define LCD_DATA5 PIN_A1 ////
#define LCD_DATA6 PIN_A2 ////
#define LCD_DATA7 PIN_A3 ////
#include <lcd.c>
int32 Datos;
int32 DatosAux;
int32 Verif;
char contador_bits;
int16 Lambda;
int16 L;
int16 H;
enum {
Lambda_1=0,
Lambda_2,
Obtener_datos,
Datos_correctos,
Datos_incorrectos,
Paquete_obtenido,
Mostrar_resultados,
Paquete_fallido
};
Struct Supervisor {
int Tarea;
int Resultado;
}Supervisor;
void display();
#INT_RB
void int_rb_sir (){
switch (Supervisor.Tarea){
case Lambda_1:
if(input(RX)){
Lambda = 0;
L = 0;
H = 0;
set_timer0(0);
clear_interrupt(int_timer0);
enable_interrupts(int_timer0);
set_timer1(0);
Supervisor.Tarea = Lambda_2;
}
break;
case Lambda_2: //Se obtiene el valor de Lambda
if(!input(RX)){
Lambda = get_timer1();
L = 0;
H = 0;
contador_bits = 0;
set_timer0(0);
set_timer1(0);
Supervisor.Tarea = Obtener_datos;
}
break;
case Obtener_datos: //Comienza a medirse la duración del pulso bajo
if(input(RX)){
set_timer0(0);
L = get_timer1();
set_timer1(0);
}
else { //Comienza a medirse la duración del pulso alto
set_timer0(0);
H = get_timer1();
set_timer1(0);
}
if (H>0 && L>0){
if(L>((2*Lambda)+Margen)){
disable_interrupts(global);
Supervisor.Resultado = Datos_incorrectos;
}
else if(L<(Lambda-Margen)){
disable_interrupts(global);
Supervisor.Resultado = Datos_incorrectos;
}
else if(H>((2*Lambda)+Margen)){
disable_interrupts(global);
Supervisor.Resultado = Datos_incorrectos;
}
else if(H<(Lambda-Margen)){
disable_interrupts(global);
Supervisor.Resultado = Datos_incorrectos;
}
else {
if (L>H){
bit_set(Datos,contador_bits);
}
else if (L<H){
bit_clear(Datos,contador_bits);
}
L = 0;
H = 0;
contador_bits++;
Supervisor.Tarea = Obtener_datos;
}
}
break;
case Paquete_obtenido:
break;
case Mostrar_resultados:
break;
case Paquete_fallido:
break;
default:
clear_interrupt(int_timer0);
clear_interrupt(int_rb);
enable_interrupts(int_rb);
enable_interrupts(int_timer0);
enable_interrupts(global);
break;
}
}
#int_timer0
void interr_timer0(int32) {
clear_interrupt (int_timer0);
disable_interrupts (GLOBAL);
Supervisor.Tarea = Paquete_fallido;
}
void main () {
disable_interrupts(global);
set_tris_B (0x14); // RB4 = 1, RB2 = 1
setup_timer_0 (RTCC_DIV_4 | RTCC_INTERNAL);
setup_timer_1 (T1_DIV_BY_1 | T1_INTERNAL);
setup_oscillator(OSC_4MHZ);
setup_ccp1 (CCP_OFF);
enable_interrupts (INT_RB);
lcd_init();
Datos = 0;
contador_bits = 0;
Lambda = 0;
H = 0;
L = 0;
Supervisor.Tarea = Lambda_1;
Supervisor.Resultado = Datos_correctos;
enable_interrupts (GLOBAL);
while (true) {
switch(Supervisor.Tarea){
case Lambda_1:
break;
case Lambda_2:
break;
case Obtener_datos:
if(contador_bits < 28){
Supervisor.Tarea = Obtener_datos;
}
else {
DatosAux = Datos;
Verif = DatosAux &= 0x0A000000;
if(Verif == 0x0A000000){
Supervisor.Tarea = Mostrar_resultados;
}
else{
Supervisor.Tarea = Paquete_fallido;
}
}
break;
case Paquete_obtenido:
if(Supervisor.Resultado == Datos_correctos){
Supervisor.Tarea = Mostrar_resultados;
}
else{
Supervisor.Tarea = Paquete_fallido;
}
break;
case Mostrar_resultados:
display();
case Paquete_fallido:
disable_interrupts(int_timer0);
default:
Datos = 0;
Supervisor.Resultado = Datos_correctos;
Supervisor.Tarea = Lambda_1;
contador_bits = 0;
Lambda = 0;
L = 0;
H = 0;
clear_interrupt(int_rb);
clear_interrupt(int_timer0);
enable_interrupts(global);
break;
}
}
}
void display(){
contador_bits = 0;
lcd_gotoxy(1,1);
printf(lcd_putc,"%LX",Datos);
delay_ms(500);
}
|
And here is the project in proteus so you can prove it working:
http://www.4shared.com/file/sIDyDwD3ba/pru.html |
|
|
ze.vana
Joined: 11 Jun 2011 Posts: 15
|
Thankyou Arsenic although I have partialy solved this case, |
Posted: Sat Oct 29, 2016 12:48 pm |
|
|
Now I have a few problems on record code control in an eeprom.
But I will try the your code. Thanks again. |
|
|
Arsenic
Joined: 23 Sep 2016 Posts: 13
|
Re: Thankyou Arsenic although I have partialy solved this ca |
Posted: Mon Nov 07, 2016 12:48 am |
|
|
ze.vana wrote: | Now I have a few problems on record code control in an eeprom.
But I will try the your code. Thanks again. |
Try to store the decoded data into an array. That way, it should be easier to use the write_eeprom and read_eeprom functions. You can use something like the following:
Code: |
int i;
int32 data[32]; //stores the decoded data
int array1[8]M //3 arrays with the decoded data to separate the received
int array2[8]; //bits on 3 arrays of 8 bits to store them into the EEPROM.
int array3[8];
.
.
.
void int32_to_3_int8 (void); //converts the entire data to 3
//arrangements of 8 bits.
.
.
.
void data_to_array (){
for (i = 0; i<8; i++){
array1[i] = data[i];
array2[i] = data[i+8];
array3[i] = data[i+16];
}
}
.
.
.
void program_control(){
if(!input_button && i<cont_eeprom){
int32_to_3_int8();
write_eeprom(array1,address);
write_eeprom(array2,address);
write_eeprom(array3,address);
}
}
//cont_eeprom is a counter that indicates if there is enough memory to
//store the data. Since data transmitted is 24bits long and each address of
//memory is 8 bits long, we need to divide the eeprom size between 3. //That number gives us the total of remote controls that we can program.
//I suggest you to compare the data, so you can be able to detect if
//the code is a new one or if it's repeated. Have in mind that we haven't
//a comfortable memory size, although you can add an external one
//if you need several number of remote controls.
|
That should work. The data stored in the EEPROM is 8 bits long by address, so you can't store the entire 24bits long of received data directly. You need to separate that array on 3 different and numbered (order is required) arrays. Note that if you make that program function imperatively, you probably will storing the same data two or more times. Compare the data to write before, so you can store it if is different or depreciate if the data you send is already stored on the EEPROM. The function read_eeprom(address); can help you this time.
Note: The code I passed above is not functional. It's just a model to give you an idea and help you recording/reading the EEPROM. Good luck!!! If there's anything else I can do for you, just let me know. |
|
|
Arsenic
Joined: 23 Sep 2016 Posts: 13
|
|
Posted: Mon Nov 07, 2016 1:00 am |
|
|
BTW, "button" is the push button you need to press in order to enter on program mode (the receiver is a learning-receiver one and I assume that your control(s) have unique(s) factory-recorded code(s)). Of course, you also need another button to clear the EEPROM (0xFF from address 0 to the top EEPROM-address). |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|