CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Need Help on PIC16F877A

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
wailoon86



Joined: 13 Sep 2007
Posts: 2

View user's profile Send private message

Need Help on PIC16F877A
PostPosted: Thu Sep 13, 2007 7:42 pm     Reply with quote

Hello..
I am new to PIC programming. I'm currently trying to program PIC16F877A to light up an LED. Below is my code. Can someone try to advise me regarding this. Much appreciated.

#include <16F877A>
#use delay(clock=20000000)
#fuses hs,nowdt,noprotect

void main()
{
set_tris_d(0b00000000);
for(;;)
{
output_high(PIN_B0);
delay_ms(1000);
output_low(PIN_B0);
delay_ms(1000);
}
}

Is there any else that i miss?
misaeldv



Joined: 10 Nov 2005
Posts: 11

View user's profile Send private message

PostPosted: Thu Sep 13, 2007 8:49 pm     Reply with quote

What kind of problems are you facing?
inservi



Joined: 13 May 2007
Posts: 128

View user's profile Send private message

PostPosted: Fri Sep 14, 2007 4:31 am     Reply with quote

Hello,

you don not need 'set_tris_d(0b00000000); '.
It is only necessary with #use fast_io (port).

dro.
_________________
in médio virtus
adrian



Joined: 08 Sep 2003
Posts: 92
Location: Glasgow, UK

View user's profile Send private message

PostPosted: Fri Sep 14, 2007 5:59 am     Reply with quote

Hmm two posters with the same problem - must be homework time!

delay_ms(1000), will not work as you have found out.
You can only use delay_ms() with a 'variable' with a value of upto 255. I suggest you go and read the manual.
You can extend this value to 65535 by using a 'constant' - this is what I think you want to do.
Or you can call delay_ms(250) four times.
Ken Johnson



Joined: 23 Mar 2006
Posts: 197
Location: Lewisburg, WV

View user's profile Send private message

PostPosted: Fri Sep 14, 2007 6:29 am     Reply with quote

As inservi? said, you don't need the set_tris_d. But if you do want to use fast_io, use set_tris_b if you're using pins on port b

Ken
inservi



Joined: 13 May 2007
Posts: 128

View user's profile Send private message

PostPosted: Fri Sep 14, 2007 7:02 am     Reply with quote

Hello,
Quote:
delay_ms(1000), will not work as you have found out.
You can only use delay_ms() with a 'variable' with a value of upto 255. I suggest you go and read the manual.
You can extend this value to 65535 by using a 'constant' - this is what I think you want to do.
Or you can call delay_ms(250) four times.


I'm sorry but i often use delay_ms(1000) and it work perfectly with my PCWH as well with v3.xxx than 4.xxx.

dro.
_________________
in médio virtus
Foppie



Joined: 16 Sep 2005
Posts: 138
Location: The Netherlands

View user's profile Send private message Send e-mail Visit poster's website MSN Messenger

PostPosted: Fri Sep 14, 2007 7:31 am     Reply with quote

I am not entirely ure but I think the line
Code:
#use delay(clock=20000000)

must be after the fuses, so:
Code:
#fuses hs,nowdt,noprotect
#use delay(clock=20000000)

further I don't think the compiler should have any problems with the set_tris_d(0b00000000); line, but it's better to delete it, if only for human understanding ;)

Hope this helps,
Jos
inservi



Joined: 13 May 2007
Posts: 128

View user's profile Send private message

PostPosted: Fri Sep 14, 2007 10:27 am     Reply with quote

Hello,

My last program with 16f876 (about same as 16f877) have these lines and working right:

Code:
#use delay(clock=20000000)
#fuses NOWDT,HS, PUT, NOPROTECT, BROWNOUT, NOLVP, NOCPD, NOWRT, NODEBUG


Foppie,
Quote:
further I don't think the compiler should have any problems with the set_tris_d(0b00000000); line, but it's better to delete it, if only for human understanding ;)
I agree with you.

This code is working !
Code:
void main() {
  for(;;){
    output_high(PIN_A2);
    delay_ms(1000);
    output_low(PIN_A2);
    delay_ms(1000);
  }
}


wailoon86,
What kind of problems are you facing ?
Are you sure that your programmer is working right ?
Are you already programed other pic ?


dro.
_________________
in médio virtus
umka



Joined: 28 Aug 2007
Posts: 99
Location: New Zealand

View user's profile Send private message

PostPosted: Sat Sep 15, 2007 4:01 am     Reply with quote

in the main routine does one not need a while(1) loop?

so use

Code:
void main()
{
  while(1)
 {
    output_high(PIN_A2);
    delay_ms(1000);
    output_low(PIN_A2);
    delay_ms(1000);
  }
}
Vodka



Joined: 13 Sep 2007
Posts: 14

View user's profile Send private message

PostPosted: Sat Sep 15, 2007 6:41 am     Reply with quote

everything goes well till delay_ms() apear..i have the same problem....pls tell me why???
wailoon86



Joined: 13 Sep 2007
Posts: 2

View user's profile Send private message

Reply...
PostPosted: Sat Sep 15, 2007 9:19 am     Reply with quote

Dear Inversi,
I also not sure whats happening with the PIC. I'm using the Cytron Programmer WINPIC800 UP00A to program it. Using the CCS C compiler, i took the .hex file and program it to the PIC.

Also, one of my colleague told me to check whether is the hardware or software problem.

Here's how I did.
output_high(PIN_B0)
output_low(PIN_B1)
:
output_high(PIN_B7)
and so on.

when i connect my multimeter, output of B5 to B3 are low.

1.And I would like to ask, must I connect pin 1 (which is Master Clear Inverted) to Vss everytime I connect the circuit?

2.I noticed certain pins have two functions. I was wondering is there a way that I can I access it?

I been reading the datasheet and CCS C Manual over and over again.
Thanks for your guys help.
Much appreciate it.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group