1
\$\begingroup\$

I want to thank you for reading this question , keep in mind it might seem silly but it has been troubling me for a couple of hours.

I am using a PIC16F628. All i am trying to do for now is turn a simple LED on. I have created the following code using MikroC:

void main()
{
  TRISA=0x00;
  PORTA=0xFF;
}

Have simulated the following circuit with Proteus: Proteus Schematic

I am aware that only 4 leds would light up.

An uploaded the code to the PIC and veryfied it using PICkit2 (Software and Programmer).

I have read that the Programming pin (RB4/PGM) should be set on low , which I have done.

The PIC is wired on testing board and it doesn't turn on any LED. None of the pins (RA0,RA1,RA2,RA3) give enough voltage (they give about 0.3V).

1)I am supplying the circuit with 5V.

2)I am using the correct pins.

3)I have reprogrammed it a couple of times , no success.

4)MCLR is connected through a resistor to Vdd.

5)PGM pin is connected to GND (Vss)

6)LED are the correct way connected (even tried to rotate them in case I had mistaken).

7)I have tested the wiring , it is not interrupted.

It doesn't work , and I don't know what to do. Could somebody ,please explain what I have done wrong ?

\$\endgroup\$
2
  • 3
    \$\begingroup\$ If you're not using series resistors for the LEDs you may have fried the output pins when you first tried to turn them on. It doesn't take long! \$\endgroup\$
    – bitsmack
    Commented Feb 17, 2016 at 19:40
  • \$\begingroup\$ I don't know mikroc and without all of your code it's hard to tell but... Have you set The config bits accordingly To your hardware or even at all? \$\endgroup\$
    – zakkos
    Commented Feb 18, 2016 at 1:28

4 Answers 4

3
\$\begingroup\$

It's hard to tell what's going on without showing us your entire code, and a schematic of your physical implementation.

However this is what you can look into:

  1. You should add a for-ever loop at the end of your code. Your microcontroller might be shutting off after one run. Add at the end a while(1) or for(;;)

  2. Try adding the following code to your initialization (or whichever format your micro controller header defines these registers)

ANSEL = 0; /* Configure analog pins as digital*/

CMCON = 7; /* Disable comparators*/

  1. I haven't used microchip controllers under MikroC, but are you sure it's TRISA and PORTA instead of TRISO and GPIO?

  2. Make sure you configured the internal oscillator (INTOSC) appropriately. You can configure it by settings bits 0-2 (FOSC2:FOSC0) of CONFIG register to either101 or 100for INTOSC

\$\endgroup\$
8
  • \$\begingroup\$ I have added a while loop , disbled comparators but ANSEL ,nor ANSELH, do not exist for this particular PIC. For MikroC the correct command is TRISA and PORTA , tried TRIS0 and GIP0 and it does not understand the commands. Changed the PIC in case it was damaged and still no result. \$\endgroup\$
    – morty1993
    Commented Feb 17, 2016 at 20:49
  • \$\begingroup\$ Disable the watchdog \$\endgroup\$
    – Iancovici
    Commented Feb 17, 2016 at 20:58
  • \$\begingroup\$ Watchdog Timer (WDT) already disabled . Highspeed Oscillator (HS) is enabled and Low Voltage Programing (LVP)s dissabled. \$\endgroup\$
    – morty1993
    Commented Feb 17, 2016 at 21:06
  • \$\begingroup\$ I have 100 Ohm resistors for a LEDs and 10K Ohm resistor for MCLR. I pressume it's ok. \$\endgroup\$
    – morty1993
    Commented Feb 17, 2016 at 21:08
  • \$\begingroup\$ We can skip the led concerns by removing hem completely and just probing the voltage output of these channels. \$\endgroup\$
    – Iancovici
    Commented Feb 17, 2016 at 21:20
2
\$\begingroup\$

In addition to what lancovici said:

  • Do your LEDs have series resistors?
  • What is the configuration word value you use?

A first step could be that you check your hardware setup with a know-working .hex file. There are a few (including two (with and without crystal) for the 628) at my age-old blink page: http://www.voti.nl/blink

\$\endgroup\$
2
  • \$\begingroup\$ Unfortunately I don't have a Wisp628 programmer. But the information could still be helpfull , thank you. \$\endgroup\$
    – morty1993
    Commented Feb 17, 2016 at 20:52
  • 1
    \$\begingroup\$ A .hex file is 100% programmer-independent. You can use any programmer you want to transfer a .hex file into your PIC chip. \$\endgroup\$ Commented Feb 18, 2016 at 7:21
1
\$\begingroup\$

Your schematic shows now crystal or other clock source. This leads me to assume that you are intending to use the internal oscillator.

However, based on your comment on another answer, you say you have the configuration bits set to use HS mode. HS stands for High-Speed Crystal Oscillator/Resonator. In order for this mode to work, you need an 8MHz to 20MHz crystal or resonator attached to the OSCIN/OSCOUT pins. As you do not have this in your schematic (and so I assume do not have this set up), then you will have no clock source for your PIC to run on - and as such it will appear to do nothing at all.

For the internal 4MHz oscillator, the correct option is INTRC as per page 95 of the datasheet.

Try changing the setting to this and see if it starts working as expected.

\$\endgroup\$
0
\$\begingroup\$

TRISA and PORTA are in different banks, according to the datasheet, so you need to set the STATUS register properly before each access.

From "FIGURE 3-2: DATA MEMORY MAP OF THE PIC16F627 AND PIC16F628", PORTA is in bank 0, while TRISA is in bank 1.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.