Apparent code size problem


Closed Thread
Results 1 to 11 of 11

Hybrid View

  1. #1
    Join Date
    Sep 2006
    Posts
    8


    Did you find this post helpful? Yes | No

    Default Results so far

    There is one thing I did forget to mention (and I aplogize to all of you that have offered help). The mcu initialization is done in assembly. That code block is located immediately after all the variable declarations, etc.
    -----------------------------------------------------------------

    Mike,
    I tried the dummy variable fix, it did not cure the problem. after putting the dummies in I checked the address of every word variable in the asm listing to make sure none crossed a page. Here is the asm listing of the page banks and the dummy declarations.

    RAM_START EQU 00020h
    RAM_END EQU 001EFh
    RAM_BANKS EQU 00004h
    BANK0_START EQU 00020h
    BANK0_END EQU 0007Fh
    BANK1_START EQU 000A0h
    BANK1_END EQU 000EFh
    BANK2_START EQU 00120h
    BANK2_END EQU 0016Fh
    BANK3_START EQU 00190h
    BANK3_END EQU 001EFh
    EEPROM_START EQU 02100h
    EEPROM_END EQU 021FFh


    '******************************************
    ' Dummy Variable Declarations *
    '******************************************
    bogus_0 VAR BYTE $07F
    bogus_1 VAR BYTE $0EF
    bogus_2 VAR BYTE $16F
    bogus_3 VAR BYTE $1EF

    ----------------------------------------------------------------

    Bruce,
    The code that displays the splash screen is physically located early in the code and is the first code ran once the initializatin sequences are finished.
    I doubled checked my routines, as you suggested, everything ok there.

    I know it is hard to help when you can't see the code, and believe me if I could I would upload the entire project and let everyone have a field day with it.


    The code blocks out like this:

    fuse settings
    defines
    constant declarations
    variable decalrations

    GOTO Start

    INI:
    assembly block (with return) to setup the chip

    Setup:
    routine (with return) to set initial state of variables, etc

    Start:
    GOSUB INI
    GOSUB Setup

    Splash screen is displayed here.

    Some initail instrument checks ( proper hookup, etc) are performed here

    Switch polling routine here

    rest of code body.

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Have you tried replacing your .asm initialization with a BASIC version?

    I know you can sometimes save a few bytes by doing some things in .asm,
    but if you initialize everything in banks PBP doesn't insert a ton of bank
    switching code flipping back & forth between banks. I.E.

    ' Bank0 first
    PORTB = 0
    PORTC = 0
    T2CON = 0
    ' Bank1 next
    TRISA = 0
    TRISB = 0
    CMCON1 = 7, etc, etc,

    Are you using assembler in other routines?

    I would think either something in the INI or Setup routines is causing
    the problem since the splash screen routine is supposed to run directly
    after Setup.

    If one routine is causing the problem, it should be easy to spot.

    Start:
    GOSUB INI
    blink an LED on return to here x times
    GOSUB Setup
    blink an LED on return to here x times, etc, etc,.

    Of course you could always run it through MPSIM too.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    Join Date
    Sep 2006
    Posts
    8


    Did you find this post helpful? Yes | No

    Default

    Bruce,

    I tried the idea of replacing the asm routine with a basic one; pared the program down to just the ini and setup stuff and a display routine. Two versions, one all PBP and the other with the asm block.

    Now... I really feel stupid, the all basic one will not run, the other works just fine. So before I can actually try your idea I now have to figure out what I am doing wrong with the ini code in basic. ( and just in case everyone is wondering at this point... yes, I did write the asm block)

    I have included both below so that anyone who wants ( after they get up off the floor from laughing) can point out my mistake if they would.

    hope I got the code formatting command right so it is easy to read.

    Robert

    [code]
    '************************************************* ***************
    ' MCU Setup - inline assembly block *
    '************************************************* ***************
    INIMCU:
    asm
    bsf STATUS,RP0 ; Select Bank 1

    movlw 07h ; turn off comparators
    movwf CMCON0

    movlw 0xEC ; set A<5,1,0> as digital I/O
    movwf ANSEL ; A<3:2> and E<2:0> as analog

    movlw 0xFF ; set A<7:0> input; (A<3:2> analog; A<7:4,1:0> digital)
    movwf TRISA

    movlw 50h ; set A2D Clock 10h:Fosc/8 50h:Fosc/16
    movwf ADCON1

    movlw 00h ; set PORTB as outputs
    movwf TRISB

    movlw 0xF8 ; set PORTC C<7:3> as inputs; C<2:0> as outputs
    movwf TRISC

    movlw 0x00 ; set PORTD as inputs
    movwf TRISD

    movlw 0Fh ; set PORTE as inputs
    movwf TRISE

    bcf STATUS,RP0 ; Select Bank 2
    bsf STATUS,RP1 ;

    clrf LCDCON ; Disable VLCD<3:1>
    ; inputs on RC<2:0>

    bcf STATUS,RP0 ; Select Bank 0
    bcf STATUS,RP1
    endasm
    return



    '******************************
    ' MCU Setup - PBP
    '******************************
    INIMCU:
    CMCON0 = 7
    ANSEL = $EC
    TRISA = $FF
    ADCON1 = $50
    TRISB = 0
    TRISC = $F8
    TRISD = 0
    TRISE = $0F
    LCDCON = 0
    return

    [\code]

  4. #4
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    970


    Did you find this post helpful? Yes | No

    Default

    Robert

    I am wondering if you can do the following. Bruce already suggested this. I am just reminding you of the possibility (to catch a problem) of debugging this technique offers.

    Code:
    GOTO Start 
    
    INI:
    assembly block (with return) to setup the chip
    
    Setup:
    routine (with return) to set initial state of variables, etc
    
    Start:
       Led = 1:pause 1000:Led = 0
    GOSUB INI 
       Led = 1:pause 1000:Led = 0
    GOSUB Setup
       Led = 1:pause 1000:Led = 0
    
    Splash screen is displayed here.
    
    Some initail instrument checks ( proper hookup, etc) are performed here
    
    Switch polling routine here
    
    rest of code body
    if you see 3 flashes of the led, you have reached the splash screen code.

    Perhaps this will help you find if you are missing a return / stacking too deep. You may have a problem due to the limited caller stack size. Have you looked into this too?

    Jerson

Similar Threads

  1. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 9th December 2008, 00:40
  2. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 09:26
  3. problem with my code
    By civicgundam in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 3rd February 2008, 02:52
  4. Setting code size boundaries
    By Charles Linquis in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 8th March 2007, 21:11
  5. Servo Code problem
    By ALFRED in forum General
    Replies: 1
    Last Post: - 2nd March 2006, 04:30

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts