Hola,
Me encuentro con un problema cuando pase del compilador 3.249 al 4.101, dejo de andar la lectura /escritura de la memoria externa (eeprom),revise todo mil veces, descubri que si en el programa esta solo la rutina para leer/escribir la eeprom anda,pero si agrego mas codigo, que no tendria que interferir para nada con esa rutina, deja de andar y siempre lee 255 de en la memoria...si vuelbo y compilo con la version vieja 3.249 siempre anda..
---este es el programa que anda (usando 4.101--si le agrego mas codigo abajo deja de andar-- )
#include "16f648A.h"
#fuses INTRC_IO,NOLVP,NOWDT,NOPROTECT,NOCPD,NOMCLR
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_B4, rcv=PIN_A4, STREAM=PUER_DE)
#DEFINE LED1 PIN_B3
#DEFINE LED2 PIN_A3
#INCLUDE<2465.C>
//****************************MAIN!!!!!!!!!*****PROGAMA ANDANDO *******************************
void main() {
int recibi;
int cant_readers;
set_tris_a (5);
set_tris_b (211);
output_high (LED1);
output_high (LED2);
delay_ms(2000);
output_low(LED1);
output_low(LED2);
init_ext_eeprom();
write_ext_eeprom(59,82);//escribo en la posicion 59 el valor 82
delay_ms(2000);
recibi=read_ext_eeprom(59);//leo la posicion 59
Fprintf(PUER_DE,"recibi:%u\n\r",recibi); //lee 82--anda bien
}
Esta es la version que no anda cuando le agrego codigo abajo------
#include "16f648A.h"
#fuses INTRC_IO,NOLVP,NOWDT,NOPROTECT,NOCPD,NOMCLR
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_B2, rcv=PIN_B1,STREAM=PUER_PIC,PARITY = N, BITS = 9,ERRORS,DISABLE_INTS)
#use rs232(baud=9600, xmit=PIN_A7, rcv=PIN_A0, STREAM=PUER_PC)
#use rs232(baud=9600, xmit=PIN_B4, rcv=PIN_A4, STREAM=PUER_DE)
#DEFINE LED1 PIN_B3
#DEFINE LED2 PIN_A3
#DEFINE MANDAME PIN_B5
#DEFINE INTE PIN_B0
#INCLUDE<2465.C>
#byte intcon =11
#byte rcreg =26
#byte option =129
#byte rcsta =24
#byte txsta=152
#DEFINE TX9D txsta,0
#byte pir1=12
static short timeout_error=false ,timeout_error1=false,recibir=false,llamada=false,hice_la_bus=false;
static int D[36] ;
static int a[36];
static int encab,indice=0,error=0,bytes_direcciones,cant_readers=0,conta=0;
static long registros=0,indice_reader=0;
void main() {
long m,indice_reader=0;
short marca=0,bien=0,resp=0,bue=0,ceros=0,rompe=0,pedido=0;
//int mando[10];
int recibi=0,check=0,intentos=0,error=0,h=0,i,i1;
setup_comparator (NC_NC_NC_NC);
set_tris_a (5);
set_tris_b (211);
ext_int_edge( H_TO_L );
bit_clear(intcon,4);//apago timer 0
bit_clear(intcon,1);//
bit_clear(option,6);
disable_interrupts(GLOBAL);
indice_reader=0;
port_b_pullups (TRUE);
OUTPUT_high(MANDAME);
output_high (LED1);
output_high (LED2);
delay_ms(2000);
output_low(LED1);
output_low(LED2);
init_ext_eeprom();
delay_ms(500);
write_ext_eeprom(59,29);//escribo en la posicion 59 el valor 29
delay_ms(2000);
recibi=read_ext_eeprom(59);//leo la posicion 59
Fprintf(PUER_DE,"recibi:%u\n\r",recibi); // NO ANDA--LEE 255!!!
delay_ms(2000);
cant_readers =read_eeprom(0);
IF (cant_readers==0){
ahi: WHILE(TRUE){
output_high (LED1);
delay_ms(300);
output_low (LED1);
delay_ms(300);
if (bit_test(intcon,1)==1){
bit_clear(intcon,1);
recibir_pc();
break;
}
}
if (cant_readers==0){goto ahi; }//si cuando salgo de verif,no tengo reader<>0 entonce vuelvo al lazo
}
ELSE
{
// bytes_direcciones=1;
indice_reader=0;
bytes_direcciones=read_eeprom(1);//SI CANTIDAD DE READERS <> 0 YA ESTA TODO SETADO,LEO CANTIDAD DE BYTES
}
registros = 256 * read_eeprom (2)+ read_eeprom (3);
WHILE (TRUE){
///**************************************BIG LOOP CHEQUEO READERS*****************************************
while(TRUE) {
//Fprintf(PUER_DE,"%S\n\r","otro reader");
//Fprintf(PUER_DE,"otro reader");
error=0;
intentos=0;
rompe=0;
for (i1=0; i1<=9; i1=i1+1){ //MANDAR = False for (i1=0; i1<=20; i1=i1+1)
for (m=1; m<=50000; m=m+1){
if (bit_test(intcon,1)==1){
bit_clear(intcon,1);
recibir_pc();
rompe=1;
//break;
}
delay_us(4);
// }
}
}
// if (rompe==1){
// rompe=0;
// bit_clear(intcon,1);
// delay_en_ms(1000);
//// break;} //sacr si anda bien!!!
// }
//}
if (rompe==1){
rompe=0;
for (i1=0; i1<=9; i1=i1+1){
for (m=1; m<=50000; m=m+1){
if (bit_test(intcon,1)==1){
bit_clear(intcon,1);
recibir_pc();
break;
}
delay_us(4);
}
}
}
//delay_ms(3000);
indice_reader=indice_reader+1;
if (indice_reader >= cant_readers+1){
indice_reader=1; }
volver : if (indice_reader==0){indice_reader=1;}
// Fprintf(PUER_DE,"indice_reader:%LU\n\r",indice_reader);
bit_set(txsta,0);// TX9d=1 - envio 9bits - address detect
fprintf(PUER_PIC,"%C",indice_reader); //mando pedido de datos pic 1
DELAY_MS(1);
bit_clear(txsta,0);// TX9d=0 //mando 8 bits
DELAY_MS(30);
// DELAY_MS(1);
fprintf(PUER_PIC,"%C",1); //COMANDO DE LLAMADA PARA PEDIR MARCADAS:tarea
DELAY_MS(10);
// bit_set(txsta,0);// TX9d=1 - envio 9bits - address detect
recibi=0;//Borro checheo si recibio algo de respuesta-
while(true) {
intentos=0;
volver1: resp=false; //bandera respuesta de computadora
marca=0; //bandera se interrupio la transmision
for (i=0;i<=8;i=i+1){ //recibo los datos(1 solo 8 bytes + checksum=9)
a =timed_getc(); //a= fgetc(PUER_PIC) ;
if(timeout_error==true)
{ marca=1;
Errores();
pedido=1;
// Fprintf(PUER_DE,"%S\n\r","Time out");
break; } //rompe el lazo de for(no se queda esperando por otros 7)
}
saltito:
if (marca==0){ // recibi un byte y lo proceso!!!
ceros=0;
if (a[0]==0 && a[1]==0 && a[2]==0 && a[3]==0 && a[4]==0 && a[5]==0 && a[6]==0 && a[7]==0 ){
// marca=1;
ceros=1;
}
// for (i=0;i<=8;i=i+1){ //SACAR!!!!
// fprintf(PUER_DE,"%U\n\r",a);
// }
//
recibi=recibi+1;
check = a[0] ^ a[1];
for (i=2;i<=7;i=i+1){
check= check ^ a;}
// fprintf(PUER_DE,"check :%U\n\r",check);
// fprintf(PUER_DE,"a[8]: %U\n\r",a[8]);
// fprintf(PUER_DE,"%s\n\r","***");
// fprintf(PUER_DE,"a[8]: %U\n\r",a[8]);
bit_clear(txsta, 0);// TX9d=0 //mando 8 bits
if ((a[8]!=check) || (ceros==1)){
intentos=intentos+1;//RECIBO DATOS MAL
// fprintf(PUER_DE,"Intentos: %U\n\r",intentos);
fprintf(PUER_PIC,"%C",8);//ENVIO RESPUESTA MAL ,PARA QUE MANDE DE NUEVO(
// fprintf(PUER_DE,"%S\n\r","8");
if (intentos >=5)
{
// bit_set(txsta, 0);// TX9d=0 //mando 9 bits
intentos=0;
AVISO(76,1); //L=76
Fprintf(PUER_PC,"%C", indice_reader);
pedido=1;
break;
}
else
{
delay_en_ms(3);
// bit_set(txsta, 0);// TX9d=0 //mando 9 bits
// error=1;
// break;
// Errores();
goto volver1; //VUELVE A RECIBIR EL DATO,EL ESCLAVO VUELVE A ENVIAR
}
}
else
{
error=0;
fprintf(PUER_PIC,"%C",6);
// fprintf(PUER_DE,"%S\n\r","6");
}
// bit_set(txsta, 0);// TX9d=0 //mando 9 bits
// noresp[indice_reader]=0;//esta variable(0 o 1 espara saber si ya mande la info a la compu o memo que un reader no contesta esto es cero o uno-creo quiere decir que el reader contesta.
//si no hubo errores en la recepcion de esos 8 bits/se sigue transmitiendo
//************************COMPUTADORA PRENDIDA??****************************
a[8]=indice_reader;
resp=prueba_pc(); //me fijo si la pc esta prendida
if (resp==false)
{
fprintf(PUER_DE,"%S\n\r","N_PC");
//fprintf(PUER_PC,"%S\n\r","analizo");
// delay_en_us(2300);
analizar();} //COMPUTADORA APAGADA
else//COMPUTADORA prendida
{
delay_ms(1);
fprintf(PUER_DE,"%S\n\r","S_PC");
// if (a[0]!=5 && a[1]!=5) {
// for (i=0;i<=8;i=i+1){
// Fprintf(PUER_PC,"%u",6); //si estan entrando datos ,no son 5,mando el 6 a la compu que retrasa el control de controller por 5 minutos)
// delay_en_us(200);
// }//le mando ndo un mnesaje a l pc para que no moleste con el testeo de controller minetras recibe datos
// }
//*********COMPUTADORA PRENDIDA**********************************
for (i=0;i<=8;i=i+1){ //0 a 8 =9 datos
// delay_en_us(200);
delay_en_us(600);
// Fprintf(PUER_DE,"%U\n\r",a);
Fprintf(PUER_PC,"%C",a); // VOLVER A PONER!!!!!!! ENERO
}//mando los datos a la PC/ENERO
}
}
else //marca=1 ************TIME OUT O CABLE DESCONCETADO // o time out bien porque ya recibio ***************************************
{
// fprintf(PUER_PC,"%S\n\r","marca1");
if (recibi >= 1) {//me fijo si cuando me voy si recibi datos del pic
error=0;
marca=0;
// output_high (LED2); //indico que responde bien el controller /LED VERDE
output_high (LED1);
delay_en_ms(30);
// output_low (LED2);
output_LOW (LED1);
// Fprintf(PUER_DE,"BIEN:%LU\n\r",indice_reader);
pedido=1;
break;
}
else
{ //NO CONTESTO PEDIDO DATOS!!!!
marca=0;
error=error+1;
delay_en_ms(10);
AVISO(54,0);
// PONER!! fprintf (PUER_PC,"666666666");//le mando un mnesaje a l pc para que no moleste con el testeo de controller
//printf(PUER_DE,"ERROR:%U\n\r",error);
if(error>=3){ //NO CONTESTE 10 VECES!!
error=0;
resp=prueba_pc();
if (resp==true){
delay_en_ms(10);
AVISO(57,1);
// fprintf (PUER_PC,"99999999");//MANDO A LA PC EL NUMERO DE READER QUE NO RESPONDE
Fprintf(PUER_PC,"%C", indice_reader);
error=0;
pedido=1;
break;//salgo del l
}
else
{error=0;
pedido=1;
break;}
}
else
{
output_high (LED2); //indico que responde MAL el controller/LED AMARILLO
// fprintf(PUER_DE,"NO resp");
for (m=0;m<=1000;m=m+1){//5000
if (bit_test(intcon,1)==1){
pedido=1;
break;
}
delay_en_ms(1);
}
output_low (LED2);
if (hice_la_bus==true){
hice_la_bus=false;
error=0;
break;
}
else
{ goto volver ;} //VULEVE A MANDAR DESDE EL PRINCIPIO ESE READER
}
}
}
}
}
//cuando hago break vengo aca
if (pedido==1){
//Fprintf(PUER_DE,"rompo lazo");
pedido=0;
break;}
//cuando hago break vengo aca
}//este ya es el while del lazo principal-sigue con otro reader
}