CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Bug in 18F4525 ?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Orcino



Joined: 07 Sep 2003
Posts: 56

View user's profile Send private message

Bug in 18F4525 ?
PostPosted: Tue Nov 06, 2007 10:28 am     Reply with quote

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;
 

  }

treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Tue Nov 06, 2007 11:35 am     Reply with quote

With a few debug changes ((and using 3.249)) I'm getting
Quote:
START

Valor 0 posicao 0
Valor 1 posicao 1
Valor 3 posicao 2
Valor 4 posicao 3
Valor 8 posicao 4
Valor 9 posicao 5
Valor 11 posicao 6
Valor 12 posicao 7
Valor 13 posicao 8
Valor 15 posicao 9
Valor 19 posicao 10
Valor 32 posicao 11
Valor 33 posicao 12
Valor 34 posicao 13
Valor 45 posicao 14
Valor 56 posicao 15
Valor 65 posicao 16
Valor 67 posicao 17
Valor 73 posicao 18
Valor 100 posicao 19


What are you expecting?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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