Autor Tema: brujla CMPS03 con CSS y pic18f452  (Leído 1993 veces)

0 Usuarios y 2 Visitantes están viendo este tema.

Desconectado fabian12

  • PIC10
  • *
  • Mensajes: 5
brujla CMPS03 con CSS y pic18f452
« en: 28 de Noviembre de 2010, 06:58:24 »
Estimado AMIGOS, necesito vuestro apoyo te escribo desde peru , tengo problemas para sacar extraer la data de a brujulA DIGITAL CMPS03 con el compilador Css , les,, pego un codigo q halle en internet y no me funciona haber si me dan una mano del porque no me funciona ,yo uso 47k como resitencias de pull up , he visto q con este cogido usan 2.2l o 1.2k no se si este sea el problemaa espero tus comentarios,espero que alguno ya haya trabajado con esta brujula con csss
gracias de antemano por el apoyo,,

saludos de fabian12 (peru)

/////////////
#include <18F452>
#device adc=10

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       //High speed Osc (> 4mhz)
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOPROTECT                //Code not protected from reading
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES LVP               //Low Voltage Programming on B3(PIC16)or B5(PIC18)
#FUSES NOCPD                    //No EE protection
#FUSES NOWRT                    //Program memory not write protected
#FUSES NODEBUG                  //No Debug mode for ICD

#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#use i2c(Master,Fast,sda=PIN_C4,scl=PIN_C3)

long   read_compass()
{
   long   value;

   i2c_start();
   i2c_write( 0xC0 );   // The address of the compass (READ LOW)
   i2c_write( 0x02 );   // Command (read 360 degrees)

   i2c_start();         // Restart to change data dir
   i2c_write( 0xC1 );   // The address of the compass (READ HIGH)

   // Read 2 bytes (HI/LO) and combine into one LONG
   value = i2c_read() << 8;      // Read the HI value * 256
   value = value + i2c_read();   // Read the LO value and add it
   i2c_stop();

   return( value );
}

void main()
{
   long   heading;

   setup_adc_ports(AN0_AN1_AN2_AN3_AN4);
   setup_adc(ADC_CLOCK_INTERNAL);
   setup_psp(PSP_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);

   do
   {
      // Take a compass reading
      heading = read_compass();

      printf("%Lu\r\n", heading );
      delay_ms( 1000 );
   } while( TRUE );