Init on C??

Thread Starter

Rk17

Joined Apr 23, 2011
43
ive got this code right here. Im just starting wioth c programing but i dont find
Rich (BB code):
init
command in the command list of C. Im using dev C++, and i cant quite understand the meaning of init in this program. What's the function of it. and also
Rich (BB code):
TRISB = 0b00000000
what does this stands for?

Rich (BB code):
#include <htc.h>
__CONFIG(FOSC_XT & WDTE_OFF & PWRTE_OFF & BOREN_OFF & LVP_OFF & WRT_OFF);
void init(void)
{
// port directions: 1=input, 0=output
TRISB = 0b00000000;
}
char counter;
void main(void)
{
counter = 0;
init();
while (1){
PORTB = counter;
_delay(10000);
counter++;
}
}
i slightly understand the other commands aside from those two. tnx for any reply. More power allaboutcircuits!.
 

DumboFixer

Joined Feb 10, 2009
217
As used here init (actually init() ) is a function call. Have a look at 9 lines above the init() in your code and you'll see
Rich (BB code):
void init(void)
which is the start of the definition of the function.

In this instance the call to init() does this:

Rich (BB code):
TRISB=0b00000000;
All this does is set all the Port B pins to be outputs - as the comment above the line describes.

More info on this can be found in the datasheet for the chip you are using.
 

t06afre

Joined May 11, 2009
5,934
Im using dev C++, and i cant quite understand the meaning of init in this program.
That program you refer to is written for HI-Tech C for PIC MCUs. And will only work for the latter compiler. But the C++ reference does really confuse me. Are we still talking PIC MCUs, and HI-Tech C here :confused:
 

Thread Starter

Rk17

Joined Apr 23, 2011
43
@Dumbofixer>> tnx for the reply dumbofixer.. so what is the difference between

Rich (BB code):
void init (void) and void main (void)
do they have the same function w/c is as you said earlier to start the definition of the function?

and regarding
Rich (BB code):
TRISB=0b00000000;
so the 0 means outputs? how bout the
Rich (BB code):
small letter "b"
what does it mean? do the zeros in the code indicate the pins on the ic? im still really confused.

@to6afre im using the devc++ software but im still learning the basics of c. I just want to understand the simple program that i posted and relate it to what im learning right now thats why im asking questions about it :)
 

DumboFixer

Joined Feb 10, 2009
217
@Dumbofixer>> tnx for the reply dumbofixer.. so what is the difference between

Rich (BB code):
void init (void) and void main (void)
do they have the same function w/c is as you said earlier to start the definition of the function?

and regarding
Rich (BB code):
TRISB=0b00000000;
so the 0 means outputs? how bout the
Rich (BB code):
small letter "b"
what does it mean? do the zeros in the code indicate the pins on the ic? im still really confused.

@to6afre im using the devc++ software but im still learning the basics of c. I just want to understand the simple program that i posted and relate it to what im learning right now thats why im asking questions about it :)
To answer the first bit, main is the part of the code executed when the program first starts. From there program execution and flow is up to you.

The '0' indicates that that particular bit in the pport is designated an output, a '1' would designate it an input so you code have a mixture of inputs and outputs on the same port which are pins on the chip itself.

The "b" signifies that the following number is a binary number, an"x" would signify hex and "o" would be octal. This is used to simplify setting up the bits as a number like "00110011" is easier to see which bits are inputs etc than using 51.
 

Thread Starter

Rk17

Joined Apr 23, 2011
43
so if zeros mean outputs, and there are 10 zeros in trisb? that does mean that their are 10 pins being used? tnx dumbofixer..
 

t06afre

Joined May 11, 2009
5,934
You have to learn to crawl before you can walk, and walk before you can run. From your postings I have a feeling that you are still on the crawl level then it comes to PICs. So my advice to you is allow yourself to have a learning curve. Start simple and then you are confident take a step up. Trying to learn all at once will only confuse you. Then it comes to microcontrollers it is also important that you at least have some basic idea about the inner workings. Also knowledge about the binary and hexadecimal number systems are important. All this are topics you must learn by your self. We may give you push in the correct direction. But we will not be able tutor every detail. Hope you understand
 

Thread Starter

Rk17

Joined Apr 23, 2011
43
:) yeah i understand to6afre,, maybe im just getting too excited bout this stuff, ive already learned basic c programming in school but that was 2 years ago. I was not that interested at that time not knowing that it was this important in my higher years. Anyway thanks for the help ill continue learning the basics first and ask some questions about things i dont understand much...
 
Top