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.

PCLATH Code Problem.

Status
Not open for further replies.

Suraj143

Active Member
Hi!

I'm calling a subroutine (Load_Buffer).In that subroutine I'm calling another table which is in a different page (0x0500).My problem is do I need to clear the PCLATH after calling the subroutine?

Note that I don't know the exact starting position of the Load_Buffer subroutine.It can be in another page or boundary crossed.

Code:
		call	Load_Buffer

Load_Buffer	movlw	High Table_1
		movwf	PCLATH
		movf	Pointer,W	
		call	Table_1
		movwf	Buffer_97
		call	Make_Shift	; A long routine
		----
		----
		----
                
		return	

		org	0x0500			
Table_1		addwf	PCL,F			
		retlw	00h
		retlw	.1
		retlw	.6
		retlw	.12
		retlw	.18
		retlw	.24
 
Last edited:
You will have to clear (or load) it if you access a table with a different high address or use call or goto a different page (above 0x7ff).

Are you aware that you can do tables that can be anywhere in memory.

Mike.
 
Hi Mike my code is less than 2K memory.

The problem is the code gets resets from short while I cannot solved that problem.This is not a Watch Dog issue.This is a code problem.
 
Hi mike this is what I'm doing.

Code:
Run_Begin	movlw	.6			; A
		movwf	Pointer
		movlw	.6
		movwf	Width
		call	Shift_Char_Loop
		movlw	.12			; B
		movwf	Pointer
		movlw	.6
		movwf	Width
		call	Shift_Char_Loop
		movlw	.18			; C
		movwf	Pointer
		movlw	.6
		movwf	Width
		call	Shift_Char_Loop
		goto	Run_Begin


Shift_Char_Loop	btfss	Flag_Register,End_Frame		; update the string after each frame
		goto	$-1
		bcf	Flag_Register,End_Frame
		;		
		call	Make_Shift_Left		
		return
							
Make_Shift_Left	movf	Col_2,W
		movwf	Col_1
		movf	Col_3,W
		movwf	Col_2
		movf	Col_4,W
		movwf	Col_3
		movf	Col_5,W
		movwf	Col_4
		movf	Col_6,W
		movwf	Col_5
		movf	Col_7,W
		movwf	Col_6
		movf	Col_8,W
		movwf	Col_7
		movf	Col_9,W
		movwf	Col_8
		movf	Col_10,W
		movwf	Col_9
		movf	Col_11,W
		movwf	Col_10
		movf	Col_12,W
		movwf	Col_11
		movf	Col_13,W
		movwf	Col_12
		movf	Col_14,W
		movwf	Col_13
		movf	Col_15,W
		movwf	Col_14
		movf	Col_16,W
		movwf	Col_15
		movf	Col_17,W
		movwf	Col_16
		movf	Col_18,W
		movwf	Col_17
		movf	Col_19,W
		movwf	Col_18			
		movf	Col_20,W
		movwf	Col_19
		movf	Col_21,W
		movwf	Col_20
		movf	Col_22,W
		movwf	Col_21
		movf	Col_23,W
		movwf	Col_22
		movf	Col_24,W
		movwf	Col_23
		movf	Col_25,W
		movwf	Col_24			
		movf	Col_26,W
		movwf	Col_25
		movf	Col_27,W
		movwf	Col_26
		movf	Col_28,W
		movwf	Col_27
		movf	Col_29,W
		movwf	Col_28
		movf	Col_30,W
		movwf	Col_29
		movf	Col_31,W
		movwf	Col_30
		movf	Col_32,W
		movwf	Col_31
		movf	Col_33,W
		movwf	Col_32
		movf	Col_34,W
		movwf	Col_33
		movf	Col_35,W
		movwf	Col_34
		movf	Col_36,W
		movwf	Col_35
		movf	Col_37,W
		movwf	Col_36
		movf	Col_38,W
		movwf	Col_37
		movf	Col_39,W
		movwf	Col_38
		movf	Col_40,W
		movwf	Col_39
		movf	Col_41,W
		movwf	Col_40
		movf	Col_42,W
		movwf	Col_41
		movf	Col_43,W
		movwf	Col_42
		movf	Col_44,W
		movwf	Col_43
		movf	Col_45,W
		movwf	Col_44
		movf	Col_46,W
		movwf	Col_45
		movf	Col_47,W
		movwf	Col_46
		movf	Col_48,W
		movwf	Col_47			
			;
		bsf	STATUS,RP0		; B1
		movf	Col_49,W
		bcf	STATUS,RP0		; B0
		movwf	Col_48
		bsf	STATUS,RP0		; B1
 			;
		movf	Col_50,W
		movwf	Col_49
		movf	Col_51,W
		movwf	Col_50
		movf	Col_52,W
		movwf	Col_51
		movf	Col_53,W
		movwf	Col_52
		movf	Col_54,W
		movwf	Col_53			
		movf	Col_55,W
		movwf	Col_54
		movf	Col_56,W
		movwf	Col_55
		movf	Col_57,W
		movwf	Col_56
		movf	Col_58,W
		movwf	Col_57
		movf	Col_59,W
		movwf	Col_58			
		movf	Col_60,W
		movwf	Col_59
		movf	Col_61,W
		movwf	Col_60
		movf	Col_62,W
		movwf	Col_61
		movf	Col_63,W
		movwf	Col_62
		movf	Col_64,W
		movwf	Col_63			
		movf	Col_65,W
		movwf	Col_64
		movf	Col_66,W
		movwf	Col_65
		movf	Col_67,W
		movwf	Col_66
		movf	Col_68,W
		movwf	Col_67
		movf	Col_69,W
		movwf	Col_68			
		movf	Col_70,W
		movwf	Col_69
		movf	Col_71,W
		movwf	Col_70
		movf	Col_72,W
		movwf	Col_71
		movf	Col_73,W
		movwf	Col_72
		movf	Col_74,W
		movwf	Col_73			
		movf	Col_75,W
		movwf	Col_74
		movf	Col_76,W
		movwf	Col_75
		movf	Col_77,W
		movwf	Col_76
		movf	Col_78,W
		movwf	Col_77
		movf	Col_79,W
		movwf	Col_78			
		movf	Col_80,W
		movwf	Col_79
		movf	Col_81,W
		movwf	Col_80
		movf	Col_82,W
		movwf	Col_81
		movf	Col_83,W
		movwf	Col_82
		movf	Col_84,W
		movwf	Col_83			
		movf	Col_85,W
		movwf	Col_84
		movf	Col_86,W
		movwf	Col_85
		movf	Col_87,W
		movwf	Col_86
		movf	Col_88,W
		movwf	Col_87
		movf	Col_89,W
		movwf	Col_88
		movf	Col_90,W
		movwf	Col_89
		movf	Col_91,W
		movwf	Col_90
		movf	Col_92,W
		movwf	Col_91
		movf	Col_93,W
		movwf	Col_92
		movf	Col_94,W
		movwf	Col_93
		movf	Col_95,W
		movwf	Col_94
		movf	Col_96,W
		movwf	Col_95
			;
		bcf	STATUS,RP0		; B0			
		movf	Buffer_97,W
		bsf	STATUS,RP0		; B1
		movwf	Col_96
		bcf	STATUS,RP0		; B0
		return
Note that the display multiplex routine is in ISR (not mentioned here) it works fine.From Col_1 to Col_48 is in B0 & the other 48 columns in B1.

The code works but from short while it resets.
 
Last edited:
I can't see anything wrong with that code so it may be elsewhere. Can you post a working example?

There is also a much better way to accomplish the scroll using FSR.

Mike.
 
In case your curious, this is how I would do the shift left code,
Code:
	clrf	STATUS
	movlw	Col_1
	movwf	FSR
Shift	incf	FSR,f
	movfw	INDF
	decf	FSR,f
	movwf	INDF
	incf	FSR,f
	movlw	Col_48
	xorwf	FSR,w
	btfss	STATUS,Z
	goto	Shift
	
	movlw	Col_49
	movwf	FSR
	movfw	INDF
	movwf	Col_48
Shift2	incf	FSR,f
	movfw	INDF
	decf	FSR,f
	movwf	INDF
	incf	FSR,f
	movlw	Col_96
	xorwf	FSR,w
	btfss	STATUS,Z
	goto	Shift2
	movfw	Buffer_97
	movwf	INDF

I can add comments if you're unsure how it works.

Mike.
 
Last edited:
Mike thanks for your compact code surely I'll use that.I can understand your code it very well.

Mike this is a working code I posted it will scroll ABC.The problem is it resets after short while.I'll try your method & see.
 
My ISR context saving is like this


Code:
		org	0004h
ISR_Enter	movwf   W_Temp          ; save off current W register contents
		movf	STATUS,W        ; move status register into W register		
		movwf	S_Temp		; 
		movf	FSR,W
		movwf	S_FSR
		movf	PCLATH,W
		movwf	S_PCLATH
		clrf	STATUS

		----
		----

ISR_Exit	movf	S_PCLATH,W
		movwf	PCLATH
		movf	S_FSR,W
		movwf	FSR
		movf    S_Temp,W     	; retrieve copy of STATUS register
		movwf	STATUS         	; restore pre-isr STATUS register contents
		swapf   W_Temp,F
		swapf   W_Temp,W        ; restore pre-isr W register contents
		retfie

I'm wondering I haven't clear the STATUS on top of the scrolling loop starts will that the problem!!
 
Last edited:
If you are using PCLATH in your ISR then make sure it has the correct value.

Mike.
 
Hi Mike it worked perfectly.The problem was I was enabled BODEN.When LED's takes more current it will reset.There is no any SFR to adjust the BODEN voltage level.

I also added your compact code snippets they all worked well.

Thanks for your help.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top