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 CCS Technical Support

hmc6352 help

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



Joined: 24 May 2011
Posts: 14

View user's profile Send private message

hmc6352 help
PostPosted: Wed Jun 08, 2011 12:23 pm     Reply with quote

Can anyone help me when I turn the compass 90 degrees the led will on ???
Seriously i need help here.
This is the coding from the forum. I done doing the compass part but to make led on when 90 degree still not achieved. Please.
Code:

#include <16F877A.H>
#fuses hs, no protect, nowdt, nolvp
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#use i2c(Master, sda=PIN_C4, scl=PIN_C3, FORCE_HW)
#define use_portb_lcd TRUE
#include <lcd.c>

#byte PORTa=5
#byte PORTb=6
#byte PORTc=7
#byte PORTd=8
#byte PORTe=9

#define SLAVE2_WRT_ADDR   0x14
#define SLAVE2_READ_ADDR  0x15

#define HMC6352_GET_DATA_COMMAND 0x41
#define HMC6352_I2C_WRITE_ADDRESS 0x42
#define HMC6352_I2C_READ_ADDRESS  0x43
#define HMC6352_I2C_UPDATE_ADDRESS  0x4F

void led();

//int16 heading();
// Read the compass heading.  This is in units
// of 1/10's of a degree, from 0 to 3599.
int16 HMC6352_read_heading(void)
{
int8 lsb;
int8 msb;

i2c_start();

i2c_write(HMC6352_I2C_WRITE_ADDRESS);

i2c_write(HMC6352_GET_DATA_COMMAND);
i2c_stop();

delay_ms(7);  // Allow 1 ms extra for safety

i2c_start();
i2c_write(HMC6352_I2C_READ_ADDRESS);
msb = i2c_read();
lsb = i2c_read(0);
i2c_stop();

return((msb*256)+lsb);
}

void led

if
//===================================
void main()
{

int16 heading;
set_tris_d(0x00);
set_tris_b(0x00);
lcd_init();

while(1)
  {

   heading = HMC6352_read_heading();





      lcd_gotoxy(1,1);
      lcd_putc("                     ");
      delay_ms(200);

      lcd_gotoxy(1,1);
      printf(lcd_putc,"Degrees is %lu\n\r",heading/10);

       //turn left
       //loop
       //dalam loop kena check
       //if heading/10 >90//stop motor

   delay_ms(500);

  }

}



What I need to declare and which statement I need to use ?? Teach me Sad Sad
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 08, 2011 1:21 pm     Reply with quote

If you want to turn on an LED if the heading is at least 90 degrees, then
do something like this:
Code:

while(1)
  {
   heading = HMC6352_read_heading(); 

   heading = heading /10;  // Get heading in degrees from 0 to 359

  if(heading >= 90)   // Is heading from 90 to 359 ?
     output_high(PIN_B0);  // If so, turn on LED
  else
     output_low(PIN_B0);  // If not, turn off LED
 }
autova



Joined: 24 May 2011
Posts: 14

View user's profile Send private message

PostPosted: Wed Jun 08, 2011 1:33 pm     Reply with quote

so , i don't need to declare anything else ?

one more thing . are the code effect my lcd output ?
autova



Joined: 24 May 2011
Posts: 14

View user's profile Send private message

PostPosted: Wed Jun 08, 2011 2:14 pm     Reply with quote

i already test the code but what happen is the led on when i push the on switch .

what actually happen ? i really confuse here :(
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