View previous topic :: View next topic |
Author |
Message |
caffca
Joined: 28 Apr 2004 Posts: 5
|
Very simple LED program for PIC16F873 |
Posted: Tue May 04, 2004 2:25 pm |
|
|
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 /*
}
}
} |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue May 04, 2004 2:39 pm |
|
|
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);
}
} |
|
|
![](templates/subSilver/images/spacer.gif) |
Kasper
Joined: 14 Jan 2004 Posts: 88 Location: Aurora, Ontario, Canada
|
|
Posted: Tue May 04, 2004 2:42 pm |
|
|
try this
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 |
|
![](templates/subSilver/images/spacer.gif) |
Woody
Joined: 11 Sep 2003 Posts: 76 Location: Warmenhuizen - NL
|
|
Posted: Tue May 04, 2004 3:03 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
adrian
Joined: 08 Sep 2003 Posts: 92 Location: Glasgow, UK
|
|
Posted: Wed May 05, 2004 5:58 am |
|
|
Woody wrote: | Or, since the invention of the 'output_toggle' statement:
Paul |
Which version did that appear in? |
|
![](templates/subSilver/images/spacer.gif) |
Woody
Joined: 11 Sep 2003 Posts: 76 Location: Warmenhuizen - NL
|
|
Posted: Wed May 05, 2004 3:27 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
output_toggle |
Posted: Sat Nov 13, 2004 12:18 pm |
|
|
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!!!! |
|
![](templates/subSilver/images/spacer.gif) |
dyeatman
Joined: 06 Sep 2003 Posts: 1924 Location: Norman, OK
|
|
Posted: Sat Nov 13, 2004 1:25 pm |
|
|
Output_Toggle() is documented in the new manual on the download page. |
|
![](templates/subSilver/images/spacer.gif) |
|