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

My exercise B under the USB Master Exerise Book not working.

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



Joined: 28 Aug 2011
Posts: 5
Location: Vail Arizona USA

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

My exercise B under the USB Master Exerise Book not working.
PostPosted: Wed Nov 06, 2013 2:59 pm     Reply with quote

Confused

Dear programmers.
I am trying to get the exercise B under the "USB Master Exercise Book" to function. Under the FURTHER STUDY section of the book to write a MACRO called "delay_seconds".

I am a novice C programmer just starting out.

It should turn on the Green LED D5 for five seconds then turn it off for five seconds then turn on the Yellow D1 LED for one second then turn it off for one second then finally turn the RED LED D0 on for five seconds then turn it off for five seconds then this program repeats this sequence. Please see my code below. I have attempted this exercise using an example code clip from a CCS compiler help topic. This work is done on the CCS Company PIC18F67J10 trainer PCB. My IDE version is 5.013 .

This is my first request for help under the CCS Forum Index -> General CCS C Discussion.

Thank you for your help.

Mark A Carter, KD7PHW, [email protected].
_____________________________________________________________
Code:


#include <18F67J10.h>
#device ICD=TRUE
#fuses HS,NOWDT
#use delay (clock=10000000)

#define GREEN_LED PIN_D5
#define YELLOW_LED PIN_D1
#define RED_LED PIN_D0

void delay_seconds(int n) {
      for (;n!=0;n--) {
      delay_ms (1000);
      }
}
 
  #define delay_seconds(n)

void main () {
      while (TRUE)   {
            output_low (GREEN_LED);
            delay_seconds (5);
            output_high (GREEN_LED);
            delay_seconds (5);
            output_low (YELLOW_LED);
            delay_seconds (1);
            output_high (YELLOW_LED);
            delay_seconds (1);
            output_low (RED_LED);
            delay_seconds (5);
            output_high (RED_LED);
            delay_seconds (5);           
      }
}


ANY
_________________
Mark A Carter

KD7PHW
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Nov 06, 2013 3:30 pm     Reply with quote

Quote:
void delay_seconds(int n) {
for (;n!=0;n--) {
delay_ms (1000);
}
}

#define delay_seconds(n)

void main () {
while (TRUE) {
output_low (GREEN_LED);

The reason it doesn't work is because you have defined your delay routine
out of existence. First you have the function. That's good. But then you
follow it with an empty macro declaration. Why ? The net effect is that
the compiler substitutes the empty macro for your delay function and
you can see this in the .LST file:
Code:

....................       while (TRUE)   { 
....................             output_low (GREEN_LED); 
00012:  BCF    TRISD.5
00014:  BCF    LATD.5
....................             delay_seconds (5); 
....................             output_high (GREEN_LED); 
00016:  BCF    TRISD.5
00018:  BSF    LATD.5
....................             delay_seconds (5); 
....................             output_low (YELLOW_LED); 
0001A:  BCF    TRISD.1
0001C:  BCF    LATD.1
....................             delay_seconds (1); 
....................             output_high (YELLOW_LED); 
0001E:  BCF    TRISD.1
00020:  BSF    LATD.1
....................             delay_seconds (1); 
....................             output_low (RED_LED); 
00022:  BCF    TRISD.0
00024:  BCF    LATD.0
....................             delay_seconds (5); 
....................             output_high (RED_LED); 
00026:  BCF    TRISD.0
00028:  BSF    LATD.0
....................             delay_seconds (5);             
0002A:  BRA    0012
....................       } 
.................... } 
.................... 
0002C:  BRA    002C
.................... 
.................... 

There's no delay routine. There's nothing. The only thing left is your
code to toggle the LEDs.

Comment the following line out as shown below, re-compile and see
what happens:
Code:
//  #define delay_seconds(n)
Mark A Carter



Joined: 28 Aug 2011
Posts: 5
Location: Vail Arizona USA

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

My exercise B under the USB Master Exerise Book not working.
PostPosted: Wed Nov 06, 2013 4:12 pm     Reply with quote

Very Happy

Dear Mr. PCM programmer.
The commenting out of that line did fix the problem.
The three LEDs not sequence correctly.

I do have one addition question through.
How do I make my void delay_seconds(int n) {
for (;n!=0;n--) {
delay_ms (1000);
}
}

code section into a FUNCTION as per the books exercise part B request?

Thank you.

Mark A Carter, [email protected] .
_________________
Mark A Carter

KD7PHW
Mark A Carter



Joined: 28 Aug 2011
Posts: 5
Location: Vail Arizona USA

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

My exercise B under the USB Master Exerise Book now working!
PostPosted: Wed Nov 06, 2013 4:37 pm     Reply with quote

Very Happy

Dear Mr. PCM programmer

Thank you for your help.
It now works.
I also have gotten the #DEFINE function to work in the CCS book exercise.

Please see my corrected functioning code below.
Code:

#device ICD=TRUE
#fuses HS,NOWDT
#use delay (clock=10000000)

#define GREEN_LED PIN_D5
#define YELLOW_LED PIN_D1
#define RED_LED PIN_D0
#define delay_in_seconds delay_seconds

void delay_seconds(int n) {
      for (;n!=0;n--) {
      delay_ms (1000);
      }
}
 
void main () {
      while (TRUE)   {
            output_low (GREEN_LED);
            delay_in_seconds (5);
            output_high (GREEN_LED);
            delay_in_seconds (5);
            output_low (YELLOW_LED);
            delay_in_seconds (1);
            output_high (YELLOW_LED);
            delay_in_seconds (1);
            output_low (RED_LED);
            delay_in_seconds (5);
            output_high (RED_LED);
            delay_in_seconds (5);           
      }
}

_________________
Mark A Carter

KD7PHW
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