C to Assembly

Thread Starter

MaxHeadRoom

Joined Jul 18, 2013
28,703
I have a short program in C that I would like to convert to Assembly, I seem to remember reading somewhere that when compiled in C an Assembly like listing can be made or requested.
Anyone confirm this and if so, possibly how?
Max.
 

Thread Starter

MaxHeadRoom

Joined Jul 18, 2013
28,703
Thanks, evidently there are two options ASMLIST and -S.
Code:
  PIC16F628A - 20MHz HS xtal (see web page for schematic)
  Compiler - MikroC for PIC v8
  PIC pins;
  RA0 = digital ST input, quad encoder A
  RA1 = digital ST input, quad encoder B
  RB3 = CCP1 output, PWM to motor, HI = ON
  RB0 = echo encoder A output
  RB1 = echo encoder A output

  PIC configs; MCRLE off, BODEN off, BORES off, WDT off, LVP off, PWRT on
******************************************************************************/

// This constant sets the motor speed. The value is in nanoSeconds per pulse,
// as we are using a quadrature encoder there are 4 pulses per encoder slot.
// My encoder had 36 slots, so that makes 36*4 or 144 pulses per revolution.
// Example; 1 motor rev per second = 144 pulses /sec.
// nS per pulse = 1 billion / 144 = 6944444
//#define  MOTOR_PULSE_PERIOD  1736111  // 4 RPS
//#define  MOTOR_PULSE_PERIOD  3472222  // 2 RPS
#define  MOTOR_PULSE_PERIOD  6944444  // 1 RPS
//#define  MOTOR_PULSE_PERIOD  13888889  // 0.5 RPS

// This constant sets the proportional gain. Basically it sets how much
// more PWM % is added for each pulse behind that the motor gets.
// ie; if set to 10, the PWM is increased by 10% for each pulse behind.
// Values must be within 1-50. Values of 10 or 16 worked well with
// low motor RPMs, for higher RPMs a smaller value like 2 to 8 can be used.
#define  MOTOR_PROP_GAIN  10

// global vars
unsigned char rpos;  // reference position of xtal based freq
unsigned char mpos;  // actual motor position
unsigned char mlag;  // amount the motor lags the reference
unsigned char enc_new;  // holds motor's quadrature encoder data for testing
unsigned char enc_last;
unsigned long bres;  // bresenham accumulator used to make ref frequency
unsigned char pins;  // temporary var for echoing encoder signals


//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void interrupt()
{
  //-------------------------------------------------------
  // This is TMR0 int, prescaled at 2:1 so we get here every 512 instructions.
  // This int does the entire closed loop speed control;
  //  1. updates encoder to see if motor has moved, records it position
  //  2. updates reference freq generator, records its position
  //  3. compares the two, sets PWM if motor lags behind reference
  //  4. limit both counts, so they never roll, but still retain all error
  //-------------------------------------------------------
  // clear int flag straight away to give max safe time
  INTCON.T0IF = 0;

  //  1. updates encoder to see if motor has moved, records it position
  enc_new = (PORTA & 0b00000011);  // get the 2 encoder bits
  if(enc_new != enc_last)
  {
  if(enc_new.F1 != enc_last.F0) mpos++;  // record new motor position
  else  mpos--;
  enc_last = enc_new;
  }

  //  2. updates reference freq generator, records its position
  bres += 102400;  // add nS per interrupt period (512 insts * 200nS)
  if(bres >= MOTOR_PULSE_PERIOD)  // if reached a new reference step
  {
  bres -= MOTOR_PULSE_PERIOD;
  rpos++;  // record new xtal-locked reference position
  }

  //  3. compares the two, set PWM% if motor lags behind reference
  if(mpos < rpos)  // if motor lagging behind
  {
  mlag = (rpos - mpos);  // find how far it's lagging behind
  if(mlag >= (100/MOTOR_PROP_GAIN)) CCPR1L = 100;  // full power if is too far behind
  else CCPR1L = (mlag * MOTOR_PROP_GAIN);  // else adjust PWM if slightly behind
  }
  else  // else if motor is fast, cut all power!
  {
  CCPR1L = 0;
  }

  //  4. limit both counts, so they never roll, but still retain all error
  if(rpos>250 || mpos>250)
  {
  rpos -= 50;
  mpos -= 50;
  }

}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


//=============================================================================
//  MAIN
//=============================================================================
void main()
{
  //-------------------------------------------------------
  // setup PIC 16F628A
  CMCON = 0b00000111;  // comparators OFF, all pins digital

  PORTA = 0b00000000;  //
  TRISA = 0b00000011;  // RA0,RA1 used for digital ST encoder inputs

  PORTB = 0b00000000;  //
  TRISB = 0b00000000;  // RB3 is CCP1 PWM out, RB0,RB1 are encoder echo outputs

  // set TMR2 to roll every 100 ticks, PWM freq = 5mil/16/100 = 3125 Hz
  T2CON = 0b00000111;  // TMR2 ON, 16:1 prescale
  PR2 = (100-1);  // PWM total period of 100

  // set PWM out on CCP1
  CCPR1L = 0;  // PWM range 0-100% = start  with PWM of 0%
  CCP1CON = 0b00001100;  // CCP1 on, set to PWM mode

  // TMR0 used for interrupt, makes interrupt every 512 insts
  OPTION_REG = 0b10000000;  // PORTB pullups OFF, TMR0 on, 2:1 prescale


  //-------------------------------------------------------
  // setup before main loop
  Delay_mS(200);  // allow PSU voltages time to stabilise

  // setup vars etc, will be used in interrupt
  bres = 0;
  rpos = 0;
  mpos = 0;

  // finally start TMR0 roll interrupt
  INTCON = 0b10100000;  // GIE=on, TMR0IE=on

  //-------------------------------------------------------
  // main run loop
  while(1)
  {
  //-------------------------------------------------
  // We don't need to do anything in main loop as the motor speed
  // control is done entirely in the TMR0 interrupt.


  //-------------------------------------------------
  // For convenience in setting up the encoder trimpots,
  // echo the two encoder pins out two spare PORTB digital outputs!
  pins = 0;
  if(PORTA.F0) pins.F0 = 1;
  if(PORTA.F1) pins.F1 = 1;
  PORTB = pins;  // output those two pins only (PWM output is not affected)
  }
}
//-----------------------------------------------------------------------------
Max.
 

John P

Joined Oct 14, 2008
2,026
Well, as a first pass, here's a list file. I called the program MAXH.C. It compiled with no errors, but it doesn't look like efficient code:

Code:
;  LST file generated by mikroListExporter - v.2.0
; Date/Time: 5/22/2017 10:52:26 PM
;----------------------------------------------

;Address Opcode  ASM
0x0000  0x28C4  GOTO  196
_interrupt:
0x0004  0x00FF  MOVWF  R15
0x0005  0x0E03  SWAPF  STATUS, 0
0x0006  0x0183  CLRF  STATUS
0x0007  0x00AD  MOVWF  ___saveSTATUS
0x0008  0x080A  MOVF  PCLATH, 0
0x0009  0x00AE  MOVWF  ___savePCLATH
0x000A  0x018A  CLRF  PCLATH
0x000B  0x087C  MOVF  R12, 0
0x000C  0x00A0  MOVWF  32
;maxh.c,42 ::  void interrupt()
;maxh.c,53 ::  INTCON.T0IF = 0;
0x000D  0x110B  BCF  INTCON, 2
;maxh.c,56 ::  enc_new = (PORTA & 0b00000011);  // get the 2 encoder bits
0x000E  0x3003  MOVLW  3
0x000F  0x0505  ANDWF  PORTA, 0
0x0010  0x00F1  MOVWF  R1
0x0011  0x0871  MOVF  R1, 0
0x0012  0x00A7  MOVWF  _enc_new
;maxh.c,57 ::  if(enc_new != enc_last)
0x0013  0x0871  MOVF  R1, 0
0x0014  0x0624  XORWF  _enc_last, 0
0x0015  0x1903  BTFSC  STATUS, 2
0x0016  0x2824  GOTO  L_interrupt0
;maxh.c,59 ::  if(enc_new.F1 != enc_last.F0) mpos++;  // record new motor position
0x0017  0x18A7  BTFSC  _enc_new, 1
0x0018  0x281C  GOTO  L__interrupt19
0x0019  0x1C24  BTFSS  _enc_last, 0
0x001A  0x2821  GOTO  L_interrupt1
0x001B  0x281F  GOTO  L__interrupt20
L__interrupt19:
0x001C  0x1C24  BTFSS  _enc_last, 0
0x001D  0x281F  GOTO  L__interrupt20
0x001E  0x2821  GOTO  L_interrupt1
L__interrupt20:
0x001F  0x0AA5  INCF  _mpos, 1
0x0020  0x2822  GOTO  L_interrupt2
L_interrupt1:
;maxh.c,60 ::  else  mpos--;
0x0021  0x03A5  DECF  _mpos, 1
L_interrupt2:
;maxh.c,61 ::  enc_last = enc_new;
0x0022  0x0827  MOVF  _enc_new, 0
0x0023  0x00A4  MOVWF  _enc_last
;maxh.c,62 ::  }
L_interrupt0:
;maxh.c,65 ::  bres += 102400;  // add nS per interrupt period (512 insts * 200nS)
0x0024  0x3000  MOVLW  0
0x0025  0x00F1  MOVWF  R1
0x0026  0x3090  MOVLW  144
0x0027  0x00F2  MOVWF  R1+1
0x0028  0x3001  MOVLW  1
0x0029  0x00F3  MOVWF  R1+2
0x002A  0x3000  MOVLW  0
0x002B  0x00F4  MOVWF  R1+3
0x002C  0x0829  MOVF  _bres, 0
0x002D  0x07F1  ADDWF  R1, 1
0x002E  0x082A  MOVF  _bres+1, 0
0x002F  0x1803  BTFSC  STATUS, 0
0x0030  0x0F2A  INCFSZ  _bres+1, 0
0x0031  0x07F2  ADDWF  R1+1, 1
0x0032  0x082B  MOVF  _bres+2, 0
0x0033  0x1803  BTFSC  STATUS, 0
0x0034  0x0F2B  INCFSZ  _bres+2, 0
0x0035  0x07F3  ADDWF  R1+2, 1
0x0036  0x082C  MOVF  _bres+3, 0
0x0037  0x1803  BTFSC  STATUS, 0
0x0038  0x0F2C  INCFSZ  _bres+3, 0
0x0039  0x07F4  ADDWF  R1+3, 1
0x003A  0x0871  MOVF  R1, 0
0x003B  0x00A9  MOVWF  _bres
0x003C  0x0872  MOVF  R1+1, 0
0x003D  0x00AA  MOVWF  _bres+1
0x003E  0x0873  MOVF  R1+2, 0
0x003F  0x00AB  MOVWF  _bres+2
0x0040  0x0874  MOVF  R1+3, 0
0x0041  0x00AC  MOVWF  _bres+3
;maxh.c,66 ::  if(bres >= MOTOR_PULSE_PERIOD)  // if reached a new reference step
0x0042  0x3000  MOVLW  0
0x0043  0x0274  SUBWF  R1+3, 0
0x0044  0x1D03  BTFSS  STATUS, 2
0x0045  0x2850  GOTO  L__interrupt21
0x0046  0x3069  MOVLW  105
0x0047  0x0273  SUBWF  R1+2, 0
0x0048  0x1D03  BTFSS  STATUS, 2
0x0049  0x2850  GOTO  L__interrupt21
0x004A  0x30F6  MOVLW  246
0x004B  0x0272  SUBWF  R1+1, 0
0x004C  0x1D03  BTFSS  STATUS, 2
0x004D  0x2850  GOTO  L__interrupt21
0x004E  0x30BC  MOVLW  188
0x004F  0x0271  SUBWF  R1, 0
L__interrupt21:
0x0050  0x1C03  BTFSS  STATUS, 0
0x0051  0x2869  GOTO  L_interrupt3
;maxh.c,68 ::  bres -= MOTOR_PULSE_PERIOD;
0x0052  0x30BC  MOVLW  188
0x0053  0x00F0  MOVWF  R0
0x0054  0x30F6  MOVLW  246
0x0055  0x00F1  MOVWF  R0+1
0x0056  0x3069  MOVLW  105
0x0057  0x00F2  MOVWF  R0+2
0x0058  0x3000  MOVLW  0
0x0059  0x00F3  MOVWF  R0+3
0x005A  0x0870  MOVF  R0, 0
0x005B  0x02A9  SUBWF  _bres, 1
0x005C  0x0871  MOVF  R0+1, 0
0x005D  0x1C03  BTFSS  STATUS, 0
0x005E  0x0F71  INCFSZ  R0+1, 0
0x005F  0x02AA  SUBWF  _bres+1, 1
0x0060  0x0872  MOVF  R0+2, 0
0x0061  0x1C03  BTFSS  STATUS, 0
0x0062  0x0F72  INCFSZ  R0+2, 0
0x0063  0x02AB  SUBWF  _bres+2, 1
0x0064  0x0873  MOVF  R0+3, 0
0x0065  0x1C03  BTFSS  STATUS, 0
0x0066  0x0F73  INCFSZ  R0+3, 0
0x0067  0x02AC  SUBWF  _bres+3, 1
;maxh.c,69 ::  rpos++;  // record new xtal-locked reference position
0x0068  0x0AA8  INCF  _rpos, 1
;maxh.c,70 ::  }
L_interrupt3:
;maxh.c,73 ::  if(mpos < rpos)  // if motor lagging behind
0x0069  0x0828  MOVF  _rpos, 0
0x006A  0x0225  SUBWF  _mpos, 0
0x006B  0x1803  BTFSC  STATUS, 0
0x006C  0x2881  GOTO  L_interrupt4
;maxh.c,75 ::  mlag = (rpos - mpos);  // find how far it's lagging behind
0x006D  0x0825  MOVF  _mpos, 0
0x006E  0x0228  SUBWF  _rpos, 0
0x006F  0x00F1  MOVWF  R1
0x0070  0x0871  MOVF  R1, 0
0x0071  0x00A3  MOVWF  _mlag
;maxh.c,76 ::  if(mlag >= (100/MOTOR_PROP_GAIN)) CCPR1L = 100;  // full power if is too far behind
0x0072  0x300A  MOVLW  10
0x0073  0x0271  SUBWF  R1, 0
0x0074  0x1C03  BTFSS  STATUS, 0
0x0075  0x2879  GOTO  L_interrupt5
0x0076  0x3064  MOVLW  100
0x0077  0x0095  MOVWF  CCPR1L
0x0078  0x2880  GOTO  L_interrupt6
L_interrupt5:
;maxh.c,77 ::  else CCPR1L = (mlag * MOTOR_PROP_GAIN);  // else adjust PWM if slightly behind
0x0079  0x0823  MOVF  _mlag, 0
0x007A  0x00F0  MOVWF  R0
0x007B  0x300A  MOVLW  10
0x007C  0x00F4  MOVWF  R4
0x007D  0x20AB  CALL  _Mul_8X8_U
0x007E  0x0870  MOVF  R0, 0
0x007F  0x0095  MOVWF  CCPR1L
L_interrupt6:
;maxh.c,78 ::  }
0x0080  0x2882  GOTO  L_interrupt7
L_interrupt4:
;maxh.c,81 ::  CCPR1L = 0;
0x0081  0x0195  CLRF  CCPR1L
;maxh.c,82 ::  }
L_interrupt7:
;maxh.c,85 ::  if(rpos>250 || mpos>250)
0x0082  0x0828  MOVF  _rpos, 0
0x0083  0x3CFA  SUBLW  250
0x0084  0x1C03  BTFSS  STATUS, 0
0x0085  0x288B  GOTO  L__interrupt16
0x0086  0x0825  MOVF  _mpos, 0
0x0087  0x3CFA  SUBLW  250
0x0088  0x1C03  BTFSS  STATUS, 0
0x0089  0x288B  GOTO  L__interrupt16
0x008A  0x288F  GOTO  L_interrupt10
L__interrupt16:
;maxh.c,87 ::  rpos -= 50;
0x008B  0x3032  MOVLW  50
0x008C  0x02A8  SUBWF  _rpos, 1
;maxh.c,88 ::  mpos -= 50;
0x008D  0x3032  MOVLW  50
0x008E  0x02A5  SUBWF  _mpos, 1
;maxh.c,89 ::  }
L_interrupt10:
;maxh.c,91 ::  }
L_end_interrupt:
L__interrupt18:
0x008F  0x0820  MOVF  32, 0
0x0090  0x00FC  MOVWF  R12
0x0091  0x082E  MOVF  ___savePCLATH, 0
0x0092  0x008A  MOVWF  PCLATH
0x0093  0x0E2D  SWAPF  ___saveSTATUS, 0
0x0094  0x0083  MOVWF  STATUS
0x0095  0x0EFF  SWAPF  R15, 1
0x0096  0x0E7F  SWAPF  R15, 0
0x0097  0x0009  RETFIE
; end of _interrupt
_____DoICP:
;__Lib_System.c,6 ::  
;__Lib_System.c,9 ::  
0x0098  0x1283  BCF  STATUS, 5
0x0099  0x1303  BCF  STATUS, 6
0x009A  0x0822  MOVF  ___DoICPAddr+1, 0
0x009B  0x008A  MOVWF  PCLATH
;__Lib_System.c,10 ::  
0x009C  0x0821  MOVF  ___DoICPAddr, 0
0x009D  0x0082  MOVWF  PCL
;__Lib_System.c,12 ::  
L_end_____DoICP:
0x009E  0x0008  RETURN
; end of _____DoICP
___CC2DW:
;__Lib_System.c,134 ::  
;__Lib_System.c,137 ::  
_CC2D_Loop1:
;__Lib_System.c,139 ::  
0x009F  0x2098  CALL  _____DoICP
0x00A0  0x118A  BCF  PCLATH, 3
0x00A1  0x120A  BCF  PCLATH, 4
;__Lib_System.c,141 ::  
0x00A2  0x0080  MOVWF  INDF
;__Lib_System.c,142 ::  
0x00A3  0x0A84  INCF  FSR, 1
;__Lib_System.c,143 ::  
0x00A4  0x0AA1  INCF  ___DoICPAddr, 1
;__Lib_System.c,145 ::  
0x00A5  0x1903  BTFSC  STATUS, 2
;__Lib_System.c,146 ::  
0x00A6  0x0AA2  INCF  ___DoICPAddr+1, 1
;__Lib_System.c,147 ::  
0x00A7  0x03F0  DECF  R0, 1
;__Lib_System.c,149 ::  
0x00A8  0x1D03  BTFSS  STATUS, 2
;__Lib_System.c,150 ::  
0x00A9  0x289F  GOTO  _CC2D_Loop1
;__Lib_System.c,152 ::  
L_end___CC2DW:
0x00AA  0x0008  RETURN
; end of ___CC2DW
_Mul_8X8_U:
;__Lib_Math.c,103 ::  
;__Lib_Math.c,108 ::  
0x00AB  0x1283  BCF  STATUS, 5
;__Lib_Math.c,109 ::  
0x00AC  0x1303  BCF  STATUS, 6
;__Lib_Math.c,110 ::  
0x00AD  0x0870  MOVF  R0, 0
;__Lib_Math.c,111 ::  
0x00AE  0x00F1  MOVWF  R1
;__Lib_Math.c,112 ::  
0x00AF  0x01F0  CLRF  R0
;__Lib_Math.c,113 ::  
0x00B0  0x3008  MOVLW  8
;__Lib_Math.c,114 ::  
0x00B1  0x00FC  MOVWF  R12
;__Lib_Math.c,115 ::  
0x00B2  0x0871  MOVF  R1, 0
;__Lib_Math.c,116 ::  
0x00B3  0x0CF4  RRF  R4, 1
;__Lib_Math.c,117 ::  
0x00B4  0x1803  BTFSC  STATUS, 0
;__Lib_Math.c,118 ::  
0x00B5  0x28BA  GOTO  $+5
;__Lib_Math.c,119 ::  
0x00B6  0x0BFC  DECFSZ  R12, 1
;__Lib_Math.c,120 ::  
0x00B7  0x28B3  GOTO  $-4
;__Lib_Math.c,121 ::  
0x00B8  0x01F1  CLRF  R1
;__Lib_Math.c,122 ::  
0x00B9  0x3400  RETLW  0
;__Lib_Math.c,123 ::  
0x00BA  0x1003  BCF  STATUS, 0
;__Lib_Math.c,124 ::  
0x00BB  0x28BF  GOTO  $+4
;__Lib_Math.c,125 ::  
0x00BC  0x0CF4  RRF  R4, 1
;__Lib_Math.c,126 ::  
0x00BD  0x1803  BTFSC  STATUS, 0
;__Lib_Math.c,127 ::  
0x00BE  0x07F1  ADDWF  R1, 1
;__Lib_Math.c,128 ::  
0x00BF  0x0CF1  RRF  R1, 1
;__Lib_Math.c,129 ::  
0x00C0  0x0CF0  RRF  R0, 1
;__Lib_Math.c,130 ::  
0x00C1  0x0BFC  DECFSZ  R12, 1
;__Lib_Math.c,131 ::  
0x00C2  0x28BC  GOTO  $-6
;__Lib_Math.c,133 ::  
;__Lib_Math.c,134 ::  
L_end_Mul_8X8_U:
0x00C3  0x0008  RETURN
; end of _Mul_8X8_U
_main:
;maxh.c,98 ::  void main()
;maxh.c,102 ::  CMCON = 0b00000111;  // comparators OFF, all pins digital
0x00C4  0x3007  MOVLW  7
0x00C5  0x1283  BCF  STATUS, 5
0x00C6  0x1303  BCF  STATUS, 6
0x00C7  0x009F  MOVWF  CMCON
;maxh.c,104 ::  PORTA = 0b00000000;  //
0x00C8  0x0185  CLRF  PORTA
;maxh.c,105 ::  TRISA = 0b00000011;  // RA0,RA1 used for digital ST encoder inputs
0x00C9  0x3003  MOVLW  3
0x00CA  0x1683  BSF  STATUS, 5
0x00CB  0x0085  MOVWF  TRISA
;maxh.c,107 ::  PORTB = 0b00000000;  //
0x00CC  0x1283  BCF  STATUS, 5
0x00CD  0x0186  CLRF  PORTB
;maxh.c,108 ::  TRISB = 0b00000000;  // RB3 is CCP1 PWM out, RB0,RB1 are encoder echo outputs
0x00CE  0x1683  BSF  STATUS, 5
0x00CF  0x0186  CLRF  TRISB
;maxh.c,111 ::  T2CON = 0b00000111;  // TMR2 ON, 16:1 prescale
0x00D0  0x3007  MOVLW  7
0x00D1  0x1283  BCF  STATUS, 5
0x00D2  0x0092  MOVWF  T2CON
;maxh.c,112 ::  PR2 = (100-1);  // PWM total period of 100
0x00D3  0x3063  MOVLW  99
0x00D4  0x1683  BSF  STATUS, 5
0x00D5  0x0092  MOVWF  PR2
;maxh.c,115 ::  CCPR1L = 0;  // PWM range 0-100% = start  with PWM of 0%
0x00D6  0x1283  BCF  STATUS, 5
0x00D7  0x0195  CLRF  CCPR1L
;maxh.c,116 ::  CCP1CON = 0b00001100;  // CCP1 on, set to PWM mode
0x00D8  0x300C  MOVLW  12
0x00D9  0x0097  MOVWF  CCP1CON
;maxh.c,119 ::  OPTION_REG = 0b10000000;  // PORTB pullups OFF, TMR0 on, 2:1 prescale
0x00DA  0x3080  MOVLW  128
0x00DB  0x1683  BSF  STATUS, 5
0x00DC  0x0081  MOVWF  OPTION_REG
;maxh.c,124 ::  Delay_mS(200);  // allow PSU voltages time to stabilise
0x00DD  0x3003  MOVLW  3
0x00DE  0x00FB  MOVWF  R11
0x00DF  0x3008  MOVLW  8
0x00E0  0x00FC  MOVWF  R12
0x00E1  0x3077  MOVLW  119
0x00E2  0x00FD  MOVWF  R13
L_main11:
0x00E3  0x0BFD  DECFSZ  R13, 1
0x00E4  0x28E3  GOTO  L_main11
0x00E5  0x0BFC  DECFSZ  R12, 1
0x00E6  0x28E3  GOTO  L_main11
0x00E7  0x0BFB  DECFSZ  R11, 1
0x00E8  0x28E3  GOTO  L_main11
;maxh.c,127 ::  bres = 0;
0x00E9  0x1283  BCF  STATUS, 5
0x00EA  0x01A9  CLRF  _bres
0x00EB  0x01AA  CLRF  _bres+1
0x00EC  0x01AB  CLRF  _bres+2
0x00ED  0x01AC  CLRF  _bres+3
;maxh.c,128 ::  rpos = 0;
0x00EE  0x01A8  CLRF  _rpos
;maxh.c,129 ::  mpos = 0;
0x00EF  0x01A5  CLRF  _mpos
;maxh.c,132 ::  INTCON = 0b10100000;  // GIE=on, TMR0IE=on
0x00F0  0x30A0  MOVLW  160
0x00F1  0x008B  MOVWF  INTCON
;maxh.c,136 ::  while(1)
L_main12:
;maxh.c,146 ::  pins = 0;
0x00F2  0x01A6  CLRF  _pins
;maxh.c,147 ::  if(PORTA.F0) pins.F0 = 1;
0x00F3  0x1C05  BTFSS  PORTA, 0
0x00F4  0x28F6  GOTO  L_main14
0x00F5  0x1426  BSF  _pins, 0
L_main14:
;maxh.c,148 ::  if(PORTA.F1) pins.F1 = 1;
0x00F6  0x1C85  BTFSS  PORTA, 1
0x00F7  0x28F9  GOTO  L_main15
0x00F8  0x14A6  BSF  _pins, 1
L_main15:
;maxh.c,149 ::  PORTB = pins;  // output those two pins only (PWM output is not affected)
0x00F9  0x0826  MOVF  _pins, 0
0x00FA  0x0086  MOVWF  PORTB
;maxh.c,150 ::  }
0x00FB  0x28F2  GOTO  L_main12
;maxh.c,151 ::  }
L_end_main:
0x00FC  0x28FC  GOTO  $+0
; end of _main
Symbol List:
//** Routines locations **
//ADDRESS  SIZE  PROCEDURE
//----------------------------------------------
0x0004  [148]  _interrupt
0x0098  [7]  _____DoICP
0x009F  [12]  ___CC2DW
0x00AB  [25]  _Mul_8X8_U
0x00C4  [57]  _main
//** Variables locations **
//ADDRESS  SIZE  VARIABLE
//----------------------------------------------
0x0000  [1]  INDF
0x0002  [1]  PCL
0x0003  [1]  STATUS
0x0004  [1]  FSR
0x0005  [1]  PORTA
0x0006  [1]  PORTB
0x000A  [1]  PCLATH
0x000B  [1]  INTCON
0x0012  [1]  T2CON
0x0015  [1]  CCPR1L
0x0017  [1]  CCP1CON
0x001F  [1]  CMCON
0x0021  [2]  ___DoICPAddr
0x0023  [1]  _mlag
0x0024  [1]  _enc_last
0x0025  [1]  _mpos
0x0026  [1]  _pins
0x0027  [1]  _enc_new
0x0028  [1]  _rpos
0x0029  [4]  _bres
0x002D  [1]  ___saveSTATUS
0x002E  [1]  ___savePCLATH
0x0070  [1]  R0
0x0071  [1]  R1
0x0072  [1]  R2
0x0073  [1]  R3
0x0074  [1]  R4
0x0075  [1]  R5
0x0076  [1]  R6
0x0077  [1]  R7
0x0078  [1]  R8
0x0079  [1]  R9
0x007A  [1]  R10
0x007B  [1]  R11
0x007C  [1]  R12
0x007D  [1]  R13
0x007E  [1]  R14
0x007F  [1]  R15
0x0081  [1]  OPTION_REG
0x0085  [1]  TRISA
0x0086  [1]  TRISB
0x0092  [1]  PR2
 

MrSoftware

Joined Oct 29, 2013
2,202
Embedded is not my strong point, but I noticed you're doing quite a bit inside your interrupt routine. Instead of just clearing the bit and hoping to get through all that code before the timer expires again, you may consider disabling interrupts when you enter the routine, then re-enable interrupts when you exit the routine. Or just set a flag inside the routine and handle the heavy lifting in your main loop, just be sure the flag variable has the volatile attribute. Just food for thought, good luck with your project. :)
 

Thread Starter

MaxHeadRoom

Joined Jul 18, 2013
28,703
Interrupts are automatically disabled once the interrupt routine is entered.
They are automatically re-enabled with the retfie (return from interrupt, Interrupts Enabled).;)
Max.
 

AlbertHall

Joined Jun 4, 2014
12,347
Embedded is not my strong point, but I noticed you're doing quite a bit inside your interrupt routine. Instead of just clearing the bit and hoping to get through all that code before the timer expires again, you may consider disabling interrupts when you enter the routine, then re-enable interrupts when you exit the routine. Or just set a flag inside the routine and handle the heavy lifting in your main loop, just be sure the flag variable has the volatile attribute. Just food for thought, good luck with your project. :)
This is tried and tested code from Roman Black so it's gonna work as it is.
 
Top