Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

symbol not previously defined

Status
Not open for further replies.

Gaston

Member
i am working on nigel's led tutorial. the last part with the tables. i modified the table to run a unipolar stepper. it works fine. then i went to modify it to turn,delay,reverse,delay and repeat. i added a second delay because i had to shorten the first to gain speed on the motor. i named the secon delay delay2 and d1 d2 and delay_0 delay_2.i added the call delay2 at the top of the table right before addwf pcl,f. when i go to assemble the code it gives me an error symbol not previously defined ( delay2). i don't see where the original delay was defined anywhere. i know you have to declare a space in memory for a register like count and count b but i don't understand whats going on here.
 
i got rid of the the second delay routine and used only the one delay and it gives me the same error. so i guess i cant take the error message too literally. it must be the way i am putting the delay on the first line of the table. any thoughts on this? or a different approach?
 
# LIST p=16F628 ;tell assembler what chip we are using
include "P16F628.inc" ;include the defaults for the chip
__config 0x3D18 ;sets the configuration settings (oscillator type etc.)

cblock 0x20 ;start of general purpose registers
count ;used in table read routine
count1 ;used in delay routine
counta ;used in delay routine
countb ;used in delay routine
endc

LEDPORT Equ PORTB ;set constant LEDPORT = 'PORTB'
LEDTRIS Equ TRISB ;set constant for TRIS register

org 0x0000 ;org sets the origin, 0x0000 for the 16F628,
;this is where the program starts running
movlw 0x07
movwf CMCON ;turn comparators off (make it like a 16F84)

bsf STATUS, RP0 ;select bank 1
movlw b'00000000' ;set PortB all outputs
movwf LEDTRIS
bcf STATUS, RP0 ;select bank 0
clrf LEDPORT ;set all outputs low


Start1 clrf count ;set counter register to zero
Read1 movf count, w ;put counter value in W
call Table1
movwf LEDPORT
call Delay1
incf count, w
xorlw d'4' ;check for last (4th) entry
btfsc STATUS, Z
goto Start2 ;if start from start2 ( reverse )
incf count, f ;else do next
goto Read1

Table1 call delay2
ADDWF PCL, f ;data table for bit pattern
retlw b'01100000'
retlw b'10100000'
retlw b'10010000'
retlw b'01010000'

Start2 clrf count ;set counter register to zero
Read2 movf count, w ;put counter value in W
call Table2
movwf LEDPORT
call Delay1
incf count, w
xorlw d'4' ;check for last (4th) entry
btfsc STATUS, Z
goto Start1 ;if start from start1 ( forward )
incf count, f ;else do next
goto Read2

Table2 call delay2
ADDWF PCL,f ;data table for reverse bit pattern
retlw b'10010000'
retlw b'01010000'
retlw b'10100000'
retlw b'01100000'


Delay1 movlw d'2' ;delay ? ms (4 MHz clock)for motor speed
movwf count1
d1 movlw 0xC7
movwf counta
movlw 0x01
movwf countb
Delay_1
decfsz counta, f
goto $+2
decfsz countb, f
goto Delay_1

decfsz count1 ,f
goto d1
retlw 0x00


Delay2 movlw d'100' ;delay ? ms (4 MHz clock)for reversing delay
movwf count1
d2 movlw 0xC7
movwf counta
movlw 0x01
movwf countb
Delay_2
decfsz counta, f
goto $+2
decfsz countb, f
goto Delay_2

decfsz count1 ,f
goto d2
retlw 0x00

end #
 
Like this!.

Code:
	LIST p=16F628 ;tell assembler what chip we are using
	include "P16F628.inc" ;include the defaults for the chip
	__config 0x3D18 ;sets the configuration settings (oscillator type etc.)

	cblock 0x20 ;start of general purpose registers
		count ;used in table read routine
		count1 ;used in delay routine
		counta ;used in delay routine
		countb ;used in delay routine
	endc

LEDPORT Equ PORTB ;set constant LEDPORT = 'PORTB'
LEDTRIS Equ TRISB ;set constant for TRIS register

	org 0x0000 ;org sets the origin, 0x0000 for the 16F628,
;this is where the program starts running 
	movlw 0x07
	movwf CMCON ;turn comparators off (make it like a 16F84)

	bsf STATUS, RP0 ;select bank 1
	movlw b'00000000' ;set PortB all outputs
	movwf LEDTRIS
	bcf STATUS, RP0 ;select bank 0
	clrf LEDPORT ;set all outputs low


Start1 clrf count ;set counter register to zero
Read1 movf count, w ;put counter value in W
	call Table1
	movwf LEDPORT
	call Delay1
	incf count, w
	xorlw d'4' ;check for last (4th) entry
	btfsc STATUS, Z
	goto Start2 ;if start from start2 ( reverse )
	incf count, f ;else do next
	goto Read1

Table1 call Delay2
	ADDWF PCL, f ;data table for bit pattern
	retlw b'01100000'
	retlw b'10100000'
	retlw b'10010000'
	retlw b'01010000'

Start2 clrf count ;set counter register to zero
Read2 movf count, w ;put counter value in W
	call Table2 
	movwf LEDPORT
	call Delay1
	incf count, w
	xorlw d'4' ;check for last (4th) entry
	btfsc STATUS, Z
	goto Start1 ;if start from start1 ( forward )
	incf count, f ;else do next
	goto Read2

Table2 call Delay2
	ADDWF PCL,f ;data table for reverse bit pattern
	retlw b'10010000'
	retlw b'01010000'
	retlw b'10100000'
	retlw b'01100000'


Delay1 movlw d'2' ;delay ? ms (4 MHz clock)for motor speed
	movwf count1
d1 movlw 0xC7
	movwf counta
	movlw 0x01
	movwf countb
Delay_1
	decfsz counta, f
	goto $+2
	decfsz countb, f
	goto Delay_1

	decfsz count1 ,f
	goto d1
	retlw 0x00


Delay2 movlw d'100' ;delay ? ms (4 MHz clock)for reversing delay
	movwf count1
d2 movlw 0xC7
	movwf counta
	movlw 0x01
	movwf countb
Delay_2
	decfsz counta, f
	goto $+2
	decfsz countb, f
	goto Delay_2

	decfsz count1 ,f
	goto d2
	retlw 0x00

	end

You had spelt 'Delay2' wrongly, you spelt it 'delay2'
 
i feel like an a**. i will definetly remember this lesson from now on. i don't see a "#" button on advanced reply page. i see manage attachments and there are some icons that appear as an x to me so i don't know what its supposed to be. one has a c next to. does that mean code?
 
Click on 'Go Advanced', and it's the button with a '#' on it, next to the 'Quote' button.

MPASM is case sensitive (by default) so missing the capital D gave an error, you can turn it off if you want though.
 
sorry. i had to go into the user control panel and change a setting to get the more advanced menu for the reply. thanks for the help
 
You should also change your code slightly. The Delay2 subroutine modifies W (clears it) and so when it returns it will always access the first value in the table.

Mike.

Remove Delay2 from the table subroutine and change your main code to be something like,
Code:
Read1     call Delay2
             movf count, w ;put counter value in W
             call Table1
             movwf LEDPORT
 
1)
Is there any different between these two codes?
****
MOVLW 0x00
MOVWF count
****
CLRF count

2) I can’t use all program memory for coding. It’s only up to 0300h (16F84A)
Some times it froze and don’t write EEPROM.
 
Kitt354 said:
1)
Is there any different between these two codes?
****
MOVLW 0x00
MOVWF count
****
CLRF count

Not in the effect it has on 'count', they both zero it - CLRF is obviously twice as fast though, and doesn't alter W.

2) I can’t use all program memory for coding. It’s only up to 0300h (16F84A)
Some times it froze and don’t write EEPROM.

Possibly a problem with your programmer?.
 
Thanks Mr.Nigel.

I changed the programmer (to yours) but the result is same.
--
First thought there must be some wrong in my code. Finally I discover the fault. It’s the program memory size. I checked this using NOP’s and deleting some codes. When ii reduce the size every thing is fine. STRANGE PROBLEM!!

I think bad quality parts? (pic16f84a)
 
Kitt354 said:
Thanks Mr.Nigel.

I changed the programmer (to yours) but the result is same.
--
First thought there must be some wrong in my code. Finally I discover the fault. It’s the program memory size. I checked this using NOP’s and deleting some codes. When ii reduce the size every thing is fine. STRANGE PROBLEM!!

I think bad quality parts? (pic16f84a)

Try increasing the programming delay see if that helps?.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top