2

I have recently begun working with pic micro-controllers, and I haven't had that much trouble with the PIC16F877A series. But i found the PIC16F88 really troublesome. I don't know whether it is already a faulty IC(I just bought it), but after i wrote the following program with hopes to make an led blink, all the pins of the IC produce a high out put. I am using mikroC to write the program and pickit 3 to program the device.

void main() {

   ANSEL = 0;
   TRISA = 0;           

  do {
    PORTA = 0x00;     
    Delay_ms(1000);    
    PORTA = 0xFF;       
    Delay_ms(1000);    
  } while(1);          
}

As one can understand from the code, an LED connected to PORT A should blink and PORT B shouldn't produce and out out. Is there a particular scenario or mistake that makes all pins of a microcontroller high?

1 Answers1

0

When you write

PORTA = 0xFF; 

You're essentially turning on all of the pins for PortA. A port is usually a set of 8 (or less) individual pins on the chip. If you want to turn on just one of the pins within the port, then you need to specify which one. There are a number of different ways to do this. Let's say you wanted to turn on PortA pin 3. Here are a few ways to accomplish that:

PORTA.B3 = 1;
PORTA = 0x4; //Hex
PORTA = 0b00000100;  //Binary
PORTA = 4; //Decimal

Each of the above statements will turn PortA pin 3 on and leave the rest off. I personally prefer the PORTA.B3 method as it allows the other pins on the port to remain unchanged.

Having said all of that, you're saying that all of the pins on your chip are going high when you execute PORTA = 0xFF? According to the datasheet, you should only see pins 17, 18, 1, 2, 3, 4, 15, and 16 turn on. The rest should remain unchanged. If you're seeing them all go high then I would try a different chip to ensure the first is not faulty. I always buy these chips in bulk since they're so cheap.

Matt Ruwe
  • 3,386
  • 6
  • 39
  • 77