View previous topic :: View next topic |
Author |
Message |
Atma
Joined: 08 Aug 2005 Posts: 22
|
LED flashing problem |
Posted: Wed Oct 19, 2005 6:27 am |
|
|
Hi there
I am new to using the CCS compiler. I was trying to flash an LED just as a test program but the LED doesnt flash. My code is as below:
Code: |
#include "C:\Documents and Settings\Atmadarshini dd\My Documents\trial.h"
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#int_RDA
#define MCLR PIN_B1
#define DATA_OUT PIN_B2
#define DATA_IN PIN_B4
#define CLOCK PIN_B5
RDA_isr() {
}
void main() {
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_CLOCK_DIV_2);
setup_spi(FALSE);
setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
enable_interrupts(INT_RDA);
enable_interrupts(global);
for(;;)
{
output_low(CLOCK);
delay_ms(200);
output_high(CLOCK);
delay_ms(200);
}
}
|
could someone tell me what i am doing wrong asap.
Thanks |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
Re: LED flashing problem |
Posted: Wed Oct 19, 2005 7:44 am |
|
|
Atma wrote: | #include "C:\Documents and Settings\Atmadarshini dd\My Documents\trial.h"
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#int_RDA
#define MCLR PIN_B1
#define DATA_OUT PIN_B2
#define DATA_IN PIN_B4
#define CLOCK PIN_B5
// I'm going to comment this out, as you should
//RDA_isr() { // NEVER leave an empty interrupt handler!!!!
//}
void main() {
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_CLOCK_DIV_2);
setup_spi(FALSE);
setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
// since you're not using the RDA interrupt, DON'T enable it unless you
// have a proper handler for it!!!
//enable_interrupts(INT_RDA);
//enable_interrupts(global);
//for(;;) I'm going to replace this for loop with something more "standard"
while (TRUE)
{
output_low(CLOCK);
delay_ms(200);
output_high(CLOCK);
delay_ms(200);
}
}
[/code]
|
Try it with the changes above. |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1635 Location: Perth, Australia
|
|
Posted: Wed Oct 19, 2005 7:56 am |
|
|
You forgot to add Code: | #use delay(clock=....) |
_________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Wed Oct 19, 2005 8:14 am |
|
|
Code: |
#include <16F877.h> // Change according with your uC
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000) // change according with the Xtal you are using
void main()
{
while(1)
{
output_toggle(PIN_B5);
delay_ms(200);
}
}
|
Humberto
Last edited by Humberto on Wed Oct 19, 2005 10:12 am; edited 1 time in total |
|
|
Atma
Joined: 08 Aug 2005 Posts: 22
|
Re: LED flashing problem |
Posted: Wed Oct 19, 2005 8:17 am |
|
|
newguy wrote: | Atma wrote: | #include "C:\Documents and Settings\Atmadarshini dd\My Documents\trial.h"
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#int_RDA
#define MCLR PIN_B1
#define DATA_OUT PIN_B2
#define DATA_IN PIN_B4
#define CLOCK PIN_B5
// I'm going to comment this out, as you should
//RDA_isr() { // NEVER leave an empty interrupt handler!!!!
//}
Hi i tried it...It didnt work
I have a 1K resistor that is connected to pin RB5 and the resistor goes to LED and the LED is connected to 5V(the postive side of the LED).
The same circuit works when use the cc5x compiler.
void main() {
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_CLOCK_DIV_2);
setup_spi(FALSE);
setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
// since you're not using the RDA interrupt, DON'T enable it unless you
// have a proper handler for it!!!
//enable_interrupts(INT_RDA);
//enable_interrupts(global);
//for(;;) I'm going to replace this for loop with something more "standard"
while (TRUE)
{
output_low(CLOCK);
delay_ms(200);
output_high(CLOCK);
delay_ms(200);
}
}
[/code]
|
Try it with the changes above. |
|
|
|
Atma
Joined: 08 Aug 2005 Posts: 22
|
|
Posted: Wed Oct 19, 2005 8:19 am |
|
|
asmallri wrote: | You forgot to add Code: | #use delay(clock=....) |
|
hi this is added in the .h file. so i presume that it gets added to the project. |
|
|
Atma
Joined: 08 Aug 2005 Posts: 22
|
|
Posted: Wed Oct 19, 2005 8:22 am |
|
|
Humberto wrote: | Code: |
#include <16F877.h> // Change according with your uC
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000) // change according with the Xtal you are using
void main()
{
while(1)
{
output_toggle(PIN_B5);
delay_ms(500);
}
}
|
Humberto |
hi
it says undefined output_toggle when i se your code above |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Wed Oct 19, 2005 8:37 am |
|
|
Quote: |
it says undefined output_toggle when i se your code above
|
Output_toggle can be replaced by:
Code: |
while(1)
{
output_high(CLOCK);
delay_ms(200);
output_low(CLOCK);
delay_ms(200);
}
|
You would know that in your inquire you must include:
1) Compiler version. (3.xxx format)
2) Full header.
3) Short and concise hardware description.
Keep well,
Humberto |
|
|
|