CCS PCM C Compiler, Version 4.106, 47914 15-V-13 18:53
Filename: Z:\home\kaklik\svnMLAB\Modules\Sensors\MAG01A\SW\PIC16F887\main.lst
ROM used: 821 words (10%)
Largest free fragment is 2048
RAM used: 18 (5%) at main() level
27 (7%) worst case
Stack: 2 locations
*
0000: MOVLW 02
0001: MOVWF 0A
0002: GOTO 250
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 32,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
*
010C: MOVLW 08
010D: MOVWF 33
010E: MOVF 77,W
010F: MOVWF 34
0110: BSF 20.4
0111: MOVF 20,W
0112: BSF 03.5
0113: MOVWF 07
0114: NOP
0115: BCF 03.5
0116: BSF 20.3
0117: MOVF 20,W
0118: BSF 03.5
0119: MOVWF 07
011A: BCF 03.5
011B: BTFSS 07.3
011C: GOTO 11B
011D: BTFSC 07.4
011E: BSF 03.0
011F: BTFSS 07.4
0120: BCF 03.0
0121: RLF 78,F
0122: NOP
0123: BCF 20.3
0124: MOVF 20,W
0125: BSF 03.5
0126: MOVWF 07
0127: BCF 03.5
0128: BCF 07.3
0129: DECFSZ 33,F
012A: GOTO 110
012B: BSF 20.4
012C: MOVF 20,W
012D: BSF 03.5
012E: MOVWF 07
012F: NOP
0130: BCF 03.5
0131: BCF 07.4
0132: MOVF 34,W
0133: BTFSC 03.2
0134: GOTO 13A
0135: BCF 20.4
0136: MOVF 20,W
0137: BSF 03.5
0138: MOVWF 07
0139: BCF 03.5
013A: NOP
013B: BSF 20.3
013C: MOVF 20,W
013D: BSF 03.5
013E: MOVWF 07
013F: BCF 03.5
0140: BTFSS 07.3
0141: GOTO 140
0142: NOP
0143: BCF 07.3
0144: BCF 20.3
0145: MOVF 20,W
0146: BSF 03.5
0147: MOVWF 07
0148: NOP
0149: BCF 03.5
014A: BCF 07.4
014B: BCF 20.4
014C: MOVF 20,W
014D: BSF 03.5
014E: MOVWF 07
014F: BCF 03.5
0150: RETURN
.................... #use rs232(baud=9600,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 0BC
00AE: BCF 78.7
00AF: RRF 35,F
00B0: BTFSC 03.0
00B1: BSF 07.7
00B2: BTFSS 03.0
00B3: BCF 07.7
00B4: BSF 78.6
00B5: GOTO 0BC
00B6: BCF 78.6
00B7: DECFSZ 78,F
00B8: GOTO 0AF
00B9: GOTO 0BA
00BA: NOP
00BB: BSF 07.7
00BC: MOVLW 3F
00BD: MOVWF 04
00BE: DECFSZ 04,F
00BF: GOTO 0BE
00C0: NOP
00C1: BTFSC 78.7
00C2: GOTO 0AE
00C3: BTFSC 78.6
00C4: GOTO 0B6
00C5: 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 32
0084: CALL 01F
.................... i2c_write(reg);
0085: MOVF 2C,W
0086: MOVWF 32
0087: CALL 01F
.................... i2c_write(data);
0088: MOVF 2D,W
0089: MOVWF 32
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};
*
0271: CLRF 21
0272: CLRF 22
0273: CLRF 23
0274: CLRF 24
0275: CLRF 25
0276: 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();
*
0151: BSF 20.4
0152: MOVF 20,W
0153: BSF 03.5
0154: MOVWF 07
0155: NOP
0156: BCF 03.5
0157: BSF 20.3
0158: MOVF 20,W
0159: BSF 03.5
015A: MOVWF 07
015B: NOP
015C: BCF 03.5
015D: BCF 07.4
015E: BCF 20.4
015F: MOVF 20,W
0160: BSF 03.5
0161: MOVWF 07
0162: NOP
0163: BCF 03.5
0164: BCF 07.3
0165: BCF 20.3
0166: MOVF 20,W
0167: BSF 03.5
0168: MOVWF 07
.................... i2c_write(HMC5883L_WRT_ADDR);
0169: MOVLW 3C
016A: BCF 03.5
016B: MOVWF 32
016C: CALL 01F
.................... i2c_write(HMC5883L_X_MSB_REG); // Point to X-msb register
016D: MOVLW 03
016E: MOVWF 32
016F: CALL 01F
.................... i2c_start();
0170: BSF 20.4
0171: MOVF 20,W
0172: BSF 03.5
0173: MOVWF 07
0174: NOP
0175: BCF 03.5
0176: BSF 20.3
0177: MOVF 20,W
0178: BSF 03.5
0179: MOVWF 07
017A: NOP
017B: BCF 03.5
017C: BTFSS 07.3
017D: GOTO 17C
017E: BCF 07.4
017F: BCF 20.4
0180: MOVF 20,W
0181: BSF 03.5
0182: MOVWF 07
0183: NOP
0184: BCF 03.5
0185: BCF 07.3
0186: BCF 20.3
0187: MOVF 20,W
0188: BSF 03.5
0189: MOVWF 07
.................... i2c_write(HMC5883L_READ_ADDR);
018A: MOVLW 3D
018B: BCF 03.5
018C: MOVWF 32
018D: CALL 01F
....................
.................... x_msb = i2c_read();
018E: MOVLW 01
018F: MOVWF 77
0190: CALL 10C
0191: MOVF 78,W
0192: MOVWF 2D
.................... x_lsb = i2c_read();
0193: MOVLW 01
0194: MOVWF 77
0195: CALL 10C
0196: MOVF 78,W
0197: MOVWF 2C
....................
.................... z_msb = i2c_read();
0198: MOVLW 01
0199: MOVWF 77
019A: CALL 10C
019B: MOVF 78,W
019C: MOVWF 31
.................... z_lsb = i2c_read();
019D: MOVLW 01
019E: MOVWF 77
019F: CALL 10C
01A0: MOVF 78,W
01A1: MOVWF 30
....................
.................... y_msb = i2c_read();
01A2: MOVLW 01
01A3: MOVWF 77
01A4: CALL 10C
01A5: MOVF 78,W
01A6: MOVWF 2F
.................... y_lsb = i2c_read(0); // do a NACK on last read
01A7: CLRF 77
01A8: CALL 10C
01A9: MOVF 78,W
01AA: MOVWF 2E
....................
.................... i2c_stop();
01AB: BCF 20.4
01AC: MOVF 20,W
01AD: BSF 03.5
01AE: MOVWF 07
01AF: NOP
01B0: BCF 03.5
01B1: BSF 20.3
01B2: MOVF 20,W
01B3: BSF 03.5
01B4: MOVWF 07
01B5: BCF 03.5
01B6: BTFSS 07.3
01B7: GOTO 1B6
01B8: NOP
01B9: GOTO 1BA
01BA: NOP
01BB: BSF 20.4
01BC: MOVF 20,W
01BD: BSF 03.5
01BE: MOVWF 07
01BF: NOP
....................
.................... // Combine high and low bytes into 16-bit values.
.................... compass.x = make16(x_msb, x_lsb);
01C0: BCF 03.5
01C1: MOVF 2D,W
01C2: MOVWF 22
01C3: MOVF 2C,W
01C4: MOVWF 21
.................... compass.y = make16(y_msb, y_lsb);
01C5: MOVF 2F,W
01C6: MOVWF 24
01C7: MOVF 2E,W
01C8: MOVWF 23
.................... compass.z = make16(z_msb, z_lsb);
01C9: MOVF 31,W
01CA: MOVWF 26
01CB: MOVF 30,W
01CC: MOVWF 25
.................... }
01CD: BCF 0A.3
01CE: BCF 0A.4
01CF: GOTO 2EE (RETURN)
....................
....................
....................
....................
....................
.................... void main()
.................... {
*
0250: CLRF 04
0251: BCF 03.7
0252: MOVLW 1F
0253: ANDWF 03,F
0254: MOVLW 71
0255: BSF 03.5
0256: MOVWF 0F
0257: MOVF 0F,W
0258: BCF 03.5
0259: BCF 20.7
025A: MOVF 20,W
025B: BSF 03.5
025C: MOVWF 07
025D: BCF 03.5
025E: BSF 07.7
025F: BSF 03.5
0260: BSF 03.6
0261: MOVF 09,W
0262: ANDLW C0
0263: MOVWF 09
0264: BCF 03.6
0265: BCF 1F.4
0266: BCF 1F.5
0267: MOVLW 00
0268: BSF 03.6
0269: MOVWF 08
026A: BCF 03.5
026B: CLRF 07
026C: CLRF 08
026D: CLRF 09
*
0277: CLRF 29
0278: CLRF 28
.................... int1 last;
.................... unsigned int16 anemo_round=0;
.................... unsigned int16 i;
....................
....................
.................... //signed int16 X,Y,Z;
.................... setup_adc_ports(NO_ANALOGS|VSS_VDD);
0279: BSF 03.5
027A: BSF 03.6
027B: MOVF 09,W
027C: ANDLW C0
027D: MOVWF 09
027E: BCF 03.6
027F: BCF 1F.4
0280: BCF 1F.5
0281: MOVLW 00
0282: BSF 03.6
0283: MOVWF 08
.................... setup_adc(ADC_CLOCK_DIV_2);
0284: BCF 03.5
0285: BCF 03.6
0286: BCF 1F.6
0287: BCF 1F.7
0288: BSF 03.5
0289: BCF 1F.7
028A: BCF 03.5
028B: BSF 1F.0
.................... setup_spi(SPI_SS_DISABLED);
028C: BCF 14.5
028D: BCF 20.5
028E: MOVF 20,W
028F: BSF 03.5
0290: MOVWF 07
0291: BCF 03.5
0292: BSF 20.4
0293: MOVF 20,W
0294: BSF 03.5
0295: MOVWF 07
0296: BCF 03.5
0297: BCF 20.3
0298: MOVF 20,W
0299: BSF 03.5
029A: MOVWF 07
029B: MOVLW 01
029C: BCF 03.5
029D: MOVWF 14
029E: MOVLW 00
029F: BSF 03.5
02A0: MOVWF 14
.................... setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
02A1: MOVF 01,W
02A2: ANDLW C7
02A3: IORLW 08
02A4: MOVWF 01
.................... setup_timer_1(T1_DISABLED);
02A5: BCF 03.5
02A6: CLRF 10
.................... setup_timer_2(T2_DISABLED,0,1);
02A7: MOVLW 00
02A8: MOVWF 78
02A9: MOVWF 12
02AA: MOVLW 00
02AB: BSF 03.5
02AC: MOVWF 12
.................... setup_ccp1(CCP_OFF);
02AD: BCF 03.5
02AE: BSF 20.2
02AF: MOVF 20,W
02B0: BSF 03.5
02B1: MOVWF 07
02B2: BCF 03.5
02B3: CLRF 17
02B4: BSF 03.5
02B5: CLRF 1B
02B6: CLRF 1C
02B7: MOVLW 01
02B8: MOVWF 1D
.................... setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
02B9: BCF 03.5
02BA: BSF 03.6
02BB: CLRF 07
02BC: CLRF 08
02BD: CLRF 09
....................
.................... // Init the HMC5883L. Set Mode register for
.................... // continuous measurements.
.................... hmc5883l_write_reg(HMC5883L_CFG_A_REG, 0x18); // no average, maximal update range
02BE: BCF 03.6
02BF: CLRF 2C
02C0: MOVLW 18
02C1: MOVWF 2D
02C2: CALL 069
.................... hmc5883l_write_reg(HMC5883L_CFG_B_REG, 0xE0); // maximal range
02C3: MOVLW 01
02C4: MOVWF 2C
02C5: MOVLW E0
02C6: MOVWF 2D
02C7: CALL 069
.................... hmc5883l_write_reg(HMC5883L_MODE_REG, 0x00);
02C8: MOVLW 02
02C9: MOVWF 2C
02CA: CLRF 2D
02CB: 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",);
02CC: MOVLW 04
02CD: BSF 03.6
02CE: MOVWF 0D
02CF: MOVLW 00
02D0: MOVWF 0F
02D1: BCF 03.6
02D2: CALL 0C6
.................... printf("(c)mlab JACHO 2013: \r\n",);
02D3: MOVLW 0D
02D4: BSF 03.6
02D5: MOVWF 0D
02D6: MOVLW 00
02D7: MOVWF 0F
02D8: BCF 03.6
02D9: CALL 0C6
.................... printf("X, Y, Z \r\n",);
02DA: MOVLW 19
02DB: BSF 03.6
02DC: MOVWF 0D
02DD: MOVLW 00
02DE: MOVWF 0F
02DF: BCF 03.6
02E0: CALL 0C6
....................
.................... /* 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<=1000;i++)
02E1: CLRF 2B
02E2: CLRF 2A
02E3: MOVF 2B,W
02E4: SUBLW 03
02E5: BTFSS 03.0
02E6: GOTO 303
02E7: BTFSS 03.2
02E8: GOTO 2ED
02E9: MOVF 2A,W
02EA: SUBLW E8
02EB: BTFSS 03.0
02EC: GOTO 303
.................... {
.................... // delay_ms();
.................... hmc5883l_read_data();
02ED: GOTO 151
....................
.................... if(compass.x < 0)
02EE: BTFSS 22.7
02EF: GOTO 2F6
.................... {
.................... if(last == 1) anemo_round++;
02F0: BTFSS 27.0
02F1: GOTO 2F5
02F2: INCF 28,F
02F3: BTFSC 03.2
02F4: INCF 29,F
.................... last=0;
02F5: BCF 27.0
.................... }
.................... if(compass.x > 0) last=1;
02F6: BTFSC 22.7
02F7: GOTO 2FF
02F8: MOVF 22,F
02F9: BTFSS 03.2
02FA: GOTO 2FE
02FB: MOVF 21,W
02FC: SUBLW 00
02FD: BTFSS 03.0
02FE: BSF 27.0
.................... }
02FF: INCF 2A,F
0300: BTFSC 03.2
0301: INCF 2B,F
0302: GOTO 2E3
....................
.................... printf("%6Ld %6Ld %6Ld %6Ld \n\r", compass.x, compass.y, compass.z, anemo_round);
0303: MOVLW 00
0304: MOVWF 04
0305: MOVF 22,W
0306: MOVWF 2D
0307: MOVF 21,W
0308: MOVWF 2C
0309: CALL 1D0
030A: MOVLW 20
030B: MOVWF 35
030C: CALL 0A2
030D: MOVLW 00
030E: MOVWF 04
030F: MOVF 24,W
0310: MOVWF 2D
0311: MOVF 23,W
0312: MOVWF 2C
0313: CALL 1D0
0314: MOVLW 20
0315: MOVWF 35
0316: CALL 0A2
0317: MOVLW 00
0318: MOVWF 04
0319: MOVF 26,W
031A: MOVWF 2D
031B: MOVF 25,W
031C: MOVWF 2C
031D: CALL 1D0
031E: MOVLW 20
031F: MOVWF 35
0320: CALL 0A2
0321: MOVLW 00
0322: MOVWF 04
0323: MOVF 29,W
0324: MOVWF 2D
0325: MOVF 28,W
0326: MOVWF 2C
0327: CALL 1D0
0328: MOVLW 20
0329: MOVWF 35
032A: CALL 0A2
032B: MOVLW 0A
032C: MOVWF 35
032D: CALL 0A2
032E: MOVLW 0D
032F: MOVWF 35
0330: CALL 0A2
.................... anemo_round=0;
0331: CLRF 29
0332: CLRF 28
.................... }
0333: GOTO 2E1
....................
.................... }
....................
....................
....................
0334: SLEEP
Configuration Fuses:
Word 1: 2CF5 INTRC NOWDT NOPUT MCLR NOPROTECT NOCPD NOBROWNOUT IESO FCMEN NOLVP NODEBUG
Word 2: 3FFF NOWRT BORV40