go_away

Author Topic: Variables in Programming  (Read 1247 times)

0 Members and 1 Guest are viewing this topic.

Offline OrrinTopic starter

  • Jr. Member
  • **
  • Posts: 10
  • Helpful? 0
Variables in Programming
« on: September 20, 2008, 10:10:40 PM »
I want to start building my first robot. I think I'm going to make something similar to Stampy. I need some help though.

sensor_left=a2dConvert8bit(5);
sensor_right=a2dConvert8bit(4);

LED_on(); and LED_off();
Turns on and off your LED. The LED is on port D4.
By bringing port D4 low, you are turning on the LED.

a2dInit(); // initialize analog to digital converter (ADC)
a2dSetPrescaler(ADC_PRESCALE_DIV32); // configure ADC scaling
a2dSetReference(ADC_REFERENCE_AVCC);

I understand the rest of the code, I just wonder if these commands are universal or not, and where I can find a list.

If I buy a different microcontroller, will it tell me what these commands will be called in the manual? I've checked a couple manuals online and I can't seem to find a listing of these and what commands I can use. I don't want to be dependent on someone else's program, I'd rather write my own and buy any microcontroller without worrying about compatibility.

I can't seem to find the words this late at night, so I'm sorry if this is confusing. I have programmed other things before, and I understand the logic and concept, I just don't get where these commands are listed (I assume they are specific to their controller? Assuming is never good which is why I've come here.  :-\).

Any help would be appreciated.  ;D
Orrin

P.S.: Great Website!

Offline Ro-Bot-X

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,431
  • Helpful? 25
  • Store: RoBotXDesigns.ca
Re: Variables in Programming
« Reply #1 on: September 21, 2008, 07:25:32 AM »
Wellcome to the forum!

To answer your questions, all these word followed by parenthesis are functions defined in one of the function library files (header files) that you include at the beginning of your program. They are made to ease up your life (programming...) so you don't have to mess up with the registers directly. Every microcontroller has some specific and some common registers, so some of the functions work with any micro, some of them have to be "tweaked" to access the proper register. You have to see what registers the functions access, read the datasheet for the microcontroller you want to use and compare it with the one the functions were written for. The simple functions like LED_on() will work with any micro, other functions like PWM controll will be different.

Practically, all languages (be it C or Basic) access the same registers of the microcontroller to do a specific function, but the commands (functions) may be differently implemented.
Check out the uBotino robot controller!

Offline OrrinTopic starter

  • Jr. Member
  • **
  • Posts: 10
  • Helpful? 0
Re: Variables in Programming
« Reply #2 on: September 21, 2008, 07:40:20 PM »
Thank you very much for your quick response!  ;D
I am probably going to buy the parts for my robot within the next week or so, and I feel more confident now. I know C++ and C so it shouldn't be too hard to figure things out. Besides, if I get it wrong I can always come here!

Hoping to post some pics/videos of the only robot in my school! (It's South Dakota, what do you expect?)  :o

Thanks again,
Orrin

 


Get Your Ad Here

data_list