16F689 problem when prog. exceeds Page 0

General discussion on mikroPascal PRO for PIC.
Post Reply
Author
Message
Malcolm_M
Posts: 184
Joined: 12 May 2007 13:01
Location: Bristol, UK

16F689 problem when prog. exceeds Page 0

#1 Post by Malcolm_M » 06 Oct 2011 14:26

I have finally migrated from mP V6.0 to mP PRO 5.0 :oops: and I am very impressed with the additional features in mP PRO - well done mE :D

mP PRO V5.0, optimisation level 0 and PIC16F689 on custom PCB. Timer 1 is used for a 100ms interupt and WDT is OFF.

The program is fine while it fits into Page 0 memory. If I add the procedure 'Log_Events_Uart' to the code, I can see from the List file that the procedures are in Page 0 and Main is now in Page 1 and the program no longer runs.

The program does not get to 'LEDs_All_ON;' turning LEDs on which is at the start of the program after the initialisation.

Code: Select all

//** Routines locations **
//ADDRESS    SIZE    PROCEDURE
//----------------------------------------------
0x0004     [155]    _Interrupt
0x009F      [29]    _Div_16x16_U
0x00BC      [26]    _Div_8x8_U
0x00D6      [47]    _ByteToStr
0x0105      [15]    _EEPROM_Read
0x0114      [10]    _UART1_Write
0x011E      [67]    _WordToStr
0x0161      [43]    _Mul_16x16_U
0x018C      [24]    _Event_to_ASCII
0x01A4       [7]    _Delay_22us
0x01AB      [23]    _UART1_Write_Text
0x01C2      [17]    _Event_Num_to_ASCII
0x01D3     [107]    _Run_Hr_Min_ASCII
0x023E      [10]    _Uart_Output_CR_LF
0x0248      [35]    _EEProm_Read_Event
0x026B      [24]    _Setup_to_ASCII
0x0283      [35]    _EEPROM_Write
0x02A6      [10]    _LEDs_OFF
0x02B0      [10]    _EE_Write_Buzz_Mode
0x02BA      [13]    _Del_10ms
0x02C7      [45]    _ADC_Read
0x02F4     [226]    _Log_Events_Uart
0x03D6       [7]    _Buzzers_OFF
0x03DD      [57]    _EEProm_Save_Event
0x0416      [10]    _LEDs_All_ON
0x0420      [26]    _Find_Start_Log
0x043A      [27]    _EEProm_Read_Word
0x0455      [10]    _LEDs_All_OFF
0x045F      [16]    _UART1_Init
0x046F       [7]    _Buzzers_ON
0x0800    [1216]    _main
I am not an expert with assembly but the compiler seems to be setting PCLATH correctly to switch between Page 0 & 1

Code: Select all

;Address Opcode         ASM
0x0000        0x158A              BSF        PCLATH, 3
0x0001        0x2800              GOTO       2048

;LWA_TOW_10.mpas,751 ::                 Buzzers_ON;
0x083C        0x118A              BCF        PCLATH, 3
0x083D        0x246F              CALL       _Buzzers_ON
0x083E        0x158A              BSF        PCLATH, 3

Code: Select all

begin

// Initialise TIMER & WDT

   WDTCON := %00001000;    // ~5.12 secs DISabled
   CLRWDT;                 // Watchdog 10ms min.

   OSCCON := %01100001;    // Internal OSC @4Mhz

   OPTION_REG := %10001111;

   INTCON := %00000000;

   PIR1 := %00000000;

   PIR2 := %00000000;

   PIE1 := %00000000;

   PIE2 := %00000000;

   CM1CON0 := %10000111;

   CM2CON0 := %00010111;

// CM2CON1

   // 0.6V reference enabled for comparator 1
   VRCON := %00010000;    // bit 7 = C1VREN (Comparator 1 Vref select)

//
// RCON register contains details of reset source - do not initialise
//

   ANSEL  := %00000001;   // ONLY RA0 is Analog
   ANSELH := %00000000;   // ONLY RA0 is Analog

//
// Initialise PORTA
//
   PORTA  := %00000000;   // All low
   TRISA  := %11111111;   // All inputs !!!A/D MUST be inputs
   WPUA   := %00110110;   // Weak pullup enabled

//
// Initialise PORTB
//
   PORTB  := %00000000;   // All low
   TRISB  := %00100000;   // RB7,RB6 & RB4 OUTPUTS and RB5 (RXD) INPUT

//
// Initialise PORTC
//
   PORTC  := %00000000;   // All low
   TRISC  := %11001000;   // RC5,RC4,RC2,RC1 & RC0 OUTPUTS and RC7,RC6 & RC3 INPUTS


   // Self test
   LEDs_All_ON;  <<<<<<<<<<<<<<  
   Buzzers_ON;
What am I missing ?

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

Re: 16F689 problem when prog. exceeds Page 0

#2 Post by janni » 06 Oct 2011 17:55

For starters you could try your code with optimisation level 4. I don't think the compiler is thoroughly tested for level 0 :( .
Other than that - I haven't heard of any paging problems so your trouble may well lay elsewhere. Hard to say without seeing all the code.

Malcolm_M
Posts: 184
Joined: 12 May 2007 13:01
Location: Bristol, UK

Re: 16F689 problem when prog. exceeds Page 0

#3 Post by Malcolm_M » 07 Oct 2011 08:31

Thanks janni,

I tried the code with optimisation level 4 and no change.

All the project files are attached:

If you comment out lines 821 & 822 the code is fine and used ROM is 1552 and only page 0 used:

Code: Select all

Logged_Addr := 0;
Log_Events_Uart;
If these lines are included the code doesn't run and used ROM is 2355 with Main in Page 1.

Strange as from statistics 'Log_Events_Uart;' is 266. 1552 + 266 = 1818 which easily fits into page size of 2047 ($7FF).

Extra info: I have just started with mP PRO and started the code in mP V6.0.

With both mP & mP PRO IDE's open I started a new project in mP PRO, cut the code from mP and pasted it into mP PRO.

I didn't use the 'Import Project' function - may or may not be significant.
Attachments
LWA_TOW_10.zip
(103.69 KiB) Downloaded 149 times

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: 16F689 problem when prog. exceeds Page 0

#4 Post by janko.kaljevic » 07 Oct 2011 13:24

Hello,

Please can you send us two projects (folders with all files)
First one that is not working.
Second one with minimal changes, and the program works.

This way we will be able to establish what is wrong.

It is important that you compile those projects, since we do not have your PCB and this chip has no ICD.

Best regards.

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

Re: 16F689 problem when prog. exceeds Page 0

#5 Post by janni » 07 Oct 2011 17:23

If these lines are included the code doesn't run and used ROM is 2355 with Main in Page 1.

Strange as from statistics 'Log_Events_Uart;' is 266. 1552 + 266 = 1818 which easily fits into page size of 2047 ($7FF).
Adding Log_Events_Uart you also adds other routines used by it so the arithmetic is not that simple :wink: .

To check whether the problem is only with page switching, you may move main to page 1 with org directive. With Log_Events_Uart commented out, add

Code: Select all

org 0x0800;
after begin in main and see how it affects program execution. If the code runs then, the problem lays in the additional procedures, not in paging.

Malcolm_M
Posts: 184
Joined: 12 May 2007 13:01
Location: Bristol, UK

Re: 16F689 problem when prog. exceeds Page 0

#6 Post by Malcolm_M » 07 Oct 2011 18:18

Problem solved :oops: I am using Microchip MPLAB/ ICD2 to program the uP and it was only importing code to $7FF :evil:

A newer version of MPLAB imports to $FFF and of course the software runs as expected :D

Thank you janni for your help.
Adding Log_Events_Uart you also adds other routines used by it so the arithmetic is not that simple
janni I see that now :oops:

Thank you Janko for offering to look at the code.

As is often the case the problem was where I least expected it.

I have the mikroProg and it is time I purchased the mikroProg to ICD2/ICD3 adapter board so I can start using it.

arvinfx
Posts: 115
Joined: 22 Feb 2010 18:44

Re: 16F689 problem when prog. exceeds Page 0

#7 Post by arvinfx » 22 Jul 2023 21:22

I have same issue with pic16f877a .
How to solve it?
Sould i seperate my code to small sub procedures and call them one by one insted of a big code or what we can do?

Post Reply

Return to “mikroPascal PRO for PIC General”