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.

Paging in 877a

Status
Not open for further replies.

MessUpMymind

New Member
hi there,

i am currently trying to use lookup table to simplify my program ,
below is the coding:-
Code:
pcl 	equ 03h

movlw 0x00        ;get high 8 bits of Table address
movwf PCLATH            ;save to PCLATH (may not be correct, yet)	
movlw 0x80		         ;get Table low address
addwf offset,W          ;add value of offset, keep result in W
                        ;if page is crossed, carry will be set
btfsc STATUS,C          ;check page crossed? Skip next if NO
incf PCLATH             ;yes, increment PCLATH

call Table              ;call to table



org 0x50		
Table:	
		movwf	pcl
		retlw	0x88
		retlw	0x70
		retlw	0x38
		
	
		movwf	PORTD	
		call	DELAY

what i wan to do is just display those value on PORTD , but it seem not working =(...can anybody help me??
 
You are using 0x80 as the table address instead of 0x50. Also the code will return after the call to table so you need something after the call.

BTW, you can use movlw low(table) to load W with the low byte. Likewise, you can use movlw high(table) for the high byte.

Mike.
 
Hi mike,

thanks for your quick reply, i have tried as what u said

Code:
        pcl equ 02h

        movlw 0x00        		;get high 8 bits of Table address
	movwf PCLATH            ;save to PCLATH (may not be correct, yet)	

	
	movlw 0x50		        ;get Table low address
        addwf offset,w                ;if page is crossed, carry will be set
	btfsc STATUS,C          
	incf PCLATH 
	call Table           
	movwf PORTD
	call	DELAY
	

org 0x50
Table:	movwf	pcl	
		retlw	0x88
		retlw	0x70
		retlw	0x38
		retlw	0xff
		retlw	0xff

but seem like it doesn't light on those led , and another issue should i increase the PCL after i complete the retlw ?? or it actually will flow by it own??

your help is much appreciated!!
 
If you post snippets of code then it is very difficult to help. If you post an example that can be assembled then it is easy to see what is wrong. In your code above I have no idea what is in location "offset" or if you have set the port to output etc.

Mike.
 
hi mike ,

sorry for bringing you trouble here's the complete code ,
Code:
#include "P16f877a.inc"
__CONFIG 0x399A

cblock 0x20
offset
endc

COUNT1	EQU	2DH 	
COUNT2	EQU	2EH 
pcl 	equ 02h

org 0x00

		BSF	STATUS,5   ; set bit 5 of STATUS to change to bank 1
		BANKSEL TRISB
		clrf	TRISB
		BCF	STATUS,5
		BANKSEL	PORTB
		clrf	PORTB

	movlw 0x00        		;get high 8 bits of Table address (Page 0)
	movwf PCLATH            ;store into PCLATH 	
	movlw	0x50
	addwf        offset,w		
	btfsc STATUS,C          
	incf PCLATH 
	call Table           
	movwf	PORTD
	call	DELAY
	

org 0x50
Table:	movwf pcl	
		retlw	0x88
		retlw	0x70
		retlw	0x38
		retlw	0xff
		retlw	0xff			
		
DELAY					; common delay for all condition
		MOVLW	d'200'	
		MOVWF	COUNT1
DELAY1	
		DECFSZ	COUNT2,1
		GOTO	DELAY1
		DECFSZ	COUNT1,1
		GOTO	DELAY1
		RETURN



		

END

there's nothing on the output ..
 
You haven't put a valid value in offset. You are also setting PortB to output and then writing to PortD.

This should get you started,
Code:
#include	"P16f877a.inc" 
		__config 0x399A

		cblock	0x20
offset
		endc

COUNT1		equ	2DH 
COUNT2		equ	2EH 
pcl		equ	02h

		org	0x00

		bsf	STATUS,5	; set bit 5 of STATUS to change to bank 1
		banksel	TRISB
		clrf	TRISB
		clrf	TRISD		;set port D to output
		bcf	STATUS,5
		banksel	PORTB
		clrf	PORTB
again		movlw	1		;start at entry 1
		movwf	offset
Loop
		movlw	0x00		;get high 8 bits of Table address (Page 0)
		movwf	PCLATH		;store into PCLATH 
		movlw	0x50
		addwf	offset,w
		btfsc	STATUS,C          
		incf	PCLATH 
		call	Table           
		movwf	PORTD
		call	DELAY
		incf	offset,f	;move to next entry
		movlw	6		;length of table
		xorwf	offset,W
		btfss	STATUS,Z	;reached the end?
		goto	Loop		;no so keep going
		goto	again		;yes so reset offset

		org	0x50
Table:		movwf	pcl
		retlw	0x88
		retlw	0x70
		retlw	0x38
		retlw	0xff
		retlw	0xff

DELAY					; common delay for all condition 
		movlw	d'200'
		movwf	COUNT1
DELAY1
		decfsz	COUNT2,1
		goto	DELAY1
		decfsz	COUNT1,1
		goto	DELAY1
		return

		end

Mike.
 
Mike, are you sure MOVWF PCL is not a mistake, I would think it to be ADDWF PCL?
From what I understand the way the table works is by adding to the program counter latch "PCL" you advance the program, if you add 3 it skips 3 instructions and goes to the 3rd item on the table. Do I misunderstand?
 
The way the code above is written it calculates the address in the table and so movwf is correct. You can use addwf but then the table cannot cross a page boundary. Try running the above code in the simulator to see the difference.

Mike.
 
hi mike,

thanks a lot...you are always so kind helping me...it's working , if i didnt set offset it will be 255 inside right?? and that cause an error??

regards tk
 
If you don't write a value it will just be a random number and jump to a random point in your code. This was why it was crashing.

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top