It is currently 24 Oct 2017 02:10

All times are UTC + 1 hour




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: examlpes not working
PostPosted: 16 Jul 2008 13:45 
Offline

Joined: 16 Jul 2008 13:41
Posts: 3
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:

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.


Top
 Profile  
 
 Post subject:
PostPosted: 16 Jul 2008 15:04 
Offline

Joined: 16 Aug 2007 03:49
Posts: 1074
Location: St. Louis, MO
Consult the datasheet (section 3.1) but I think you need to add:

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.


Top
 Profile  
 
 Post subject:
PostPosted: 16 Jul 2008 16:44 
Offline

Joined: 16 Jul 2008 13:41
Posts: 3
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.


Top
 Profile  
 
 Post subject:
PostPosted: 16 Jul 2008 20:33 
Offline

Joined: 09 Apr 2008 12:56
Posts: 173
I have compiled your code with MikroC and simulated it with the MikroC simulation and it works fine. How are you simulating your code?


Top
 Profile  
 
 Post subject:
PostPosted: 17 Jul 2008 12:29 
Offline

Joined: 28 Sep 2005 19:43
Posts: 243
Location: Romania
Check these in configuration of the project:
    WDT OFF (important)
    Oscillator as needed (HS, XT, ...)
    PWRT ON (not quite necessary)

_________________
Regards,
thenoble66
--------------------------------------------------------------------


Top
 Profile  
 
 Post subject:
PostPosted: 17 Jul 2008 16:16 
Offline

Joined: 16 Jul 2008 13:41
Posts: 3
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...


Top
 Profile  
 
 Post subject:
PostPosted: 17 Jul 2008 16:31 
Offline

Joined: 28 Sep 2005 19:43
Posts: 243
Location: Romania
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
--------------------------------------------------------------------


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron