Orcino
Joined: 07 Sep 2003 Posts: 56
|
Bug in 18F4525 ? |
Posted: Tue Nov 06, 2007 10:28 am |
|
|
Hi, i have a problem with the small prg for test, in 18F452 work right, but in 18F4525 not work right, see below
Code: |
// #include <18F452.h>
#include <18F4525.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //Reset when brownout detected
#FUSES PUT //Power Up Timer
#use delay(clock = 20 Mhz)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
//*****************************************************************************
struct SGPSCoord
{
int buffer_latitude;
int buffer_longetude;
int distancia;
int ponto;
int status;
int flag_lido;
};
struct SGPSCoord GPSCOORD[100];
//******************************************************************************
// Funções
//******************************************************************************
void InverteElementos(struct SGPSCoord *pCoordenadas, int nE1, int nE2 );
void BubbleSort( int nQtdElementos, struct SGPSCoord *pCoordenadas );
void preenche_estrutura(void);
void mostra(void);
void calcula_distancias_ordena(void);
//******************************************************************************
void main()
{
int cont1;
preenche_estrutura();
BubbleSort(20,GPSCOORD);
for(cont1=0;cont1 < 20 ; cont1++)
{
printf("\nValor %u posicao %u\r",GPSCOORD[cont1].distancia, cont1 );
}
while(1)
{ }
}
//******************************************************************************
// Ordenação
//******************************************************************************
void BubbleSort( int nQtdElementos, struct SGPSCoord *pCoordenadas )
{
int nBase, nCursor;
for( nBase = 0; nBase < nQtdElementos - 1; ++nBase )
{
for( nCursor = nBase + 1; nCursor < nQtdElementos; ++nCursor )
{
if( pCoordenadas[ nBase ].distancia > pCoordenadas[nCursor ].distancia )
InverteElementos( pCoordenadas, nBase, nCursor );
}
}
}
//******************************************************************************
// SWAP
//******************************************************************************
void InverteElementos(struct SGPSCoord *pCoordenadas, int nE1, int nE2 )
{
struct SGPSCoord sTemp;
memcpy( &sTemp, &pCoordenadas[ nE1 ], sizeof( sTemp ));
memcpy( &pCoordenadas[ nE1 ], &pCoordenadas[ nE2 ], sizeof( sTemp ));
memcpy( &pCoordenadas[ nE2 ], &sTemp, sizeof( sTemp ));
}
//******************************************************************************
// Test
//******************************************************************************
void preenche_estrutura(void)
{
GPSCOORD[0].distancia = 12;
GPSCOORD[1].distancia = 33;
GPSCOORD[2].distancia = 32;
GPSCOORD[3].distancia = 45;
GPSCOORD[4].distancia = 67;
GPSCOORD[5].distancia = 34;
GPSCOORD[6].distancia = 65;
GPSCOORD[7].distancia = 73;
GPSCOORD[8].distancia = 56;
GPSCOORD[9].distancia = 19;
GPSCOORD[10].distancia = 0;
GPSCOORD[11].distancia = 1;
GPSCOORD[12].distancia = 4;
GPSCOORD[13].distancia = 8;
GPSCOORD[14].distancia = 9;
GPSCOORD[15].distancia = 3;
GPSCOORD[16].distancia = 11;
GPSCOORD[17].distancia = 13;
GPSCOORD[18].distancia = 15;
GPSCOORD[19].distancia = 100;
}
|
|
|