Jump to content

Incorrect Variable Allocation?


Recommended Posts

Hi, I'm using BoostC 6.13, target 12F675

 

When I compile an inline function that uses bit postfixes on PIC special function registers incorrect code seems to be generated (ie the compiler allocates new bit variables rather than use the PIC special function register) e.g.

 

inline void Initialise() {

/*

Disable global interrupts

Enable timer0 Interrupt

Enable peripheral interrupts

*/

intcon = 01100000b;

/*

Set Timer0 to timer mode (incremented by the system clock)

Set Timer0 pre-scaler to / 4

Enable GPIO weak pullup resisters

*/

option_reg = 00000001b;

 

// Ensure all I/O pins are swithed off (logic 0, 0 Volts)

gpio = 0;

 

// Set the chips 6 I/O pins GP0 - GP5 to inputs

// 1 = input, 0 = output

trisio = 00111111b;

 

// Set the I/O pin assigned to PWM current to a digital output

trisio.PWM = 0;

 

// **** TEMP **** Inital pulse width setting

pulse_width = PULSE_MAX_2S + 512;

 

// Enable global interrupts

intcon.GIE = 1;

}

 

 

generates the code...

 

void main() {

 

Initialise();

0010 3060 MOVLW 0x60

0011 1283 BCF STATUS, RP0

0012 1303 BCF STATUS, RP1

0013 008B MOVWF gbl_intcon

0014 3001 MOVLW 0x01

0015 1683 BSF STATUS, RP0

0016 0081 MOVWF gbl_option_reg

0017 1283 BCF STATUS, RP0

0018 0185 CLRF gbl_gpio

0019 303F MOVLW 0x3F

001A 1683 BSF STATUS, RP0

001B 0085 MOVWF gbl_trisio

001C 1283 BCF STATUS, RP0

001D 1020 BCF main_4_trisio,0

001E 01A2 CLRF gbl_pulse_width

001F 30FE MOVLW 0xFE

0020 00A3 MOVWF gbl_pulse_width+D'1'

0021 14A0 BSF main_4_intcon,1

 

The last instruction for the Pic INTCON register (0021 14A0 BSF main_4_intcon,1) uses an incorrect register address.

 

If the function is NOT compiled inline the correct code is generated:

 

void Initialise() {

 

/*

Disable global interrupts

Enable timer0 Interrupt

Enable peripheral interrupts

*/

intcon = 01100000b;

0010 3060 MOVLW 0x60

0011 1283 BCF STATUS, RP0

0012 1303 BCF STATUS, RP1

0013 008B MOVWF gbl_intcon

 

/*

Set Timer0 to timer mode (incremented by the system clock)

Set Timer0 pre-scaler to / 4

Enable GPIO weak pullup resisters

*/

option_reg = 00000001b;

0014 3001 MOVLW 0x01

0015 1683 BSF STATUS, RP0

0016 0081 MOVWF gbl_option_reg

 

 

// Ensure all I/O pins are swithed off (logic 0, 0 Volts)

gpio = 0;

0017 1283 BCF STATUS, RP0

0018 0185 CLRF gbl_gpio

 

 

// Set the chips 6 I/O pins GP0 - GP5 to inputs

// 1 = input, 0 = output

trisio = 00111111b;

0019 303F MOVLW 0x3F

001A 1683 BSF STATUS, RP0

001B 0085 MOVWF gbl_trisio

 

 

// Set the I/O pin assigned to PWM current to a digital output

trisio.PWM = 0;

001C 1185 BCF gbl_trisio,3

 

 

// **** TEMP **** Inital pulse width setting

pulse_width = PULSE_MAX_2S + 512;

001D 1283 BCF STATUS, RP0

001E 01A2 CLRF gbl_pulse_width

001F 30FE MOVLW 0xFE

0020 00A3 MOVWF gbl_pulse_width+D'1'

 

 

// Enable global interrupts

intcon.GIE = 1;

0021 178B BSF gbl_intcon,7

 

}

0022 0008 RETURN

 

 

That is 0021 178B BSF gbl_intcon,7

Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...