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.

How to change several port bits in one step?

Status
Not open for further replies.

yfx4

Member
I am using a 16f628a and int clock 4MHz in assembly using MPlab 8.xx. I have 7 LEDs on PortB <1:7> and am reserving RB0 as an input for IOC. (Sounds like I know a little huh? Don't be fooled!) I want to be able to flash the lamps on 1, 3, and 6 (or 2, 4, and 7) irrespective and ignoring and not altering the status of the other LEDs.

I can:
Flashloop
bsf Portb, 1
bsf Portb, 3
bsf Portb, 6
Delay
bcf Portb, 1
bcf Portb, 3
bcf Portb, 6
Delay
goto Flashloop

Is there a way to do the bsf and bcf for all three LEDs in a single step??? Like bsf <1,3,6> or something along that line??

Thank you!
 
Last edited:
Use a shadow register. The shadow register is a variable to hold the value that you want to write to the port. You update that variable (via ANDs and ORs) and then write the full value to the port.
 
Code:
movlw 0b01001010
IORwf PORTB
delay
movlw 0b10110101
andwf PORTB

That just from the top of my head, but should be correct, give it a try

Cheers
Roman
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top