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

Very simple LED program for PIC16F873

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



Joined: 28 Apr 2004
Posts: 5

View user's profile Send private message Send e-mail Yahoo Messenger

Very simple LED program for PIC16F873
PostPosted: Tue May 04, 2004 2:25 pm     Reply with quote

Can anyone tell if there if something wrong with this code?
It compiles fine, but the LED doesn't light up........ The LED is on the RB0 register.......... I am pretty new to all this, but I can't see what is wrong.....
Any help would be great,
Thanks,
L

void main ( void )
{
set_bit ( STATUS, RP0 ) ; /* Select the Register bank 1 */
TRISB = 0xff ; /* set all of PORTB for input */
TRISA = 0xfe ; /* set bit 0 of PORTA for output */
clear_bit ( STATUS, RP0 ) ;/* now use Register bank 0 */

while (1) {
if( input_pin_port_b(0)){
output_high_port_a(0);
}
else{
output_low_port_a (0) ; /* light LED /*
}
}
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue May 04, 2004 2:39 pm     Reply with quote

Most of the code in your program is completely unnecessary
for the CCS compiler. Here is a simple program which will
blink a LED on Pin B0. Try this program.

(If your crystal is a different frequency than 4 MHz, then
change the #use delay statement. If your crystal is 20 MHz,
then change the 'XT' in the #fuses statement to be 'HS',
in the program below).

Code:
#include <16F873.h>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)

//===================================

main()
{

while(1)
  {
   output_high(PIN_B0);
   delay_ms(500);
   output_low(PIN_B0);
   delay_ms(500);
  }

}
Kasper



Joined: 14 Jan 2004
Posts: 88
Location: Aurora, Ontario, Canada

View user's profile Send private message Visit poster's website

PostPosted: Tue May 04, 2004 2:42 pm     Reply with quote

try this Smile

Code:

#include <16F873.H>
#use delay(clock=6000000,RESTART_WDT)
void main(void) {
while(1){
output_high(PIN_B0);
delay_ms(200);
output_low(pin_B0);
delay_ms(200);

}// end while

}// end main





edit: beat me to it :P
Woody



Joined: 11 Sep 2003
Posts: 83
Location: Warmenhuizen - NL

View user's profile Send private message

PostPosted: Tue May 04, 2004 3:03 pm     Reply with quote

Or, since the invention of the 'output_toggle' statement:


Code:

#include <16F873.h>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)

//===================================

main()
{

while(1)
  {
   output_toggle(PIN_B0);
   delay_ms(500);
  }

}


Paul
adrian



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

View user's profile Send private message

PostPosted: Wed May 05, 2004 5:58 am     Reply with quote

Woody wrote:
Or, since the invention of the 'output_toggle' statement:
Paul


Which version did that appear in?
Woody



Joined: 11 Sep 2003
Posts: 83
Location: Warmenhuizen - NL

View user's profile Send private message

PostPosted: Wed May 05, 2004 3:27 pm     Reply with quote

I am not sure. I renewed my license last week, downloaded 3.190, read the readme and there it was mentioned.

I do not have the versions between 3.152 and 3.190 so I cannot tell you when it appeared.

Paul
Guest








output_toggle
PostPosted: Sat Nov 13, 2004 12:18 pm     Reply with quote

output_toggle

I have the 3.206 version, and "output_toggle" compiles but the help didn't show me nothing about it.-
Excuse me for my english is very poor.-
I am from Argentina (Maradona).
Thanks!!!!
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Sat Nov 13, 2004 1:25 pm     Reply with quote

Output_Toggle() is documented in the new manual on the download page.
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