+ Reply to Thread
Results 1 to 13 of 13

Thread: Paging in 877a

  1. #1
    MessUpMymind Newbie
    Join Date
    Oct 2008
    Posts
    64

    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??


  2. #2
    Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent
    Join Date
    Mar 2005
    Location
    Brisbane Australia
    Posts
    6,696

    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.

  3. #3
    MessUpMymind Newbie
    Join Date
    Oct 2008
    Posts
    64

    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!!

  4. #4
    birdman0_o Excellent birdman0_o Excellent birdman0_o Excellent birdman0_o Excellent birdman0_o Excellent birdman0_o Excellent
    Join Date
    Feb 2009
    Location
    Montreal, Quebec
    Posts
    1,061

    Shouldnt you do

    "ADDWF PCL,f
    ...
    ...
    ..."
    You are just reseting the PCL not advancing it
    Mike
    My website: www.ElectroBird.net

  5. #5
    Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent
    Join Date
    Mar 2005
    Location
    Brisbane Australia
    Posts
    6,696

    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.

  6. #6
    MessUpMymind Newbie
    Join Date
    Oct 2008
    Posts
    64

    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 ..

  7. #7
    MessUpMymind Newbie
    Join Date
    Oct 2008
    Posts
    64

    hi mike,

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

    thanks...

  8. #8
    Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent
    Join Date
    Mar 2005
    Location
    Brisbane Australia
    Posts
    6,696

    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.

  9. #9
    birdman0_o Excellent birdman0_o Excellent birdman0_o Excellent birdman0_o Excellent birdman0_o Excellent birdman0_o Excellent
    Join Date
    Feb 2009
    Location
    Montreal, Quebec
    Posts
    1,061

    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

  10. #10
    Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent
    Join Date
    Mar 2005
    Location
    Brisbane Australia
    Posts
    6,696

    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.

  11. #11
    MessUpMymind Newbie
    Join Date
    Oct 2008
    Posts
    64

    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

  12. #12
    Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent
    Join Date
    Mar 2005
    Location
    Brisbane Australia
    Posts
    6,696

    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.

  13. #13
    MessUpMymind Newbie
    Join Date
    Oct 2008
    Posts
    64

    hi mike ,

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

    Regards,
    TK

+ Reply to Thread

Similar Threads

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

Tags for this Thread