Moderadores: andre_luis, 51, guest2003, Renie
u8 p_GetCRC(u8 *p_data, u8 len)
{
u8 u8_CRC = 0;
while (len--)
{
u8_CRC ^= *p_data++;
}
return (u8_CRC);
}
barboza escreveu:Como o pacote é pequeno e mencionou algo simples, é bem possível que seja só XOR entre os dados.
- Código: Selecionar todos
u8 p_GetCRC(u8 *p_data, u8 len)
{
u8 u8_CRC = 0;
while (len--)
{
u8_CRC ^= *p_data++;
}
return (u8_CRC);
}
/* Programa esteira sem sensor */
#include <16f873.H>
#include <stdlib.h>
//#fuses HS,PROTECT,WDT,PUT,BROWNOUT
#fuses HS,NOPROTECT,WDT,PUT,BROWNOUT,NOLVP
#define MAX_RAM_BAT 7
#use delay(clock=16000000)
#use RS232 (BAUD=19200,XMIT=PIN_C6,RCV=PIN_C7,RESTART_WDT,PARITY=N,BITS=8) //9600
#use i2c(master,sda=PIN_B6, scl=PIN_B7,slow)
#include <ds1307b.c>
#define sinal_saida PIN_A2
#define seguranca_ok PIN_A3
#define Sobe_inclinacao PIN_A5
#define Desce_inclinacao PIN_B1
#define pc_painel_I PIN_C0
#define pc_painel_II PIN_C1
#bit brown = 0x8e.0
#BIT TMR1IF=0x0C.0
#bit cren = 0x18.4 // Continuous recive bit
#bit ferr = 0x18.2 // Framing Error bit
#bit oerr = 0x18.1 // Overrun Error bit
#bit adden = 0x18.3
/*------------------------------- PROGRAMACAO ----------------------------------- */
#define DESCIDA_120 50 // tempo entre desaceleracao qdo a velocidade estiver acima de 12Km/h
#define SUBIDA 50 // tempo entre acelecacao
#define DESCIDA 50 // tempo entre a desaceleracao normal
#define MAX_PROGRAMAS 10 // numero de programas
#define MAX_ITENS 10 // numero de itens em cada programa
#define INVERSOR_85 // para 2 CV, colocar // na frente qdo for inversor de 3/4 ou 1 CV
#ifdef INVERSOR_85
#define MULTIPLICADOR 62 // 85Hz
#else
#define MULTIPLICADOR 53 // 100Hz
#endif
#define limite_vel 160 // limite de velocidade (Km/h)*10
#define vel_min 15 // velocidade minima (km/h)*10 em que o motor comece a girar */
void Manda_Pacote_PC();
void Manda_Pacote_Painel();
void Recebe_Pacote();
char timed_getc();
unsigned long calcrc(unsigned char *ptr, unsigned char count);
void Inicializa_Var_Recebe_Pacote();
struct Programa
{
unsigned byte Velocidade[MAX_ITENS];
unsigned byte Tempo[MAX_ITENS];
};
const struct Programa Programas[MAX_PROGRAMAS+1]=
{
{{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0}},
{{20,30,35,25,0,0,0,0,0,0},{6,12,18,24,30,36,42,48,54,60}},
{{20,30,40,35,0,0,0,0,0,0},{6,12,18,24,30,36,42,48,54,60}},
{{30,45,50,45,0,0,0,0,0,0},{6,12,18,24,30,36,42,48,54,60}},
{{40,45,50,55,0,0,0,0,0,0},{6,12,18,24,30,36,42,48,54,60}},
{{40,50,55,60,0,0,0,0,0,0},{6,12,18,24,30,36,42,48,54,60}},
{{45,55,65,50,0,0,0,0,0,0},{6,12,18,24,30,36,42,48,54,60}},
{{50,60,70,60,0,0,0,0,0,0},{6,12,18,24,30,36,42,48,54,60}},
{{55,65,80,90,0,0,0,0,0,0},{6,12,18,24,30,36,42,48,54,60}},
{{60,80,100,110,0,0,0,0,0,0},{6,12,18,24,30,36,42,48,54,60}},
{{60,90,100,110,0,0,0,0,0,0},{6,12,18,24,30,36,42,48,54,60}}
};
/*------------------------ FIM DA PROGRAMACAO ----------------------------------- */
byte J,k,l;
byte r,t;
long Cont_Centimetros;
long DISTANCIA_PERCORRIDA;
byte Velocidade_Requerida;
unsigned long Cont_Segundos_Parcial,Cont_Segundos_Parcial_O;
unsigned long Cont_Mili_Bat,Cont_Mili_Bat_Med,Cont_Mili_Bat_Mat[MAX_RAM_BAT+1];
byte buf_segundos;
float distancia_percorrida_calc; //,calc_aux;
unsigned long calc_aux, calc_periodo2, calc_aux_2;
byte I_M;
unsigned char SEGUNDOS,MINUTOS,HORAS_RTC,SEGUNDOS_RTC,MINUTOS_RTC;
float Velocidade;
byte Opcao,Opcao_Segundos;
float Caloria_Consumida;
unsigned byte Batimento_Cardiaco;
byte Segundos_C,Segundos_B;
byte Opcoes_Programa;
short Ativa_Prog;
short Automatico;
short saida_freq;
short muda_opcao;
unsigned long temp_dist;
short pressionada_anterior;
unsigned vel_prog;
unsigned long valor_calc;
byte indice;
byte buf_minuto;
unsigned int tempo_decorrido;
short em_programacao;
byte slave;
unsigned char NOVA_VELOCIDADE;
unsigned char NUMERO_PROGRAMA_ACERTO;
unsigned char LIGA_DESLIGA;
short Habilita_Esteira;
unsigned char temp,message;
short timeout_error;
unsigned char buffer[34];
unsigned char CRC16_H,CRC16_L;
long int CRC16_H_L;
unsigned char Mensagem_ou_Noticia;
byte Inclinacao_Desejada;
byte Inclinacao_Atual;
long int Split_Caloria;
void Oeer_f()
{
if(oerr)
{
cren=0;
cren=1;
adden=1;
}
}
void Painel()
{
OUTPUT_LOW(PC_PAINEL_I);
DELAY_ms(1);
Manda_Pacote_Painel();
DELAY_ms(1);
}
void Le_Hora()
{
HORAS_RTC=make_dec(read_ext_rtc(0x2));
MINUTOS_RTC=make_dec(read_ext_rtc(0x1));
}
void Putc_Basico()
{
putc(255);
putc(buffer[0]); // Slave
putc(buffer[1]); // Batimento_Cardiaco
putc(buffer[2]); // Caloria Consumida LSB
putc(buffer[3]); //Distancia_Percorrida
putc(buffer[4]); //Velocidade_Requerida
putc(buffer[5]); //Minutos
putc(buffer[6]); //Segundos
putc(buffer[7]); // Caloria Consumida MSB
putc(buffer[8]); //Opcoes_Programa
putc(buffer[9]); //Indice+1
putc(buffer[10]); //HORAS_RTC
putc(buffer[11]); //MINUTOS_RTC
}
void Buffer_Basico()
{
buffer[0]=slave;
buffer[1]=Batimento_Cardiaco;
split_caloria=Caloria_Consumida;
buffer[2]=split_caloria % 256; //8 bits menos significativos enviar
buffer[3]=Distancia_Percorrida;
buffer[4]=Velocidade_Requerida;
buffer[5]=Minutos;
buffer[6]=Segundos;
buffer[7]=split_caloria / 256; //8 bits mais significativos enviar
buffer[8]=Opcoes_Programa;
buffer[9]=Indice+1;
Le_Hora();
buffer[10]=HORAS_RTC;
buffer[11]=MINUTOS_RTC;
}
void Manda_Crc()
{
putc(CRC16_H_L/256); //CRC H
putc(CRC16_H_L%256); //CRC L
}
void Manda_Pacote_PC()
{
Buffer_Basico();
t=Buffer[12]; //salva
Buffer[12]=Read_Adc()/25;
CRC16_H_L=calcrc(buffer,13);
Putc_Basico();
putc(buffer[12]); //AD (inclinacao)
Manda_Crc();
Buffer[12]=t; //Restaura
}
void Manda_Pacote_Painel()
{
Buffer_Basico();
Buffer[32]=Mensagem_ou_Noticia;
Inclinacao_Atual=Read_Adc()/25;
Buffer[33]=Inclinacao_Atual;
CRC16_H_L=calcrc(buffer,34);
Putc_Basico();
for(t=12;t<=31;t++)
putc(buffer[t]);
putc(buffer[32]); //MENSAGEM OU NOTICIA
putc(buffer[33]); //AD
Manda_Crc();
}
void Zerando()
{
Distancia_Percorrida=0;
Caloria_Consumida=0.0;
distancia_percorrida_calc=0;
SEGUNDOS=0;
MINUTOS=0;
}
void Ve_Se_Zera_Dist_Ou_Calorias_ou_Programa()
{
if(!em_programacao)
{
if(INPUT(PIN_C4))
pressionada_anterior=1;
if(!INPUT(PIN_C4)) //RESET
{
if(INPUT(PIN_C5)) // NAO MOD
{
if(pressionada_anterior)
{
pressionada_anterior=0;
Ativa_Prog=0;
if(automatico)
{
Automatico=0;
Opcoes_Programa=0;
}
else
{
Zerando();
}
}
}
else
{
if(velocidade_requerida==0)
Ativa_Prog=1;
}
}
}
}
void Calcula_Velocidade()
{
if(velocidade_requerida>0)
calc_aux=VALOR_CALC/velocidade_requerida;
}
void Zera_Elementos_Tabela(void)
{
Cont_Mili_Bat_Mat[0]=0;
Cont_Mili_Bat_Mat[1]=0;
Cont_Mili_Bat_Mat[2]=0;
Cont_Mili_Bat_Mat[3]=0;
Cont_Mili_Bat_Mat[4]=0;
Cont_Mili_Bat_Mat[5]=0;
I_M=0;
}
void Calcula_Batimento()
{
if(SEGUNDOS_B>=3)
{
if(Cont_Mili_Bat>5000) // GRAMPO DESPRENDIDO
Zera_Elementos_Tabela();
Cont_Mili_Bat_Med=0;
for(J=1;J<=I_M;J++)
Cont_Mili_Bat_Med=Cont_Mili_Bat_Med+Cont_Mili_Bat_Mat[J];
Cont_Mili_Bat_Med=Cont_Mili_Bat_Med/I_M;
Batimento_Cardiaco = (float) 112000/((float) Cont_Mili_Bat_Med);
SEGUNDOS_B=0;
}
}
void Retira_Elemento_Tabela(void)
{
for(r=MAX_RAM_BAT-1;r>=2;r--)
Cont_Mili_Bat_Mat[r]=Cont_Mili_Bat_Mat[r-1];
}
#int_ext
void Batimento_Cardiaco_Interrupt()
{
if(Cont_Mili_Bat>170 && Cont_Mili_Bat<2000)
{
Retira_Elemento_Tabela();
Cont_Mili_Bat_Mat[1]=Cont_Mili_Bat;
I_M++;
if(I_M>MAX_RAM_BAT-1)
I_M=MAX_RAM_BAT-1;
}
Cont_Mili_Bat=0;
}
#int_timer1
void gera_freq()
{
set_timer1(65408);
calc_periodo2++;
if(velocidade_requerida>0 && input(seguranca_ok))
{
if(velocidade_requerida<50)
calc_aux_2=calc_aux;
if(calc_periodo2>calc_aux_2)
{
calc_periodo2=0;
if(calc_aux_2>calc_aux)
calc_aux_2--;
if(calc_aux_2<calc_aux)
calc_aux_2++;
if(saida_freq==1)
{
output_low(sinal_saida);
}
else
{
output_high(sinal_saida);
}
saida_freq=!saida_freq;
}
}
else
{
velocidade_requerida=0;
output_low(sinal_saida);
}
}
#int_timer2 //#int_rtcc
Timer_0_Interrupt()
{
Restart_wdt();
Cont_Mili_Bat++;
Cont_Segundos_Parcial++;
Cont_Segundos_Parcial_O++;
if(Cont_Segundos_Parcial_O==200)
{
//Acende_Leds();
if(INPUT(PIN_C5)==0 && em_programacao==0)
{
if(!(INPUT(PIN_C4)==0))
{
muda_opcao=1;
}
}
Cont_Segundos_Parcial_O=0;
Ve_Se_Zera_Dist_Ou_Calorias_ou_Programa();
}
if(input(seguranca_ok))
{
if(Cont_Segundos_Parcial>=1953)
{
Cont_Segundos_Parcial=0;
if(Opcao_Segundos)
Opcao_Segundos=Opcao_Segundos-1;
SEGUNDOS_B++;
if(velocidade_requerida>0)
{
SEGUNDOS++;
SEGUNDOS_C++;
if(SEGUNDOS==60)
{
MINUTOS++;
SEGUNDOS=0;
}
iF(MINUTOS==60)
MINUTOS=0;
}
}
}
}
void Zera_Parcial()
{
OPCAO=1;
Zerando();
Velocidade_Requerida=0;
pressionada_anterior=1;
Opcao_Segundos=10;
}
void Programas_Esteira()
{
Ativa_Prog=0;
em_programacao=1;
Opcoes_Programa=1;
DISABLE_INTERRUPTS(INT_TIMER1);
delay_ms(1500);
Painel(); //Para Já Avisar painel da Opcao Programas
while(1)
{
if(INPUT(PIN_C3)==0)
{
Opcoes_Programa++;
if(Opcoes_Programa>MAX_PROGRAMAS)
Opcoes_Programa=1;
delay_ms(200);
Painel();
}
if(INPUT(PIN_A1)==0)
{
if(Opcoes_Programa)
{
Opcoes_Programa--;
if(Opcoes_Programa==0)
Opcoes_Programa=MAX_PROGRAMAS;
}
else
opcoes_programa=MAX_PROGRAMAS;
delay_ms(200);
Painel();
}
if(INPUT(PIN_C5) && !INPUT(PIN_C4))
{
Zera_Parcial();
Automatico=0;
delay_ms(500);
ENABLE_INTERRUPTS(INT_TIMER1);
ENABLE_INTERRUPTS(GLOBAL);
opcoes_Programa=0;
indice=0;
em_programacao=0;
return;
}
if(!INPUT(PIN_C5)) //C4
{
Zera_Parcial();
Automatico=1;
buf_minuto=minutos;
tempo_decorrido=0;
vel_prog=Programas[Opcoes_Programa].Velocidade[0];
delay_ms(500);
indice=0;
em_programacao=0;
goto sai_Enable_Interrupt;
}
delay_ms(150);
Painel();
}
sai_Enable_Interrupt:
ENABLE_INTERRUPTS(INT_TIMER1);
ENABLE_INTERRUPTS(GLOBAL);
}
void Soma_Calorias_Consumidas()
{
if(Segundos_C>=5)
{
Caloria_Consumida=Caloria_Consumida+0.00868056 * (float) Velocidade_requerida;
Segundos_c=0;
}
}
void Zera_Parcial_II()
{
Automatico=0;
Velocidade_Requerida=0;
segundos=0;
vel_prog=0;
}
void Ativar_Piloto()
{
if(buf_minuto!=minutos)
{
buf_minuto=minutos;
if((++tempo_decorrido)>=Programas[Opcoes_Programa].tempo[indice])
{
if(++indice<MAX_ITENS)
{
vel_prog=Programas[Opcoes_Programa].Velocidade[indice];
if(vel_prog==0)
{
Zera_Parcial_II();
}
}
else
{
Zera_Parcial_II();
indice=0;
}
}
}
if(Velocidade_Requerida<vel_prog)
{
Velocidade_Requerida++;
delay_ms(SUBIDA);
}
if(Velocidade_Requerida>vel_prog)
{
Velocidade_Requerida--;
if(velocidade_requerida<120)
delay_ms(DESCIDA);
else
delay_ms(DESCIDA_120);
}
}
/* (Extracted from a document edited by Chuck Forsberg of
* Omen Technology in Portland, Oregon)
*
* This function calculates the CRC used by the XMODEM/CRC Protocol
* The first argument is a pointer to the message block.
* The second argument is the number of bytes in the message block.
* The function returns an integer which contains the CRC.
* The low order 16 bits are the coefficients of the CRC.
*/
unsigned long calcrc(unsigned char *ptr, unsigned char count)
{
unsigned long crc,temporario;
crc = 0;
for(k=1;k<=count;k++)
{
temporario=*ptr++ * 0x100;
crc = (crc ^ temporario);
for (l = 0; l <=7;l++)
{
if (crc & 0x8000)
{
crc = (( crc * 2) ^ 0x1021);
}
else
{
crc = ( crc * 2);
}
crc = crc & 0xFFFF;
}
}
return (crc & 0xFFFF);
}
void Acerta_Hora()
{
write_ext_rtc(0x0,SEGUNDOS_RTC);
write_ext_rtc(0x1,make_bcd(MINUTOS_RTC));
write_ext_rtc(0x2,make_bcd(HORAS_RTC));
}
main()
{
reseta:
if(RESTART_CAUSE()==NORMAL_POWER_UP)
{
Habilita_Esteira=1;
Inicializa_Var_Recebe_Pacote();
DISTANCIA_PERCORRIDA=0;
Velocidade=0;
Velocidade_Requerida=0;
Cont_Segundos_Parcial=0;
Cont_Segundos_Parcial_O=0;
MINUTOS=0;
Opcao=1;
Caloria_Consumida=0.0;
Batimento_Cardiaco=0;
Segundos_C=0;
Segundos_B=0;
Opcao_Segundos=0;
Cont_Mili_Bat=0;
Cont_Mili_Bat_Med=0;
I_M=0;
Opcoes_Programa=0;
Ativa_Prog=0;
Zera_Elementos_Tabela();
brown=1;
distancia_percorrida_calc=0;
Slave=0;
Inclinacao_Desejada=250;
}
SET_TRIS_B(0x01); //00000001
SET_TRIS_A(0x0B); //00001011
SET_TRIS_C(0xBA); //00111010
setup_adc_ports(RA0_ANALOG );
setup_adc(ADC_CLOCK_INTERNAL );
set_adc_channel(0);
PORT_B_PULLUPS(TRUE);
SETUP_TIMER_1(T1_INTERNAL | T1_DIV_BY_1);
SETUP_TIMER_2(T2_DIV_BY_4,127,4);
ENABLE_INTERRUPTS(GLOBAL);
ENABLE_INTERRUPTS(INT_TIMER1);
ENABLE_INTERRUPTS(INT_TIMER2);
ENABLE_INTERRUPTS(INT_EXT);
EXT_INT_EDGE(L_TO_H);
SET_RTCC(0);
SET_TIMER2(0);
brown=1;
buf_segundos=0;
muda_opcao=0;
em_programacao=0;
VALOR_CALC=limite_vel*MULTIPLICADOR;
OUTPUT_LOW(PC_PAINEL_I);
while(1)
{
if(brown==0)
goto reseta;
Calcula_Velocidade();
if(INPUT(PIN_A1)==0 && !Automatico && HABILITA_ESTEIRA)
{
if(!(Velocidade_Requerida==0) && !Automatico)
velocidade_Requerida--;
if(velocidade_requerida<=(vel_min-1))
velocidade_requerida=0;
if(velocidade_requerida<120)
delay_ms(DESCIDA);
else
delay_ms(DESCIDA_120);
Painel();
}
if(INPUT(PIN_C3)==0 && !Automatico && HABILITA_ESTEIRA)
{
if(!(Velocidade_Requerida==(limite_vel)))
Velocidade_Requerida++;
if(velocidade_requerida<=(vel_min-1) && velocidade_requerida>0)
velocidade_requerida=vel_min;
delay_ms(SUBIDA);
Painel();
}
Soma_Calorias_Consumidas();
if(segundos!=buf_segundos)
{
buf_segundos=segundos;
distancia_percorrida_calc=(float)distancia_percorrida_calc+(float)((float)velocidade_requerida/((float)3600));
temp_dist=distancia_percorrida_calc;
if(temp_dist>distancia_percorrida)
distancia_percorrida=temp_dist;
if(distancia_percorrida>999)
{
distancia_percorrida=0;
distancia_percorrida_calc=0;
}
}
Calcula_Batimento();
if(muda_opcao==1)
{
while(!input(pin_c5))
{
if(kbhit())
{
temp=getch();
Oeer_f();
}
}
Opcao++;
if(opcao>3)
opcao=1;
muda_opcao=0;
}
if(Ativa_Prog==1 && HABILITA_ESTEIRA)
Programas_Esteira();
if(Automatico==1)
Ativar_Piloto();
if(!(Inclinacao_Atual==250))
{
if(Inclinacao_Atual>Inclinacao_Desejada)
output_High(desce_inclinacao);
else
output_low(desce_inclinacao);
if(Inclinacao_Atual<Inclinacao_Desejada)
output_High(Sobe_inclinacao);
else
output_low(Sobe_inclinacao);
}
Recebe_Pacote();
}
}
char timed_getc() {
long timeout;
unsigned char car_temp;
timeout_error=FALSE;
timeout=0;
while(!kbhit()&&(++timeout<6250)) // 1/2 second //50000
{
delay_us(10);
if(!input(PIN_C3) || !input(PIN_A1))
break;
}
if(kbhit())
{
car_temp=getc();
Oeer_f();
return(car_temp);
}
else {
timeout_error=TRUE;
return(0);
}
}
void Inicializa_Var_Recebe_Pacote()
{
Automatico=0;
vel_prog=0;
indice=0;
segundos=0;
}
void Recebe_Pacote()
{
temp=timed_getc();
if(timeout_error==TRUE)
goto sai;
if(temp==255)
{
SLAVE=timed_getc();
buffer[0]=SLAVE;
if(timeout_error==TRUE)
goto sai;
if(SLAVE==1)
{
LIGA_DESLIGA=timed_getc(); //liga desliga //
buffer[1]=LIGA_DESLIGA;
if(timeout_error==TRUE)
goto sai;
NOVA_VELOCIDADE=timed_getc(); //nova velocidade
buffer[2]=NOVA_VELOCIDADE;
if(timeout_error==TRUE)
goto sai;
NUMERO_PROGRAMA_ACERTO=timed_getc(); //numero programa acerto
buffer[3]=NUMERO_PROGRAMA_ACERTO;
if(timeout_error==TRUE)
goto sai;
HORAS_RTC=timed_getc(); //numero programa acerto
buffer[4]=HORAS_RTC;
if(timeout_error==TRUE)
goto sai;
MINUTOS_RTC=timed_getc(); //numero programa acerto
buffer[5]=MINUTOS_RTC;
if(timeout_error==TRUE)
goto sai;
SEGUNDOS_RTC=timed_getc(); //numero programa acerto
buffer[6]=SEGUNDOS_RTC;
if(timeout_error==TRUE)
goto sai;
Mensagem_ou_Noticia=timed_getc(); //128=MENSAGEM //127=NOTICIA
buffer[7]=Mensagem_ou_Noticia;
if(timeout_error==TRUE)
goto sai;
Temp=timed_getc(); //Inclinacao
if(!(Temp==250))
Inclinacao_Desejada=Temp;
buffer[8]=Temp;
if(timeout_error==TRUE)
goto sai;
for(t=9;t<=31;t++) //descarta 4 bytes //FUTURAS IMPLEMENTAÇÓES // for(s=8;s<=11;s++)
{
buffer[t]=timed_getc();
if(timeout_error==TRUE)
goto sai;
}
//for(s=12;s<=31;s++) //mensagem for(s=12;s<=31;s++)
//{
// buffer[s]=timed_getc();
// if(timeout_error==TRUE)
// goto sai;
//}
CRC16_H=timed_getc(); //numero programa acerto
if(timeout_error==TRUE)
goto sai;
CRC16_L=timed_getc(); //numero programa acerto
if(timeout_error==TRUE)
goto sai;
CRC16_H_L=calcrc(buffer,32);
if(!(CRC16_H==(CRC16_H_L/256)) || !(CRC16_L==(CRC16_H_L%256)))
goto sai;
if(LIGA_DESLIGA==0x44) //0x44 = DESLIGA //0x55 = LIGA
{
Inicializa_Var_Recebe_Pacote();
Velocidade_Requerida=0;
Habilita_Esteira=0;
}
if(LIGA_DESLIGA==0x55) //0x44 = DESLIGA //0x55 = LIGA
Habilita_Esteira=1;
if(NOVA_VELOCIDADE<=160 && !(VELOCIDADE_REQUERIDA==NOVA_VELOCIDADE)) //NOVA_VELOCIDADE = 0 //FAZ NADA
{
Inicializa_Var_Recebe_Pacote();
Opcoes_Programa=0;
Velocidade_Requerida=NOVA_VELOCIDADE;
}
if((NUMERO_PROGRAMA_ACERTO>0 && NUMERO_PROGRAMA_ACERTO<=10) && !(OPCOES_PROGRAMA==NUMERO_PROGRAMA_ACERTO) )
{
OPCAO=1;
Zerando();
Velocidade_Requerida=0;
Automatico=1;
pressionada_anterior=1;
Opcao_Segundos=10;
buf_minuto=minutos;
tempo_decorrido=0;
Opcoes_Programa=NUMERO_PROGRAMA_ACERTO;
vel_prog=Programas[Opcoes_Programa].Velocidade[0];
indice=0;
delay_ms(500);
ENABLE_INTERRUPTS(INT_TIMER1);
ENABLE_INTERRUPTS(GLOBAL);
em_programacao=0;
}
if((HORAS_RTC<=23) && (MINUTOS_RTC<=59) && (SEGUNDOS_RTC<=59))
Acerta_Hora();
OUTPUT_HIGH(PC_PAINEL_I);
DELAY_ms(1);
Manda_Pacote_PC();
DELAY_ms(1);
}
}
sai:
Painel();
#asm
nop
#endasm
}
vtrx escreveu:Voce não poderia usar o check sum utilizado nos arquivos Intel hex?
É simples e eficaz.
fabim escreveu:vtrx escreveu:Voce não poderia usar o check sum utilizado nos arquivos Intel hex?
É simples e eficaz.
Sim, PODO sim, basta eu ter certeza se o que eu disse esta certo !!
char [16];
signed char *Ponteiro;
signed char CHKSUM8;
char cont;
Ponteiro = &char[0];
for(cont=0;cont<16;cont++){
Ponteiro = &char[cont];
CHKSUM8 += *Ponteiro;
}
CHKSUM8 = cheksum de 15 bytes !!!
Ai mando do post processor para o processor 17 bytes.
(DATA-16)+(CHKSUM8-1) !!
Ta certo isso ?
A pergunta é essa mesma, nunca usei CHKSUM de unha, só coisa pronta, que me deu dor de cabeça !! agora vou fazer o meu próprô !!
lellis escreveu:...pra mim checksum era só pra checar a soma dos bytes...
Usuários navegando neste fórum: Nenhum usuário registrado e 1 visitante