#include <18F4550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN,NOPBADEN
#use delay(clock=48000000)
#USE RS232 (baud=9600,bits=8,parity=N,xmit=PIN_C6,rcv=PIN_C7)
//#build(reset=0x000800,interrupt=0x000808:0x000818)
// Necesario para indicarle al compilador a partir de donde alojar mi programa
//#ORG 0x000, 0x07FF {} // Espacio reservado para alojar el bootloader
#byte PORTA = 0xF80// Son las direcciones de memoria de los puertos en este PIC
#byte PORTB = 0xF81
#byte PORTC = 0xF82
#byte PORTD = 0xF83
#byte PORTE = 0xF84
#define entrada1 PIN_A0
#define entrada2 PIN_A1
#define salida1 PIN_B0
#define salida2 PIN_B1
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use fast_io(D)
#use fast_io(E)
typedef struct{
long pin;
int8 contando;
int8 pasaron_20ms;
} mi_LS;// mi Limit Switch
void estado_pin(int16);//
void main(void) {
mi_LS ls_art_1, ls_art_2;
int16 * ls1, * ls2;
*ls1=ls_art_1;
*ls2=ls_art_2;
ls_art_1.pin=entrada1;
ls_art_1.contando=0;
ls_art_1.pasaron_20ms=0;
ls_art_2.pin=entrada2;
ls_art_2.contando=0;
ls_art_2.pasaron_20ms=0;
set_tris_a(0b00000011);
set_tris_b(0);
set_tris_c(0b10000000);
output_low(salida1);
output_low(salida2);
while (TRUE){
estado_pin(&ls1);
if (ls_art_1.contando) {output_high(salida1);}
else output_low(salida1);
estado_pin(&ls2);
if (ls_art_2.contando) {output_high(salida2);}
else output_low(salida2);
}
}
void estado_pin(int16 ls){
if (input(*ls)) *(ls+2)=1;// hago un desplazamiento de 2 bytes para ubicar a
else *(ls+2)=0; // ls.contando y asignarle un valor
}typedef struct{
long pin;
int8 contando;
int8 pasaron_20ms;
} mi_LS;// mi Limit Switchmi_LS ls_art_1, ls_art_2; ls_art_1.pin=entrada1;
ls_art_1.contando=0;
ls_art_1.pasaron_20ms=0;
ls_art_2.pin=entrada2;
ls_art_2.contando=0;
ls_art_2.pasaron_20ms=0;void estado_pin(int16);//#include <18F4550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN,NOPBADEN
#use delay(clock=48000000)
#USE RS232 (baud=9600,bits=8,parity=N,xmit=PIN_C6,rcv=PIN_C7)
//#build(reset=0x000800,interrupt=0x000808:0x000818)
// Necesario para indicarle al compilador a partir de donde alojar mi programa
//#ORG 0x000, 0x07FF {} // Espacio reservado para alojar el bootloader
#byte PORTA = 0xF80// Son las direcciones de memoria de los puertos en este PIC
#byte PORTB = 0xF81
#byte PORTC = 0xF82
#byte PORTD = 0xF83
#byte PORTE = 0xF84
#define entrada1 PIN_A0
#define entrada2 PIN_A1
#define salida1 PIN_B0
#define salida2 PIN_B1
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use fast_io(D)
#use fast_io(E)
typedef struct{
long pin;
int8 contando;
int8 pasaron_20ms;
} mi_LS;// mi Limit Switch
void estado_pin(mi_LS *);//
void main(void) {
mi_LS ls_art_1={entrada1 0 0};
mi_LS ls_art_2={entrada2 0 0};
set_tris_a(0b00000011);
set_tris_b(0);
set_tris_c(0b10000000);
output_low(salida1);
output_low(salida2);
while (TRUE){
estado_pin(&ls_art_1);
if (ls_art_1.contando) {output_high(salida1);}
else output_low(salida1);
estado_pin(&ls_art_2);
if (ls_art_2.contando) {output_high(salida2);}
else output_low(salida2);
}
}
void estado_pin(mi_LS *ls){
if (input(ls->pin)) (ls->contando)=1;
else (ls->contando)=0;
}Pin to read. Pins are defined in the devices .h file. The actual value is a bit address. For example, port a (byte 5) bit 3 would have a value of 5*8+3 or 43. This is defined as follows: #define PIN_A3 43.
The PIN could also be a variable. The variable must have a value equal to one of the constants (like PIN_A1) to work properly
...
Cuando accedias a *(ls+2) estabas accediendo a *(&ls + sizeof(mi_LS) * 2), comprueba en que direccion estaba ls, y si aparecia un 1 en alguna direccion de memoria cercana...
...
estado_pin(&ls_art_1)y haciendo *(ls+2)=1 modificamos el byte bajo de ls_art_2, es decir, a la dirección de memoria 0x0B le asignamos 1, esto es ls_art_2.pin=1
#include <18F4550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN,NOPBADEN
#use delay(clock=48000000)
#USE RS232 (baud=9600,bits=8,parity=N,xmit=PIN_C6,rcv=PIN_C7)
//#build(reset=0x000800,interrupt=0x000808:0x000818)
// Necesario para indicarle al compilador a partir de donde alojar mi programa
//#ORG 0x000, 0x07FF {} // Espacio reservado para alojar el bootloader
#byte PORTA = 0xF80// Son las direcciones de memoria de los puertos en este PIC
#byte PORTB = 0xF81
#byte PORTC = 0xF82
#byte PORTD = 0xF83
#byte PORTE = 0xF84
#define entrada1 PIN_A0
#define entrada2 PIN_A1
#define salida1 PIN_B0
#define salida2 PIN_B1
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use fast_io(D)
#use fast_io(E)
typedef struct{
long pin;
int8 contando;
int8 pasaron_20ms;
} mi_LS;// mi Limit Switch
void estado_pin(mi_LS *);//
void main(void) {
mi_LS ls_art_1={entrada1 0 0};
mi_LS ls_art_2={entrada2 0 0};
set_tris_a(0b00000011);
set_tris_b(0);
set_tris_c(0b10000000);
output_low(salida1);
output_low(salida2);
while (TRUE){
estado_pin(&ls_art_1);
if (ls_art_1.pasaron_20ms) {output_high(salida1);}
else output_low(salida1);
estado_pin(&ls_art_2);
if (ls_art_2.pasaron_20ms) {output_high(salida2);}
else output_low(salida2);
}
}
void estado_pin(mi_LS * ls){
if (input(ls)) *(ls+1)=1;
else *(ls+1)=0;
}