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.

pic maths - how to enforce 8 bits?

Status
Not open for further replies.

kardzzz

New Member
My project requires 5 modes. {0-4}, using a 12F683.

I increment a register using ADDWF by 0x34 (dec 52).
My problem is I don't understand what the PIC is doing once it encounter 'dec 260' hence see a 9 bit binary.

52 110100
104 1101000
156 10011100
208 11010000
260 100000100 (9bit)

I don't have a simulator, does, it simply do a 260-255 = 5 and store b'101' ?
How can I force the processor to store a '0' if above 255?

Thanks
 
It rolls over once it gets to 255 and starts back at 0. Don't you have Mplab It's free and can simulate your chip.
 
The simplest way to do it is to check the Carry flag.

Code:
		movlw	.52		;add 52 decimal
		addwf	Var,F		;to Variable
		btfsc	STATUS,C	;gone past 255?	
		clrf	Var		;yes so variable = 0

Mike.
 
Thanks for your replies, I manage to solve my problem.
I have mplab already but need to find time to learn more about debugging
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top