Ir ao conteúdo
  • Cadastre-se

Ajuda com pic16f877a


pramos65

Posts recomendados

Boa noite, estou começando a programar em c para controladores pic.

Através do MatheusLPS aqui do forum, tenho o código conforme link http://forum.clubedohardware.com.br/resolvido-relogio-ds1307/952470/2,

e preciso de dicas para gravar na eeprom do pic16f877a uma temperatura e 03 horários de acionamento de uma bomba.Ex: está fora da temperatura programada ? sim, está dentro dos horários programados? sim então aciona a bomba até atingir a temperatura ou o fim do horário programado.


#device adc=10 //Habilitar ADC de 10 bits, obrigatório. Pode
//ser utilizado de 8 bits também.
#FUSES NOWDT //No Watch Dog Timer
#FUSES XT //Clock <=4Mhz
#FUSES PUT //Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection

#use delay(clock=4000000)

#include <ds1307.c>
#include <lcd.c>

#define botao_incremento PIN_B0
#define botao_decremento PIN_B1

BYTE sec;
BYTE mim;
BYTE hrs;
BYTE day;
BYTE month;
BYTE yr;
BYTE dow;

int8 modo;
int16 adc;
float temperatura;

int8 tempo;

char dia_da_semana[7][8]=
{
"DOMINGO",
"SEGUNDA",
"TERCA",
"QUARTA",
"QUINTA",
"SEXTA",
"sábado",
};

#int_timer1
void trata_tempo()
{
tempo++;

if (tempo == 10)
{
output_toggle (PIN_B7);
tempo=0;
disable_interrupts( INT_TIMER1); //Habilita interrupção timer1
}
set_timer1 (3036);
}

#int_ccp1
void trata_ccp_1()
{
if ((modo == 0) && (tempo ==0))
{
output_toggle (PIN_B7);
enable_interrupts( INT_TIMER1); //Habilita interrupção timer1
set_timer1 (3036);
}
}

#int_ccp2
void trata_ccp_2()
{
modo++;
if (modo == 1)
{
disable_interrupts(INT_TIMER1); //Habilita interrupção timer1
output_high (PIN_b7);
}

if (modo > 7 )
{
modo = 0;
}

if (modo == 0 )
{
enable_interrupts( INT_TIMER1); //Habilita interrupção timer1
}
}

void main()
{
output_high (PIN_B7);
setup_ccp1(CCP_CAPTURE_RE);
setup_ccp2(CCP_CAPTURE_RE);
setup_timer_1 (T1_INTERNAL | T1_DIV_BY_8); //Configuração do Timer1 para clock interno = 1E6 dividido por 8
set_timer1 (3036); //Preload do Timer1

enable_interrupts( INT_TIMER1); //Habilita interrupção timer1
enable_interrupts (int_ccp1);
enable_interrupts (int_ccp2);
enable_interrupts (global);

setup_adc_ports(AN0); //Configura canal 0 analógico
setup_adc(ADC_CLOCK_INTERNAL); //De acordo com relógio interno.

set_adc_channel(0); //Habilita canal 0
delay_us(20); //Espera um pouco, obrigatório!

ds1307_init();
lcd_init();
modo = 0;

while(1)
{
switch (modo)
{
case 1:
{
if (input(BOTAO_INCREMENTO))
{
delay_ms (75);
hrs++;
}

if (input(BOTAO_DECREMENTO))
{
delay_ms (75);
hrs--;
}

if (hrs == 24 )
{
hrs = 0;
}

if (hrs == 255 )
{
hrs = 23;
}

printf(lcd_putc,"\fAjustar Hora:\n%u",hrs);
delay_ms (100);
break;
}

case 2:
{
if (input(BOTAO_INCREMENTO))
{
delay_ms (75);
mim++;
}

if (input(BOTAO_DECREMENTO))
{
delay_ms (75);
mim--;
}

if (mim == 60 )
{
mim = 0;
}

if (mim == 255 )
{
mim = 59;
}

printf(lcd_putc,"\fAjustar Minutos:\n%u",mim);
delay_ms (100);
break;
}

case 3:
{
if (input(BOTAO_INCREMENTO))
{
delay_ms (75);
sec++;
}

if (input(BOTAO_DECREMENTO))
{
delay_ms (75);
sec--;
}

if (sec == 60 )
{
sec = 0;
}

if (sec == 255 )
{
sec = 59;
}

printf(lcd_putc,"\fAjustar Segundos:\n%u",sec);
delay_ms (100);
break;
}

case 4:
{
if (input(BOTAO_INCREMENTO))
{
delay_ms (75);
day++;
}

if (input(BOTAO_DECREMENTO))
{
delay_ms (75);
day--;
}

if (day == 32 )
{
day = 1;
}

if (day == 0 )
{
day = 31;
}

printf(lcd_putc,"\fDia do Mes:\n%u",day);
delay_ms (100);
break;
}

case 5:
{
if (input(BOTAO_INCREMENTO))
{
delay_ms (75);
month++;
}

if (input(BOTAO_DECREMENTO))
{
delay_ms (75);
month--;
}

if (month == 13 )
{
month = 1;
}

if (month == 0 )
{
month = 12;
}

printf(lcd_putc,"\fAjustar Mes:\n%u",month);
delay_ms (100);
break;
}

case 6:
{
if (input(BOTAO_INCREMENTO))
{
delay_ms (75);
yr++;
}

if (input(BOTAO_DECREMENTO))
{
delay_ms (75);
yr--;
}

if (yr == 100 )
{
yr = 1;
}

if (yr == 0 )
{
yr = 99;
}

printf(lcd_putc,"\fAjustar Ano:\n%u",yr);
delay_ms (100);
break;
}

case 7:
{
if (input(BOTAO_INCREMENTO))
{
delay_ms (75);
dow++;
}

if (input(BOTAO_DECREMENTO))
{
delay_ms (75);
dow--;
}

if (dow > 7 )
{
dow = 1;
}

if (dow == 0)
{
dow = 7;
}

printf(lcd_putc,"\fDia da Semana:\n%s",dia_da_semana[dow-1]);
delay_ms (100);
ds1307_set_date_time(day,month,yr,dow,hrs,mim,sec);

break;
}

default:
{
adc = read_adc(); //Lê canal 0
temperatura = (5.0 * adc * 100) / 1024.0; //Conversão para tensão.


ds1307_get_date(day,month,yr,dow);
ds1307_get_time(hrs,mim,sec);

printf(lcd_putc,"\f%s %02d:\%02d:\%02d\n%02d/\%02d/\%02d %2.0f%cC",dia_da_semana[dow-1],hrs,mim,sec,day,month,yr,temperatura,0xdf);
delay_ms(1000);
}
}
}
}
#include <16F877A.h>

Desde já agradeço pela atenção recebida e fico no aguardo.

Link para o comentário
Compartilhar em outros sites

Hum......

Terei que fazer umas modificações nesse código para que o mesmo possa gravar na eeprom.

Só uma dica, quando for colar um código aqui no fórum, utilize as tags assim:

[/b][color=Blue]seu código aqui[/color][b][.code][/b]. Onde você substitui o . (ponto) por / (barra).

Falou

Link para o comentário
Compartilhar em outros sites

Bom, seguindo aquele mesmo tópico, com a ajuda do Matheus e do janascimento, fiz algumas modificações no código.

Além do acerto das horas e dia da semana, ele solicita a temperatura que desejo, hora e minuto de início de um evento e hora e minuto do final gravando essas informações na eeprom para o caso de falta de energia (não estou usando os minutos ainda, somente hora cheia).

O Matheus havia colocado uma rotina de temporização do backlight, mas eu a retirei por falta de espaço de memória do PIC.

Segue o código para melhor entendimento:


#include <16F877A.h>
#device adc=10 //Habilitar ADC de 10 bits, obrigatório. Pode
//ser utilizado de 8 bits também.
#FUSES NOWDT //No Watch Dog Timer
#FUSES XT //Clock <=4Mhz
#FUSES PUT //Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection

#use delay(clock=4000000)

#include <ds1307.c>
#include <lcd.c>

#define botao_incremento PIN_B0
#define botao_decremento PIN_B1
#define rele1 PIN_B6 //Rele da temperatura
#define rele2 PIN_B7 //Rele da luz

BYTE sec;
BYTE mim;
BYTE hrs;
BYTE day;
BYTE month;
BYTE yr;
BYTE dow;
BYTE mimini;
BYTE hrsini;
BYTE mimfim;
BYTE hrsfim;
BYTE temp_ideal;

int8 modo;
int16 adc;
float temperatura;

char dia_da_semana[7][8]=
{
"DOMINGO",
"SEGUNDA",
"TERCA",
"QUARTA",
"QUINTA",
"SEXTA",
"sábado",
};

#int_ccp2
void trata_ccp_2()
{
modo++;
if (modo > 12 )
{
modo = 0;
}
}

void main()
{
temp_ideal = 20;
setup_ccp2(CCP_CAPTURE_RE);
enable_interrupts (int_ccp2);
enable_interrupts (global);

setup_adc_ports(AN0); //Configura canal 0 analógico
setup_adc(ADC_CLOCK_INTERNAL); //De acordo com relógio interno.

set_adc_channel(0); //Habilita canal 0
delay_us(20); //Espera um pouco, obrigatório!

ds1307_init();
lcd_init();
modo = 0;

while(1)
{
switch (modo)
{
case 1:
{
if (input(BOTAO_INCREMENTO))
{
delay_ms (75);
hrs++;
}

if (input(BOTAO_DECREMENTO))
{
delay_ms (75);
hrs--;
}

if (hrs > 23 )
{
hrs = 0;
}

printf(lcd_putc,"\fAjustar Hora:\n%u",hrs);
delay_ms (100);
break;
}

case 2:
{
if (input(BOTAO_INCREMENTO))
{
delay_ms (75);
mim++;
}

if (input(BOTAO_DECREMENTO))
{
delay_ms (75);
mim--;
}

if (mim > 59 )
{
mim = 0;
}

printf(lcd_putc,"\fAjustar Minutos:\n%u",mim);
delay_ms (100);
break;
}

case 3:
{
if (input(BOTAO_INCREMENTO))
{
delay_ms (75);
sec++;
}

if (input(BOTAO_DECREMENTO))
{
delay_ms (75);
sec--;
}

if (sec > 59 )
{
sec = 0;
}

printf(lcd_putc,"\fAjustar Segundos:\n%u",sec);
delay_ms (100);
break;
}

case 4:
{
if (input(BOTAO_INCREMENTO))
{
delay_ms (75);
day++;
}

if (input(BOTAO_DECREMENTO))
{
delay_ms (75);
day--;
}

if (day > 31 )
{
day = 1;
}

if (day == 0 )
{
day = 31;
}

printf(lcd_putc,"\fDia do Mes:\n%u",day);
delay_ms (100);
break;
}

case 5:
{
if (input(BOTAO_INCREMENTO))
{
delay_ms (75);
month++;
}

if (input(BOTAO_DECREMENTO))
{
delay_ms (75);
month--;
}

if (month > 12 )
{
month = 1;
}

if (month == 0 )
{
month = 12;
}

printf(lcd_putc,"\fAjustar Mes:\n%u",month);
delay_ms (100);
break;
}

case 6:
{
if (input(BOTAO_INCREMENTO))
{
delay_ms (75);
yr++;
}

if (input(BOTAO_DECREMENTO))
{
delay_ms (75);
yr--;
}

if (yr > 99 )
{
yr = 1;
}

if (yr == 0 )
{
yr = 99;
}

printf(lcd_putc,"\fAjustar Ano:\n%u",yr);
delay_ms (100);
break;
}

case 7:
{
if (input(BOTAO_INCREMENTO))
{
delay_ms (75);
dow++;
}

if (input(BOTAO_DECREMENTO))
{
delay_ms (75);
dow--;
}

if (dow > 7 )
{
dow = 1;
}

if (dow == 0)
{
dow = 7;
}

printf(lcd_putc,"\fDia da Semana:\n%s",dia_da_semana[dow-1]);
delay_ms (100);
break;
}

case 8:
{
if (input(BOTAO_INCREMENTO))
{
delay_ms (75);
hrsini++;
}

if (input(BOTAO_DECREMENTO))
{
delay_ms (75);
hrsini--;
}

if (hrsini > 23 )
{
hrsini = 0;
}

printf(lcd_putc,"\fAj. Hr Inicio:\n%u",hrsini);
delay_ms (100);
break;
}

case 9:
{
if (input(BOTAO_INCREMENTO))
{
delay_ms (75);
mimini++;
}

if (input(BOTAO_DECREMENTO))
{
delay_ms (75);
mimini--;
}

if (mimini > 59 )
{
mimini = 0;
}

printf(lcd_putc,"\fAj. Min. Inicio:\n%u",mimini);
delay_ms (100);
break;
}

case 10:
{
if (input(BOTAO_INCREMENTO))
{
delay_ms (75);
hrsfim++;
}

if (input(BOTAO_DECREMENTO))
{
delay_ms (75);
hrsfim--;
}

if (hrsfim > 23 )
{
hrsfim = 0;
}

printf(lcd_putc,"\fAj. Hr Fim:\n%u",hrsfim);
delay_ms (100);
break;
}

case 11:
{
if (input(BOTAO_INCREMENTO))
{
delay_ms (75);
mimfim++;
}

if (input(BOTAO_DECREMENTO))
{
delay_ms (75);
mimfim--;
}

if (mimfim > 59 )
{
mimfim = 0;
}

printf(lcd_putc,"\fAj. Min. Fim:\n%u",mimfim);
delay_ms (100);

break;
}

case 12:
{
if (input(BOTAO_INCREMENTO))
{
delay_ms (75);
temp_ideal++;
}

if (input(BOTAO_DECREMENTO))
{
delay_ms (75);
temp_ideal--;
}

if (temp_ideal > 40 )
{
temp_ideal = 40;
}

printf(lcd_putc,"\fAj. Temperatura:\n%u",temp_ideal);
delay_ms (100);
write_eeprom (1, hrsini);
write_eeprom (2, mimini);
write_eeprom (3, hrsfim);
write_eeprom (4, mimfim);
write_eeprom (5, temp_ideal);
ds1307_set_date_time(day,month,yr,dow,hrs,mim,sec);
break;
}

default:
{
hrsini = read_eeprom(1);
mimini = read_eeprom(2);
hrsfim = read_eeprom(3);
mimfim = read_eeprom(4);
temp_ideal = read_eeprom(5);

adc = read_adc(); //Lê canal 0
temperatura = (5.0 * adc * 100) / 1024.0; //Conversão para tensão.


//ds1307_get_date(day,month,yr,dow);
ds1307_get_time(hrs,mim,sec);

printf(lcd_putc,"\fHorario:%02d:\%02d:\%02d\n Temp: \%2.0f\xDFC",hrs,mim,sec,temperatura);

If (temperatura < temp_ideal)
{
output_high(rele1);
}
If (temperatura > temp_ideal+1)
{
output_low(rele1);
}

If ((hrs >= hrsini) && (hrs < hrsfim))
{
output_high(rele2);
}
else
{
output_low(rele2);
}
delay_ms(500);
}
}
}
}


Está funcionando perfeito a uns tres dias (na protoboard), ainda sem ligação das luzes e do calefator, mas sei que funciona pelo clique do atracamento dos reles.

Nesse caso foi sorte, pois vou ter que acrescentar mais um rele, pois sendo a temperatura ideal para o aqua em torno dos 26ºC, mesmo sem ligar o calefator a água hoje chegou aos 28ºC (brasília é quente), então vou usar outro rele para acionar coolers que ficarão na tampa do aqua.

Link para o comentário
Compartilhar em outros sites

Bom, seguindo aquele mesmo tópico, com a ajuda do Matheus e do janascimento, fiz algumas modificações no código.

Além do acerto das horas e dia da semana, ele solicita a temperatura que desejo, hora e minuto de início de um evento e hora e minuto do final gravando essas informações na eeprom para o caso de falta de energia (não estou usando os minutos ainda, somente hora cheia).

O Matheus havia colocado uma rotina de temporização do backlight, mas eu a retirei por falta de espaço de memória do PIC.

Segue o código para melhor entendimento:


#include <16F877A.h>
#device adc=10 //Habilitar ADC de 10 bits, obrigatório. Pode
//ser utilizado de 8 bits também.
#FUSES NOWDT //No Watch Dog Timer
#FUSES XT //Clock <=4Mhz
#FUSES PUT //Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection

#use delay(clock=4000000)

#include <ds1307.c>
#include <lcd.c>

#define botao_incremento PIN_B0
#define botao_decremento PIN_B1
#define rele1 PIN_B6 //Rele da temperatura
#define rele2 PIN_B7 //Rele da luz

BYTE sec;
BYTE mim;
BYTE hrs;
BYTE day;
BYTE month;
BYTE yr;
BYTE dow;
BYTE mimini;
BYTE hrsini;
BYTE mimfim;
BYTE hrsfim;
BYTE temp_ideal;

int8 modo;
int16 adc;
float temperatura;

char dia_da_semana[7][8]=
{
"DOMINGO",
"SEGUNDA",
"TERCA",
"QUARTA",
"QUINTA",
"SEXTA",
"sábado",
};

#int_ccp2
void trata_ccp_2()
{
modo++;
if (modo > 12 )
{
modo = 0;
}
}

void main()
{
temp_ideal = 20;
setup_ccp2(CCP_CAPTURE_RE);
enable_interrupts (int_ccp2);
enable_interrupts (global);

setup_adc_ports(AN0); //Configura canal 0 analógico
setup_adc(ADC_CLOCK_INTERNAL); //De acordo com relógio interno.

set_adc_channel(0); //Habilita canal 0
delay_us(20); //Espera um pouco, obrigatório!

ds1307_init();
lcd_init();
modo = 0;

while(1)
{
switch (modo)
{
case 1:
{
if (input(BOTAO_INCREMENTO))
{
delay_ms (75);
hrs++;
}

if (input(BOTAO_DECREMENTO))
{
delay_ms (75);
hrs--;
}

if (hrs > 23 )
{
hrs = 0;
}

printf(lcd_putc,"\fAjustar Hora:\n%u",hrs);
delay_ms (100);
break;
}

case 2:
{
if (input(BOTAO_INCREMENTO))
{
delay_ms (75);
mim++;
}

if (input(BOTAO_DECREMENTO))
{
delay_ms (75);
mim--;
}

if (mim > 59 )
{
mim = 0;
}

printf(lcd_putc,"\fAjustar Minutos:\n%u",mim);
delay_ms (100);
break;
}

case 3:
{
if (input(BOTAO_INCREMENTO))
{
delay_ms (75);
sec++;
}

if (input(BOTAO_DECREMENTO))
{
delay_ms (75);
sec--;
}

if (sec > 59 )
{
sec = 0;
}

printf(lcd_putc,"\fAjustar Segundos:\n%u",sec);
delay_ms (100);
break;
}

case 4:
{
if (input(BOTAO_INCREMENTO))
{
delay_ms (75);
day++;
}

if (input(BOTAO_DECREMENTO))
{
delay_ms (75);
day--;
}

if (day > 31 )
{
day = 1;
}

if (day == 0 )
{
day = 31;
}

printf(lcd_putc,"\fDia do Mes:\n%u",day);
delay_ms (100);
break;
}

case 5:
{
if (input(BOTAO_INCREMENTO))
{
delay_ms (75);
month++;
}

if (input(BOTAO_DECREMENTO))
{
delay_ms (75);
month--;
}

if (month > 12 )
{
month = 1;
}

if (month == 0 )
{
month = 12;
}

printf(lcd_putc,"\fAjustar Mes:\n%u",month);
delay_ms (100);
break;
}

case 6:
{
if (input(BOTAO_INCREMENTO))
{
delay_ms (75);
yr++;
}

if (input(BOTAO_DECREMENTO))
{
delay_ms (75);
yr--;
}

if (yr > 99 )
{
yr = 1;
}

if (yr == 0 )
{
yr = 99;
}

printf(lcd_putc,"\fAjustar Ano:\n%u",yr);
delay_ms (100);
break;
}

case 7:
{
if (input(BOTAO_INCREMENTO))
{
delay_ms (75);
dow++;
}

if (input(BOTAO_DECREMENTO))
{
delay_ms (75);
dow--;
}

if (dow > 7 )
{
dow = 1;
}

if (dow == 0)
{
dow = 7;
}

printf(lcd_putc,"\fDia da Semana:\n%s",dia_da_semana[dow-1]);
delay_ms (100);
break;
}

case 8:
{
if (input(BOTAO_INCREMENTO))
{
delay_ms (75);
hrsini++;
}

if (input(BOTAO_DECREMENTO))
{
delay_ms (75);
hrsini--;
}

if (hrsini > 23 )
{
hrsini = 0;
}

printf(lcd_putc,"\fAj. Hr Inicio:\n%u",hrsini);
delay_ms (100);
break;
}

case 9:
{
if (input(BOTAO_INCREMENTO))
{
delay_ms (75);
mimini++;
}

if (input(BOTAO_DECREMENTO))
{
delay_ms (75);
mimini--;
}

if (mimini > 59 )
{
mimini = 0;
}

printf(lcd_putc,"\fAj. Min. Inicio:\n%u",mimini);
delay_ms (100);
break;
}

case 10:
{
if (input(BOTAO_INCREMENTO))
{
delay_ms (75);
hrsfim++;
}

if (input(BOTAO_DECREMENTO))
{
delay_ms (75);
hrsfim--;
}

if (hrsfim > 23 )
{
hrsfim = 0;
}

printf(lcd_putc,"\fAj. Hr Fim:\n%u",hrsfim);
delay_ms (100);
break;
}

case 11:
{
if (input(BOTAO_INCREMENTO))
{
delay_ms (75);
mimfim++;
}

if (input(BOTAO_DECREMENTO))
{
delay_ms (75);
mimfim--;
}

if (mimfim > 59 )
{
mimfim = 0;
}

printf(lcd_putc,"\fAj. Min. Fim:\n%u",mimfim);
delay_ms (100);

break;
}

case 12:
{
if (input(BOTAO_INCREMENTO))
{
delay_ms (75);
temp_ideal++;
}

if (input(BOTAO_DECREMENTO))
{
delay_ms (75);
temp_ideal--;
}

if (temp_ideal > 40 )
{
temp_ideal = 40;
}

printf(lcd_putc,"\fAj. Temperatura:\n%u",temp_ideal);
delay_ms (100);
write_eeprom (1, hrsini);
write_eeprom (2, mimini);
write_eeprom (3, hrsfim);
write_eeprom (4, mimfim);
write_eeprom (5, temp_ideal);
ds1307_set_date_time(day,month,yr,dow,hrs,mim,sec);
break;
}

default:
{
hrsini = read_eeprom(1);
mimini = read_eeprom(2);
hrsfim = read_eeprom(3);
mimfim = read_eeprom(4);
temp_ideal = read_eeprom(5);

adc = read_adc(); //Lê canal 0
temperatura = (5.0 * adc * 100) / 1024.0; //Conversão para tensão.


//ds1307_get_date(day,month,yr,dow);
ds1307_get_time(hrs,mim,sec);

printf(lcd_putc,"\fHorario:%02d:\%02d:\%02d\n Temp: \%2.0f\xDFC",hrs,mim,sec,temperatura);

If (temperatura < temp_ideal)
{
output_high(rele1);
}
If (temperatura > temp_ideal+1)
{
output_low(rele1);
}

If ((hrs >= hrsini) && (hrs < hrsfim))
{
output_high(rele2);
}
else
{
output_low(rele2);
}
delay_ms(500);
}
}
}
}


Está funcionando perfeito a uns tres dias (na protoboard), ainda sem ligação das luzes e do calefator, mas sei que funciona pelo clique do atracamento dos reles.

Nesse caso foi sorte, pois vou ter que acrescentar mais um rele, pois sendo a temperatura ideal para o aqua em torno dos 26ºC, mesmo sem ligar o calefator a água hoje chegou aos 28ºC (brasília é quente), então vou usar outro rele para acionar coolers que ficarão na tampa do aqua.

Obrigado pela ajuda Rick_DF, ajudou muito e MatheusLPS aguardo a tua ajuda tb.

Grato.

Link para o comentário
Compartilhar em outros sites

Quais outros macetes posso fazer pra economizar espaço no PIC?

Moderador se quiser mover o post fique a vontade, mas como se trata de algo generico e inerente a qualquer projeto com mcu PIC acho plausivel comentar aqui.

Respondendo a dúvida, existem algumas coisas que pode ser feitas para economizar memoria RAM do PIC:

- Evite o uso de variáveis globais, use realmente quando necessário, caso precise de uma variável que não aletera seu conteudo ao sair de uma função, prefira as variaveis locais do tipo static;

- Em vez de utilizar variaveis globais, prefira o uso de ponteiros e unioes de estruturas;

- Evitar o uso de variaveis tipo float, pois além de consumirem mais processamento, cada variavel dessa ocupa um bom espaço na RAM, caso precisa de resultados com numeros "quebrados" opte por fazer uma rotina decalculco com ponto binario usando um long.

esses são alguns dos macetes para economia de memoria RAM do PIC.

Abs.

Link para o comentário
Compartilhar em outros sites

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...

Ebook grátis: Aprenda a ler resistores e capacitores!

EBOOK GRÁTIS!

CLIQUE AQUI E BAIXE AGORA MESMO!