18F*** Port Question

Status
Not open for further replies.

Zedrow

New Member
Hi,

I've been a longtime lurker here and find this forum gives a lot of good advice for electronics and microcontrollers, and have even read through, and learned from, many of the tutorials from members.

With that said, here is my question. I've been programming PIC 18F452, and 18F458 chips for years now and recently I've started with 18F1220 as I needed a smaller package.

On the previous chips, when I wanted to set or clear port bits to light leds I had no problems. Now with the 1220 I am able to light the leds, but sometimes when I do, some or all previously lit LEDs turn off.

I generally do this as: bsf PORTA,2 for example. So if I did the following it would initially light LED,0 then 1, then when it lights LED,2, 0 and 1 turn off.

Code:
bsf   porta,0
bsf   porta,1
bsf   porta,2

As I said, this hasn't happened with the 452 or 458. What I ended up doing for now was create a shadow of PORTA and then move the file to the port, and this seems to work, so I know it isn't a power issue.

I can keep doing this if need be but it adds some code that I don't think is necessary. I also thought about setting the LATA register to get around this, but I haven't tried yet.

Thanks,

Zed
 
Hi,

No need to lurk about - just join in

Well forgive the obvious but have you set up PORTA /TRISA to be Digital Outputs ?

Perhaps if you could show more of your code something might be easier to spot.
 
Go ahead and switch to the LAT register. It does what you are doing in software but in hardware.

If that does not work make sure you have the port digital. See the bit of asm code in the datasheet for setting up the port.
 

hi and Welcome.
This page is from the 18F2550 datasheet regarding the LATn function.
 

Attachments

  • AAesp01.gif
    94.2 KB · Views: 188
Last edited:
Thanks for the replies, I appreciate it.

I think you all are right, I didn't set the ports as digital I guess. I read the datasheet as being set for digital inputs and I didn't think it was required for outputs. In looking at the datasheet I can set individual PORTA ports as either digital or analog, which is perfect because I need to do some A/D conversions as well.

Thanks for all your help, and as you can see, my lurking days are over

Zed
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…