WAS NOT DECLARED Error

Beta Testing discussion on mikroBasic PRO for PIC.
Post Reply
Author
Message
Bytex
Posts: 459
Joined: 23 Jun 2008 00:58
Location: Palmanova (UD), Italy
Contact:

WAS NOT DECLARED Error

#1 Post by Bytex » 25 Mar 2009 13:06

Dear Me,
What does it mean this error ?

This piece of code is a unit module called from a project.
I already included the file into the project and call it by
include "module_name"

Thanks.

Image

Best regards,
Max

http://www.b-vu.com

User avatar
marko.ziv
mikroElektronika team
Posts: 531
Joined: 06 Dec 2007 10:11
Contact:

#2 Post by marko.ziv » 25 Mar 2009 15:31

Hi,

can you start to comment out parts of code until you get the minimal possible code that produces this error.
Then zip or rar your whole project folder (all the files) and send it to

Code: Select all

marko.ziv@mikroe.com
If you can share your source that is :)

Regards

Bytex
Posts: 459
Joined: 23 Jun 2008 00:58
Location: Palmanova (UD), Italy
Contact:

#3 Post by Bytex » 25 Mar 2009 15:45

OK
This is a general pourpose TMR0 library testing program
On mb7.2 works with P16 and P18 mcus.


Main program:

Code: Select all

program TMR0_Test
include "General_TMR0_Library"

Symbol GreenLed = PORTD.5

Sub Procedure interrupt

	TMR0_InterruptCall

End Sub

    
main:
	
    TRISD = 0
    PORTD = 0

    '// Set TMR0 prescaler and start value
    '// ----------------------------------
	TMR0_Start(256,61)


	while true

        '// switch on LED every second
        '// --------------------------
		if TMR0_Counter > 40 then ' 1 second
			TMR0_Counter = 0
            GreenLed = true
			DELAY_ms(100)
            GreenLed = false
		end if
 
	wend
       
end.

Module code:

Code: Select all

'*****************************************************
'* Name: General_TMR0_Library                        *
'* Date: March-2009                                  *
'* Bytex                                             *
'*****************************************************
module General_TMR0_Library


Dim TMR0_StartValue        	as byte
Dim TMR0_Counter			as integer
Dim TMR0_Interrupt_Trigger	as byte

implements
'*******************************************************************************
' Rules:
'
' Period (uS):
' T = Prescaler * 4 / XTAL  [uSecs.]
' Where:
' XTAL frequency MHz
' Prescaler 1:2..1:256
'
' OverFlow time [uS]:
' Oftime = T * 256
'
' Timer start value:
' tStart = 256 - InterruptTimeValue / T
'
' InterruptTimeValue = T * (256 - TimerStartValue)  [uS]
'
'*******************************************************************************


'+-----------------------------------------------------------------------------+
'+ Procedure: TMR0_Start                                                       +
'+ Passing arguments: prescaler value, start value                             +
'+ Output: nothing                                                             +
'+                                                                             +
'+-----------------------------------------------------------------------------+
Sub procedure TMR0_Start(Dim cPrescaler as integer,
                            Dim mStartValue as byte)


    #IFDEF P18 then

        Select case cPrescaler
            case 2
                T0CON.T0PS2 = 0
                T0CON.T0PS1 = 0
                T0CON.T0PS0 = 0
            case 4
                T0CON.T0PS2 = 0
                T0CON.T0PS1 = 0
                T0CON.T0PS0 = 1
            case 8
                T0CON.T0PS2 = 0
                T0CON.T0PS1 = 1
                T0CON.T0PS0 = 0
            case 16
                T0CON.T0PS2 = 0
                T0CON.T0PS1 = 1
                T0CON.T0PS0 = 1
            case 32
                T0CON.T0PS2 = 1
                T0CON.T0PS1 = 0
                T0CON.T0PS0 = 0
            case 64
                T0CON.T0PS2 = 1
                T0CON.T0PS1 = 0
                T0CON.T0PS0 = 1
            case 128
                T0CON.T0PS2 = 1
                T0CON.T0PS1 = 1
                T0CON.T0PS0 = 0
            case 256
                T0CON.T0PS2 = 1
                T0CON.T0PS1 = 1
                T0CON.T0PS0 = 1
        end select

        T0CON.TMR0ON = 0
        T0CON.T08BIT = 1
        T0CON.T0CS = 0
        T0CON.T0SE = 0

        if cPrescaler >= 2 then
            T0CON.PSA = 0
        else
            T0CON.PSA = 1
        end if

        INTCON2.TMR0IP = 0

        ' The interrupt can be masked by clearing
        ' the TMR0IE bit (INTCON<5>). Before re-enabling
        ' the interrupt, the TMR0IF bit must be cleared in
        ' software by the Interrupt Service Routine.


    #ELSE

        Dim mP      as byte
         '**********************************************************************
         ' OPTION_REG REGISTER
         '**********************************************************************
         '
         '    bit 7 RBPU: PORTB Pull-up Enable bit
         '        1 = PORTB pull-ups are disabled
         '        0 = PORTB pull-ups are enabled by individual port latch values
         '    bit 6 INTEDG: Interrupt Edge Select bit
         '        1 = Interrupt on rising edge of RB0/INT pin
         '        0 = Interrupt on falling edge of RB0/INT pin
         '    bit 5 T0CS: TMR0 Clock Source Select bit
         '        1 = Transition on RA4/T0CKI pin
         '        0 = Internal instruction cycle clock (CLKOUT)
         '    bit 4 T0SE: TMR0 Source Edge Select bit
         '        1 = Increment on high-to-low transition on RA4/T0CKI pin
         '        0 = Increment on low-to-high transition on RA4/T0CKI pin
         '    bit 3 PSA: Prescaler Assignment bit
         '        1 = Prescaler is assigned to the WDT
         '        0 = Prescaler is assigned to the Timer0 module
         '    bit 2-0 PS2:PS0: Prescaler Rate Select bits
         '
         '       ---------------------------
         '       bits 210
         '
         '            000    1:2
         '            001    1:4
         '            010    1:8
         '            011    1:16
         '            100    1:32
         '            101    1:64
         '            110    1:128
         '            111    1:256

         OPTION_REG = 0
         OPTION_REG.7 = 1
         OPTION_REG.T0CS = 0
         OPTION_REG.PSA = 0

         Select case cPrescaler
             case 2
                 mp = %00000000
             case 4
                 mp = %00000001
             case 8
                 mp = %00000010
             case 16
                 mp = %00000011
             case 32
                 mp = %00000100
             case 64
                 mp = %00000101
             case 128
                 mp = %00000110
             case 256
                 mp = %00000111
        end select

        OPTION_REG = (OPTION_REG OR mp)

        #IFDEF P16F628A then
            INTCON.T0IE = 0
            INTCON.T0IF = 0
        #ELSE
            INTCON.TMR0IE = 0
            INTCON.TMR0IF = 0
        #ENDIF

    #ENDIF

    TMR0_StartValue = mStartValue

	' Enable TMR0 interrupt mask
    #IFDEF P16F628A then
        INTCON.T0IF = 0
        INTCON.T0IE = 1
    #ELSE
        INTCON.TMR0IF = 0
        INTCON.TMR0IE = 1
    #ENDIF

    INTCON.GIE = 1   ' enable GIE

    TMR0_Counter = 0
    TMR0_Interrupt_Trigger = false

    #IFDEF P18 then
        TMR0L = TMR0_StartValue
        TMR0H = 0
    #ELSE
        TMR0 = TMR0_StartValue
    #ENDIF

    #IFDEF P18 then
        T0CON.TMR0ON = 1
    #ENDIF

    #IFDEF P16F628A THEN
      	INTCON.T0IE = 1
    #ENDIF


End Sub


Sub Procedure TMR0_InterruptCall

    'ClearBit(INTCON,GIE)

    '//--------------------------/
    ' TMR0 interrupt occurred ?  '
    '//--------------------------/
    #IFDEF P16 THEN
        if ((INTCON.T0IF = 1) and (INTCON.T0IE = 1)) then
            inc(TMR0_Counter)				' must be cleared in software
            TMR0_Interrupt_Trigger = true   ' must be cleared in software
            TMR0 = TMR0_StartValue
          	INTCON.TMR0IF = 0
        end if
    #ELSE
        if ((INTCON.TMR0IF = 1) and (INTCON.TMR0IE = 1)) then
            inc(TMR0_Counter)				' must be cleared in software
            TMR0_Interrupt_Trigger = true   ' must be cleared in software
            TMR0L = TMR0_StartValue
            TMR0H = 0
          	INTCON.TMR0IF = 0
        end if
    #ENDIF

    'SetBit(INTCON,GIE)

End Sub

'*******************************************************************************
'*******************************************************************************
'  OOOOOOO OO    O OOOOOO     OOOOO  OOOOOO   OOOOOO OOO O     OOOOOOO
'  O       O O   O O     O   O     O O        O       O  O     O
'  OOOO    O  O  O O     O   O     O OOO      OOO     O  O     OOOO
'  O       O   O O O     O   O     O O        O       O  O     O
'  OOOOOOO O    OO OOOOOO     OOOOO  O        O      OOO OOOOO OOOOOOO
'*******************************************************************************
'*******************************************************************************
end.


Thank You

Best regards,
Max

http://www.b-vu.com

Bytex
Posts: 459
Joined: 23 Jun 2008 00:58
Location: Palmanova (UD), Italy
Contact:

#4 Post by Bytex » 25 Mar 2009 16:35

SOLVED

Hi Marko,
I've found this:

You have to declare subroutines and function before 'implements'
Like:

Code: Select all

Sub procedure TMR0_Start(Dim cPrescaler as integer, Dim mStartValue as byte)
Sub Procedure TMR0_InterruptCall
implements
And it works.
I don't know we have to do that :shock:
Anyway Thanks

Best regards,
Max

http://www.b-vu.com

User avatar
marko.ziv
mikroElektronika team
Posts: 531
Joined: 06 Dec 2007 10:11
Contact:

#5 Post by marko.ziv » 25 Mar 2009 16:36

Hi,

a few things had to be changed for this code to work:
Main code:

Code: Select all

program TMR0_Test
include "General_TMR0_Library"

Symbol GreenLed = RD5_bit    ' same as PORTD.5, this is the new aproach to bits

Sub Procedure interrupt

   TMR0_InterruptCall

End Sub


main:

    TRISD = 0
    PORTD = 0

    '// Set TMR0 prescaler and start value
    '// ----------------------------------
   TMR0_Start(256,61)


   while true

        '// switch on LED every second
        '// --------------------------
      if TMR0_Counter > 40 then ' 1 second
         TMR0_Counter = 0
            GreenLed = 1
         DELAY_ms(100)
            GreenLed = 0
      end if

   wend

end.
Module code:

Code: Select all

'*****************************************************
'* Name: General_TMR0_Library                        *
'* Date: March-2009                                  *
'* Bytex                                             *
'*****************************************************
module General_TMR0_Library
'#DEFINE P16
#DEFINE P18
Dim TMR0_StartValue           as byte
Dim TMR0_Counter         as integer
Dim TMR0_Interrupt_Trigger   as byte

' these two procedures have to have its definitions before implements
' statement so they would be visible from the main code
Sub procedure TMR0_Start(Dim cPrescaler as integer, Dim mStartValue as byte)
Sub Procedure TMR0_InterruptCall

implements
'*******************************************************************************
' Rules:
'
' Period (uS):
' T = Prescaler * 4 / XTAL  [uSecs.]
' Where:
' XTAL frequency MHz
' Prescaler 1:2..1:256
'
' OverFlow time [uS]:
' Oftime = T * 256
'
' Timer start value:
' tStart = 256 - InterruptTimeValue / T
'
' InterruptTimeValue = T * (256 - TimerStartValue)  [uS]
'
'*******************************************************************************


'+-----------------------------------------------------------------------------+
'+ Procedure: TMR0_Start                                                       +
'+ Passing arguments: prescaler value, start value                             +
'+ Output: nothing                                                             +
'+                                                                             +
'+-----------------------------------------------------------------------------+
Sub procedure TMR0_Start(Dim cPrescaler as integer,
                            Dim mStartValue as byte)


    #IFDEF P18 then

        Select case cPrescaler
            case 2
                T0CON.T0PS2 = 0
                T0CON.T0PS1 = 0
                T0CON.T0PS0 = 0
            case 4
                T0CON.T0PS2 = 0
                T0CON.T0PS1 = 0
                T0CON.T0PS0 = 1
            case 8
                T0CON.T0PS2 = 0
                T0CON.T0PS1 = 1
                T0CON.T0PS0 = 0
            case 16
                T0CON.T0PS2 = 0
                T0CON.T0PS1 = 1
                T0CON.T0PS0 = 1
            case 32
                T0CON.T0PS2 = 1
                T0CON.T0PS1 = 0
                T0CON.T0PS0 = 0
            case 64
                T0CON.T0PS2 = 1
                T0CON.T0PS1 = 0
                T0CON.T0PS0 = 1
            case 128
                T0CON.T0PS2 = 1
                T0CON.T0PS1 = 1
                T0CON.T0PS0 = 0
            case 256
                T0CON.T0PS2 = 1
                T0CON.T0PS1 = 1
                T0CON.T0PS0 = 1
        end select

        T0CON.TMR0ON = 0
        T0CON.T08BIT = 1
        T0CON.T0CS = 0
        T0CON.T0SE = 0

        if cPrescaler >= 2 then
            T0CON.PSA = 0
        else
            T0CON.PSA = 1
        end if

        INTCON2.TMR0IP = 0

        ' The interrupt can be masked by clearing
        ' the TMR0IE bit (INTCON<5>). Before re-enabling
        ' the interrupt, the TMR0IF bit must be cleared in
        ' software by the Interrupt Service Routine.


    #ELSE

        Dim mP      as byte
         '**********************************************************************
         ' OPTION_REG REGISTER
         '**********************************************************************
         '
         '    bit 7 RBPU: PORTB Pull-up Enable bit
         '        1 = PORTB pull-ups are disabled
         '        0 = PORTB pull-ups are enabled by individual port latch values
         '    bit 6 INTEDG: Interrupt Edge Select bit
         '        1 = Interrupt on rising edge of RB0/INT pin
         '        0 = Interrupt on falling edge of RB0/INT pin
         '    bit 5 T0CS: TMR0 Clock Source Select bit
         '        1 = Transition on RA4/T0CKI pin
         '        0 = Internal instruction cycle clock (CLKOUT)
         '    bit 4 T0SE: TMR0 Source Edge Select bit
         '        1 = Increment on high-to-low transition on RA4/T0CKI pin
         '        0 = Increment on low-to-high transition on RA4/T0CKI pin
         '    bit 3 PSA: Prescaler Assignment bit
         '        1 = Prescaler is assigned to the WDT
         '        0 = Prescaler is assigned to the Timer0 module
         '    bit 2-0 PS2:PS0: Prescaler Rate Select bits
         '
         '       ---------------------------
         '       bits 210
         '
         '            000    1:2
         '            001    1:4
         '            010    1:8
         '            011    1:16
         '            100    1:32
         '            101    1:64
         '            110    1:128
         '            111    1:256

         OPTION_REG = 0
         OPTION_REG.7 = 1
         OPTION_REG.T0CS = 0
         OPTION_REG.PSA = 0

         Select case cPrescaler
             case 2
                 mp = %00000000
             case 4
                 mp = %00000001
             case 8
                 mp = %00000010
             case 16
                 mp = %00000011
             case 32
                 mp = %00000100
             case 64
                 mp = %00000101
             case 128
                 mp = %00000110
             case 256
                 mp = %00000111
        end select

        OPTION_REG = (OPTION_REG OR mp)

        #IFDEF P16F628A then
            INTCON.T0IE = 0
            INTCON.T0IF = 0
        #ELSE
            INTCON.TMR0IE = 0
            INTCON.TMR0IF = 0
        #ENDIF

    #ENDIF

    TMR0_StartValue = mStartValue

   ' Enable TMR0 interrupt mask
    #IFDEF P16F628A then
        INTCON.T0IF = 0
        INTCON.T0IE = 1
    #ELSE
        INTCON.TMR0IF = 0
        INTCON.TMR0IE = 1
    #ENDIF

    INTCON.GIE = 1   ' enable GIE

    TMR0_Counter = 0
    TMR0_Interrupt_Trigger = false

    #IFDEF P18 then
        TMR0L = TMR0_StartValue
        TMR0H = 0
    #ELSE
        TMR0 = TMR0_StartValue
    #ENDIF

    #IFDEF P18 then
        T0CON.TMR0ON = 1
    #ENDIF

    #IFDEF P16F628A THEN
         INTCON.T0IE = 1
    #ENDIF


End Sub


Sub Procedure TMR0_InterruptCall

    'ClearBit(INTCON,GIE)

    '//--------------------------/
    ' TMR0 interrupt occurred ?  '
    '//--------------------------/
    #IFDEF P16 THEN
        if ((INTCON.T0IF = 1) and (INTCON.T0IE = 1)) then
            inc(TMR0_Counter)            ' must be cleared in software
            TMR0_Interrupt_Trigger = true   ' must be cleared in software
            TMR0 = TMR0_StartValue
             INTCON.TMR0IF = 0
        end if
    #ELSE
        if ((INTCON.TMR0IF = 1) and (INTCON.TMR0IE = 1)) then
            inc(TMR0_Counter)            ' must be cleared in software
            TMR0_Interrupt_Trigger = true   ' must be cleared in software
            TMR0L = TMR0_StartValue
            TMR0H = 0
             INTCON.TMR0IF = 0
        end if
    #ENDIF

    'SetBit(INTCON,GIE)

End Sub

'*******************************************************************************
'*******************************************************************************
'  OOOOOOO OO    O OOOOOO     OOOOO  OOOOOO   OOOOOO OOO O     OOOOOOO
'  O       O O   O O     O   O     O O        O       O  O     O
'  OOOO    O  O  O O     O   O     O OOO      OOO     O  O     OOOO
'  O       O   O O O     O   O     O O        O       O  O     O
'  OOOOOOO O    OO OOOOOO     OOOOO  O        O      OOO OOOOO OOOOOOO
'*******************************************************************************
'*******************************************************************************
end.
The changes are as follows:
- PORTD.5 changed to RD5_bit (new approach to bits)
- Added lines

Code: Select all

#DEFINE P16
#DEFINE P18
those lines were added because of the another bug reported but related to this code. http://www.mikroe.com/forum/viewtopic.php?t=19090
- and finally prototypes of the functions had to be declared before the implements statement so they could be visible from the main code.

Like we stated in topic above, problem with defines will be fixed for the official release.

Regards

User avatar
marko.ziv
mikroElektronika team
Posts: 531
Joined: 06 Dec 2007 10:11
Contact:

#6 Post by marko.ziv » 25 Mar 2009 16:37

Split second too late :)
Glad you sorted it out.

Regards

Bytex
Posts: 459
Joined: 23 Jun 2008 00:58
Location: Palmanova (UD), Italy
Contact:

#7 Post by Bytex » 25 Mar 2009 16:44

Thanks a lot.

I know from about two weeks PRO will be in my pockets.
Right now it remember me the migrating from Microsoft VB6 and the NET.

Have a nice job.

Best regards,
Max

http://www.b-vu.com

Post Reply

Return to “mikroBasic PRO for PIC Beta Testing”