2 Replies - 24636 Views - Last Post: 02 March 2006 - 10:34 AM Rate Topic: -----

#1 strifenl  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 01-March 06

PIC 16F877 - Tilt Sensor - Convert Hex to Decimal

Posted 01 March 2006 - 01:27 PM

Hi, I'm new to C programming, but have a slight background knowledge of C++. I'm trying to create a program used by a PIC 16F877 microcontroller that would receive information from a tilt sensor and display it on a screen. So far I am able to get the hexadecimal value to display and change as the sensor tilts, but I'm having trouble converting the hex numbers to decimal for easier reading. I don't know where to start with the conversion. Another problem is the way the angles of the tilt is measured. 00 in hex is -45 in decimal and FF is +45. Any help you could provide would be great.

:huh:

#include <16F877.h>
#include <STDLIB.h>
#fuses HS,NOWDT,NOPROTECT,NOPUT,NOBROWNOUT
#use delay(clock = 19660800)
#use rs232 (baud=19200, xmit=PIN_C6, rcv=PIN_C7, Parity=N, Bits=8)

void main()
{
      int roll;
      delay_us(10);

while(1)
   {
     delay_ms(50);
     printf("1");                   //sends a 1 to the Tilt sensor 
     gets(roll);                    //receives X-axis data from Tilt sensor
     putc(254);                   //sends a command to LCD display
     putc(88);                     //clears the LCD display
     delay_us(250);
     printf(roll);                  //displays angle (in hex) in LCD display
     delay_ms(500);

}
}

This post has been edited by skyhawk133: 02 March 2006 - 11:49 AM


Is This A Good Question/Topic? 0
  • +

Replies To: PIC 16F877 - Tilt Sensor - Convert Hex to Decimal

#2 dec1pher  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 116
  • Joined: 27-January 06

Re: PIC 16F877 - Tilt Sensor - Convert Hex to Decimal

Posted 01 March 2006 - 02:21 PM

replace this line
printf(roll);



with this line
 printf("%d", roll);



i dunno if it's ok for an lcd display or not but for C it must work :)

This post has been edited by dec1pher: 01 March 2006 - 02:21 PM

Was This Post Helpful? 0
  • +
  • -

#3 strifenl  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 01-March 06

Re: PIC 16F877 - Tilt Sensor - Convert Hex to Decimal

Posted 02 March 2006 - 10:34 AM

the code worked, however I'm running into the same problem when I tried to put a statement "The Roll is " before the outputed value. The program will run through and output the value only once. It won't continuously cycle through the program updated the value.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1