Problem with comparison.
/Modules/Sensors/MAG01A/SW/PIC16F887/main.c
0,0 → 1,71
#include "main.h"
#include "HMC5883L.h"
#include <math.h>
 
void main()
{
float last,b,anemo_speed;
unsigned int16 anemo_round=0;
unsigned int16 i;
 
 
//signed int16 X,Y,Z;
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_2);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_ccp1(CCP_OFF);
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
 
// Init the HMC5883L. Set Mode register for
// continuous measurements.
hmc5883l_write_reg(HMC5883L_CFG_A_REG, 0x18); // no average, maximal update range
hmc5883l_write_reg(HMC5883L_CFG_B_REG, 0xE0); // maximal range
hmc5883l_write_reg(HMC5883L_MODE_REG, 0x00);
 
// Continuously read and display the x,y,z results.
// Wait at least 67 ms between reads, re the HMC5883L data sheet.
 
 
printf("Magnetometr: \r\n",);
printf("(c)mlab JACHO 2013: \r\n",);
printf("X, Y, Z \r\n",);
 
/* while(true)
{
X = mag_readX();
Y = mag_readY();
Z = mag_readZ();
printf("%4Ld %4Ld %4Ld \r\n", X, Y, Z);
Delay_ms(50);
}
*/
 
while(TRUE)
{
 
// for(i=0;i<=10;i++)
// {
hmc5883l_read_data();
// b = atan2((float)compass.y,(float)compass.x); // vypocet azimutu z kartezskych souradnic
// b = (b/3.141596)*180; // prevod na stupne
// b += 180;
 
// anemo_speed += (b-last);
// last=b;
// delay_ms(10);
// }
// anemo_speed=anemo_speed/10;
 
printf("%6Ld %6Ld %6Ld \n\r", compass.x, compass.y, compass.z);
// delay_ms(100);
}
 
}
 
 
 
/Modules/Sensors/MAG01A/SW/PIC16F887/main.cof
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/Modules/Sensors/MAG01A/SW/PIC16F887/main.err
0,0 → 1,7
>>> Warning 202 "main.c" Line 7(7,11): Variable never used: last
>>> Warning 202 "main.c" Line 7(12,13): Variable never used: b
>>> Warning 202 "main.c" Line 7(14,25): Variable never used: anemo_speed
>>> Warning 202 "main.c" Line 8(16,27): Variable never used: anemo_round
>>> Warning 202 "main.c" Line 9(16,17): Variable never used: i
Memory usage: ROM=9% RAM=8% - 10%
0 Errors, 5 Warnings.
/Modules/Sensors/MAG01A/SW/PIC16F887/main.esym
0,0 → 1,610
C L "MAIN" 0 20 1 "FUNCTION"
D G "__PCM__" 0 73 ""4.106""
D G "__DEVICE__" 0 73 "887"
D G "__DATE__" 0 73 ""15-V-13""
D G "__TIME__" 0 73 ""20:34:15"" "Standard Header file for the PIC16F887 device ////////////////"
d G "PIN_A0" 2 20 "40"
d G "PIN_A1" 2 21 "41"
d G "PIN_A2" 2 22 "42"
d G "PIN_A3" 2 23 "43"
d G "PIN_A4" 2 24 "44"
d G "PIN_A5" 2 25 "45"
d G "PIN_A6" 2 26 "46"
d G "PIN_A7" 2 27 "47"
d G "PIN_B0" 2 29 "48"
d G "PIN_B1" 2 30 "49"
d G "PIN_B2" 2 31 "50"
d G "PIN_B3" 2 32 "51"
d G "PIN_B4" 2 33 "52"
d G "PIN_B5" 2 34 "53"
d G "PIN_B6" 2 35 "54"
d G "PIN_B7" 2 36 "55"
d G "PIN_C0" 2 38 "56"
d G "PIN_C1" 2 39 "57"
d G "PIN_C2" 2 40 "58"
d G "PIN_C3" 2 41 "59"
d G "PIN_C4" 2 42 "60"
d G "PIN_C5" 2 43 "61"
d G "PIN_C6" 2 44 "62"
d G "PIN_C7" 2 45 "63"
d G "PIN_D0" 2 47 "64"
d G "PIN_D1" 2 48 "65"
d G "PIN_D2" 2 49 "66"
d G "PIN_D3" 2 50 "67"
d G "PIN_D4" 2 51 "68"
d G "PIN_D5" 2 52 "69"
d G "PIN_D6" 2 53 "70"
d G "PIN_D7" 2 54 "71"
d G "PIN_E0" 2 56 "72"
d G "PIN_E1" 2 57 "73"
d G "PIN_E2" 2 58 "74"
d G "PIN_E3" 2 59 "75"
d G "FALSE" 2 62 "0"
d G "TRUE" 2 63 "1"
d G "BYTE" 2 65 "int8"
d G "BOOLEAN" 2 66 "int1"
d G "getc" 2 68 "getch"
d G "fgetc" 2 69 "getch"
d G "getchar" 2 70 "getch"
d G "putc" 2 71 "putchar"
d G "fputc" 2 72 "putchar"
d G "fgets" 2 73 "gets"
d G "fputs" 2 74 "puts"
d G "WDT_FROM_SLEEP" 2 79 "3"
d G "WDT_TIMEOUT" 2 80 "11"
d G "MCLR_FROM_SLEEP" 2 81 "19"
d G "MCLR_FROM_RUN" 2 82 "27"
d G "NORMAL_POWER_UP" 2 83 "25"
d G "BROWNOUT_RESTART" 2 84 "26"
d G "T0_INTERNAL" 2 91 "0"
d G "T0_EXT_L_TO_H" 2 92 "32"
d G "T0_EXT_H_TO_L" 2 93 "48"
d G "T0_DIV_1" 2 95 "8"
d G "T0_DIV_2" 2 96 "0"
d G "T0_DIV_4" 2 97 "1"
d G "T0_DIV_8" 2 98 "2"
d G "T0_DIV_16" 2 99 "3"
d G "T0_DIV_32" 2 100 "4"
d G "T0_DIV_64" 2 101 "5"
d G "T0_DIV_128" 2 102 "6"
d G "T0_DIV_256" 2 103 "7"
d G "T0_8_BIT" 2 106 "0"
d G "RTCC_INTERNAL" 2 108 "0" "The following are provided for compatibility"
d G "RTCC_EXT_L_TO_H" 2 109 "32" "with older compiler versions"
d G "RTCC_EXT_H_TO_L" 2 110 "48"
d G "RTCC_DIV_1" 2 111 "8"
d G "RTCC_DIV_2" 2 112 "0"
d G "RTCC_DIV_4" 2 113 "1"
d G "RTCC_DIV_8" 2 114 "2"
d G "RTCC_DIV_16" 2 115 "3"
d G "RTCC_DIV_32" 2 116 "4"
d G "RTCC_DIV_64" 2 117 "5"
d G "RTCC_DIV_128" 2 118 "6"
d G "RTCC_DIV_256" 2 119 "7"
d G "RTCC_8_BIT" 2 120 "0"
d G "WDT_18MS" 2 132 "8"
d G "WDT_36MS" 2 133 "9"
d G "WDT_72MS" 2 134 "10"
d G "WDT_144MS" 2 135 "11"
d G "WDT_288MS" 2 136 "12"
d G "WDT_576MS" 2 137 "13"
d G "WDT_1152MS" 2 138 "14"
d G "WDT_2304MS" 2 139 "15"
d G "WDT_ON" 2 143 "0x4100"
d G "WDT_OFF" 2 144 "0"
d G "WDT_DIV_16" 2 145 "0x100"
d G "WDT_DIV_8" 2 146 "0x300"
d G "WDT_DIV_4" 2 147 "0x500"
d G "WDT_DIV_2" 2 148 "0x700"
d G "WDT_TIMES_1" 2 149 "0x900" "Default"
d G "WDT_TIMES_2" 2 150 "0xB00"
d G "WDT_TIMES_4" 2 151 "0xD00"
d G "WDT_TIMES_8" 2 152 "0xF00"
d G "WDT_TIMES_16" 2 153 "0x1100"
d G "WDT_TIMES_32" 2 154 "0x1300"
d G "WDT_TIMES_64" 2 155 "0x1500"
d G "WDT_TIMES_128" 2 156 "0x1700"
d G "T1_DISABLED" 2 162 "0"
d G "T1_INTERNAL" 2 163 "5"
d G "T1_EXTERNAL" 2 164 "7"
d G "T1_EXTERNAL_SYNC" 2 165 "3"
d G "T1_CLK_OUT" 2 167 "8"
d G "T1_DIV_BY_1" 2 169 "0"
d G "T1_DIV_BY_2" 2 170 "0x10"
d G "T1_DIV_BY_4" 2 171 "0x20"
d G "T1_DIV_BY_8" 2 172 "0x30"
d G "T1_GATE" 2 174 "0x40"
d G "T1_GATE_INVERTED" 2 175 "0xC0"
d G "T2_DISABLED" 2 180 "0"
d G "T2_DIV_BY_1" 2 181 "4"
d G "T2_DIV_BY_4" 2 182 "5"
d G "T2_DIV_BY_16" 2 183 "6"
d G "CCP_OFF" 2 189 "0"
d G "CCP_CAPTURE_FE" 2 190 "4"
d G "CCP_CAPTURE_RE" 2 191 "5"
d G "CCP_CAPTURE_DIV_4" 2 192 "6"
d G "CCP_CAPTURE_DIV_16" 2 193 "7"
d G "CCP_COMPARE_SET_ON_MATCH" 2 194 "8"
d G "CCP_COMPARE_CLR_ON_MATCH" 2 195 "9"
d G "CCP_COMPARE_INT" 2 196 "0xA"
d G "CCP_COMPARE_RESET_TIMER" 2 197 "0xB"
d G "CCP_PWM" 2 198 "0xC"
d G "CCP_PWM_PLUS_1" 2 199 "0x1c"
d G "CCP_PWM_PLUS_2" 2 200 "0x2c"
d G "CCP_PWM_PLUS_3" 2 201 "0x3c"
d G "CCP_PWM_H_H" 2 206 "0x0c"
d G "CCP_PWM_H_L" 2 207 "0x0d"
d G "CCP_PWM_L_H" 2 208 "0x0e"
d G "CCP_PWM_L_L" 2 209 "0x0f"
d G "CCP_PWM_FULL_BRIDGE" 2 211 "0x40"
d G "CCP_PWM_FULL_BRIDGE_REV" 2 212 "0xC0"
d G "CCP_PWM_HALF_BRIDGE" 2 213 "0x80"
d G "CCP_SHUTDOWN_ON_COMP1" 2 215 "0x100000"
d G "CCP_SHUTDOWN_ON_COMP2" 2 216 "0x200000"
d G "CCP_SHUTDOWN_ON_COMP" 2 217 "0x300000"
d G "CCP_SHUTDOWN_ON_INT0" 2 218 "0x400000"
d G "CCP_SHUTDOWN_ON_COMP1_INT0" 2 219 "0x500000"
d G "CCP_SHUTDOWN_ON_COMP2_INT0" 2 220 "0x600000"
d G "CCP_SHUTDOWN_ON_COMP_INT0" 2 221 "0x700000"
d G "CCP_SHUTDOWN_AC_L" 2 223 "0x000000"
d G "CCP_SHUTDOWN_AC_H" 2 224 "0x040000"
d G "CCP_SHUTDOWN_AC_F" 2 225 "0x080000"
d G "CCP_SHUTDOWN_BD_L" 2 227 "0x000000"
d G "CCP_SHUTDOWN_BD_H" 2 228 "0x010000"
d G "CCP_SHUTDOWN_BD_F" 2 229 "0x020000"
d G "CCP_SHUTDOWN_RESTART" 2 231 "0x80000000"
d G "CCP_PULSE_STEERING_A" 2 233 "0x01000000"
d G "CCP_PULSE_STEERING_B" 2 234 "0x02000000"
d G "CCP_PULSE_STEERING_C" 2 235 "0x04000000"
d G "CCP_PULSE_STEERING_D" 2 236 "0x08000000"
d G "CCP_PULSE_STEERING_SYNC" 2 237 "0x10000000"
d G "SPI_MASTER" 2 245 "0x20"
d G "SPI_SLAVE" 2 246 "0x24"
d G "SPI_L_TO_H" 2 247 "0"
d G "SPI_H_TO_L" 2 248 "0x10"
d G "SPI_CLK_DIV_4" 2 249 "0"
d G "SPI_CLK_DIV_16" 2 250 "1"
d G "SPI_CLK_DIV_64" 2 251 "2"
d G "SPI_CLK_T2" 2 252 "3"
d G "SPI_SS_DISABLED" 2 253 "1"
d G "SPI_SAMPLE_AT_END" 2 255 "0x8000"
d G "SPI_XMIT_L_TO_H" 2 256 "0x4000"
d G "UART_ADDRESS" 2 262 "2"
d G "UART_DATA" 2 263 "4"
d G "UART_AUTODETECT" 2 264 "8"
d G "UART_AUTODETECT_NOWAIT" 2 265 "9"
d G "UART_WAKEUP_ON_RDA" 2 266 "10"
d G "UART_SEND_BREAK" 2 267 "13"
d G "NC_NC_NC_NC" 2 273 "0x00"
d G "NC_NC" 2 274 "0x00"
d G "CP1_A0_A3" 2 277 "0x00090080"
d G "CP1_A1_A3" 2 278 "0x000A0081"
d G "CP1_B3_A3" 2 279 "0x00880082"
d G "CP1_B1_A3" 2 280 "0x00280083"
d G "CP1_A0_VREF" 2 281 "0x00010084"
d G "CP1_A1_VREF" 2 282 "0x00020085"
d G "CP1_B3_VREF" 2 283 "0x00800086"
d G "CP1_B1_VREF" 2 284 "0x00200087"
d G "CP1_OUT_ON_A4" 2 286 "0x00000020"
d G "CP1_INVERT" 2 287 "0x00000010"
d G "CP1_ABSOLUTE_VREF" 2 288 "0x20000000"
d G "CP2_A0_A2" 2 291 "0x00058000"
d G "CP2_A1_A2" 2 292 "0x00068100"
d G "CP2_B3_A2" 2 293 "0x00848200"
d G "CP2_B1_A2" 2 294 "0x00248300"
d G "CP2_A0_VREF" 2 295 "0x00018400"
d G "CP2_A1_VREF" 2 296 "0x00028500"
d G "CP2_B3_VREF" 2 297 "0x00808600"
d G "CP2_B1_VREF" 2 298 "0x00208700"
d G "CP2_OUT_ON_A5" 2 300 "0x00002000"
d G "CP2_INVERT" 2 301 "0x00001000"
d G "CP2_ABSOLUTE_VREF" 2 302 "0x10000000"
d G "CP2_T1_SYNC" 2 305 "0x01000000"
d G "CP2_T1_GATE" 2 306 "0x02000000"
d G "VREF_LOW" 2 315 "0xa0"
d G "VREF_HIGH" 2 316 "0x80"
d G "OSC_31KHZ" 2 322 "1"
d G "OSC_125KHZ" 2 323 "0x11"
d G "OSC_250KHZ" 2 324 "0x21"
d G "OSC_500KHZ" 2 325 "0x31"
d G "OSC_1MHZ" 2 326 "0x41"
d G "OSC_2MHZ" 2 327 "0x51"
d G "OSC_4MHZ" 2 328 "0x61"
d G "OSC_8MHZ" 2 329 "0x71"
d G "OSC_INTRC" 2 330 "1"
d G "OSC_NORMAL" 2 331 "0"
d G "OSC_STATE_STABLE" 2 333 "4"
d G "OSC_31KHZ_STABLE" 2 334 "2"
d G "ADC_OFF" 2 342 "0" "ADC Off"
d G "ADC_CLOCK_DIV_2" 2 343 "0x100"
d G "ADC_CLOCK_DIV_8" 2 344 "0x40"
d G "ADC_CLOCK_DIV_32" 2 345 "0x80"
d G "ADC_CLOCK_INTERNAL" 2 346 "0xc0" "Internal 2-6us"
d G "sAN0" 2 350 "1" "| A0"
d G "sAN1" 2 351 "2" "| A1"
d G "sAN2" 2 352 "4" "| A2"
d G "sAN3" 2 353 "8" "| A3"
d G "sAN4" 2 354 "16" "| A5"
d G "sAN5" 2 355 "32" "| E0"
d G "sAN6" 2 356 "64" "| E1"
d G "sAN7" 2 357 "128" "| E2"
d G "sAN8" 2 358 "0x10000" "| B2"
d G "sAN9" 2 359 "0x20000" "| B3"
d G "sAN10" 2 360 "0x40000" "| B1"
d G "sAN11" 2 361 "0x80000" "| B4"
d G "sAN12" 2 362 "0x100000" "| B0"
d G "sAN13" 2 363 "0x200000" "| B5"
d G "NO_ANALOGS" 2 364 "0" "None"
d G "ALL_ANALOG" 2 365 "0x1F00FF" "A0 A1 A2 A3 A5 E0 E1 E2 B0 B1 B2 B3 B4 B5"
d G "VSS_VDD" 2 368 "0x0000" "| Range 0-Vdd"
d G "VSS_VREF" 2 369 "0x1000" "| Range 0-Vref"
d G "VREF_VREF" 2 370 "0x3000" "| Range Vref-Vref"
d G "VREF_VDD" 2 371 "0x2000" "| Range Vref-Vdd"
d G "ADC_START_AND_READ" 2 375 "7" "This is the default if nothing is specified"
d G "ADC_START_ONLY" 2 376 "1"
d G "ADC_READ_ONLY" 2 377 "6"
d G "L_TO_H" 2 389 "0x40"
d G "H_TO_L" 2 390 "0"
d G "GLOBAL" 2 392 "0x0BC0"
d G "INT_RTCC" 2 393 "0x000B20"
d G "INT_RB" 2 394 "0x01FF0B08"
d G "INT_EXT_L2H" 2 395 "0x50000B10"
d G "INT_EXT_H2L" 2 396 "0x60000B10"
d G "INT_EXT" 2 397 "0x000B10"
d G "INT_AD" 2 398 "0x008C40"
d G "INT_TBE" 2 399 "0x008C10"
d G "INT_RDA" 2 400 "0x008C20"
d G "INT_TIMER1" 2 401 "0x008C01"
d G "INT_TIMER2" 2 402 "0x008C02"
d G "INT_CCP1" 2 403 "0x008C04"
d G "INT_CCP2" 2 404 "0x008D01"
d G "INT_SSP" 2 405 "0x008C08"
d G "INT_BUSCOL" 2 406 "0x008D08"
d G "INT_EEPROM" 2 407 "0x008D10"
d G "INT_TIMER0" 2 408 "0x000B20"
d G "INT_OSC_FAIL" 2 409 "0x008D80"
d G "INT_COMP" 2 410 "0x008D20"
d G "INT_COMP2" 2 411 "0x008D40"
d G "INT_ULPWU" 2 412 "0x008D04"
d G "INT_RB0" 2 413 "0x0010B08"
d G "INT_RB1" 2 414 "0x0020B08"
d G "INT_RB2" 2 415 "0x0040B08"
d G "INT_RB3" 2 416 "0x0080B08"
d G "INT_RB4" 2 417 "0x0100B08"
d G "INT_RB5" 2 418 "0x0200B08"
d G "INT_RB6" 2 419 "0x0400B08"
d G "INT_RB7" 2 420 "0x0800B08"
D G "MAG_ADDR_R" 3 1 "0x3D" "addresa pro cteni"
D G "MAG_ADDR_W" 3 2 "0x3C"
D G "MAG_ROZ088" 3 7 "0x00"
D G "MAG_ROZ130" 3 8 "0x20"
D G "MAG_ROZ190" 3 9 "0x40"
D G "MAG_ROZ250" 3 10 "0x60"
D G "MAG_ROZ400" 3 11 "0x80"
D G "MAG_ROZ470" 3 12 "0xA0"
D G "MAG_ROZ560" 3 13 "0xC0"
D G "MAG_ROZ810" 3 14 "0xE0"
D G "HMC5883L_WRT_ADDR" 4 2 "0x3C"
D G "HMC5883L_READ_ADDR" 4 3 "0x3D"
D G "HMC5883L_CFG_A_REG" 4 6 "0x00"
D G "HMC5883L_CFG_B_REG" 4 7 "0x01"
D G "HMC5883L_MODE_REG" 4 8 "0x02"
D G "HMC5883L_X_MSB_REG" 4 9 "0x03"
C L "hmc5883l_write_reg" 4 1 1 "FUNCTION"
F G "hmc5883l_write_reg" 4 14 "void(int8 reg,int8 data)"
V L "reg" 4 14 "int8"
V L "data" 4 14 "int8"
F G "hmc5883l_read_reg" 4 24 "int8(int8 reg)"
V L "reg" 4 24 "int8"
V L "retval" 4 26 "int8"
T G "hmc5883l_result" 4 45 "{sint16 x,sint16 y,sint16 z}" "This global structure holds the values read"
V G "compass" 4 49 "hmc5883l_result"
F G "hmc5883l_read_data" 4 52 "void()"
V L "x_lsb" 4 54 "int8"
V L "x_msb" 4 55 "int8"
V L "y_lsb" 4 57 "int8"
V L "y_msb" 4 58 "int8"
V L "z_lsb" 4 60 "int8"
V L "z_msb" 4 61 "int8"
C L "hmc5883l_read_data" 4 1 1 "FUNCTION"
C L "hmc5883l_read_data" 4 1 1 "FUNCTION"
C L "hmc5883l_read_data" 4 1 1 "FUNCTION"
D G "MATH_H" 5 21 ""
D G "PI" 5 26 "3.1415926535897932"
D G "SQRT2" 5 29 "1.4142135623730950"
C L "CEIL_FLOOR" 5 2 3 "FUNCTION"
F G "CEIL_FLOOR" 5 36 "float(float x,int8 n)"
V L "x" 5 36 "float"
V L "n" 5 36 "int8"
V L "y" 5 38 "float"
V L "res" 5 38 "float"
V L "l" 5 39 "int16"
V L "s" 5 40 "int1"
C L "floor" 5 2 5 "FUNCTION"
F G "floor" 5 192 "float(float x)"
V L "x" 5 192 "float"
C L "ceil" 5 2 5 "FUNCTION"
F G "ceil" 5 218 "float(float x)"
V L "x" 5 218 "float"
D G "fabs" 5 244 "abs"
C L "fmod" 5 2 6 "FUNCTION"
F G "fmod" 5 256 "float(float x,float y)"
V L "x" 5 256 "float"
V L "y" 5 256 "float"
V L "i" 5 258 "float"
D G "LN2" 5 319 "0.6931471805599453"
V G "pe" 5 321 "float[6]"
F G "exp" 5 325 "float(float x)"
V L "x" 5 325 "float"
V L "y" 5 327 "float"
V L "res" 5 327 "float"
V L "r" 5 327 "float"
V L "n" 5 331 "sint8"
V L "s" 5 332 "int1"
C L "exp" 5 2 1 "FUNCTION"
V G "pl" 5 496 "float[4]"
V G "ql" 5 497 "float[4]"
C L "log" 5 2 3 "FUNCTION"
F G "log" 5 505 "float(float x)"
V L "x" 5 505 "float"
V L "y" 5 507 "float"
V L "res" 5 507 "float"
V L "r" 5 507 "float"
V L "y2" 5 507 "float"
V L "n" 5 511 "sint8"
C L "log" 5 2 1 "FUNCTION"
D G "LN10" 5 729 "2.3025850929940456"
C L "log10" 5 2 3 "FUNCTION"
F G "log10" 5 737 "float(float x)"
V L "x" 5 737 "float"
V L "r" 5 739 "float"
C L "modf" 5 2 8 "FUNCTION"
F G "modf" 5 778 "float(float value,*float iptr)"
V L "value" 5 778 "float"
V L "iptr" 5 778 "*float"
C L "pwr" 5 2 6 "FUNCTION"
F G "pwr" 5 806 "float(float x,float y)"
V L "x" 5 806 "float"
V L "y" 5 806 "float"
C L "pow" 5 2 7 "FUNCTION"
F G "pow" 5 869 "float(float x,float y)"
V L "x" 5 869 "float"
V L "y" 5 869 "float"
C L "sqrt" 5 2 5 "FUNCTION"
F G "sqrt" 5 930 "float(float x)"
V L "x" 5 930 "float"
V L "y" 5 932 "float"
V L "res" 5 932 "float"
V L "p" 5 936 "*int8"
D G "PI_DIV_BY_TWO" 5 1125 "1.5707963267948966"
C L "cos" 5 2 3 "FUNCTION"
F G "cos" 5 1136 "float(float x)"
V L "x" 5 1136 "float"
V L "y" 5 1138 "float"
V L "t" 5 1138 "float"
V L "t2" 5 1138 "float"
V L "quad" 5 1139 "int8"
V L "i" 5 1139 "int8"
V L "frac" 5 1140 "float"
V L "p" 5 1141 "float[6]" "by the series definition for cosine"
C L "cos" 5 2 1 "FUNCTION"
C L "cos" 5 2 2 "FUNCTION"
C L "cos" 5 2 1 "FUNCTION"
C L "cos" 5 2 1 "FUNCTION"
C L "cos" 5 2 1 "FUNCTION"
C L "cos" 5 2 1 "FUNCTION"
C L "cos" 5 2 1 "FUNCTION"
C L "cos" 5 2 1 "FUNCTION"
C L "sin" 5 2 5 "FUNCTION"
F G "sin" 5 1278 "float(float x)"
V L "x" 5 1278 "float"
C L "tan" 5 2 5 "FUNCTION"
F G "tan" 5 1304 "float(float x)"
V L "x" 5 1304 "float"
V L "c" 5 1306 "float"
V L "s" 5 1306 "float"
V G "pas" 5 1344 "float[3]"
V G "qas" 5 1345 "float[3]"
F G "ASIN_COS" 5 1347 "float(float x,int8 n)"
V L "x" 5 1347 "float"
V L "n" 5 1347 "int8"
V L "y" 5 1349 "float"
V L "res" 5 1349 "float"
V L "r" 5 1349 "float"
V L "y2" 5 1349 "float"
V L "s" 5 1350 "int1"
C L "ASIN_COS" 5 2 1 "FUNCTION"
C L "ASIN_COS" 5 2 1 "FUNCTION"
C L "asin" 5 2 5 "FUNCTION"
F G "asin" 5 1493 "float(float x)"
V L "x" 5 1493 "float"
V L "r" 5 1495 "float"
C L "acos" 5 2 5 "FUNCTION"
F G "acos" 5 1527 "float(float x)"
V L "x" 5 1527 "float"
V L "r" 5 1529 "float"
V G "pat" 5 1555 "float[4]"
V G "qat" 5 1556 "float[4]"
C L "atan" 5 2 3 "FUNCTION"
F G "atan" 5 1564 "float(float x)"
V L "x" 5 1564 "float"
V L "y" 5 1566 "float"
V L "res" 5 1566 "float"
V L "r" 5 1566 "float"
V L "s" 5 1567 "int1"
V L "flag" 5 1567 "int1"
C L "atan" 5 2 1 "FUNCTION"
C L "atan2" 5 2 7 "FUNCTION"
F G "atan2" 5 1697 "float(float y,float x)"
V L "y" 5 1697 "float"
V L "x" 5 1697 "float"
V L "z" 5 1699 "float"
V L "sign" 5 1700 "int1"
V L "quad" 5 1701 "int8"
C L "atan2" 5 2 1 "FUNCTION"
C L "atan2" 5 2 1 "FUNCTION"
C L "cosh" 5 2 7 "FUNCTION"
F G "cosh" 5 1919 "float(float x)"
V L "x" 5 1919 "float"
C L "sinh" 5 2 6 "FUNCTION"
F G "sinh" 5 1946 "float(float x)"
V L "x" 5 1946 "float"
C L "tanh" 5 2 6 "FUNCTION"
F G "tanh" 5 1976 "float(float x)"
V L "x" 5 1976 "float"
D G "LOG2" 5 2006 ".30102999566398119521"
F G "frexp" 5 2007 "float(float x,*sint8 exp)"
V L "x" 5 2007 "float"
V L "exp" 5 2007 "*sint8"
V L "res" 5 2009 "float"
V L "sign" 5 2010 "int1"
C L "ldexp" 5 2 6 "FUNCTION"
F G "ldexp" 5 2152 "float(float value,sint8 exp)"
V L "value" 5 2152 "float"
V L "exp" 5 2152 "sint8"
C L "MAIN" 5 2 2 "FUNCTION"
F G "MAIN" 0 5 "void()"
V L "last" 0 7 "float"
V L "b" 0 7 "float"
V L "anemo_speed" 0 7 "float"
V L "anemo_round" 0 8 "int16"
V L "i" 0 9 "int16" "signed int16 X,Y,Z;"
C L "MAIN" 0 20 3 "FUNCTION"
C L "MAIN" 0 20 1 "FUNCTION"
C L "MAIN" 0 20 1 "FUNCTION"
C L "MAIN" 0 20 2 "FUNCTION"
C L "MAIN" 0 20 6 "FUNCTION"
C L "MAIN" 0 20 1 "FUNCTION"
C L "MAIN" 0 20 7 "FUNCTION"
F B "reset_cpu" 0 0
F B "abs" 1 0
F B "sleep_ulpwu" 1 0
F B "sleep" 0 0
F B "delay_cycles" 1 0
F B "read_bank" 2 0
F B "write_bank" 3 0
F B "shift_left" 2 2
F B "shift_right" 2 2
F B "rotate_left" 2 0
F B "rotate_right" 2 0
F B "_mul" 2 0
F B "memset" 3 0
F B "isamoung" 2 0
F B "isamong" 2 0
F B "bit_set" 2 0
F B "bit_clear" 2 0
F B "bit_test" 2 0
F B "toupper" 1 0
F B "tolower" 1 0
F B "swap" 1 0
F B "printf" 1 255
F B "fprintf" 1 255
F B "sprintf" 1 255
F B "make8" 2 0
F B "make16" 2 0
F B "make32" 1 255
F B "label_address" 1 1
F B "goto_address" 1 0
F B "_va_arg" 1 0
F B "offsetofbit" 2 2
F B "enable_interrupts" 1 0
F B "disable_interrupts" 1 0
F B "interrupt_active" 1 0
F B "clear_interrupt" 1 0
F B "jump_to_isr" 1 0
F B "ext_int_edge" 1 2
F B "read_eeprom" 1 0
F B "write_eeprom" 2 0
F B "read_program_eeprom" 1 0
F B "write_program_eeprom" 2 0
F B "write_program_memory" 4 0
F B "write_program_memory8" 4 0
F B "read_program_memory" 4 0
F B "read_program_memory8" 4 0
F B "erase_program_eeprom" 1 0
F B "strcpy" 2 0
F B "memcpy" 3 0
F B "strstr100" 2 0
F B "output_high" 1 0
F B "output_low" 1 0
F B "input" 1 0
F B "input_state" 1 0
F B "output_float" 1 0
F B "output_drive" 1 0
F B "output_bit" 1 1
F B "output_toggle" 1 0
F B "output_a" 1 0
F B "output_b" 1 0
F B "output_c" 1 0
F B "output_d" 1 0
F B "output_e" 1 0
F B "input_a" 0 0
F B "input_b" 0 0
F B "input_c" 0 0
F B "input_d" 0 0
F B "input_e" 0 0
F B "set_tris_a" 1 0
F B "set_tris_b" 1 0
F B "set_tris_c" 1 0
F B "set_tris_d" 1 0
F B "set_tris_e" 1 0
F B "get_tris_a" 0 0
F B "get_tris_b" 0 0
F B "get_tris_c" 0 0
F B "get_tris_d" 0 0
F B "get_tris_e" 0 0
F B "input_change_a" 0 0
F B "input_change_b" 0 0
F B "input_change_c" 0 0
F B "input_change_d" 0 0
F B "input_change_e" 0 0
F B "port_b_pullups" 1 0
F B "setup_counters" 2 0
F B "setup_wdt" 1 0
F B "restart_cause" 0 0
F B "restart_wdt" 0 0
F B "get_rtcc" 0 0
F B "set_rtcc" 1 0
F B "get_timer0" 0 0
F B "set_timer0" 1 0
F B "setup_comparator" 1 0
F B "setup_port_a" 1 0
F B "setup_adc_ports" 1 0
F B "setup_adc" 1 0
F B "set_adc_channel" 1 0
F B "read_adc" 0 1
F B "adc_done" 0 0
F B "setup_timer_0" 1 0
F B "setup_vref" 1 0
F B "setup_timer_1" 1 0
F B "get_timer1" 0 0
F B "set_timer1" 1 0
F B "setup_timer_2" 3 0
F B "get_timer2" 0 0
F B "set_timer2" 1 0
F B "setup_ccp1" 1 2
F B "set_pwm1_duty" 1 0
F B "setup_ccp2" 1 0
F B "set_pwm2_duty" 1 0
F B "setup_oscillator" 1 2
F B "setup_spi" 1 0
F B "spi_read" 0 1
F B "spi_write" 1 0
F B "spi_data_is_in" 0 0
F B "setup_spi2" 1 0
F B "spi_read2" 0 1
F B "spi_write2" 1 0
F B "spi_data_is_in2" 0 0
F B "brownout_enable" 1 0
F B "delay_ms" 1 0
F B "delay_us" 1 0
F B "i2c_read" 0 2
F B "i2c_write" 1 2
F B "i2c_start" 0 2
F B "i2c_stop" 0 1
F B "i2c_isr_state" 0 1
F B "putchar" 1 2
F B "puts" 1 2
F B "getch" 0 1
F B "gets" 1 3
F B "kbhit" 0 1
/Modules/Sensors/MAG01A/SW/PIC16F887/main.h
0,0 → 1,21
#include <16F887.h>
#device adc=8
 
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC //Internal RC Osc
#FUSES NOPUT //No Power Up Timer
#FUSES MCLR //Master Clear pin enabled
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOCPD //No EE protection
#FUSES NOBROWNOUT //No brownout reset
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOWRT //Program memory not write protected
#FUSES BORV40 //Brownout reset at 4.0V
 
#use delay(clock=8000000)
#use i2c(master, sda=PIN_C4, scl=PIN_C3)
#use rs232(baud=115200,parity=N,xmit=PIN_C7,rcv=PIN_C6,bits=8) //rcv TXD xmit RXD
 
/Modules/Sensors/MAG01A/SW/PIC16F887/main.hex
0,0 → 1,101
:1000000002308A004F2A0000CD306737653AEF365C
:10001000653A721D20100D050000A831A936EC309C
:100020006210CA2043244F103218B1193A10A006AA
:100030000A005816A02C2C105A100D05000108308B
:10004000F80000008711A011200883168700000027
:100050008312BD0D0712031C3328201620088316B7
:10006000870037288312201220088316870000009B
:100070008312A0152008831687008312871D3E284F
:10008000F80B212800008711A01120088316870093
:10009000000083122016200883168700000000004D
:1000A0008312A0152008831687008312871D562807
:1000B000F8010000071A78148711A0112008831690
:1000C00087008312071220122008831687008312EC
:1000D0000800201620088316870000008312A01550
:1000E00020088316870000008312071220122008C0
:1000F00083168700000083128711A0112008831641
:1001000087003C308312BD001F203708BD001F2030
:100110003808BD001F202012200883168700000029
:100120008312A0152008831687008312871D962846
:1001300000009A280000201620088316870000007F
:1001400083120800A01320088316870083128713E8
:100150000830F800AB280000F817C028F813400852
:10016000F900F90C03188717031C87137817C028A8
:100170007813F80BB1287908C000BE280000871753
:10018000F81BAE28781BB8280800831603178C17B5
:100190000C140000000083120C087F390319092990
:1001A0000313B70003170D080313B80003170F0854
:1001B0000313B9003708C000A220380803178D00C8
:1001C0000313390803178F0083168C170C140000D3
:1001D000000083120C0D0E0D7F390319092903133A
:1001E000B70003170D080313B80003170F08031314
:1001F000B9003708C000A220380803178D00031388
:10020000390803178F008D0A03198F0A0313C528B5
:100210000317031308000830BE007708BF0020163C
:1002200020088316870000008312A015200883167B
:1002300087008312871D1A29071A0314071E03104B
:10024000F80D0000A0112008831687008312871183
:10025000BE0B0F292016200883168700000083128A
:1002600007123F0803193929201220088316870036
:1002700083120000A0152008831687008312871DB3
:100280003F2900008711A011200883168700000075
:100290008312071220122008831687008312080099
:1002A000201620088316870000008312A01520085E
:1002B000831687000000831207122012200883167D
:1002C0008700000083128711A01120088316870081
:1002D0003C308312BD001F200330BD001F202016BC
:1002E00020088316870000008312A01520088316BB
:1002F000870000008312871D7B2907122012200827
:1003000083168700000083128711A011200883162E
:1003100087003D308312BD001F200130F7000B2104
:100320007808B8000130F7000B217808B7000130D9
:10033000F7000B217808BC000130F7000B2178088A
:10034000BB000130F7000B217808BA00F7010B2140
:100350007808B90020122008831687000000831255
:10036000A0152008831687008312871DB529000079
:10037000B929000020162008831687000000831288
:100380003808A2003708A1003A08A4003908A300E1
:100390003C08A6003B08A5008A110A12E12ABF0109
:1003A0000408BE003F10831B3F14B81FDF29BE178F
:1003B0003E1EBE0AB709B809B70A0319B80A380EB3
:1003C000F038BA00BA07E23EBB00323EBD00380842
:1003D0000F39BB07BB07BD07E93EBC00BC07BC0724
:1003E000370E0F39BC07BD07BC0DBD0DBD09BD0DD6
:1003F00037080F39BD07BA0D0730B9000A30BD07FD
:10040000BC03031CFF29BC07BB03031C032ABB0757
:10041000BA03031C072ABA07B903031C0B2A393095
:100420008400831307303E053E1384033E05031DFD
:10043000202A3E1A840A3E1A202A2030F7003D2A3C
:1004400084073D30040203193E170008F700031D1E
:10045000312A3E1B312A3E1A4B2ABE19312A20303E
:100460003C2ABE1F392A2D30F70084033E13BE13E9
:100470003D2ABE153E123030F707B8010408B70018
:100480003810831B38147708C000A2203708840076
:10049000831338188317840A3E1F212A0800840119
:1004A00083131F308305713083168F000F0883126A
:1004B000A01320088316870083128717831603175B
:1004C0000908C039890003131F129F120030031757
:1004D00088008312870188018901FF300313A0007F
:1004E000A101A201A301A401A501A601B401B301C8
:1004F000831603170908C039890003131F129F12BE
:10050000003003178800831203131F139F138316F1
:100510009F1383121F149412A012200883168700C1
:10052000831220162008831687008312A01120084A
:1005300083168700013083129400003083169400E4
:100540000108C73908388100831290010030F80093
:100550009200003083169200831220152008831623
:1005600087008312970183169B019C0101309D0037
:10057000831203178701880189010313B70118301B
:10058000B80069200130B700E030B80069200230BF
:10059000B700B8016920043003178D0000308F00C8
:1005A0000313C5200D3003178D0000308F00031397
:1005B000C520193003178D0000308F000313C520AC
:1005C0005029003084002208B8002108B700CF214C
:1005D0002030C000A220003084002408B800230886
:1005E000B700CF212030C000A220003084002608B0
:1005F000B8002508B700CF212030C000A2200A3063
:0E060000C000A2200D30C000A220E02A63003E
:04400E00F52CFF3F4F
:00000001FF
;PIC16F887
;CRC=32C6 CREATED="15-V-13 20:34"
/Modules/Sensors/MAG01A/SW/PIC16F887/main.lst
0,0 → 1,2944
CCS PCM C Compiler, Version 4.106, 47914 15-V-13 20:34
 
Filename: Z:\home\kaklik\svnMLAB\Modules\Sensors\MAG01A\SW\PIC16F887\main.lst
 
ROM used: 775 words (9%)
Largest free fragment is 2048
RAM used: 28 (8%) at main() level
38 (10%) worst case
Stack: 2 locations
 
*
0000: MOVLW 02
0001: MOVWF 0A
0002: GOTO 24F
0003: NOP
.................... #include "main.h"
.................... #include <16F887.h>
.................... //////// Standard Header file for the PIC16F887 device ////////////////
.................... #device PIC16F887
.................... #list
....................
.................... #device adc=8
....................
.................... #FUSES NOWDT //No Watch Dog Timer
.................... #FUSES INTRC //Internal RC Osc
.................... #FUSES NOPUT //No Power Up Timer
.................... #FUSES MCLR //Master Clear pin enabled
.................... #FUSES NOPROTECT //Code not protected from reading
.................... #FUSES NOCPD //No EE protection
.................... #FUSES NOBROWNOUT //No brownout reset
.................... #FUSES IESO //Internal External Switch Over mode enabled
.................... #FUSES FCMEN //Fail-safe clock monitor enabled
.................... #FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
.................... #FUSES NODEBUG //No Debug mode for ICD
.................... #FUSES NOWRT //Program memory not write protected
.................... #FUSES BORV40 //Brownout reset at 4.0V
....................
.................... #use delay(clock=8000000)
.................... #use i2c(master, sda=PIN_C4, scl=PIN_C3)
*
001F: MOVLW 08
0020: MOVWF 78
0021: NOP
0022: BCF 07.3
0023: BCF 20.3
0024: MOVF 20,W
0025: BSF 03.5
0026: MOVWF 07
0027: NOP
0028: BCF 03.5
0029: RLF 3D,F
002A: BCF 07.4
002B: BTFSS 03.0
002C: GOTO 033
002D: BSF 20.4
002E: MOVF 20,W
002F: BSF 03.5
0030: MOVWF 07
0031: GOTO 037
0032: BCF 03.5
0033: BCF 20.4
0034: MOVF 20,W
0035: BSF 03.5
0036: MOVWF 07
0037: NOP
0038: BCF 03.5
0039: BSF 20.3
003A: MOVF 20,W
003B: BSF 03.5
003C: MOVWF 07
003D: BCF 03.5
003E: BTFSS 07.3
003F: GOTO 03E
0040: DECFSZ 78,F
0041: GOTO 021
0042: NOP
0043: BCF 07.3
0044: BCF 20.3
0045: MOVF 20,W
0046: BSF 03.5
0047: MOVWF 07
0048: NOP
0049: BCF 03.5
004A: BSF 20.4
004B: MOVF 20,W
004C: BSF 03.5
004D: MOVWF 07
004E: NOP
004F: NOP
0050: BCF 03.5
0051: BSF 20.3
0052: MOVF 20,W
0053: BSF 03.5
0054: MOVWF 07
0055: BCF 03.5
0056: BTFSS 07.3
0057: GOTO 056
0058: CLRF 78
0059: NOP
005A: BTFSC 07.4
005B: BSF 78.0
005C: BCF 07.3
005D: BCF 20.3
005E: MOVF 20,W
005F: BSF 03.5
0060: MOVWF 07
0061: BCF 03.5
0062: BCF 07.4
0063: BCF 20.4
0064: MOVF 20,W
0065: BSF 03.5
0066: MOVWF 07
0067: BCF 03.5
0068: RETURN
*
010B: MOVLW 08
010C: MOVWF 3E
010D: MOVF 77,W
010E: MOVWF 3F
010F: BSF 20.4
0110: MOVF 20,W
0111: BSF 03.5
0112: MOVWF 07
0113: NOP
0114: BCF 03.5
0115: BSF 20.3
0116: MOVF 20,W
0117: BSF 03.5
0118: MOVWF 07
0119: BCF 03.5
011A: BTFSS 07.3
011B: GOTO 11A
011C: BTFSC 07.4
011D: BSF 03.0
011E: BTFSS 07.4
011F: BCF 03.0
0120: RLF 78,F
0121: NOP
0122: BCF 20.3
0123: MOVF 20,W
0124: BSF 03.5
0125: MOVWF 07
0126: BCF 03.5
0127: BCF 07.3
0128: DECFSZ 3E,F
0129: GOTO 10F
012A: BSF 20.4
012B: MOVF 20,W
012C: BSF 03.5
012D: MOVWF 07
012E: NOP
012F: BCF 03.5
0130: BCF 07.4
0131: MOVF 3F,W
0132: BTFSC 03.2
0133: GOTO 139
0134: BCF 20.4
0135: MOVF 20,W
0136: BSF 03.5
0137: MOVWF 07
0138: BCF 03.5
0139: NOP
013A: BSF 20.3
013B: MOVF 20,W
013C: BSF 03.5
013D: MOVWF 07
013E: BCF 03.5
013F: BTFSS 07.3
0140: GOTO 13F
0141: NOP
0142: BCF 07.3
0143: BCF 20.3
0144: MOVF 20,W
0145: BSF 03.5
0146: MOVWF 07
0147: NOP
0148: BCF 03.5
0149: BCF 07.4
014A: BCF 20.4
014B: MOVF 20,W
014C: BSF 03.5
014D: MOVWF 07
014E: BCF 03.5
014F: RETURN
.................... #use rs232(baud=115200,parity=N,xmit=PIN_C7,rcv=PIN_C6,bits=8) //rcv TXD xmit RXD
*
00A2: BCF 20.7
00A3: MOVF 20,W
00A4: BSF 03.5
00A5: MOVWF 07
00A6: BCF 03.5
00A7: BCF 07.7
00A8: MOVLW 08
00A9: MOVWF 78
00AA: GOTO 0AB
00AB: NOP
00AC: BSF 78.7
00AD: GOTO 0C0
00AE: BCF 78.7
00AF: MOVF 40,W
00B0: MOVWF 79
00B1: RRF 79,F
00B2: BTFSC 03.0
00B3: BSF 07.7
00B4: BTFSS 03.0
00B5: BCF 07.7
00B6: BSF 78.6
00B7: GOTO 0C0
00B8: BCF 78.6
00B9: DECFSZ 78,F
00BA: GOTO 0B1
00BB: MOVF 79,W
00BC: MOVWF 40
00BD: GOTO 0BE
00BE: NOP
00BF: BSF 07.7
00C0: BTFSC 78.7
00C1: GOTO 0AE
00C2: BTFSC 78.6
00C3: GOTO 0B8
00C4: RETURN
....................
....................
.................... #include "HMC5883L.h"
.................... #define MAG_ADDR_R 0x3D //addresa pro cteni
.................... #define MAG_ADDR_W 0x3C
....................
....................
.................... //Konstanty nastavujici rozsah
.................... //pro void set_mag_roz (unsigned int8 h)
.................... #define MAG_ROZ088 0x00
.................... #define MAG_ROZ130 0x20
.................... #define MAG_ROZ190 0x40
.................... #define MAG_ROZ250 0x60
.................... #define MAG_ROZ400 0x80
.................... #define MAG_ROZ470 0xA0
.................... #define MAG_ROZ560 0xC0
.................... #define MAG_ROZ810 0xE0
....................
....................
.................... #include "HMC5883L.c"
.................... // i2c slave addresses
.................... #define HMC5883L_WRT_ADDR 0x3C
.................... #define HMC5883L_READ_ADDR 0x3D
....................
.................... // Register addresses
.................... #define HMC5883L_CFG_A_REG 0x00
.................... #define HMC5883L_CFG_B_REG 0x01
.................... #define HMC5883L_MODE_REG 0x02
.................... #define HMC5883L_X_MSB_REG 0x03
....................
.................... //------------------------------
.................... // Low level routines
.................... //------------------------------
.................... void hmc5883l_write_reg(int8 reg, int8 data)
.................... {
.................... i2c_start();
*
0069: BSF 20.4
006A: MOVF 20,W
006B: BSF 03.5
006C: MOVWF 07
006D: NOP
006E: BCF 03.5
006F: BSF 20.3
0070: MOVF 20,W
0071: BSF 03.5
0072: MOVWF 07
0073: NOP
0074: BCF 03.5
0075: BCF 07.4
0076: BCF 20.4
0077: MOVF 20,W
0078: BSF 03.5
0079: MOVWF 07
007A: NOP
007B: BCF 03.5
007C: BCF 07.3
007D: BCF 20.3
007E: MOVF 20,W
007F: BSF 03.5
0080: MOVWF 07
.................... i2c_write(HMC5883L_WRT_ADDR);
0081: MOVLW 3C
0082: BCF 03.5
0083: MOVWF 3D
0084: CALL 01F
.................... i2c_write(reg);
0085: MOVF 37,W
0086: MOVWF 3D
0087: CALL 01F
.................... i2c_write(data);
0088: MOVF 38,W
0089: MOVWF 3D
008A: CALL 01F
.................... i2c_stop();
008B: BCF 20.4
008C: MOVF 20,W
008D: BSF 03.5
008E: MOVWF 07
008F: NOP
0090: BCF 03.5
0091: BSF 20.3
0092: MOVF 20,W
0093: BSF 03.5
0094: MOVWF 07
0095: BCF 03.5
0096: BTFSS 07.3
0097: GOTO 096
0098: NOP
0099: GOTO 09A
009A: NOP
009B: BSF 20.4
009C: MOVF 20,W
009D: BSF 03.5
009E: MOVWF 07
009F: NOP
.................... }
00A0: BCF 03.5
00A1: RETURN
....................
.................... //------------------------------
.................... int8 hmc5883l_read_reg(int8 reg)
.................... {
.................... int8 retval;
....................
.................... i2c_start();
.................... i2c_write(HMC5883L_WRT_ADDR);
.................... i2c_write(reg);
.................... i2c_start();
.................... i2c_write(HMC5883L_READ_ADDR);
.................... retval = i2c_read(0);
.................... i2c_stop();
....................
.................... return(retval);
.................... }
....................
.................... //------------------------------
.................... typedef struct
.................... {
.................... signed int16 x;
.................... signed int16 y;
.................... signed int16 z;
.................... }hmc5883l_result;
....................
.................... // This global structure holds the values read
.................... // from the HMC5883L x,y,z registers.
.................... hmc5883l_result compass = {0,0,0};
*
0270: CLRF 21
0271: CLRF 22
0272: CLRF 23
0273: CLRF 24
0274: CLRF 25
0275: CLRF 26
....................
.................... //------------------------------
.................... void hmc5883l_read_data(void)
.................... {
.................... unsigned int8 x_lsb;
.................... unsigned int8 x_msb;
....................
.................... unsigned int8 y_lsb;
.................... unsigned int8 y_msb;
....................
.................... unsigned int8 z_lsb;
.................... unsigned int8 z_msb;
....................
.................... i2c_start();
*
0150: BSF 20.4
0151: MOVF 20,W
0152: BSF 03.5
0153: MOVWF 07
0154: NOP
0155: BCF 03.5
0156: BSF 20.3
0157: MOVF 20,W
0158: BSF 03.5
0159: MOVWF 07
015A: NOP
015B: BCF 03.5
015C: BCF 07.4
015D: BCF 20.4
015E: MOVF 20,W
015F: BSF 03.5
0160: MOVWF 07
0161: NOP
0162: BCF 03.5
0163: BCF 07.3
0164: BCF 20.3
0165: MOVF 20,W
0166: BSF 03.5
0167: MOVWF 07
.................... i2c_write(HMC5883L_WRT_ADDR);
0168: MOVLW 3C
0169: BCF 03.5
016A: MOVWF 3D
016B: CALL 01F
.................... i2c_write(HMC5883L_X_MSB_REG); // Point to X-msb register
016C: MOVLW 03
016D: MOVWF 3D
016E: CALL 01F
.................... i2c_start();
016F: BSF 20.4
0170: MOVF 20,W
0171: BSF 03.5
0172: MOVWF 07
0173: NOP
0174: BCF 03.5
0175: BSF 20.3
0176: MOVF 20,W
0177: BSF 03.5
0178: MOVWF 07
0179: NOP
017A: BCF 03.5
017B: BTFSS 07.3
017C: GOTO 17B
017D: BCF 07.4
017E: BCF 20.4
017F: MOVF 20,W
0180: BSF 03.5
0181: MOVWF 07
0182: NOP
0183: BCF 03.5
0184: BCF 07.3
0185: BCF 20.3
0186: MOVF 20,W
0187: BSF 03.5
0188: MOVWF 07
.................... i2c_write(HMC5883L_READ_ADDR);
0189: MOVLW 3D
018A: BCF 03.5
018B: MOVWF 3D
018C: CALL 01F
....................
.................... x_msb = i2c_read();
018D: MOVLW 01
018E: MOVWF 77
018F: CALL 10B
0190: MOVF 78,W
0191: MOVWF 38
.................... x_lsb = i2c_read();
0192: MOVLW 01
0193: MOVWF 77
0194: CALL 10B
0195: MOVF 78,W
0196: MOVWF 37
....................
.................... z_msb = i2c_read();
0197: MOVLW 01
0198: MOVWF 77
0199: CALL 10B
019A: MOVF 78,W
019B: MOVWF 3C
.................... z_lsb = i2c_read();
019C: MOVLW 01
019D: MOVWF 77
019E: CALL 10B
019F: MOVF 78,W
01A0: MOVWF 3B
....................
.................... y_msb = i2c_read();
01A1: MOVLW 01
01A2: MOVWF 77
01A3: CALL 10B
01A4: MOVF 78,W
01A5: MOVWF 3A
.................... y_lsb = i2c_read(0); // do a NACK on last read
01A6: CLRF 77
01A7: CALL 10B
01A8: MOVF 78,W
01A9: MOVWF 39
....................
.................... i2c_stop();
01AA: BCF 20.4
01AB: MOVF 20,W
01AC: BSF 03.5
01AD: MOVWF 07
01AE: NOP
01AF: BCF 03.5
01B0: BSF 20.3
01B1: MOVF 20,W
01B2: BSF 03.5
01B3: MOVWF 07
01B4: BCF 03.5
01B5: BTFSS 07.3
01B6: GOTO 1B5
01B7: NOP
01B8: GOTO 1B9
01B9: NOP
01BA: BSF 20.4
01BB: MOVF 20,W
01BC: BSF 03.5
01BD: MOVWF 07
01BE: NOP
....................
.................... // Combine high and low bytes into 16-bit values.
.................... compass.x = make16(x_msb, x_lsb);
01BF: BCF 03.5
01C0: MOVF 38,W
01C1: MOVWF 22
01C2: MOVF 37,W
01C3: MOVWF 21
.................... compass.y = make16(y_msb, y_lsb);
01C4: MOVF 3A,W
01C5: MOVWF 24
01C6: MOVF 39,W
01C7: MOVWF 23
.................... compass.z = make16(z_msb, z_lsb);
01C8: MOVF 3C,W
01C9: MOVWF 26
01CA: MOVF 3B,W
01CB: MOVWF 25
.................... }
01CC: BCF 0A.3
01CD: BCF 0A.4
01CE: GOTO 2E1 (RETURN)
....................
....................
....................
....................
.................... #include <math.h>
.................... ////////////////////////////////////////////////////////////////////////////
.................... //// (C) Copyright 1996,2008 Custom Computer Services ////
.................... //// This source code may only be used by licensed users of the CCS C ////
.................... //// compiler. This source code may only be distributed to other ////
.................... //// licensed users of the CCS C compiler. No other use, reproduction ////
.................... //// or distribution is permitted without written permission. ////
.................... //// Derivative programs created using this software in object code ////
.................... //// form are not restricted in any way. ////
.................... ////////////////////////////////////////////////////////////////////////////
.................... //// ////
.................... //// History: ////
.................... //// * 9/20/2001 : Improvments are made to sin/cos code. ////
.................... //// The code now is small, much faster, ////
.................... //// and more accurate. ////
.................... //// * 2/21/2007 : Compiler handles & operator differently and does
.................... //// not return generic (int8 *) so type cast is done ////
.................... //// ////
.................... ////////////////////////////////////////////////////////////////////////////
....................
.................... #ifndef MATH_H
.................... #define MATH_H
....................
.................... #ifdef PI
.................... #undef PI
.................... #endif
.................... #define PI 3.1415926535897932
....................
....................
.................... #define SQRT2 1.4142135623730950
....................
.................... //float const ps[4] = {5.9304945, 21.125224, 8.9403076, 0.29730279};
.................... //float const qs[4] = {1.0000000, 15.035723, 17.764134, 2.4934718};
....................
.................... ///////////////////////////// Round Functions //////////////////////////////
....................
.................... float32 CEIL_FLOOR(float32 x, unsigned int8 n)
.................... {
.................... float32 y, res;
.................... unsigned int16 l;
.................... int1 s;
....................
.................... s = 0;
.................... y = x;
....................
.................... if (x < 0)
.................... {
.................... s = 1;
.................... y = -y;
.................... }
....................
.................... if (y <= 32768.0)
.................... res = (float32)(unsigned int16)y;
....................
.................... else if (y < 10000000.0)
.................... {
.................... l = (unsigned int16)(y/32768.0);
.................... y = 32768.0*(y/32768.0 - (float32)l);
.................... res = 32768.0*(float32)l;
.................... res += (float32)(unsigned int16)y;
.................... }
....................
.................... else
.................... res = y;
....................
.................... y = y - (float32)(unsigned int16)y;
....................
.................... if (s)
.................... res = -res;
....................
.................... if (y != 0)
.................... {
.................... if (s == 1 && n == 0)
.................... res -= 1.0;
....................
.................... if (s == 0 && n == 1)
.................... res += 1.0;
.................... }
.................... if (x == 0)
.................... res = 0;
....................
.................... return (res);
.................... }
....................
.................... // Overloaded Functions to take care for new Data types in PCD
.................... // Overloaded function CEIL_FLOOR() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 CEIL_FLOOR(float48 x, unsigned int8 n)
.................... {
.................... float48 y, res;
.................... unsigned int16 l;
.................... int1 s;
....................
.................... s = 0;
.................... y = x;
....................
.................... if (x < 0)
.................... {
.................... s = 1;
.................... y = -y;
.................... }
....................
.................... if (y <= 32768.0)
.................... res = (float48)(unsigned int16)y;
....................
.................... else if (y < 10000000.0)
.................... {
.................... l = (unsigned int16)(y/32768.0);
.................... y = 32768.0*(y/32768.0 - (float48)l);
.................... res = 32768.0*(float32)l;
.................... res += (float48)(unsigned int16)y;
.................... }
....................
.................... else
.................... res = y;
....................
.................... y = y - (float48)(unsigned int16)y;
....................
.................... if (s)
.................... res = -res;
....................
.................... if (y != 0)
.................... {
.................... if (s == 1 && n == 0)
.................... res -= 1.0;
....................
.................... if (s == 0 && n == 1)
.................... res += 1.0;
.................... }
.................... if (x == 0)
.................... res = 0;
....................
.................... return (res);
.................... }
....................
....................
.................... // Overloaded function CEIL_FLOOR() for data type - Float64
.................... float64 CEIL_FLOOR(float64 x, unsigned int8 n)
.................... {
.................... float64 y, res;
.................... unsigned int16 l;
.................... int1 s;
....................
.................... s = 0;
.................... y = x;
....................
.................... if (x < 0)
.................... {
.................... s = 1;
.................... y = -y;
.................... }
....................
.................... if (y <= 32768.0)
.................... res = (float64)(unsigned int16)y;
....................
.................... else if (y < 10000000.0)
.................... {
.................... l = (unsigned int16)(y/32768.0);
.................... y = 32768.0*(y/32768.0 - (float64)l);
.................... res = 32768.0*(float64)l;
.................... res += (float64)(unsigned int16)y;
.................... }
....................
.................... else
.................... res = y;
....................
.................... y = y - (float64)(unsigned int16)y;
....................
.................... if (s)
.................... res = -res;
....................
.................... if (y != 0)
.................... {
.................... if (s == 1 && n == 0)
.................... res -= 1.0;
....................
.................... if (s == 0 && n == 1)
.................... res += 1.0;
.................... }
.................... if (x == 0)
.................... res = 0;
....................
.................... return (res);
.................... }
.................... #endif
....................
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float floor(float x)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description : rounds down the number x.
.................... // Date : N/A
.................... //
.................... float32 floor(float32 x)
.................... {
.................... return CEIL_FLOOR(x, 0);
.................... }
.................... // Following 2 functions are overloaded functions of floor() for PCD
.................... // Overloaded function floor() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 floor(float48 x)
.................... {
.................... return CEIL_FLOOR(x, 0);
.................... }
....................
.................... // Overloaded function floor() for data type - Float64
.................... float64 floor(float64 x)
.................... {
.................... return CEIL_FLOOR(x, 0);
.................... }
.................... #endif
....................
....................
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float ceil(float x)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description : rounds up the number x.
.................... // Date : N/A
.................... //
.................... float32 ceil(float32 x)
.................... {
.................... return CEIL_FLOOR(x, 1);
.................... }
.................... // Following 2 functions are overloaded functions of ceil() for PCD
.................... // Overloaded function ceil() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 ceil(float48 x)
.................... {
.................... return CEIL_FLOOR(x, 1);
.................... }
....................
.................... // Overloaded function ceil() for data type - Float64
.................... float64 ceil(float64 x)
.................... {
.................... return CEIL_FLOOR(x, 1);
.................... }
.................... #endif
....................
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float fabs(float x)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description : Computes the absolute value of floating point number x
.................... // Returns : returns the absolute value of x
.................... // Date : N/A
.................... //
.................... #define fabs abs
....................
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float fmod(float x)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description : Computes the floating point remainder of x/y
.................... // Returns : returns the value of x= i*y, for some integer i such that, if y
.................... // is non zero, the result has the same isgn of x na dmagnitude less than the
.................... // magnitude of y. If y is zero then a domain error occurs.
.................... // Date : N/A
.................... //
....................
.................... float fmod(float32 x,float32 y)
.................... {
.................... float32 i;
.................... if (y!=0.0)
.................... {
.................... i=(x/y < 0.0)? ceil(x/y): floor(x/y);
.................... return(x-(i*y));
.................... }
.................... else
.................... {
.................... #ifdef _ERRNO
.................... {
.................... errno=EDOM;
.................... }
.................... #endif
.................... }
.................... }
.................... //Overloaded function for fmod() for PCD
.................... // Overloaded function fmod() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 fmod(float48 x,float48 y)
.................... {
.................... float48 i;
.................... if (y!=0.0)
.................... {
.................... i=(x/y < 0.0)? ceil(x/y): floor(x/y);
.................... return(x-(i*y));
.................... }
.................... else
.................... {
.................... #ifdef _ERRNO
.................... {
.................... errno=EDOM;
.................... }
.................... #endif
.................... }
.................... }
.................... // Overloaded function fmod() for data type - Float64
.................... float64 fmod(float64 x,float64 y)
.................... {
.................... float64 i;
.................... if (y!=0.0)
.................... {
.................... i=(x/y < 0.0)? ceil(x/y): floor(x/y);
.................... return(x-(i*y));
.................... }
.................... else
.................... {
.................... #ifdef _ERRNO
.................... {
.................... errno=EDOM;
.................... }
.................... #endif
.................... }
.................... }
.................... #endif
.................... //////////////////// Exponential and logarithmic functions ////////////////////
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float exp(float x)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description : returns the value (e^x)
.................... // Date : N/A
.................... //
.................... #define LN2 0.6931471805599453
....................
.................... float const pe[6] = {0.000207455774, 0.00127100575, 0.00965065093,
.................... 0.0554965651, 0.240227138, 0.693147172};
....................
....................
.................... float32 exp(float32 x)
.................... {
.................... float32 y, res, r;
.................... #if defined(__PCD__)
.................... int8 data1;
.................... #endif
.................... signed int8 n;
.................... int1 s;
.................... #ifdef _ERRNO
.................... if(x > 88.722838)
.................... {
.................... errno=ERANGE;
.................... return(0);
.................... }
.................... #endif
.................... n = (signed int16)(x/LN2);
.................... s = 0;
.................... y = x;
....................
.................... if (x < 0)
.................... {
.................... s = 1;
.................... n = -n;
.................... y = -y;
.................... }
....................
.................... res = 0.0;
.................... #if !defined(__PCD__)
.................... *((unsigned int8 *)(&res)) = n + 0x7F;
.................... #endif
....................
.................... #if defined(__PCD__) // Takes care of IEEE format for PCD
.................... data1 = n+0x7F;
.................... if(bit_test(data1,0))
.................... bit_set(*(((unsigned int8 *)(&res)+2)),7);
.................... rotate_right(&data1,1);
.................... bit_clear(data1,7);
.................... *(((unsigned int8 *)(&res)+3)) = data1;
.................... #endif
....................
.................... y = y/LN2 - (float32)n;
....................
.................... r = pe[0]*y + pe[1];
.................... r = r*y + pe[2];
.................... r = r*y + pe[3];
.................... r = r*y + pe[4];
.................... r = r*y + pe[5];
....................
.................... res = res*(1.0 + y*r);
....................
.................... if (s)
.................... res = 1.0/res;
.................... return(res);
.................... }
....................
....................
.................... //Overloaded function for exp() for PCD
.................... // Overloaded function exp() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 exp(float48 x)
.................... {
.................... float48 y, res, r;
.................... int8 data1;
.................... signed int8 n;
.................... int1 s;
.................... #ifdef _ERRNO
.................... if(x > 88.722838)
.................... {
.................... errno=ERANGE;
.................... return(0);
.................... }
.................... #endif
.................... n = (signed int16)(x/LN2);
.................... s = 0;
.................... y = x;
....................
.................... if (x < 0)
.................... {
.................... s = 1;
.................... n = -n;
.................... y = -y;
.................... }
....................
.................... res = 0.0;
....................
.................... data1 = n+0x7F;
.................... if(bit_test(data1,0))
.................... bit_set(*(((unsigned int8 *)(&res)+4)),7);
.................... rotate_right(&data1,1);
.................... bit_clear(data1,7);
.................... *(((unsigned int8 *)(&res)+5)) = data1;
....................
.................... y = y/LN2 - (float48)n;
....................
.................... r = pe[0]*y + pe[1];
.................... r = r*y + pe[2];
.................... r = r*y + pe[3];
.................... r = r*y + pe[4];
.................... r = r*y + pe[5];
....................
.................... res = res*(1.0 + y*r);
....................
.................... if (s)
.................... res = 1.0/res;
.................... return(res);
.................... }
....................
.................... // Overloaded function exp() for data type - Float64
.................... float64 exp(float64 x)
.................... {
.................... float64 y, res, r;
.................... unsigned int16 data1, data2;
.................... unsigned int16 *p;
.................... signed int16 n;
.................... int1 s;
.................... #ifdef _ERRNO
.................... if(x > 709.7827128)
.................... {
.................... errno=ERANGE;
.................... return(0);
.................... }
.................... #endif
.................... n = (signed int16)(x/LN2);
.................... s = 0;
.................... y = x;
....................
.................... if (x < 0)
.................... {
.................... s = 1;
.................... n = -n;
.................... y = -y;
.................... }
....................
.................... res = 0.0;
....................
.................... #if !defined(__PCD__)
.................... *((unsigned int16 *)(&res)) = n + 0x7F;
.................... #endif
.................... p= (((unsigned int16 *)(&res))+3);
.................... data1 = *p;
.................... data2 = *p;
.................... data1 = n + 0x3FF;
.................... data1 = data1 <<4;
.................... if(bit_test(data2,15))
.................... bit_set(data1,15);
.................... data2 = data2 & 0x000F;
.................... data1 ^= data2;
....................
.................... *(((unsigned int16 *)(&res)+3)) = data1;
....................
....................
.................... y = y/LN2 - (float64)n;
....................
.................... r = pe[0]*y + pe[1];
.................... r = r*y + pe[2];
.................... r = r*y + pe[3];
.................... r = r*y + pe[4];
.................... r = r*y + pe[5];
....................
.................... res = res*(1.0 + y*r);
....................
.................... if (s)
.................... res = 1.0/res;
.................... return(res);
.................... }
....................
.................... #ENDIF
....................
....................
.................... /************************************************************/
....................
.................... float32 const pl[4] = {0.45145214, -9.0558803, 26.940971, -19.860189};
.................... float32 const ql[4] = {1.0000000, -8.1354259, 16.780517, -9.9300943};
....................
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float log(float x)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description : returns the the natural log of x
.................... // Date : N/A
.................... //
.................... float32 log(float32 x)
.................... {
.................... float32 y, res, r, y2;
.................... #if defined(__PCD__)
.................... unsigned int8 data1,data2;
.................... #endif
.................... signed int8 n;
.................... #ifdef _ERRNO
.................... if(x <0)
.................... {
.................... errno=EDOM;
.................... }
.................... if(x ==0)
.................... {
.................... errno=ERANGE;
.................... return(0);
.................... }
.................... #endif
.................... y = x;
....................
.................... if (y != 1.0)
.................... {
.................... #if !defined(__PCD__)
.................... *((unsigned int8 *)(&y)) = 0x7E;
.................... #endif
....................
.................... #if defined(__PCD__) // Takes care of IEEE format
.................... data2 = *(((unsigned int8 *)(&y))+3);
.................... *(((unsigned int8 *)(&y))+3) = 0x3F;
.................... data1 = *(((unsigned int8 *)(&y))+2);
.................... bit_clear(data1,7);
.................... *(((unsigned int8 *)(&y))+2) = data1;
.................... if(bit_test(data2,7))
.................... bit_set(*(((unsigned int8 *)(&y))+3),7);
.................... #endif
....................
.................... y = (y - 1.0)/(y + 1.0);
....................
.................... y2=y*y;
....................
.................... res = pl[0]*y2 + pl[1];
.................... res = res*y2 + pl[2];
.................... res = res*y2 + pl[3];
....................
.................... r = ql[0]*y2 + ql[1];
.................... r = r*y2 + ql[2];
.................... r = r*y2 + ql[3];
....................
.................... res = y*res/r;
.................... #if !defined(__PCD__)
.................... n = *((unsigned int8 *)(&x)) - 0x7E;
.................... #endif
.................... #if defined(__PCD__)
.................... data1 = *(((unsigned int8 *)(&x)+3));
.................... rotate_left(&data1,1);
.................... data2 = *(((unsigned int8 *)(&x)+2));
.................... if(bit_test (data2,7))
.................... bit_set(data1,0);
.................... n = data1 - 0x7E;
.................... #endif
....................
.................... if (n<0)
.................... r = -(float32)-n;
.................... else
.................... r = (float32)n;
....................
.................... res += r*LN2;
.................... }
....................
.................... else
.................... res = 0.0;
....................
.................... return(res);
.................... }
....................
.................... //Overloaded function for log() for PCD
.................... // Overloaded function log() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 log(float48 x)
.................... {
.................... float48 y, res, r, y2;
.................... unsigned int8 data1,data2;
.................... signed int8 n;
.................... #ifdef _ERRNO
.................... if(x <0)
.................... {
.................... errno=EDOM;
.................... }
.................... if(x ==0)
.................... {
.................... errno=ERANGE;
.................... return(0);
.................... }
.................... #endif
.................... y = x;
....................
.................... if (y != 1.0)
.................... {
....................
.................... #if !defined(__PCD__)
.................... *((unsigned int8 *)(&y)) = 0x7E;
.................... #endif
.................... data2 = *(((unsigned int8 *)(&y))+5);
.................... *(((unsigned int8 *)(&y))+5) = 0x3F;
.................... data1 = *(((unsigned int8 *)(&y))+4);
.................... bit_clear(data1,7);
.................... *(((unsigned int8 *)(&y))+4) = data1;
....................
.................... if(bit_test(data2,7))
.................... bit_set(*(((unsigned int8 *)(&y))+4),7);
.................... y = (y - 1.0)/(y + 1.0);
....................
.................... y2=y*y;
....................
.................... res = pl[0]*y2 + pl[1];
.................... res = res*y2 + pl[2];
.................... res = res*y2 + pl[3];
....................
.................... r = ql[0]*y2 + ql[1];
.................... r = r*y2 + ql[2];
.................... r = r*y2 + ql[3];
....................
.................... res = y*res/r;
....................
.................... data1 = *(((unsigned int8 *)(&x)+5));
.................... rotate_left(&data1,1);
.................... data2 = *(((unsigned int8 *)(&x)+4));
.................... if(bit_test (data2,7))
.................... bit_set(data1,0);
....................
.................... n = data1 - 0x7E;
....................
.................... if (n<0)
.................... r = -(float48)-n;
.................... else
.................... r = (float48)n;
....................
.................... res += r*LN2;
.................... }
....................
.................... else
.................... res = 0.0;
....................
.................... return(res);
.................... }
....................
.................... // Overloaded function log() for data type - Float48
.................... #if defined(__PCD__)
.................... float32 const pl_64[4] = {0.45145214, -9.0558803, 26.940971, -19.860189};
.................... float32 const ql_64[4] = {1.0000000, -8.1354259, 16.780517, -9.9300943};
.................... #endif
.................... float64 log(float64 x)
.................... {
.................... float64 y, res, r, y2;
.................... unsigned int16 data1,data2;
.................... unsigned int16 *p;
.................... signed int16 n;
.................... #ifdef _ERRNO
.................... if(x <0)
.................... {
.................... errno=EDOM;
.................... }
.................... if(x ==0)
.................... {
.................... errno=ERANGE;
.................... return(0);
.................... }
.................... #endif
.................... y = x;
....................
.................... if (y != 1.0)
.................... {
.................... #if !defined(__PCD__)
.................... *((unsigned int8 *)(&y)) = 0x7E;
.................... #endif
.................... p= (((unsigned int16 *)(&y))+3);
.................... data1 = *p;
.................... data2 = *p;
.................... data1 = 0x3FE;
.................... data1 = data1 <<4;
.................... if(bit_test (data2,15))
.................... bit_set(data1,15);
.................... data2 = data2 & 0x000F;
.................... data1 ^=data2;
....................
.................... *p = data1;
....................
.................... y = (y - 1.0)/(y + 1.0);
....................
.................... y2=y*y;
....................
.................... res = pl_64[0]*y2 + pl_64[1];
.................... res = res*y2 + pl_64[2];
.................... res = res*y2 + pl_64[3];
....................
.................... r = ql_64[0]*y2 + ql_64[1];
.................... r = r*y2 + ql_64[2];
.................... r = r*y2 + ql_64[3];
....................
.................... res = y*res/r;
....................
.................... p= (((unsigned int16 *)(&x))+3);
.................... data1 = *p;
.................... bit_clear(data1,15);
.................... data1 = data1 >>4;
.................... n = data1 - 0x3FE;
....................
....................
.................... if (n<0)
.................... r = -(float64)-n;
.................... else
.................... r = (float64)n;
....................
.................... res += r*LN2;
.................... }
....................
.................... else
.................... res = 0.0;
....................
.................... return(res);
.................... }
.................... #endif
....................
....................
.................... #define LN10 2.3025850929940456
....................
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float log10(float x)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description : returns the the log base 10 of x
.................... // Date : N/A
.................... //
.................... float32 log10(float32 x)
.................... {
.................... float32 r;
....................
.................... r = log(x);
.................... r = r/LN10;
.................... return(r);
.................... }
....................
.................... //Overloaded functions for log10() for PCD
.................... // Overloaded function log10() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 log10(float48 x)
.................... {
.................... float48 r;
....................
.................... r = log(x);
.................... r = r/LN10;
.................... return(r);
.................... }
....................
.................... // Overloaded function log10() for data type - Float64
.................... float64 log10(float64 x)
.................... {
.................... float64 r;
....................
.................... r = log(x);
.................... r = r/LN10;
.................... return(r);
.................... }
.................... #endif
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float modf(float x)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description :breaks the argument value int integral and fractional parts,
.................... // ach of which have the same sign as the argument. It stores the integral part
.................... // as a float in the object pointed to by the iptr
.................... // Returns : returns the signed fractional part of value.
.................... // Date : N/A
.................... //
....................
.................... float32 modf(float32 value,float32 *iptr)
.................... {
.................... *iptr=(value < 0.0)? ceil(value): floor(value);
.................... return(value - *iptr);
.................... }
.................... //Overloaded functions for modf() for PCD
.................... // Overloaded function modf() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 modf(float48 value,float48 *iptr)
.................... {
.................... *iptr=(value < 0.0)? ceil(value): floor(value);
.................... return(value - *iptr);
.................... }
.................... // Overloaded function modf() for data type - Float64
.................... float64 modf(float64 value,float64 *iptr)
.................... {
.................... *iptr=(value < 0.0)? ceil(value): floor(value);
.................... return(value - *iptr);
.................... }
.................... #endif
....................
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float pwr(float x,float y)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description : returns the value (x^y)
.................... // Date : N/A
.................... // Note : 0 is returned when the function will generate an imaginary number
.................... //
.................... float32 pwr(float32 x,float32 y)
.................... {
.................... if(0 > x && fmod(y, 1) == 0) {
.................... if(fmod(y, 2) == 0) {
.................... return (exp(log(-x) * y));
.................... } else {
.................... return (-exp(log(-x) * y));
.................... }
.................... } else if(0 > x && fmod(y, 1) != 0) {
.................... return 0;
.................... } else {
.................... if(x != 0 || 0 >= y) {
.................... return (exp(log(x) * y));
.................... }
.................... }
.................... }
.................... //Overloaded functions for pwr() for PCD
.................... // Overloaded function pwr() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 pwr(float48 x,float48 y)
.................... {
.................... if(0 > x && fmod(y, 1) == 0) {
.................... if(fmod(y, 2) == 0) {
.................... return (exp(log(-x) * y));
.................... } else {
.................... return (-exp(log(-x) * y));
.................... }
.................... } else if(0 > x && fmod(y, 1) != 0) {
.................... return 0;
.................... } else {
.................... if(x != 0 || 0 >= y) {
.................... return (exp(log(x) * y));
.................... }
.................... }
.................... }
.................... // Overloaded function pwr() for data type - Float64
.................... float64 pwr(float64 x,float64 y)
.................... {
.................... if(0 > x && fmod(y, 1) == 0) {
.................... if(fmod(y, 2) == 0) {
.................... return (exp(log(-x) * y));
.................... } else {
.................... return (-exp(log(-x) * y));
.................... }
.................... } else if(0 > x && fmod(y, 1) != 0) {
.................... return 0;
.................... } else {
.................... if(x != 0 || 0 >= y) {
.................... return (exp(log(x) * y));
.................... }
.................... }
.................... }
.................... #endif
....................
.................... //////////////////// Power functions ////////////////////
....................
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float pow(float x,float y)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description : returns the value (x^y)
.................... // Date : N/A
.................... // Note : 0 is returned when the function will generate an imaginary number
.................... //
.................... float32 pow(float32 x,float32 y)
.................... {
.................... if(0 > x && fmod(y, 1) == 0) {
.................... if(fmod(y, 2) == 0) {
.................... return (exp(log(-x) * y));
.................... } else {
.................... return (-exp(log(-x) * y));
.................... }
.................... } else if(0 > x && fmod(y, 1) != 0) {
.................... return 0;
.................... } else {
.................... if(x != 0 || 0 >= y) {
.................... return (exp(log(x) * y));
.................... }
.................... }
.................... }
.................... //Overloaded functions for pow() for PCD
.................... // Overloaded function for pow() data type - Float48
.................... #if defined(__PCD__)
.................... float48 pow(float48 x,float48 y)
.................... {
.................... if(0 > x && fmod(y, 1) == 0) {
.................... if(fmod(y, 2) == 0) {
.................... return (exp(log(-x) * y));
.................... } else {
.................... return (-exp(log(-x) * y));
.................... }
.................... } else if(0 > x && fmod(y, 1) != 0) {
.................... return 0;
.................... } else {
.................... if(x != 0 || 0 >= y) {
.................... return (exp(log(x) * y));
.................... }
.................... }
.................... }
....................
.................... // Overloaded function pow() for data type - Float64
.................... float64 pow(float64 x,float64 y)
.................... {
.................... if(0 > x && fmod(y, 1) == 0) {
.................... if(fmod(y, 2) == 0) {
.................... return (exp(log(-x) * y));
.................... } else {
.................... return (-exp(log(-x) * y));
.................... }
.................... } else if(0 > x && fmod(y, 1) != 0) {
.................... return 0;
.................... } else {
.................... if(x != 0 || 0 >= y) {
.................... return (exp(log(x) * y));
.................... }
.................... }
.................... }
.................... #endif
....................
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float sqrt(float x)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description : returns the square root of x
.................... // Date : N/A
.................... //
.................... float32 sqrt(float32 x)
.................... {
.................... float32 y, res;
.................... #if defined(__PCD__)
.................... unsigned int16 data1,data2;
.................... #endif
.................... BYTE *p;
....................
.................... #ifdef _ERRNO
.................... if(x < 0)
.................... {
.................... errno=EDOM;
.................... }
.................... #endif
....................
.................... if( x<=0.0)
.................... return(0.0);
....................
.................... y=x;
....................
.................... #if !defined(__PCD__)
.................... p=&y;
.................... (*p)=(BYTE)((((unsigned int16)(*p)) + 127) >> 1);
.................... #endif
....................
.................... #if defined(__PCD__)
.................... p = (((unsigned int8 *)(&y))+3);
.................... data1 = *(((unsigned int8 *)(&y))+3);
.................... data2 = *(((unsigned int8 *)(&y))+2);
.................... rotate_left(&data1,1);
.................... if(bit_test(data2,7))
.................... bit_set(data1,0);
.................... data1 = ((data1+127) >>1);
.................... bit_clear(data2,7);
.................... if(bit_test(data1,0))
.................... bit_set(data2,7);
.................... data1 = data1 >>1;
.................... *(((unsigned int8 *)(&y))+3) = data1;
.................... *(((unsigned int8 *)(&y))+2) = data2;
....................
.................... #endif
....................
.................... do {
.................... res=y;
.................... y+=(x/y);
....................
.................... #if !defined(__PCD__)
.................... (*p)--;
.................... #endif
....................
.................... #if defined(__PCD__)
.................... data1 = *(((unsigned int8 *)(&y))+3);
.................... data2 = *(((unsigned int8 *)(&y))+2);
.................... rotate_left(&data1,1);
.................... if(bit_test(data2,7))
.................... bit_set(data1,0);
.................... data1--;
.................... bit_clear(data2,7);
.................... if(bit_test(data1,0))
.................... bit_set(data2,7);
.................... data1 = data1 >>1;
.................... *(((unsigned int8 *)(&y))+3) = data1;
.................... *(((unsigned int8 *)(&y))+2) = data2;
....................
.................... #endif
.................... } while(res != y);
....................
.................... return(res);
.................... }
.................... //Overloaded functions for sqrt() for PCD
.................... // Overloaded function sqrt() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 sqrt(float48 x)
.................... {
.................... float48 y, res;
.................... unsigned int16 data1,data2;
.................... BYTE *p;
....................
.................... #ifdef _ERRNO
.................... if(x < 0)
.................... {
.................... errno=EDOM;
.................... }
.................... #endif
....................
.................... if( x<=0.0)
.................... return(0.0);
....................
.................... y=x;
....................
.................... #if !defined(__PCD__)
.................... p=&y;
.................... (*p)=(BYTE)((((unsigned int16)(*p)) + 127) >> 1);
.................... #endif
....................
.................... #if defined(__PCD__)
.................... p = (((unsigned int8 *)(&y))+5);
.................... data1 = *(((unsigned int8 *)(&y))+5);
.................... data2 = *(((unsigned int8 *)(&y))+4);
.................... rotate_left(&data1,1);
.................... if(bit_test(data2,7))
.................... bit_set(data1,0);
.................... data1 = ((data1+127) >>1);
.................... bit_clear(data2,7);
.................... if(bit_test(data1,0))
.................... bit_set(data2,7);
.................... data1 = data1 >>1;
.................... *(((unsigned int8 *)(&y))+5) = data1;
.................... *(((unsigned int8 *)(&y))+4) = data2;
....................
.................... #endif
....................
.................... do {
.................... res=y;
.................... y+=(x/y);
....................
.................... #if !defined(__PCD__)
.................... (*p)--;
.................... #endif
....................
.................... data1 = *(((unsigned int8 *)(&y))+5);
.................... data2 = *(((unsigned int8 *)(&y))+4);
.................... rotate_left(&data1,1);
.................... if(bit_test(data2,7))
.................... bit_set(data1,0);
.................... data1--;
.................... bit_clear(data2,7);
.................... if(bit_test(data1,0))
.................... bit_set(data2,7);
.................... data1 = data1 >>1;
.................... *(((unsigned int8 *)(&y))+5) = data1;
.................... *(((unsigned int8 *)(&y))+4) = data2;
....................
.................... } while(res != y);
....................
.................... return(res);
.................... }
....................
.................... // Overloaded function sqrt() for data type - Float64
.................... float64 sqrt(float64 x)
.................... {
.................... float64 y, res;
.................... unsigned int16 *p;
.................... unsigned int16 temp1,temp2;
....................
.................... #ifdef _ERRNO
.................... if(x < 0)
.................... {
.................... errno=EDOM;
.................... }
.................... #endif
....................
.................... if( x<=0.0)
.................... return(0.0);
....................
.................... y=x;
.................... p= (((unsigned int16 *)(&y))+3);
.................... temp1 = *p;
.................... temp2 = *p;
.................... bit_clear(temp1,15);
.................... temp1 = (temp1>>4)+1023;
.................... temp1 = temp1 >> 1;
.................... temp1 = (temp1<<4) & 0xFFF0;
.................... if(bit_test(temp2,15))
.................... bit_set(temp1,15);
.................... temp2 = temp2 & 0x000F;
.................... temp1 ^= temp2;
....................
.................... (*p) = temp1;
....................
.................... do {
.................... res=y;
.................... y+=(x/y);
.................... temp1 = *p;
.................... temp2 = *p;
.................... bit_clear(temp1,15);
.................... temp1 = (temp1>>4);
.................... temp1--;
.................... temp1 = (temp1<<4) & 0xFFF0;
.................... if(bit_test(temp2,15))
.................... bit_set(temp1,15);
.................... temp2 = temp2 & 0x000F;
.................... temp1 ^= temp2;
.................... (*p) = temp1;
....................
.................... } while(res != y);
....................
.................... return(res);
.................... }
.................... #endif
....................
.................... ////////////////////////////// Trig Functions //////////////////////////////
.................... #ifdef PI_DIV_BY_TWO
.................... #undef PI_DIV_BY_TWO
.................... #endif
.................... #define PI_DIV_BY_TWO 1.5707963267948966
.................... #ifdef TWOBYPI
.................... #undef TWOBYPI
.................... #define TWOBYPI 0.6366197723675813
.................... #endif
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float cos(float x)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description : returns the cosine value of the angle x, which is in radian
.................... // Date : 9/20/2001
.................... //
.................... float32 cos(float32 x)
.................... {
.................... float32 y, t, t2 = 1.0;
.................... unsigned int8 quad, i;
.................... float32 frac;
.................... float32 p[6] = { //by the series definition for cosine
.................... -0.5, // sum ( ( (-1)^n * x^2n )/(2n)! )
.................... 0.04166666666667,
.................... -0.00138888888889,
.................... 0.00002480158730,
.................... -0.00000027557319,
.................... 0.00000000208767,
.................... //-0.00000000001147,
.................... // 0.00000000000005
.................... };
....................
.................... if (x < 0) x = -x; // absolute value of input
....................
.................... quad = (unsigned int8)(x / PI_DIV_BY_TWO); // quadrant
.................... frac = (x / PI_DIV_BY_TWO) - quad; // fractional part of input
.................... quad = quad % 4; // quadrant (0 to 3)
....................
.................... if (quad == 0 || quad == 2)
.................... t = frac * PI_DIV_BY_TWO;
.................... else if (quad == 1)
.................... t = (1-frac) * PI_DIV_BY_TWO;
.................... else // should be 3
.................... t = (frac-1) * PI_DIV_BY_TWO;
....................
.................... y = 1.0;
.................... t = t * t;
.................... for (i = 0; i <= 5; i++)
.................... {
.................... t2 = t2 * t;
.................... y = y + p[i] * t2;
.................... }
....................
.................... if (quad == 2 || quad == 1)
.................... y = -y; // correct sign
....................
.................... return (y);
.................... }
....................
....................
.................... //Overloaded functions for cos() for PCD
.................... // Overloaded function cos() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 cos(float48 x)
.................... {
.................... float48 y, t, t2 = 1.0;
.................... unsigned int8 quad, i;
.................... float48 frac;
.................... float48 p[6] = { //by the series definition for cosine
.................... -0.5, // sum ( ( (-1)^n * x^2n )/(2n)! )
.................... 0.04166666666667,
.................... -0.00138888888889,
.................... 0.00002480158730,
.................... -0.00000027557319,
.................... 0.00000000208767,
.................... //-0.00000000001147,
.................... // 0.00000000000005
.................... };
....................
.................... if (x < 0) x = -x; // absolute value of input
....................
.................... quad = (unsigned int8)(x / PI_DIV_BY_TWO); // quadrant
.................... frac = (x / PI_DIV_BY_TWO) - quad; // fractional part of input
.................... quad = quad % 4; // quadrant (0 to 3)
....................
.................... if (quad == 0 || quad == 2)
.................... t = frac * PI_DIV_BY_TWO;
.................... else if (quad == 1)
.................... t = (1-frac) * PI_DIV_BY_TWO;
.................... else // should be 3
.................... t = (frac-1) * PI_DIV_BY_TWO;
....................
.................... y = 0.999999999781;
.................... t = t * t;
.................... for (i = 0; i <= 5; i++)
.................... {
.................... t2 = t2 * t;
.................... y = y + p[i] * t2;
.................... }
....................
.................... if (quad == 2 || quad == 1)
.................... y = -y; // correct sign
....................
.................... return (y);
.................... }
....................
.................... // Overloaded function cos() for data type - Float48
.................... float64 cos(float64 x)
.................... {
.................... float64 y, t, t2 = 1.0;
.................... unsigned int8 quad, i;
.................... float64 frac;
.................... float64 p[6] = { //by the series definition for cosine
.................... -0.5, // sum ( ( (-1)^n * x^2n )/(2n)! )
.................... 0.04166666666667,
.................... -0.00138888888889,
.................... 0.00002480158730,
.................... -0.00000027557319,
.................... 0.00000000208767,
.................... //-0.00000000001147,
.................... // 0.00000000000005
.................... };
....................
.................... if (x < 0) x = -x; // absolute value of input
....................
.................... quad = (unsigned int8)(x / PI_DIV_BY_TWO); // quadrant
.................... frac = (x / PI_DIV_BY_TWO) - quad; // fractional part of input
.................... quad = quad % 4; // quadrant (0 to 3)
....................
.................... if (quad == 0 || quad == 2)
.................... t = frac * PI_DIV_BY_TWO;
.................... else if (quad == 1)
.................... t = (1-frac) * PI_DIV_BY_TWO;
.................... else // should be 3
.................... t = (frac-1) * PI_DIV_BY_TWO;
....................
.................... y = 0.999999999781;
.................... t = t * t;
.................... for (i = 0; i <= 5; i++)
.................... {
.................... t2 = t2 * t;
.................... y = y + p[i] * t2;
.................... }
....................
.................... if (quad == 2 || quad == 1)
.................... y = -y; // correct sign
....................
.................... return (y);
.................... }
....................
.................... #endif
....................
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float sin(float x)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description : returns the sine value of the angle x, which is in radian
.................... // Date : 9/20/2001
.................... //
.................... float32 sin(float32 x)
.................... {
.................... return cos(x - PI_DIV_BY_TWO);
.................... }
....................
.................... //Overloaded functions for sin() for PCD
.................... // Overloaded function sin() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 sin(float48 x)
.................... {
.................... return cos(x - PI_DIV_BY_TWO);
.................... }
....................
.................... // Overloaded function sin() for data type - Float48
.................... float64 sin(float64 x)
.................... {
.................... return cos(x - PI_DIV_BY_TWO);
.................... }
.................... #endif
....................
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float tan(float x)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description : returns the tangent value of the angle x, which is in radian
.................... // Date : 9/20/2001
.................... //
.................... float32 tan(float32 x)
.................... {
.................... float32 c, s;
....................
.................... c = cos(x);
.................... if (c == 0.0)
.................... return (1.0e+36);
....................
.................... s = sin(x);
.................... return(s/c);
.................... }
.................... //Overloaded functions for tan() for PCD
.................... // Overloaded function tan() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 tan(float48 x)
.................... {
.................... float48 c, s;
....................
.................... c = cos(x);
.................... if (c == 0.0)
.................... return (1.0e+36);
....................
.................... s = sin(x);
.................... return(s/c);
.................... }
....................
.................... // Overloaded function tan() for data type - Float48
.................... float64 tan(float64 x)
.................... {
.................... float64 c, s;
....................
.................... c = cos(x);
.................... if (c == 0.0)
.................... return (1.0e+36);
....................
.................... s = sin(x);
.................... return(s/c);
.................... }
.................... #endif
....................
.................... float32 const pas[3] = {0.49559947, -4.6145309, 5.6036290};
.................... float32 const qas[3] = {1.0000000, -5.5484666, 5.6036290};
....................
.................... float32 ASIN_COS(float32 x, unsigned int8 n)
.................... {
.................... float32 y, res, r, y2;
.................... int1 s;
.................... #ifdef _ERRNO
.................... if(x <-1 || x > 1)
.................... {
.................... errno=EDOM;
.................... }
.................... #endif
.................... s = 0;
.................... y = x;
....................
.................... if (x < 0)
.................... {
.................... s = 1;
.................... y = -y;
.................... }
....................
.................... if (y > 0.5)
.................... {
.................... y = sqrt((1.0 - y)/2.0);
.................... n += 2;
.................... }
....................
.................... y2=y*y;
....................
.................... res = pas[0]*y2 + pas[1];
.................... res = res*y2 + pas[2];
....................
.................... r = qas[0]*y2 + qas[1];
.................... r = r*y2 + qas[2];
....................
.................... res = y*res/r;
....................
.................... if (n & 2) // |x| > 0.5
.................... res = PI_DIV_BY_TWO - 2.0*res;
.................... if (s)
.................... res = -res;
.................... if (n & 1) // take arccos
.................... res = PI_DIV_BY_TWO - res;
....................
.................... return(res);
.................... }
....................
.................... //Overloaded functions for ASIN_COS() for PCD
.................... // Overloaded function ASIN_COS() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 ASIN_COS(float48 x, unsigned int8 n)
.................... {
.................... float48 y, res, r, y2;
.................... int1 s;
.................... #ifdef _ERRNO
.................... if(x <-1 || x > 1)
.................... {
.................... errno=EDOM;
.................... }
.................... #endif
.................... s = 0;
.................... y = x;
....................
.................... if (x < 0)
.................... {
.................... s = 1;
.................... y = -y;
.................... }
....................
.................... if (y > 0.5)
.................... {
.................... y = sqrt((1.0 - y)/2.0);
.................... n += 2;
.................... }
....................
.................... y2=y*y;
....................
.................... res = pas[0]*y2 + pas[1];
.................... res = res*y2 + pas[2];
....................
.................... r = qas[0]*y2 + qas[1];
.................... r = r*y2 + qas[2];
....................
.................... res = y*res/r;
....................
.................... if (n & 2) // |x| > 0.5
.................... res = PI_DIV_BY_TWO - 2.0*res;
.................... if (s)
.................... res = -res;
.................... if (n & 1) // take arccos
.................... res = PI_DIV_BY_TWO - res;
....................
.................... return(res);
.................... }
....................
.................... // Overloaded function ASIN_COS() for data type - Float64
.................... float64 ASIN_COS(float64 x, unsigned int8 n)
.................... {
.................... float64 y, res, r, y2;
.................... int1 s;
.................... #ifdef _ERRNO
.................... if(x <-1 || x > 1)
.................... {
.................... errno=EDOM;
.................... }
.................... #endif
.................... s = 0;
.................... y = x;
....................
.................... if (x < 0)
.................... {
.................... s = 1;
.................... y = -y;
.................... }
....................
.................... if (y > 0.5)
.................... {
.................... y = sqrt((1.0 - y)/2.0);
.................... n += 2;
.................... }
....................
.................... y2=y*y;
....................
.................... res = pas[0]*y2 + pas[1];
.................... res = res*y2 + pas[2];
....................
.................... r = qas[0]*y2 + qas[1];
.................... r = r*y2 + qas[2];
....................
.................... res = y*res/r;
....................
.................... if (n & 2) // |x| > 0.5
.................... res = PI_DIV_BY_TWO - 2.0*res;
.................... if (s)
.................... res = -res;
.................... if (n & 1) // take arccos
.................... res = PI_DIV_BY_TWO - res;
....................
.................... return(res);
.................... }
.................... #endif
....................
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float asin(float x)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description : returns the arcsine value of the value x.
.................... // Date : N/A
.................... //
.................... float32 asin(float32 x)
.................... {
.................... float32 r;
....................
.................... r = ASIN_COS(x, 0);
.................... return(r);
.................... }
.................... //Overloaded functions for asin() for PCD
.................... // Overloaded function asin() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 asin(float48 x)
.................... {
.................... float48 r;
....................
.................... r = ASIN_COS(x, 0);
.................... return(r);
.................... }
....................
.................... // Overloaded function asin() for data type - Float64
.................... float64 asin(float64 x)
.................... {
.................... float64 r;
....................
.................... r = ASIN_COS(x, 0);
.................... return(r);
.................... }
.................... #endif
....................
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float acos(float x)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description : returns the arccosine value of the value x.
.................... // Date : N/A
.................... //
.................... float32 acos(float32 x)
.................... {
.................... float32 r;
....................
.................... r = ASIN_COS(x, 1);
.................... return(r);
.................... }
.................... //Overloaded functions for acos() for PCD
.................... // Overloaded function acos() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 acos(float48 x)
.................... {
.................... float48 r;
....................
.................... r = ASIN_COS(x, 1);
.................... return(r);
.................... }
....................
.................... // Overloaded function acos() for data type - Float64
.................... float64 acos(float64 x)
.................... {
.................... float64 r;
....................
.................... r = ASIN_COS(x, 1);
.................... return(r);
.................... }
.................... #endif
....................
.................... float32 const pat[4] = {0.17630401, 5.6710795, 22.376096, 19.818457};
.................... float32 const qat[4] = {1.0000000, 11.368190, 28.982246, 19.818457};
....................
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float atan(float x)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description : returns the arctangent value of the value x.
.................... // Date : N/A
.................... //
.................... float32 atan(float32 x)
.................... {
.................... float32 y, res, r;
.................... int1 s, flag;
....................
.................... s = 0;
.................... flag = 0;
.................... y = x;
....................
.................... if (x < 0)
.................... {
.................... s = 1;
.................... y = -y;
.................... }
....................
.................... if (y > 1.0)
.................... {
.................... y = 1.0/y;
.................... flag = 1;
.................... }
....................
.................... res = pat[0]*y*y + pat[1];
.................... res = res*y*y + pat[2];
.................... res = res*y*y + pat[3];
....................
.................... r = qat[0]*y*y + qat[1];
.................... r = r*y*y + qat[2];
.................... r = r*y*y + qat[3];
....................
.................... res = y*res/r;
....................
....................
.................... if (flag) // for |x| > 1
.................... res = PI_DIV_BY_TWO - res;
.................... if (s)
.................... res = -res;
....................
.................... return(res);
.................... }
.................... //Overloaded functions for atan() for PCD
.................... // Overloaded function atan() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 atan(float48 x)
.................... {
.................... float48 y, res, r;
.................... int1 s, flag;
....................
.................... s = 0;
.................... flag = 0;
.................... y = x;
....................
.................... if (x < 0)
.................... {
.................... s = 1;
.................... y = -y;
.................... }
....................
.................... if (y > 1.0)
.................... {
.................... y = 1.0/y;
.................... flag = 1;
.................... }
....................
.................... res = pat[0]*y*y + pat[1];
.................... res = res*y*y + pat[2];
.................... res = res*y*y + pat[3];
....................
.................... r = qat[0]*y*y + qat[1];
.................... r = r*y*y + qat[2];
.................... r = r*y*y + qat[3];
....................
.................... res = y*res/r;
....................
....................
.................... if (flag) // for |x| > 1
.................... res = PI_DIV_BY_TWO - res;
.................... if (s)
.................... res = -res;
....................
.................... return(res);
.................... }
....................
.................... // Overloaded function atan() for data type - Float64
.................... float64 atan(float64 x)
.................... {
.................... float64 y, res, r;
.................... int1 s, flag;
....................
.................... s = 0;
.................... flag = 0;
.................... y = x;
....................
.................... if (x < 0)
.................... {
.................... s = 1;
.................... y = -y;
.................... }
....................
.................... if (y > 1.0)
.................... {
.................... y = 1.0/y;
.................... flag = 1;
.................... }
....................
.................... res = pat[0]*y*y + pat[1];
.................... res = res*y*y + pat[2];
.................... res = res*y*y + pat[3];
....................
.................... r = qat[0]*y*y + qat[1];
.................... r = r*y*y + qat[2];
.................... r = r*y*y + qat[3];
....................
.................... res = y*res/r;
....................
....................
.................... if (flag) // for |x| > 1
.................... res = PI_DIV_BY_TWO - res;
.................... if (s)
.................... res = -res;
....................
.................... return(res);
.................... }
.................... #endif
....................
.................... /////////////////////////////////////////////////////////////////////////////
.................... // float atan2(float y, float x)
.................... /////////////////////////////////////////////////////////////////////////////
.................... // Description :computes the principal value of arc tangent of y/x, using the
.................... // signs of both the arguments to determine the quadrant of the return value
.................... // Returns : returns the arc tangent of y/x.
.................... // Date : N/A
.................... //
....................
.................... float32 atan2(float32 y,float32 x)
.................... {
.................... float32 z;
.................... int1 sign;
.................... unsigned int8 quad;
.................... sign=0;
.................... quad=0; //quadrant
.................... quad=((y<=0.0)?((x<=0.0)?3:4):((x<0.0)?2:1));
.................... if(y<0.0)
.................... {
.................... sign=1;
.................... y=-y;
.................... }
.................... if(x<0.0)
.................... {
.................... x=-x;
.................... }
.................... if (x==0.0)
.................... {
.................... if(y==0.0)
.................... {
.................... #ifdef _ERRNO
.................... {
.................... errno=EDOM;
.................... }
.................... #endif
.................... }
.................... else
.................... {
.................... if(sign)
.................... {
.................... return (-(PI_DIV_BY_TWO));
.................... }
.................... else
.................... {
.................... return (PI_DIV_BY_TWO);
.................... }
.................... }
.................... }
.................... else
.................... {
.................... z=y/x;
.................... switch(quad)
.................... {
.................... case 1:
.................... {
.................... return atan(z);
.................... break;
.................... }
.................... case 2:
.................... {
.................... // return (atan(z)+PI_DIV_BY_TWO); //2L3122
.................... return (PI-atan(z));
.................... break;
.................... }
.................... case 3:
.................... {
.................... return (atan(z)-PI);
.................... break;
.................... }
.................... case 4:
.................... {
.................... return (-atan(z));
.................... break;
.................... }
.................... }
.................... }
.................... }
....................
.................... //Overloaded functions for atan2() for PCD
.................... // Overloaded function atan2() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 atan2(float48 y,float48 x)
.................... {
.................... float48 z;
.................... int1 sign;
.................... unsigned int8 quad;
.................... sign=0;
.................... quad=0; //quadrant
.................... quad=((y<=0.0)?((x<=0.0)?3:4):((x<0.0)?2:1));
.................... if(y<0.0)
.................... {
.................... sign=1;
.................... y=-y;
.................... }
.................... if(x<0.0)
.................... {
.................... x=-x;
.................... }
.................... if (x==0.0)
.................... {
.................... if(y==0.0)
.................... {
.................... #ifdef _ERRNO
.................... {
.................... errno=EDOM;
.................... }
.................... #endif
.................... }
.................... else
.................... {
.................... if(sign)
.................... {
.................... return (-(PI_DIV_BY_TWO));
.................... }
.................... else
.................... {
.................... return (PI_DIV_BY_TWO);
.................... }
.................... }
.................... }
.................... else
.................... {
.................... z=y/x;
.................... switch(quad)
.................... {
.................... case 1:
.................... {
.................... return atan(z);
.................... break;
.................... }
.................... case 2:
.................... {
.................... // return (atan(z)+PI_DIV_BY_TWO); //2L3122
.................... return (PI-atan(z));
.................... break;
.................... }
.................... case 3:
.................... {
.................... return (atan(z)-PI);
.................... break;
.................... }
.................... case 4:
.................... {
.................... return (-atan(z));
.................... break;
.................... }
.................... }
.................... }
.................... }
....................
.................... // Overloaded function atan2() for data type - Float64
.................... float64 atan2(float64 y,float64 x)
.................... {
.................... float64 z;
.................... int1 sign;
.................... unsigned int8 quad;
.................... sign=0;
.................... quad=0; //quadrant
.................... quad=((y<=0.0)?((x<=0.0)?3:4):((x<0.0)?2:1));
.................... if(y<0.0)
.................... {
.................... sign=1;
.................... y=-y;
.................... }
.................... if(x<0.0)
.................... {
.................... x=-x;
.................... }
.................... if (x==0.0)
.................... {
.................... if(y==0.0)
.................... {
.................... #ifdef _ERRNO
.................... {
.................... errno=EDOM;
.................... }
.................... #endif
.................... }
.................... else
.................... {
.................... if(sign)
.................... {
.................... return (-(PI_DIV_BY_TWO));
.................... }
.................... else
.................... {
.................... return (PI_DIV_BY_TWO);
.................... }
.................... }
.................... }
.................... else
.................... {
.................... z=y/x;
.................... switch(quad)
.................... {
.................... case 1:
.................... {
.................... return atan(z);
.................... break;
.................... }
.................... case 2:
.................... {
.................... // return (atan(z)+PI_DIV_BY_TWO); //2L3122
.................... return (PI-atan(z));
.................... break;
.................... }
.................... case 3:
.................... {
.................... return (atan(z)-PI);
.................... break;
.................... }
.................... case 4:
.................... {
.................... return (-atan(z));
.................... break;
.................... }
.................... }
.................... }
.................... }
.................... #endif
....................
.................... //////////////////// Hyperbolic functions ////////////////////
....................
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float cosh(float x)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description : Computes the hyperbolic cosine value of x
.................... // Returns : returns the hyperbolic cosine value of x
.................... // Date : N/A
.................... //
....................
.................... float32 cosh(float32 x)
.................... {
.................... return ((exp(x)+exp(-x))/2);
.................... }
.................... //Overloaded functions for cosh() for PCD
.................... // Overloaded function cosh() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 cosh(float48 x)
.................... {
.................... return ((exp(x)+exp(-x))/2);
.................... }
....................
.................... // Overloaded function cosh() for data type - Float64
.................... float64 cosh(float64 x)
.................... {
.................... return ((exp(x)+exp(-x))/2);
.................... }
.................... #endif
....................
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float sinh(float x)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description : Computes the hyperbolic sine value of x
.................... // Returns : returns the hyperbolic sine value of x
.................... // Date : N/A
.................... //
....................
.................... float32 sinh(float32 x)
.................... {
....................
.................... return ((exp(x) - exp(-x))/2);
.................... }
.................... //Overloaded functions for sinh() for PCD
.................... // Overloaded function sinh() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 sinh(float48 x)
.................... {
....................
.................... return ((exp(x) - exp(-x))/2);
.................... }
....................
.................... // Overloaded function sinh() for data type - Float48
.................... float64 sinh(float64 x)
.................... {
....................
.................... return ((exp(x) - exp(-x))/2);
.................... }
.................... #endif
....................
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float tanh(float x)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description : Computes the hyperbolic tangent value of x
.................... // Returns : returns the hyperbolic tangent value of x
.................... // Date : N/A
.................... //
....................
.................... float32 tanh(float32 x)
.................... {
.................... return(sinh(x)/cosh(x));
.................... }
.................... //Overloaded functions for tanh() for PCD
.................... // Overloaded function tanh() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 tanh(float48 x)
.................... {
.................... return(sinh(x)/cosh(x));
.................... }
....................
.................... // Overloaded function tanh() for data type - Float64
.................... float64 tanh(float64 x)
.................... {
.................... return(sinh(x)/cosh(x));
.................... }
.................... #endif
....................
.................... ////////////////////////////////////////////////////////////////////////////
.................... // float frexp(float x, signed int *exp)
.................... ////////////////////////////////////////////////////////////////////////////
.................... // Description : breaks a floating point number into a normalized fraction and an integral
.................... // power of 2. It stores the integer in the signed int object pointed to by exp.
.................... // Returns : returns the value x, such that x is a double with magnitude in the interval
.................... // [1/2,1) or zero, and value equals x times 2 raised to the power *exp.If value is zero,
.................... // both parts of the result are zero.
.................... // Date : N/A
.................... //
....................
.................... #define LOG2 .30102999566398119521
.................... float32 frexp(float32 x, signed int8 *exp)
.................... {
.................... float32 res;
.................... int1 sign = 0;
.................... if(x == 0.0)
.................... {
.................... *exp=0;
.................... return (0.0);
.................... }
.................... if(x < 0.0)
.................... {
.................... x=-x;
.................... sign=1;
.................... }
.................... if (x > 1.0)
.................... {
.................... *exp=(ceil(log10(x)/LOG2));
.................... res=x/(pow(2, *exp));
.................... if (res == 1)
.................... {
.................... *exp=*exp+1;
.................... res=.5;
.................... }
.................... }
.................... else
.................... {
.................... if(x < 0.5)
.................... {
.................... *exp=-1;
.................... res=x*2;
.................... }
.................... else
.................... {
.................... *exp=0;
.................... res=x;
.................... }
.................... }
.................... if(sign)
.................... {
.................... res=-res;
.................... }
.................... return res;
.................... }
....................
.................... //Overloaded functions for frexp() for PCD
.................... // Overloaded function frexp() for data type - Float48
.................... #if defined(__PCD__)
.................... float48 frexp(float48 x, signed int8 *exp)
.................... {
.................... float48 res;
.................... int1 sign = 0;
.................... if(x == 0.0)
.................... {
.................... *exp=0;
.................... return (0.0);
.................... }
.................... if(x < 0.0)
.................... {
.................... x=-x;
.................... sign=1;
.................... }
.................... if (x > 1.0)
.................... {
.................... *exp=(ceil(log10(x)/LOG2));
.................... res=x/(pow(2, *exp));
.................... if (res == 1)
.................... {
.................... *exp=*exp+1;
.................... res=.5;
.................... }
.................... }
.................... else
.................... {
.................... if(x < 0.5)
.................... {
.................... *exp=-1;
.................... res=x*2;
.................... }
.................... else
.................... {
.................... *exp=0;
.................... res=x;
.................... }
.................... }
.................... if(sign)
.................... {
.................... res=-res;
.................... }
.................... return res;
.................... }
....................
.................... // Overloaded function frexp() for data type - Float64
.................... float64 frexp(float64 x, signed int8 *exp)
.................... {
.................... float64 res;
.................... int1 sign = 0;
.................... if(x == 0.0)
.................... {
.................... *exp=0;
.................... return (0.0);
.................... }
.................... if(x < 0.0)
.................... {
.................... x=-x;
.................... sign=1;
.................... }
.................... if (x > 1.0)
.................... {
.................... *exp=(ceil(log10(x)/LOG2));
.................... res=x/(pow(2, *exp));
.................... if (res == 1)
.................... {
.................... *exp=*exp+1;
.................... res=.5;
.................... }
.................... }
.................... else
.................... {
.................... if(x < 0.5)
.................... {
.................... *exp=-1;
.................... res=x*2;
.................... }
.................... else
.................... {
.................... *exp=0;
.................... res=x;
.................... }
.................... }
.................... if(sign)
.................... {
.................... res=-res;
.................... }
.................... return res;
.................... }
.................... #endif
....................
.................... //////////////////////////////////////////////////////////////////////////////
.................... // float ldexp(float x, signed int *exp)
.................... //////////////////////////////////////////////////////////////////////////////
.................... // Description : multiplies a floating point number by an integral power of 2.
.................... // Returns : returns the value of x times 2 raised to the power exp.
.................... // Date : N/A
.................... //
....................
.................... float32 ldexp(float32 value, signed int8 exp)
.................... {
.................... return (value * pow(2,exp));
.................... }
.................... //Overloaded functions for ldexp() for PCD
.................... // Overloaded function ldexp() for data type - Float48
....................
.................... #if defined(__PCD__)
.................... float48 ldexp(float48 value, signed int8 exp)
.................... {
.................... return (value * pow(2,exp));
.................... }
.................... // Overloaded function ldexp() for data type - Float64
.................... float64 ldexp(float64 value, signed int8 exp)
.................... {
.................... return (value * pow(2,exp));
.................... }
.................... #endif
....................
.................... #endif
....................
....................
.................... void main()
.................... {
*
024F: CLRF 04
0250: BCF 03.7
0251: MOVLW 1F
0252: ANDWF 03,F
0253: MOVLW 71
0254: BSF 03.5
0255: MOVWF 0F
0256: MOVF 0F,W
0257: BCF 03.5
0258: BCF 20.7
0259: MOVF 20,W
025A: BSF 03.5
025B: MOVWF 07
025C: BCF 03.5
025D: BSF 07.7
025E: BSF 03.5
025F: BSF 03.6
0260: MOVF 09,W
0261: ANDLW C0
0262: MOVWF 09
0263: BCF 03.6
0264: BCF 1F.4
0265: BCF 1F.5
0266: MOVLW 00
0267: BSF 03.6
0268: MOVWF 08
0269: BCF 03.5
026A: CLRF 07
026B: CLRF 08
026C: CLRF 09
*
0276: CLRF 34
0277: CLRF 33
.................... float last,b,anemo_speed;
.................... unsigned int16 anemo_round=0;
.................... unsigned int16 i;
....................
....................
.................... //signed int16 X,Y,Z;
.................... setup_adc_ports(NO_ANALOGS|VSS_VDD);
0278: BSF 03.5
0279: BSF 03.6
027A: MOVF 09,W
027B: ANDLW C0
027C: MOVWF 09
027D: BCF 03.6
027E: BCF 1F.4
027F: BCF 1F.5
0280: MOVLW 00
0281: BSF 03.6
0282: MOVWF 08
.................... setup_adc(ADC_CLOCK_DIV_2);
0283: BCF 03.5
0284: BCF 03.6
0285: BCF 1F.6
0286: BCF 1F.7
0287: BSF 03.5
0288: BCF 1F.7
0289: BCF 03.5
028A: BSF 1F.0
.................... setup_spi(SPI_SS_DISABLED);
028B: BCF 14.5
028C: BCF 20.5
028D: MOVF 20,W
028E: BSF 03.5
028F: MOVWF 07
0290: BCF 03.5
0291: BSF 20.4
0292: MOVF 20,W
0293: BSF 03.5
0294: MOVWF 07
0295: BCF 03.5
0296: BCF 20.3
0297: MOVF 20,W
0298: BSF 03.5
0299: MOVWF 07
029A: MOVLW 01
029B: BCF 03.5
029C: MOVWF 14
029D: MOVLW 00
029E: BSF 03.5
029F: MOVWF 14
.................... setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
02A0: MOVF 01,W
02A1: ANDLW C7
02A2: IORLW 08
02A3: MOVWF 01
.................... setup_timer_1(T1_DISABLED);
02A4: BCF 03.5
02A5: CLRF 10
.................... setup_timer_2(T2_DISABLED,0,1);
02A6: MOVLW 00
02A7: MOVWF 78
02A8: MOVWF 12
02A9: MOVLW 00
02AA: BSF 03.5
02AB: MOVWF 12
.................... setup_ccp1(CCP_OFF);
02AC: BCF 03.5
02AD: BSF 20.2
02AE: MOVF 20,W
02AF: BSF 03.5
02B0: MOVWF 07
02B1: BCF 03.5
02B2: CLRF 17
02B3: BSF 03.5
02B4: CLRF 1B
02B5: CLRF 1C
02B6: MOVLW 01
02B7: MOVWF 1D
.................... setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
02B8: BCF 03.5
02B9: BSF 03.6
02BA: CLRF 07
02BB: CLRF 08
02BC: CLRF 09
....................
.................... // Init the HMC5883L. Set Mode register for
.................... // continuous measurements.
.................... hmc5883l_write_reg(HMC5883L_CFG_A_REG, 0x18); // no average, maximal update range
02BD: BCF 03.6
02BE: CLRF 37
02BF: MOVLW 18
02C0: MOVWF 38
02C1: CALL 069
.................... hmc5883l_write_reg(HMC5883L_CFG_B_REG, 0xE0); // maximal range
02C2: MOVLW 01
02C3: MOVWF 37
02C4: MOVLW E0
02C5: MOVWF 38
02C6: CALL 069
.................... hmc5883l_write_reg(HMC5883L_MODE_REG, 0x00);
02C7: MOVLW 02
02C8: MOVWF 37
02C9: CLRF 38
02CA: CALL 069
....................
.................... // Continuously read and display the x,y,z results.
.................... // Wait at least 67 ms between reads, re the HMC5883L data sheet.
....................
....................
.................... printf("Magnetometr: \r\n",);
02CB: MOVLW 04
02CC: BSF 03.6
02CD: MOVWF 0D
02CE: MOVLW 00
02CF: MOVWF 0F
02D0: BCF 03.6
02D1: CALL 0C5
.................... printf("(c)mlab JACHO 2013: \r\n",);
02D2: MOVLW 0D
02D3: BSF 03.6
02D4: MOVWF 0D
02D5: MOVLW 00
02D6: MOVWF 0F
02D7: BCF 03.6
02D8: CALL 0C5
.................... printf("X, Y, Z \r\n",);
02D9: MOVLW 19
02DA: BSF 03.6
02DB: MOVWF 0D
02DC: MOVLW 00
02DD: MOVWF 0F
02DE: BCF 03.6
02DF: CALL 0C5
....................
.................... /* while(true)
.................... {
.................... X = mag_readX();
.................... Y = mag_readY();
.................... Z = mag_readZ();
.................... printf("%4Ld %4Ld %4Ld \r\n", X, Y, Z);
.................... Delay_ms(50);
....................
.................... }
.................... */
....................
.................... while(TRUE)
.................... {
....................
.................... // for(i=0;i<=10;i++)
.................... // {
.................... hmc5883l_read_data();
02E0: GOTO 150
....................
.................... // b = atan2((float)compass.y,(float)compass.x); // vypocet azimutu z kartezskych souradnic
.................... // b = (b/3.141596)*180; // prevod na stupne
.................... // b += 180;
....................
.................... // anemo_speed += (b-last);
.................... // last=b;
.................... // delay_ms(10);
.................... // }
.................... // anemo_speed=anemo_speed/10;
....................
.................... printf("%6Ld %6Ld %6Ld \n\r", compass.x, compass.y, compass.z);
02E1: MOVLW 00
02E2: MOVWF 04
02E3: MOVF 22,W
02E4: MOVWF 38
02E5: MOVF 21,W
02E6: MOVWF 37
02E7: CALL 1CF
02E8: MOVLW 20
02E9: MOVWF 40
02EA: CALL 0A2
02EB: MOVLW 00
02EC: MOVWF 04
02ED: MOVF 24,W
02EE: MOVWF 38
02EF: MOVF 23,W
02F0: MOVWF 37
02F1: CALL 1CF
02F2: MOVLW 20
02F3: MOVWF 40
02F4: CALL 0A2
02F5: MOVLW 00
02F6: MOVWF 04
02F7: MOVF 26,W
02F8: MOVWF 38
02F9: MOVF 25,W
02FA: MOVWF 37
02FB: CALL 1CF
02FC: MOVLW 20
02FD: MOVWF 40
02FE: CALL 0A2
02FF: MOVLW 0A
0300: MOVWF 40
0301: CALL 0A2
0302: MOVLW 0D
0303: MOVWF 40
0304: CALL 0A2
.................... // delay_ms(100);
.................... }
0305: GOTO 2E0
....................
.................... }
....................
....................
....................
0306: SLEEP
 
Configuration Fuses:
Word 1: 2CF5 INTRC NOWDT NOPUT MCLR NOPROTECT NOCPD NOBROWNOUT IESO FCMEN NOLVP NODEBUG
Word 2: 3FFF NOWRT BORV40
/Modules/Sensors/MAG01A/SW/PIC16F887/main.sta
0,0 → 1,59
 
ROM used: 775 (9%)
775 (9%) including unused fragments
 
0 Average locations per line
3 Average locations per statement
 
RAM used: 28 (8%) at main() level
38 (10%) worst case
 
Stack used: 2 worst case (out of 8 total available)
 
Lines Stmts % Files
----- ----- --- -----
72 18 6 main.c
22 0 0 main.h
423 0 0 C:\Program Files (x86)\PICC\devices\16F887.h
19 0 0 HMC5883L.h
86 28 9 HMC5883L.c
2172 260 85 C:\Program Files (x86)\PICC\drivers\math.h
----- -----
2794 306 Total
 
Page ROM % RAM Vol Diff Functions:
---- --- --- --- --- ---- ----------
0 69 9 3 357 1.4 @I2C_READ_1
0 74 10 1 113 1.3 @I2C_WRITE_1
0 35 5 1 152 2.2 @PUTCHAR_1_
0 57 7 2 102 1.8 hmc5883l_write_reg
0 127 16 6 636 3.3 hmc5883l_read_data
0 184 24 16 693 3.9 MAIN
0 9 1 0 @const237
0 70 9 3 @PSTRINGC7_69
0 12 2 0 @const239
0 6 1 0 @const240
0 128 17 9 @PRINTF_LD_69
 
Program metrics:
Functions 6
Statements 306
Comments 377
Volume (V) 2949
Difficilty (D) 13.9
Effort to implement (E) 40971
Time to implement (T) 38 minutes
Est Delivered Bugs (B) 0
Cyclomatic Complexity 1
Maintainability (MI) 61
 
Segment Used Free
----------- ---- ----
00000-00003 4 0
00004-007FF 771 1273
00800-00FFF 0 2048
01000-017FF 0 2048
01800-01FFF 0 2048
 
 
 
/Modules/Sensors/MAG01A/SW/PIC16F887/main.sym
0,0 → 1,101
004-005 @READ_PROGRAM_MEMORY8.P1
004 @WRITE_PROGRAM_MEMORY8.P2
015 CCP_1_LOW
015 CCP_1
016 CCP_1_HIGH
01B CCP_2_LOW
01B CCP_2
01C CCP_2_HIGH
020 @TRIS_C
021-026 compass
027-02A MAIN.last
02B-02E MAIN.b
02F-032 MAIN.anemo_speed
033-034 MAIN.anemo_round
035-036 MAIN.i
037-038 @PRINTF_LD_69.P1
037 hmc5883l_write_reg.reg
037 hmc5883l_read_data.x_lsb
037 @PSTRINGC7_69.@SCRATCH1
038 hmc5883l_read_data.x_msb
038 hmc5883l_write_reg.data
038 @PSTRINGC7_69.@SCRATCH2
039 hmc5883l_read_data.y_lsb
039 @PSTRINGC7_69.@SCRATCH3
039 @PRINTF_LD_69.@SCRATCH1
03A hmc5883l_read_data.y_msb
03A @PRINTF_LD_69.@SCRATCH2
03B hmc5883l_read_data.z_lsb
03B @PRINTF_LD_69.@SCRATCH3
03C hmc5883l_read_data.z_msb
03C @PRINTF_LD_69.@SCRATCH4
03D @I2C_WRITE_1.P1
03D @I2C_READ_1.P2
03D @PRINTF_LD_69.@SCRATCH5
03E @I2C_READ_1.@SCRATCH1
03E @PRINTF_LD_69.@SCRATCH6
03F @I2C_READ_1.@SCRATCH2
03F @PRINTF_LD_69.@SCRATCH7
040 @PUTCHAR_1_.P1
077 @SCRATCH
078 @SCRATCH
078 _RETURN_
079 @SCRATCH
07A @SCRATCH
107.6 C1OUT
108.6 C2OUT
10D-10E @READ_PROGRAM_MEMORY8.P1
10D-10E @WRITE_PROGRAM_MEMORY8.P2
 
ROM Allocation:
010B @I2C_READ_1
001F @I2C_WRITE_1
00A2 @PUTCHAR_1_
0069 hmc5883l_write_reg
0150 hmc5883l_read_data
0800 atan2
024F MAIN
0004 @const237
00C5 @PSTRINGC7_69
000D @const239
0019 @const240
01CF @PRINTF_LD_69
024F @cinit
 
 
User Memory space:
 
User Memory space:
 
Project Directory:
Z:\home\kaklik\svnMLAB\Modules\Sensors\MAG01A\SW\PIC16F887\
 
Project Files:
main.c
main.h
C:\Program Files (x86)\PICC\devices\16F887.h
HMC5883L.h
HMC5883L.c
C:\Program Files (x86)\PICC\drivers\math.h
 
Units:
Z:\home\kaklik\svnMLAB\Modules\Sensors\MAG01A\SW\PIC16F887\main (main)
 
Compiler Settings:
Processor: PIC16F887
Pointer Size: 16
ADC Range: 0-255
Opt Level: 9
Short,Int,Long: UNSIGNED: 1,8,16
Float,Double: 32,32
 
Output Files:
Errors: main.err
Ext Symbols: main.esym
INHX8: main.hex
Symbols: main.sym
List: main.lst
Debug/COFF: main.cof
Project: main.PJT
Call Tree: main.tre
Statistics: main.sta
/Modules/Sensors/MAG01A/SW/PIC16F887/main.tre
0,0 → 1,45
ÀÄmain
ÀÄMAIN 0/184 Ram=16
ÃÄ??0??
ÃÄhmc5883l_write_reg 0/57 Ram=2
³ ÃÄ@I2C_WRITE_1 0/74 Ram=1
³ ÃÄ@I2C_WRITE_1 0/74 Ram=1
³ ÀÄ@I2C_WRITE_1 0/74 Ram=1
ÃÄhmc5883l_write_reg 0/57 Ram=2
³ ÃÄ@I2C_WRITE_1 0/74 Ram=1
³ ÃÄ@I2C_WRITE_1 0/74 Ram=1
³ ÀÄ@I2C_WRITE_1 0/74 Ram=1
ÃÄhmc5883l_write_reg 0/57 Ram=2
³ ÃÄ@I2C_WRITE_1 0/74 Ram=1
³ ÃÄ@I2C_WRITE_1 0/74 Ram=1
³ ÀÄ@I2C_WRITE_1 0/74 Ram=1
ÃÄ@PSTRINGC7_69 0/70 Ram=3
³ ÃÄ@PUTCHAR_1_ 0/35 Ram=1
³ ÀÄ@PUTCHAR_1_ 0/35 Ram=1
ÃÄ@PSTRINGC7_69 0/70 Ram=3
³ ÃÄ@PUTCHAR_1_ 0/35 Ram=1
³ ÀÄ@PUTCHAR_1_ 0/35 Ram=1
ÃÄ@PSTRINGC7_69 0/70 Ram=3
³ ÃÄ@PUTCHAR_1_ 0/35 Ram=1
³ ÀÄ@PUTCHAR_1_ 0/35 Ram=1
ÃÄhmc5883l_read_data 0/127 Ram=6
³ ÃÄ@I2C_WRITE_1 0/74 Ram=1
³ ÃÄ@I2C_WRITE_1 0/74 Ram=1
³ ÃÄ@I2C_WRITE_1 0/74 Ram=1
³ ÃÄ@I2C_READ_1 0/69 Ram=3
³ ÃÄ@I2C_READ_1 0/69 Ram=3
³ ÃÄ@I2C_READ_1 0/69 Ram=3
³ ÃÄ@I2C_READ_1 0/69 Ram=3
³ ÃÄ@I2C_READ_1 0/69 Ram=3
³ ÀÄ@I2C_READ_1 0/69 Ram=3
ÃÄ@PRINTF_LD_69 0/128 Ram=9
³ ÀÄ@PUTCHAR_1_ 0/35 Ram=1
ÃÄ@PUTCHAR_1_ 0/35 Ram=1
ÃÄ@PRINTF_LD_69 0/128 Ram=9
³ ÀÄ@PUTCHAR_1_ 0/35 Ram=1
ÃÄ@PUTCHAR_1_ 0/35 Ram=1
ÃÄ@PRINTF_LD_69 0/128 Ram=9
³ ÀÄ@PUTCHAR_1_ 0/35 Ram=1
ÃÄ@PUTCHAR_1_ 0/35 Ram=1
ÃÄ@PUTCHAR_1_ 0/35 Ram=1
ÀÄ@PUTCHAR_1_ 0/35 Ram=1
/Modules/Sensors/MAG01A/SW/PIC16F887/HMC5883L.c
0,0 → 1,85
// i2c slave addresses
#define HMC5883L_WRT_ADDR 0x3C
#define HMC5883L_READ_ADDR 0x3D
 
// Register addresses
#define HMC5883L_CFG_A_REG 0x00
#define HMC5883L_CFG_B_REG 0x01
#define HMC5883L_MODE_REG 0x02
#define HMC5883L_X_MSB_REG 0x03
 
//------------------------------
// Low level routines
//------------------------------
void hmc5883l_write_reg(int8 reg, int8 data)
{
i2c_start();
i2c_write(HMC5883L_WRT_ADDR);
i2c_write(reg);
i2c_write(data);
i2c_stop();
}
 
//------------------------------
int8 hmc5883l_read_reg(int8 reg)
{
int8 retval;
 
i2c_start();
i2c_write(HMC5883L_WRT_ADDR);
i2c_write(reg);
i2c_start();
i2c_write(HMC5883L_READ_ADDR);
retval = i2c_read(0);
i2c_stop();
 
return(retval);
}
 
//------------------------------
typedef struct
{
signed int16 x;
signed int16 y;
signed int16 z;
}hmc5883l_result;
 
// This global structure holds the values read
// from the HMC5883L x,y,z registers.
hmc5883l_result compass = {0,0,0};
 
//------------------------------
void hmc5883l_read_data(void)
{
unsigned int8 x_lsb;
unsigned int8 x_msb;
 
unsigned int8 y_lsb;
unsigned int8 y_msb;
 
unsigned int8 z_lsb;
unsigned int8 z_msb;
 
i2c_start();
i2c_write(HMC5883L_WRT_ADDR);
i2c_write(HMC5883L_X_MSB_REG); // Point to X-msb register
i2c_start();
i2c_write(HMC5883L_READ_ADDR);
 
x_msb = i2c_read();
x_lsb = i2c_read();
 
z_msb = i2c_read();
z_lsb = i2c_read();
 
y_msb = i2c_read();
y_lsb = i2c_read(0); // do a NACK on last read
 
i2c_stop();
// Combine high and low bytes into 16-bit values.
compass.x = make16(x_msb, x_lsb);
compass.y = make16(y_msb, y_lsb);
compass.z = make16(z_msb, z_lsb);
}
 
/Modules/Sensors/MAG01A/SW/PIC16F887/main.bak
0,0 → 1,32
#include "main.h"
#include "HMC5883L.h"
 
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_2);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_ccp1(CCP_OFF);
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
 
printf("Magnetometr: \r\n",);
printf("(c)mlab JACHO 2013: \r\n",);
printf("Vysledky z jednotlivych os:\r\n",);
signed int16 X,Y,Z;
 
while(true)
{
printf("Vysledky z jednotlivych os:\r\n",);
X = mag_readX();
Y = mag_readY();
Z = mag_readZ();
printf("X: %Ld \r\n", X);
printf("Y %Ld \r\n", Y);
printf("Z: %Ld \r\n", Z);
Delay_ms(500);
}
}
/Modules/Sensors/MAG01A/SW/PIC16F887/main.pjt
0,0 → 1,30
[PROJECT]
Target=main.hex
Development_Mode=
Processor_Text=PIC16F887
ToolSuite=CCS
Processor=0x887F
[main]
Type=4
Path=
FileList=
BuildTool=
OptionString=
AdditionalOptionString=
[mru-list]
1=main.c
[Windows]
0=0000 %S 0 0 796 451 3 0
[Opened Files]
1=main.c
2=HMC5883L.c
3=main.h
4=C:\Program Files (x86)\PICC\devices\16F887.h
5=HMC5883L.h
6=
[Target Data]
OptionString=-p +FM
FileList=Z:\home\kaklik\svnMLAB\Modules\Sensors\MAG01A\SW\PIC16F887\main.c
[Units]
Count=1
1=main (main)
/Modules/Sensors/MAG01A/SW/PIC16F887/HMC5883L.h
0,0 → 1,17
#define MAG_ADDR_R 0x3D //addresa pro cteni
#define MAG_ADDR_W 0x3C
 
 
//Konstanty nastavujici rozsah
//pro void set_mag_roz (unsigned int8 h)
#define MAG_ROZ088 0x00
#define MAG_ROZ130 0x20
#define MAG_ROZ190 0x40
#define MAG_ROZ250 0x60
#define MAG_ROZ400 0x80
#define MAG_ROZ470 0xA0
#define MAG_ROZ560 0xC0
#define MAG_ROZ810 0xE0
 
 
#include "HMC5883L.c"