Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC PCL and PCLATH Trouble

Status
Not open for further replies.

neoaspilet11

Full Member level 5
Joined
Sep 29, 2005
Messages
277
Helped
29
Reputation
56
Reaction score
8
Trophy points
1,298
Location
Cebu, Philippines
Activity points
4,048
pclath

Hello Everybody,

I got this funny experience in manipulating the PCL and PCLATH registers of PIC.

I have huge data table in a magnitude of 800+ memory locations. A revise edition of my data table has more than 3000 memory locations. But I have not coded it yet.

The problem goes like this

WREG = 7C; before entering to Data Table
PCLATH = 00h

Table addwf PCL,1 ; PCL =PCL + w Address =0x83
....
....
....
retlw XX ; Address = 00FF
retlw YY ; Address = 0100
retlw ZZ ; Address = 0101
.....
.....

You see when the ADD instruction is executed, PCL = 100h or it overflows! The MPU simply execute the RESET vector instead of executing Address 0100h. Hehe It took me 30 minutes to realize what was my mistake.

Although I have a solution to this problem by simply dividing the Data table by several tables and manipulating the Value to be added to PCL, PCLATH and PCL I still have some questions.

1.) Is it not automatic when PCL overflows by addtion instruction to PCL, PCLATH will be incremented ?

2.) Is there any other way to implement the TABLE by not dividing it to several tables? (It should be noted that the value to be added to PCL is more than 8 bits. This means an appropriate PCLATH manipualtion must also be done.)

3.) Is it possible to manipulate both PCL and PCLATH in just one instruction by just adding value to it?

Thanks for your ideas.
 

pic pclath

You can have big table jumps if you do it correctly. Check out the piclist, but here's an example in asm:

Code:
TABLELOOKUP:
  movlw (high) (TABLESTART)
  addwf offsetHigh, w     ;add high portion
  movwf PCLATH
  movf offsetLow, w
  addlw (low) TABLESTART ;add low portion
  btfsc STATUS, C        ;carry if low portion overflows
      incf PCLATH, f
  movwf PCL              ;jump
TABLESTART:

This code is general, there are plenty of cases where it can be shortened.
 
pic pcl

Hello jonw0224,

That was very neat indeed! Thnak you very much. Although I still have to try your code,but at least you've given me an idea.

neoaspilet11


Is the expresion (high) (TABLESTART) equal to the upper 5 bits of address TABLESTART?

Is the expresion (LOW) (TABLESTART) equal to the lower 8 bits of address TABLESTART?
 

pcl and pclath

The code, I got from the piclist (www.piclist.com) about a year ago. There are other variations of the same thing.

For 16 bit numbers, high gives the most significant 8 bits and low gives the least significant 8 bits. For 24 bit numbers, you use mid which gives the center 8 bits. So, basically, in ASM, yes.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top