Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Can we Program PIC Microcontroller in Microsoft Visual C??

Status
Not open for further replies.

Ayne

New Member
Q No:1- Which is the better Visual C# OR Visual C++ and why????

Q No:2- Can we program PIC Microcontrollers in Visual C# OR Visual C++, if yes then how, if not than why not???

Q No:3- What we need to program PIC in Visual C# OR Visual C++???
 
your first question doesn't make any sense, it's like asking "which is better, english or french?" (or any other language) It's a matter of personal preference and everyone is entitled to their opinion.

No, you cannot program a PIC in VC++ or VC#. That also doesn't even make any sense, both are written for 32-bit and 64-bit computer systems, it's crazy to think they would work on a PIC.

It is possible to program PICs in plain old C, there are a lot of compilers for that. There are one or two compilers around somewhere for C++, however they never got very popular, probably because many of the features of C++ are way too complicated to be used (or needed) on an 8-bit microcontroller.

Once again, you really need to consider what kind of extremely simple hardware you're programming for. The kind of stuff that is fine on a PC is incredibly inefficient on a PIC - 32-bit values, floating-point math, etc. There's nothing stopping you from doing some amazing stuff with these 8-bit microcontrollers, you just have to be creative in your programming.
 
Last edited:
Infact I am planing to learn one of those languages but i don't know which is best for me. Infact my object is make graphs in computer and other programs that control my Embedded system from PC.
 
Wait, are you talking about programming the PIC, or writing a PC program to interface with the PIC?

If you're talking about writing a PC program to interface with the PIC, then it's another story entirely. Either VC++ or VC# can do it quite well, as can Visual BASIC if you like that language. If you're using the .NET 2.0 framework with any of those languages, interfacing with the serial port (which is the simplest way to interface with a microcontroller from a PC) is quite easy. The first time I played with the System.IO.Ports.SerialPort object in C#, I was able to put together a simple 2-way communication serial terminal program as a demo within an hour or so.
 
Last edited:
I want to write PC programs, like u said interfacing with the serial port and making graphs and other programs.
I have read many stories that C++ is more powerfull than C#. What is ur view?
I think i will go with C++ what u say??
 
Ayne said:
I want to write PC programs, like u said interfacing with the serial port and making graphs and other programs.
I have read many stories that C++ is more powerfull than C#. What is ur view?
I think i will go with C++ what u say??

Either are equally powerful really, it's down to what you do with them - I would expect C# to be more resource hungry and run slower?.
 
Pretty much, Nigel. C++ pretty much invariably makes much faster programs, but it's also a lot more complicated to write programs in general, ESPECIALLY if you want to create applications with a GUI, as opposed to a command-line-only application.

C# is a completely object-oriented language, which is generally a very intuitive programming model, and it's generally a lot easier to write programs with it. It's also a very managed language; it makes you be clearer about what you are trying to do so you don't leave as many ambiguities and make as many stupid mistakes. With visual studio, or some of the other IDE's out there, creating a GUI application is as easy as dragging and dropping some objects (serial port, buttons, text boxes, etc) onto a form, and then writing some code to tie them together. As I said, a basic app using serial communication can be thrown together very easily, in very little time. Visual BASIC is very similar to C#, everything is structured about the same way, it just comes down to your preference of C vs BASIC.

It really comes down to what you're looking for. If you want raw speed, try C++ (or even C). Just be prepared to learn a lot - even something like opening a single, empty window in VC++ can take several dozen lines of code. If you don't want to spend a ton of time programming, something like C# or VB might be a better choice. Personally, I prefer to spend less time programming my PC software and more time working on the hardware and firmware of the PIC system, even if it means my application runs a little slower.

But just for the sake of comparison, I wrote a USB bootloader app in C#, and it takes on the order of 4 or 5 seconds to do a complete read of an 18F4550. The Microchip demo application, which is written in C++, takes about the same amount of time, maybe a second faster, but not much more. To me, the additional time that it would have taken for me to write such an application in C++ would not be worth the savings of a second or so every time it's used. If you were in an industrial setting and needed to perform this action tens of thousands of times a day, as fast as possible, then this speed difference would probably matter to you a whole lot more.

I think probably the best thing you can do is to just go search around the web and look for some example code. I'd recommend https://www.codeproject.com/ . Look at some demo applications in C++ and in C# and compare the code, and see which one you think you'd prefer.
 
Last edited:
Because you do not know C, C++, or C# I suggest you use C#. They all will work, but I think you will get apps working faster with C#. It can be easier to make things happen in C#, it does more for you, hides more details. It will use more CPU time, but a modern PC has more then enough power to handle it.

I think you will find that visual studio is a good environment to learn and program in. A bonus is that you can find C# examples that explain most of the problems you will run into on the net.

Regardless of which VS language you use you will be working with the .Net framework. The .NET 2.0 has easy to use serial port support. You drag the serialport from the toolbox to you forms design, set the baud rate etc in the properties window, and write a data recieved callback (function called on data recieved) and you are ready to go.

3v0
 
C# and C++ are both powerful in there own class. if you want to know under the hood working of system, and tweak it (forget asm ) then VC++ is the choice , and it is the native language of windows . if you just need to put a program as fast as possible with little headache , then VC# is the language to choose.
 
Between those two, I say go with C++. There are C / C++ compilers for just about every chip / OS ever made, and many of them are free. C# only has one compiler, which only writes binaries for Windows.

If you want something in a simple / high-level scripting language, I'd look into Python and Java. They're both extremely popular, and are well-supported on a lot of architectures.
 
i_build_stuff said:
Between those two, I say go with C++. There are C / C++ compilers for just about every chip / OS ever made, and many of them are free. C# only has one compiler, which only writes binaries for Windows.

If you want something in a simple / high-level scripting language, I'd look into Python and Java. They're both extremely popular, and are well-supported on a lot of architectures.

From https://www.mono-project.com/Main_Page
What is Mono?

Mono provides the necessary software to develop and run .NET client and server applications on Linux, Solaris, Mac OS X, Windows, and Unix. Sponsored by Novell (https://www.novell.com, the Mono open

3v0
 
Last edited by a moderator:
Ayne:
I understand you are new to microcontrollers but please do not plaint seeds that directly or indirectly envolve M$ with this discipline. One, such a union does not fix anything since nothing is broken. Two, such a union could only lead to the hindering of the other. Three, such a union creates complication, increased resource, and monitary, volumetric, and temporal dependencies. In other words it puts more to get out the same which inarguably means to get less. Those who have intiment knowledge of the two know why one has continually advance and the other remains relatively static.

Lets not forge microcontrolling coding from a state of being potentially to that of a guaranteed slow, ambiguous, redundant, excessive, inefficient, bloated, and monopolized. If I can save you one of them its all be worth it.
 
of course u can't...
choose the MIKROC compiler..u could also found a lot of helping files there
 
Actually, Visual Studio allows you to create a Makefile project, which allows you to then compile your application using a third-party compiler. In your case you could use PIC-C, or any other Pic command line compiler. Need to know all the command line options and setup the makefile, but it can be done. That gives you the benefits of the VS IDE and the ability to cross compile for a non Intel x86 architecture (like PIC).
 
On the PC side use "processing" They have software that makes this really easy. Processing is a odd variant of Java but easier to get into. You can extend it with full fledged Java if you want. Java is in a way the next step after C++ and is very close to C#. C# is Java after MS stole as much of Java as it could. C# runs with anything MS. Java runs anywhere ( begin flame war )

Processing is also the laguage of the PC side of the Arduino ( not the only one however ) On the uC side the Arduino uses sort of C and C++.
 
On the PC side use "processing" They have software that makes this really easy. Processing is a odd variant of Java but easier to get into. You can extend it with full fledged Java if you want. Java is in a way the next step after C++ and is very close to C#. C# is Java after MS stole as much of Java as it could. C# runs with anything MS. Java runs anywhere ( begin flame war ).
No flames but some corrections. As I understand it C# was written by Borland people hired by MS. It borrows "good stuff" from more then Java.

Mono is the open source version of C# and .NET. When I played with C# and mono a while back you could even debug an app running on a linux box from a debugger running on XP.

They have been doing some work to make the transition less painful.
The Mono Migration Analyzer (MoMA) tool helps you identify issues you may have when porting your .Net application to Mono. It helps pinpoint platform specific calls (P/Invoke) and areas that are not yet supported by the Mono project.
Do not sell it short.

3v0
 
I really avoid joining in on this type of discussions but this time I'd do it ...

Ayne, with regards for "better", tools are made for a specific job, and comparing two different tool pieces without telling "for what you wanna use them" is as evandude said comparing english and german (or to be more true, english and chineese as those are used by ~ same amount of ppl).

Anyhow, the actual answer to your question is - LEAR HOW TO PROGRAMM. it is really unimportant what language you choose. There is number of programming models like linear (assembler), procedural (pascal, c), object (c++, c#)... and many others. If you are planning to do desktop app's - object oriented model is what you need. If you are going to use C++ or C# or any other OO language - it is completely unimportant as when you learn the model, and when you learn to think like software developer, the syntax is the only difference between all the choices given to you, and syntax is something one learns in 2-3 days, so it is really not the time consuming part of "learning how to be software developer".

If you are windoze centric person, .NOT is the best starting point as there is number of ".not for morons" guides available on the internet (do not get offended by the "morons" word, I too read "moron handbook" when I learn new stuff - those are usually best books around)... of course of all .not syntaxes the C# is imho best but that's just because I like that syntax better then some other .not syntaxes (like vb for example), not because c# will do anything better/faster then any other .not compiler.

If you are not glued to windoze then some more open approach for the starting point is better so c++ or java would be my suggestion, with more points to java as there is more "java for morons" resources available for free then "c++ for morons".

I hope you understand the difference between native code and interpretted code / virtual machine code. The C++ will for example make native code for you system giving the maximum performance and wider possibilities (more direct control of the hw for example) and on the other hand c# or java will create virtual code that will be run in virtual machine. This is much slower, uses more resources and does not allow direct control over the hw, but offer some nice tools for "lousy programmers" like garbage collectors, system protection etc. The lack of hardware control is solved by special interfaces that allow you to run piece of code written in c/c++ so you can access serial port or usb port from c# or java.

All in all, choose "any" object oriented programming language and when you understand the OO model and logic behind it, switching to another language will be really a piece of cake. I use actively over 20 languages and used this way or another 40-50 other ones... and that's not counting different versions of single language (C++ is C++ disregarding if it is gcc or vc or bc or ...)

3v0, .not is fully designed and implemented by microsnot and microsnot's dev team, the concept, the run time engine / virtual machine ... The reference to Borland is because person who designed / invented Delphi is the person who was hired by microsnot to design C#. So only C# syntax/gui/compiler is designed by the Anders Hejlsberg, not the .not concept.

Mono is .not virtual machine for unix. You can run (most of) .not application compiled on widows with any widows compiler (vb, c#, java.net, delphi.net ...)... mono comes with c# compiler too iirc but .....

p.s. I apologize widows fan's for .not == .net and microsnot == m$ == microsoft .. but I'm really not widnoze person
 
Ok, so I know this is an old topic, but I am working on some graduate work and one thing I am researching is using high level languages like C# and Java to write code for the PIC. So let me start with some corrections. C# is not .Net. That is like saying Java is a Java Virtual Machine (JVM). .Net is a set of libraries what IL uses. C#, like C++, and Java are languages. If you compiler compiles them to an intermediate language for interpretation, or it compiles to machine code, it still has nothing to do with the language.
Why does C work better than C++ or some other modern language? My guess is that C is so primitive the standard really does not allow for anything better than 8 bits, thus no modifications or restrictions need to be made on the language to write programs. An example would be in C I need a char array to make up a string… because a char is 8 bit… in C++ a string is just supported, even though in the background we all know it is still a char array. In more modern languages a string or String is not a char array, but can be turned into one.
Another important point is that C# does not only have one compiler. C# is an ISO certified language, and anyone can write a compiler for it… not just Microsoft. Borland has a C# compiler… so does MS obviously.
Much of the above goes for Java as well. Is C# better than Java is better than C++ is better than C? Nope, it’s all about filling the business objective. Anyone that says “I use Java, not C# because Java can be run anywhere” clearly is foolish. Application architecture is done independent of the language and hardware. Once you know what it is you need to accomplish, you find the best fit for hardware, OS, language, etc.
So now first my interest in this thread… the question was first misinterpreted as “Can I use C# or C++ to write a program which executes natively on a PIC microcontroller?” And my thinking is, why not? Because C# and Java are so popular these days as they are much faster to produce business applications, why should that popularity not be leveraged to create a compiler that can create PIC binaries? It is true that C# and Java both have mega overhead, if you use all of the fancy framework features… but this would not implement the JDK or the .Net runtimes, it would just use the CLR… which is what is being done with C. If so many companies can come out with “BASIC” for PIC, surly we can do better and use Java and C#.
How would this help the world? I think in several ways. First you could quickly serialize object natively between a PIC and a Computer running a major OS like Windows or Linux. This could make PIC interfaces more of a SOA interface than an old Serial connection that you have to parse. Second many people already know and use C# and Java because… lets face it… that’s the “in” thing right now. If everyone in 1000 miles of me was driving a Honda or a Ford, I would be really stupid to buy a Toyota… not because Toyota is bad, but because the full community support and adaptation is poor.
Just my thinking, I am not married to this idea, but I would love for you to poke holes in it to help my research… better you ‘all than the thesis board. I can see some obvious problems with it, but no show stoppers. I bet if someone put out a compiler for just one of those languages it would sell like hot cakes.

carzydart
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top