219Views27Replies

Author Options:

ghetto programming Answered

how do i program a avr micro processer with perl? and where will i get guides on how to do this?

Discussions

is there any difference between c and c# ?

Yep. C# is an object oriented language, similar to Java and sort of what C++ could have been...

You probably won't use either C++ or C#. The more complex and OO features will likely make the code too bloated for a microcontroller. And the C library for AVRGCC, avrlibc doesn't have a C++ equivalent (although there might be wrapper out there by now.)

But all these other languages (Java and PHP, too) are C based. So time spent learning C is well spent....

DO YOU MAN PHP BY PERL? BECAUSE PERL IS BASED ON SHELL SCRIPT

When I wrote 'based,' I was referring to language syntax, not the underpinnings of execution. PHP, Perl and C all share similar syntax, and it's based on 'C.'

Isn't writing programs your main concern?

All three languages share many of the same control structures (if, while, for, etc.), use bracketing {}, are function based ( as in: myfunction() ), and terminate statements with a semi-colon.

Both perl and PHP are interpreted scripting languages, and both run interactively in the shell. Perl and PHP code can also be stored in a script file, and executed by invoking the file name. Both are commonly embedded in HTML files, and operate as server-side scripting.

However, PHP and perl are very much abstracted compared to 'C.' One example is variable definition. While you can define certain variable types (scalars, arrays, etc.) they are often implied types, not explicit types.

It's simple to declare an array of 8 bytes in C:

uint8_t my_array[] = {85, 86, 89, 90, 101, 102, 105, 106;

or (using a general syntax for unsigned short (byte) integer)

unsigned short int my_array[] ={85, 86, 89, 90, 101, 102, 105, 106};

Declared as such, this array occupies exactly 8 bytes, and the memory can also be accessed directly using the variable name (very important for micro controllers.)

There's no way to do that in perl or PHP--variables are abstracted, and integers are automatic and 'general.' A PHP or perl integer might take 4 bytes, 8 bytes, 12 bytes (or whatever) to store, and the user is insulated from even knowing how they are stored.

So in perl (or PHP) an array of 8 bytes might occupy 64 bytes (and more, with overhead.) That's pretty bad, if you only have 256 or 512 bytes of RAM in the micro controller.

(oh, and there are C interpreters (interactive shell) available....even if 99.9% of C programmers compile.)

The forums won't display square brackets, so the C array declarations above aren't correct (and I dropped a curly bracket editing one, also.) But you get the gist....

Try shutting off caps lock... or take your finger off shift... PHP is based on C, Perl is based on shell...

Yes, C# is more streamlined and powerful and better equipped to be used inside of .NET

what about java?

ive been trying vb, and its not that bad the code is well together and not as ugly as c

Hehe. Them's fightin' words...;-)

Actually, if you're already familiar with perl, what's the biggie about C? They share the much the same syntax and control structures. You'll get use to explicitly declaring variables, etc. (actually, BASIC originally handled variables that way, too.)

For all it's power, C is one of the smallest (in defined terms) languages devised. The vast majority of the 'standard C' language is function based, and that functionality was moved to libraries (stdio, math, stdlib, string, etc.) There are very few 'key words' in C, unlike VB or scripting languages.

I know that's frustrating for programmers who are used to using verbose languages; for complex ADTs, string manipulation, etc. But that is exactly the strength of it for micro processors....it's very 'lean and mean.'

ive been trying c it isnt too bad but im doing general programing programing a micro processer in in c (i found a tut on it) is much differnt I need a good tut that teaches the basics first

okay im dont wanna do this but im learning c

Make sure you get a C book, though! There's just no replacing a good programming textbook.

C isn't too bad. It may take a little while longer than some other languages, but stick with it and it wont be too bad. Plus if you have any questions, I am sure people here can help.

C# is not overly hard (but then, I have a little programming background, so that may be an influence too).

what about ruby?

Perl is an interpreted language, so you can't use it with microcontrollers. ...what I'd give to use Python... *sigh*

Yeah, you can't. (Same interpreted thing) And yeah, that's a decent tutorial.

Zach, the 'interpreted thing' isn't an absolute rule:

-- AttoBasic Byte-Wide Basic for ATtiny2313

-- A least one of the commercial FORTH environments offers an interpreter option (this would be expected, as FORTH is more highly tied to the concept of interpreted code than most languages.)

-- Even the venerable BASIC Stamp (NOT an AVR) uses interpreted BASIC, so it's not terribly uncommon.

Are interpreted languages a good thing for micro controllers? For specific applications, they are useful. But in general use the compiled languages are preferable...

Thanks for correcting me!

0
user
gmoon

10 years ago

I'm not aware that perl is a programming language option for AVR micro controllers.

There are quite a few others, however--

AVR assembly (free)
BASIC (a few free variants for specific chips, but most/best are commercial)
C/C++ (great free compilerAVRGCC, some commercial compilers, too.)
Pascal (commercial)
FORTH (commercial)

The Arduino uses it's own custom language based on C, but it's higher level. Maybe you saw this article which describes a USB link to the Arduino with perl routines.

Of course you can communicate with any AVR via a perl-driven serial connection, if you have the right interface chips (like a MAX232.) But that's not programming, per se.

im not learning c\c++ , where can i get tuts for basic?

The BASCOM AVR compiler has examples and docs. Here's the online help section.

This is a commercial compiler, but the demo version allows up to 4K of code. That's actually a decent amount (although I'm comparing to C, don't know if the BASIC libraries are included in that 4K.)

C isn't too hard to learn...