Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 6th July 2009, 04:09 AM   #1
Default Paging in 877a

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??
MessUpMymind is offline  
Old 6th July 2009, 05:47 AM   #2
Default

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.
Pommie is online now  
Old 6th July 2009, 06:02 AM   #3
Default

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!!
MessUpMymind is offline  
Old 6th July 2009, 06:06 AM   #4
Default

Shouldnt you do

"ADDWF PCL,f
...
...
..."
You are just reseting the PCL not advancing it
__________________
Mike
My website: www.ElectroBird.net
birdman0_o is offline  
Old 6th July 2009, 06:08 AM   #5
Default

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.
Pommie is online now  
Old 6th July 2009, 06:16 AM   #6
Default

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 ..
MessUpMymind is offline  
Old 6th July 2009, 06:20 AM   #7
Default

hi mike,

i haven make the changes for addwf , i get back to you after i change it..

thanks...
MessUpMymind is offline  
Old 6th July 2009, 06:29 AM   #8
Default

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.
Pommie is online now  
Old 6th July 2009, 06:33 AM   #9
Default

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?
__________________
Mike
My website: www.ElectroBird.net
birdman0_o is offline  
Old 6th July 2009, 06:38 AM   #10
Default

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.
Pommie is online now  
Old 6th July 2009, 06:38 AM   #11
Default

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
MessUpMymind is offline  
Old 6th July 2009, 06:40 AM   #12
Default

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.
Pommie is online now  
Old 6th July 2009, 07:09 AM   #13
Default

hi mike ,

oh i get what you mean , thanks =)..

Regards,
TK
MessUpMymind is offline  
Reply

Tags
877a, paging

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
Debugging 877A with MPLAB williB Micro Controllers 10 7th May 2007 04:53 PM
Pic 877A and boost converter williB Micro Controllers 15 4th May 2007 03:14 AM
Help in paging 16F877 TronicBrain Micro Controllers 6 2nd May 2007 03:16 PM
Difference between 877 and 877A? liupengjian Micro Controllers 2 19th March 2004 02:13 AM
Plaese Help!! - Programming 877A using JDM dy001 Micro Controllers 7 17th November 2003 02:38 PM



All times are GMT. The time now is 11:43 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker