|
|
View previous topic :: View next topic |
Author |
Message |
Jo�o Paulo
Joined: 03 Oct 2005 Posts: 2
|
Problem to write memory |
Posted: Mon Oct 03, 2005 1:58 pm |
|
|
Please, help me ?
I have a problem when I try to write the memory eeprom. My memory is durty when 2 sensors is on.
Code: |
#include <16f877.h>
#fuses HS,NOWDT,PUT
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include <input.c>
#include <stdlib.h>
#define g_pino_b7 input(pin_b7)
#define g_pino_b6 input(pin_b6)
#define g_pino_b5 input(pin_b5)
#define g_pino_b4 input(pin_b4)
#define g_pino_d7 input(pin_d7)
#define g_pino_d6 input(pin_d6)
#define g_pino_d5 input(pin_d5)
#define g_pino_d4 input(pin_d4)
/*** DECLARA��O VARIAVEIS GLOBAIS ***/
short int g_flag_b7=0, g_flag_b6=0, g_flag_b5=0, g_flag_b4=0,
g_flag_d7=0, g_flag_d6=0, g_flag_d5=0, g_flag_d4=0;
/*** FUN��O LIMPA ENDERE�O DE MEMORIA ***/
void zera_memoria(int v_pista)
{ if(v_pista == 1)
{ write_eeprom(0x21,0);write_eeprom(0x22,0);write_eeprom(0x23,0);
write_eeprom(0x24,0);write_eeprom(0x25,0);write_eeprom(0x26,0);
write_eeprom(0x27,0);write_eeprom(0x28,0);write_eeprom(0x29,0);
write_eeprom(0x30,0);
}
else if(v_pista == 2)
{ write_eeprom(0x31,0);write_eeprom(0x32,0);write_eeprom(0x33,0);
write_eeprom(0x34,0);write_eeprom(0x35,0);write_eeprom(0x36,0);
write_eeprom(0x37,0);write_eeprom(0x38,0);write_eeprom(0x39,0);
write_eeprom(0x40,0);
}
else if(v_pista == 3)
{ write_eeprom(0x41,0);write_eeprom(0x42,0);write_eeprom(0x43,0);
write_eeprom(0x44,0);write_eeprom(0x45,0);write_eeprom(0x46,0);
write_eeprom(0x47,0);write_eeprom(0x48,0);write_eeprom(0x49,0);
write_eeprom(0x50,0);
}
else if(v_pista == 4)
{ write_eeprom(0x51,0);write_eeprom(0x52,0);write_eeprom(0x53,0);
write_eeprom(0x54,0);write_eeprom(0x55,0);write_eeprom(0x56,0);
write_eeprom(0x57,0);write_eeprom(0x58,0);write_eeprom(0x59,0);
write_eeprom(0x60,0);
}
}
/*** FUN��O PRINCIPAL ***/
void main()
{ int v_qtd=0;
printf("\r\nPrograma Iniciado.");
//Seta status das portas de entradas e saidas
output_low(pin_b7); output_low(pin_b6); output_low(pin_b5); output_low(pin_b4);
output_low(pin_b3); output_low(pin_b2); output_low(pin_b1); output_low(pin_b0);
output_low(pin_d7); output_low(pin_d6); output_low(pin_d5); output_low(pin_d4);
output_low(pin_d3); output_low(pin_d2); output_low(pin_d1); output_low(pin_d0);
//Limpa memoria
zera_memoria(1);
zera_memoria(2);
zera_memoria(3);
zera_memoria(4);
//Loop Infinito
while(true)
{
output_high(pin_b2);
if(g_pino_b7 && !g_flag_b7 && !g_pino_d7)
{ printf("\r\n Pino B7 acionado.");
g_flag_b7=1;
v_qtd = 1 + read_eeprom(0x21);
write_eeprom(0x21,v_qtd);
printf("\r\n Variavel:%u - Memoria:%u",v_qtd,read_eeprom(0x21));
}
else if (g_pino_b6 && !g_flag_b6 && !g_pino_d6)
{ printf("\r\n Pino B6 acionado.");
g_flag_b6=1;
v_qtd = 1 + read_eeprom(0x22);
write_eeprom(0x22,v_qtd);
printf("\r\n Variavel:%u - Memoria:%u",v_qtd,read_eeprom(0x22));
}
if(g_pino_d7 && !g_flag_d7 && !g_pino_b7)
{ printf("\r\n Pino D7 acionado.");
g_flag_d7=1;
v_qtd = 1 + read_eeprom(0x23);
write_eeprom(0x23,v_qtd);
printf("\r\n Variavel:%u - Memoria:%u",v_qtd,read_eeprom(0x23));
}
else if (g_pino_d6 && !g_flag_d6 && !g_pino_b6)
{ printf("\r\n Pino D6 acionado.");
g_flag_d6=1;
v_qtd = 1 + read_eeprom(0x24);
write_eeprom(0x24,v_qtd);
printf("\r\n Variavel:%u - Memoria:%u",v_qtd,read_eeprom(0x24));
}
else if ((g_pino_b7 && g_pino_d7) && (!g_flag_d7))
{ printf("\r\n Pino B7 e D7 acionado.");
g_flag_d7=1;
write_eeprom(0x27,1);
printf("\r\n Teste :%u",read_eeprom(0x27));
v_qtd = 1 + read_eeprom(0x25);
write_eeprom(0x25,v_qtd);
printf("\r\n Variavel:%u - Memoria:%u",v_qtd,read_eeprom(0x25));
}
else if ((g_pino_b6 && g_pino_d6) && (!g_flag_d6))
{ printf("\r\n Pino B6 e D6 acionado.");
g_flag_d6=1;
v_qtd = 1 + read_eeprom(0x26);
write_eeprom(0x26,v_qtd);
printf("\r\n Variavel:%u - Memoria:%u",v_qtd,read_eeprom(0x26));
}
else if(g_pino_b5)
{ // printf("\r\n Pino B5 acionado.");
g_flag_b7=0; g_flag_b6=0; g_flag_d7=0; g_flag_d6=0; }
}
} |
|
|
|
Joshua Lai
Joined: 19 Jul 2004 Posts: 42 Location: Malaysia, PJ
|
|
Posted: Mon Oct 03, 2005 11:50 pm |
|
|
What memory? You didn't include the eeprom driver? |
|
|
Jo�o Paulo
Joined: 03 Oct 2005 Posts: 2
|
|
Posted: Tue Oct 04, 2005 5:40 am |
|
|
I use the memory insede of PIC 16F877. I need to include the memory driver ? |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Tue Oct 04, 2005 6:29 am |
|
|
Jo�o Paulo wrote: | I use the memory insede of PIC 16F877. I need to include the memory driver ? |
No you don't need a memory driver. The function you called is built in.
Do you know what a for loop is? CCS places the write_eeprom() inline. You whole zero memory function is way too complicated versus what it needs to be.
Code: |
for(i=0x21;i<=0x60;i++)
write_eeprom(i,0);
|
Now in the above code, I am assuming that you made an error in that 0x30 does not come after 0x29. It should be 0x29,0x2A,0x2B....0x2F,0x30. |
|
|
|
|
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
|