Hi Julio,
You can find the C source code for an e-compass on http://www.nxp.com/products/sensors/magnetometers/nxp-e-compass-software:E-Compass, this e-compass software includes a tilt-compensated e-compass and the Hard and Soft Iron calibration, it’s meant to be used with both, accelerometer and magnetometer, but the real thing that you need right now it’s just the compass algorithms.
To download this e-compass software, you must click on “Downloads” button and download the “Sensor Fusion Library.exe”, a “.zip” file would be downloaded when you run it. In the link, you can also find detailed documentation such as datasheets, user guides, application notes, etc.
Hope that info helps,
Darío