examlpes not working

General discussion on mikroC.
Post Reply
Author
Message
lelio
Posts: 3
Joined: 16 Jul 2008 13:41

examlpes not working

#1 Post by lelio » 16 Jul 2008 13:45

Hi all,I'm new to the microcontroller world, but quite skilled in c programming. I tried the example code for led blinking on 16f876:

Code: Select all

void main() {
  PORTA = 0;                  // Initialize PORTA
  TRISA = 0;                  // Configure PORTA as output


  while(1) {
    PORTA =  ~PORTA;          // toggle PORTA
    Delay_ms(1000);           // one second delay
  }
}
But no effect. They always turn on after a second from the beginning of program and they remain on without blinking. Can you help me? Thank you.

drdoug
Posts: 1074
Joined: 16 Aug 2007 03:49
Location: St. Louis, MO

#2 Post by drdoug » 16 Jul 2008 15:04

Consult the datasheet (section 3.1) but I think you need to add:

Code: Select all

ADCON1 = 0x06
to make all the pins digital.

On other models you may also need to turn off the comparators to get proper operation.

The datasheet is your new best friend in microcontroller world.

Hope it helps.

lelio
Posts: 3
Joined: 16 Jul 2008 13:41

#3 Post by lelio » 16 Jul 2008 16:44

Thanks for the answer. 16f876 hasn't comparator registers so I can't turn them off like in 16f877A, but i tried to turn off A/D converters on portA with no result. It could help pheraps that i'm testing my programs in "Pic Simulator IDE" and not on a real circuit.

Mike Brearley
Posts: 173
Joined: 09 Apr 2008 12:56

#4 Post by Mike Brearley » 16 Jul 2008 20:33

I have compiled your code with MikroC and simulated it with the MikroC simulation and it works fine. How are you simulating your code?

thenoble66
Posts: 243
Joined: 28 Sep 2005 19:43
Location: Romania

#5 Post by thenoble66 » 17 Jul 2008 12:29

Check these in configuration of the project:
  • WDT OFF (important)
    Oscillator as needed (HS, XT, ...)
    PWRT ON (not quite necessary)
Regards,
thenoble66
--------------------------------------------------------------------

lelio
Posts: 3
Joined: 16 Jul 2008 13:41

#6 Post by lelio » 17 Jul 2008 16:16

Nothing to do... I had fuses set like you said by default following the mikroc pdf guide,but still doesn't work. I use PIC Simulator IDE. And also when i start debugger the mikroc automatically opens another example called "led blinking" and debugs it and not my active project. I don't know what else to do...

thenoble66
Posts: 243
Joined: 28 Sep 2005 19:43
Location: Romania

#7 Post by thenoble66 » 17 Jul 2008 16:31

Save your work in a safe place.
Close current project, whatever it is: Project -> Close project
Start a new project, set configuration bits properly, controller, frequency as well, copy your safely put code into the code window and recompile.
Regards,
thenoble66
--------------------------------------------------------------------

Post Reply

Return to “mikroC General”