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.

Counting beyond f < 127?

Status
Not open for further replies.

Eric926

New Member
Hi I am a PIC chip novice basically working on a project for college. I've been reading up on the commands and have a question. In the INCF and INCFSZ functions, the Operand is listed as f <= 127. In my project, I need to have the count go to a maximum of about 900-999. Is there a way to advance the count beyond 127? If not, is there another way for me to do the count?
 
INCF and INCFSZ can count up to 255. The full lenght of the 8 bit register. The operand stated in the datasheet is the memory adress of the register you want to increase, not the content of the register (a pic can only access 127 bytes of memory at once, thats why its banked)...

Now, to count beyond 255 you must split the value into 2 bytes. One for the high byte of the counter and one for the low byte, Using 2 bytes allows you to count up to 65535. To do this you must check the Zero flag afther the increase and, if set, manually carry (add one to) the high byte

Example: CounterHI is the high byte of the counter, CounterLO contains the low byte of the counter
Code:
INCF     CounterLO, F     ;Add one to CounterLO, if it goes beyond 255 it rolls over to 0
BTFSC    STATUS, Z        ;Zero? then the low byte rolled over, add one to the high byte
INCF     CounterHI, F

Off course this means that all other things you want to do with the counter (comparing , subtracting, adding,...) will also have to be rewritten to use the 2bytes in stead of one
 
"f <= 127" refers is the address of file register.

Instructions that use direct addressing, only the lower 7 bits of the address of the file register (therefore, 0<=f<=127) plus the state of the bank select bits (RP0, RP1 of the STATUS register) determine which file register is being addressed.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top