Searching \ for '[PIC]: c test code' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/languages.htm?key=c
Search entire site for: 'c test code'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: c test code'
2003\02\24@175909 by Andre Abelian

picon face
Hi to all engineers,

I wrote simple led test code for microchip demo board2
it works but when I move main () function to top it generates
an error why?
Any help will appreciate. Hitech support said I didn't
Define port_init () function but I do not get it.


Andre





/* simple led right,left move C code for Hi-Tech compiler*/
#include <pic18.h>
#include "delay.c"
#define PORTBIT(adr, bit)       ((unsigned)(&adr)*8+(bit))
static bit      led1  @ PORTBIT(PORTB, 0);
static bit      led8  @ PORTBIT(PORTB, 7);

// led right,left test funtion
void ledrl(void){
int c;              // setup c for count
led1=1;              // make RB0 on
DelayBigMs(20);     // delay
for(c=7;c!=0;c--){  // setup counter to count 7 times
PORTB <<= 1 ;       // shift left since c!=0 it will exit when c==0
DelayBigMs(20);}     // delay
led8=1;
DelayBigMs(20);
for(c=7;c!=0;c--){
PORTB >>= 1;
DelayBigMs(20);}
}

// Port Init
void port_init(void){
   TRISB=0; // set portb output
        TRISA=1; // set portc all input
        PORTB=0; // make sure all leds off
        }

// main program
void main(void)
{
   port_init();        // setup port
   ledrl();       // call led funtion
}

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spam_OUTlistservTakeThisOuTspammitvma.mit.edu with SET PICList DIGEST in the body

2003\02\24@180941 by Ned Konz

flavicon
face
On Monday 24 February 2003 03:00 pm, Andre Abelian wrote:
> Hi to all engineers,
>
> I wrote simple led test code for microchip demo board2
> it works but when I move main () function to top it generates
> an error why?
> Any help will appreciate. Hitech support said I didn't
> Define port_init () function but I do not get it.

You should declare or define all functions that you're calling, before
you call them.

If you move main() to the beginning of the program (which is what I
believe you're trying to do), the compiler hasn't yet seen
port_init(), which you're calling from main().

You could do this:

void port_init(void); /* declare it */

void main(void)
{
   port_init();
   /* stuff */
}

void port_init(void) /* define it */
{
/* stuff */
}

--
Ned Konz
http://bike-nomad.com
GPG key ID: BEEA7EFE

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservKILLspamspam@spam@mitvma.mit.edu with SET PICList DIGEST in the body

2003\02\24@184304 by Andre Abelian

picon face
Ned,

Thanks for your info I just did that works fine so if I do
Not declare functions and I call main funtion from bottom
Of the code is that wrong?

Andre




{Original Message removed}

2003\02\24@185122 by Brent Brown

picon face
I think you have written the program correctly.

The reason it will not work when you put the function main() above
the other functions is because the compiler "reads" your program from
the top down. The compiler sees the call to functions port_init() and
ledrl() in function main() before they have been defined.

Adding a function prototype (for each function) at the top of your
program may be the solution. Perhaps someone else can explain it
better than me.

On 24 Feb 2003 at 15:00, Andre Abelian wrote:

{Quote hidden}

--
Brent Brown, Electronic Design Solutions
16 English Street, Hamilton, New Zealand
Ph/fax: +64 7 849 0069
Mobile/txt: 025 334 069
eMail:  .....brent.brownKILLspamspam.....clear.net.nz

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email EraseMElistservspam_OUTspamTakeThisOuTmitvma.mit.edu with SET PICList DIGEST in the body

2003\02\24@185642 by Dwayne Reid

flavicon
face
At 03:00 PM 2/24/03 -0800, Andre Abelian wrote:

>// Port Init
>void port_init(void){
>     TRISB=0; // set portb output
>          TRISA=1; // set portc all input
>          PORTB=0; // make sure all leds off
>          }

Not an answer to your question, but perhaps an observation: you have
written above: TRISA=1.  As far as I can tell, all that does is make pin
RA1 an input; the rest of the pins in port A are outputs.  Other words,
what you have written to TRISA is b'00000001'.

Or maybe I grok C even less than I thought.

dwayne

--
Dwayne Reid   <dwaynerspamspam_OUTplanet.eon.net>
Trinity Electronics Systems Ltd    Edmonton, AB, CANADA
(780) 489-3199 voice          (780) 487-6397 fax

Celebrating 19 years of Engineering Innovation (1984 - 2003)
 .-.   .-.   .-.   .-.   .-.   .-.   .-.   .-.   .-.   .-
    `-'   `-'   `-'   `-'   `-'   `-'   `-'   `-'   `-'
Do NOT send unsolicited commercial email to this email address.
This message neither grants consent to receive unsolicited
commercial email nor is intended to solicit commercial email.

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email @spam@listservKILLspamspammitvma.mit.edu with SET PICList DIGEST in the body

2003\02\24@190336 by Spehro Pefhany

picon face
At 04:52 PM 2/24/2003 -0700, you wrote:
>At 03:00 PM 2/24/03 -0800, Andre Abelian wrote:
>
>>// Port Init
>>void port_init(void){
>>     TRISB=0; // set portb output
>>          TRISA=1; // set portc all input
>>          PORTB=0; // make sure all leds off
>>          }
>
>Not an answer to your question, but perhaps an observation: you have
>written above: TRISA=1.  As far as I can tell, all that does is make pin
>RA1 an input; the rest of the pins in port A are outputs.  Other words,
>what you have written to TRISA is b'00000001'.
>
>Or maybe I grok C even less than I thought.

No, you are correct. It should be something like this (using C99 comments)

TRISA = 0xFF; // set port A all inputs

The comment is misleading as well, obviously.

Best regards,

Spehro Pefhany --"it's the network..."            "The Journey is the reward"
KILLspamspeffKILLspamspaminterlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email RemoveMElistservTakeThisOuTspammitvma.mit.edu with SET PICList DIGEST in the body

2003\02\24@192133 by Andre Abelian

picon face
Dwayne,

Yes you are right but portA is not used in this example.


Andre

-----Original Message-----

At 03:00 PM 2/24/03 -0800, Andre Abelian wrote:

>// Port Init
>void port_init(void){
>     TRISB=0; // set portb output
>          TRISA=1; // set portc all input
>          PORTB=0; // make sure all leds off
>          }

Not an answer to your question, but perhaps an observation: you have
written above: TRISA=1.  As far as I can tell, all that does is make pin
RA1 an input; the rest of the pins in port A are outputs.  Other words,
what you have written to TRISA is b'00000001'.

Or maybe I grok C even less than I thought.

dwayne

--
Dwayne Reid   <spamBeGonedwaynerspamBeGonespamplanet.eon.net>
Trinity Electronics Systems Ltd    Edmonton, AB, CANADA
(780) 489-3199 voice          (780) 487-6397 fax

Celebrating 19 years of Engineering Innovation (1984 - 2003)
 .-.   .-.   .-.   .-.   .-.   .-.   .-.   .-.   .-.   .-
    `-'   `-'   `-'   `-'   `-'   `-'   `-'   `-'   `-'
Do NOT send unsolicited commercial email to this email address.
This message neither grants consent to receive unsolicited
commercial email nor is intended to solicit commercial email.

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email TakeThisOuTlistservEraseMEspamspam_OUTmitvma.mit.edu with SET PICList DIGEST in the body

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email RemoveMElistservspamTakeThisOuTmitvma.mit.edu with SET PICList DIGEST in the body

2003\02\24@192141 by Eric Bohlman

picon face
2/24/03 5:45:21 PM, Andre Abelian <engelecEraseMEspam.....EARTHLINK.NET> wrote:

>Thanks for your info I just did that works fine so if I do
>Not declare functions and I call main funtion from bottom
>Of the code is that wrong?

It's not *wrong* per se; it's simply a matter of style.  When reading a program, I personally prefer
to see the main code first, then the functions it calls, then the functions they call, and so on,
but others prefer it the other way.  If you're the only one working on your code, then the best
style is whichever one you find makes it the most readable and understandable when you go back to it
in six months to make a change.  If others are going to work on it as well, take their opinions into
account.

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email EraseMElistservspammitvma.mit.edu with SET PICList DIGEST in the body

More... (looser matching)
- Last day of these posts
- In 2003 , 2004 only
- Today
- New search...