Basic PIC woes

Find out how to setup your programmer's software and how to solve many common problems.

Moderator: phalanx

Post Reply
Sillypuppy
Posts: 2
Joined: Tue Nov 07, 2017 5:59 pm

Basic PIC woes

Post by Sillypuppy » Tue Nov 07, 2017 6:17 pm

Thanks for having me.

Just so you know who you're dealing with while attempting to troubleshoot my issues - I have decades of electronics under my belt, and I'm quite proficient and comfortable with MSI logic and construction techniques. My issues will not be hardware related.

That said, it's taken me quite some time to finally get around to the PIC - always an IDE with a lousy interface that I couldn't quite grasp (As well I'm C illiterate), or didn't quite work the way some tutorial said they would.

Finally I found mikroC for pic and the PICkit2 and managed to get a working hello world program - sequential flashing LEDs on port A.

TRISA = 0
port a 0xff;
delay_ms + (1000);

etc..

Basic I know, but the leap I required - everything else from here should simply be a matter of experimenting with syntax.

So I thought.

On my way to the eventual goal of utilizing an old Dallas RTC and a bunch of old HPDL1414 displays to build a retro wristwatch, I decided to get my code on with a 16F88 and a simple 6 digit multiplexed common anode LED readout. PNP transistors driving the decades from port A, 330 ohm resistors to the segments from port B. The hardware is correct.

Yet it didn't work.

TRISB is also set to 0, and I have no reason to believe the IC is defective.

I feel as if I'm missing something very simple - any help would be appreciated.

Investigating, I found that port B is not changing state.

User avatar
phalanx
Non-SFE Guru
Posts: 1979
Joined: Sun Nov 30, 2003 8:57 am
Location: Candia, NH

Re: Basic PIC woes

Post by phalanx » Wed Nov 08, 2017 7:18 am

Hi Sillypuppy,

To start working out why PORTB isn't changing state, can you post your entire source code so we can make sure everything is configured properly? I'm not readily familiar with the mikroC compiler and its related part specific syntax, but I'm sure we can work through that.

-Bill

Sillypuppy
Posts: 2
Joined: Tue Nov 07, 2017 5:59 pm

Re: Basic PIC woes

Post by Sillypuppy » Mon Nov 13, 2017 5:55 pm

Hi Bill, thanks for the reply - sorry it took awhile to get back, Haven't been to the bench for a while.

As far as config bits, the MikroC IDE sets them with a dialog box - I'm using a 4MHz crystal, and can't really say much else except that the controller will load and run simple programs.

The most simple written:

void main() {
TRISA = 0;
TRISB = 0;
/*begin endless loop here*/
chicken: {
PORTA 0x00;
delay_ms = (1000);
PORTA 0xff;
delay_ms = (1000);
PORTB 0x00;
delay_ms = (1000)
PORTB 0xff
}
goto chicken;
}

This program will (obviously) alternately turn on and off all pins of portA (RA0-RA7) but has no effect on portB.

...

Aside, I've been playing with syntax (for example PORTx 0bxxxxxxxx) just to get a handle on what works and gain familiarity and have tried setting individual pins of port A to input (TRISA = 0x01, to set RA1 as an input), writing a similarly simple program to simply toggle between two LEDs on adjacent outputs, also without luck - although i suspect this is simply my structure.

Would you have an example of this?

Thanks again.
James.

User avatar
phalanx
Non-SFE Guru
Posts: 1979
Joined: Sun Nov 30, 2003 8:57 am
Location: Candia, NH

Re: Basic PIC woes

Post by phalanx » Wed Nov 15, 2017 3:34 pm

Sorry for taking so long to back to you as well.

What PIC are you using and can you tell me what all your configuration bits are set to? I need to know the PIC so I can look at the datasheet and see if there are any peripherals overriding the I/O functionality of PORTB by default. There are many PICs where this is the case.

-Bill

Post Reply