Program Flow In Embedded C

Program Flow and control is a control method of your program. For example, Loop constructions control repeated execution of repeated program segments where control is taken by control parameter. In this article, we will go through if/else switch/case statements and loop sentences like while, do while, for. While statement As I mentioned, three looping sentences available in C language one of them is While sentence. Let’s take an example: While(guess!=i) invokes looping operation. This causes the statement to be executed repeatedly at the beginning the condition guess!=i is checked. As long the argument is TRUE, the while sentence will be continued continuously. When guess becomes equal to i while statement will be skipped. I am not going too deep into it as there are tons of information about basic C.

Continue reading

Why C instead ASM

ASM is a specific language, also referred as a low level programming language. It is a mnemonic to a machine code. It usually takes a long time to develop embedded programs in ASM language. Today even modern 8 bit microcontrollers are powerful and complex as they were a long time ago. The program memory of tiny chips reaches megabytes; they pack many peripherals and interfaces. Hardware code is becoming more complex; functionality grows up. This is one of the main reasons for using higher-level programming languages like C. By using C language you do not have to go into details how the processor works at the hardware level. You don’t have to think about hardware logic and how bytes are shifted between registers. It is better to leave to the compiler.

Continue reading

Example of enumeration c in microcontroller programming

Enumeration allows defining a user data types in C language. For this purpose, a #define pre-processor is used, which allows for describing a set of constants. They allow reading and understanding program code much easier as you may define human readable types. For instance, using pre-processor we can define a simple numbers to be as follows: Define is a powerful tool for doing many different definitions in pre-processing stage of source code, but in C language, there is an alternative way of defining a user data types –  enumerating using keyword enum: By default, enumeration assigns values from zero and up. You can use enumeration of new types as in following example: Also, you can use an enum  to assign special characters to meaningful words like this: enum escapes { BELL = ‘\a’, BACKSPACE = ‘\b’, HTAB = ‘\t’,RETURN = ‘\r’, NEWLINE = ‘\n’, VTAB = ‘\v’ };or enum boolean { FALSE = 0, TRUE }; An advantage of enum over #define is that it has scope, which means that the variable (just like any other) is only visible within the block it was declared. Example:

Continue reading

AVR GCC Structures

Structures in GCC are used in a variety of applications, such as: Basically, Structures are nothing more than collections of variables so, called members. Structures allow to reference of all members by a single name. Variables within a structure don’t have to be the same type. General structure declaration: or In the second example, we declared the variable name. Otherwise, variables can be declared this way: Members of the structure can be accessed by using the member operator (.). The member operator connects the member name to the structure. Let’s take an example: We can set the robot’s position by using following sentence: or simply Structures can be nested. A nested structure is a structure that contains another structure as one of its members. To access robot x coordinate, we have to write: Nested structures can be used in various applications, such as representing complex data types, like records or objects, and organizing data in a more readable and maintainable manner. They’re also helpful in systems programming, where you might need to represent hardware or software components as nested data structures. Actions can be taken with structures: Of course, you can treat a structure like a variable type. So you…

Continue reading

Accessing AVR microcontroller ports with AVR GCC

All AVR ports have Read-modify-write functionality when used for general I/O functionality. The direction of each separate port pin can be changed. Each pin buffer has the symmetric capability with the ability to drive and sink source. The pin driver is strong enough to drive LED directly, but it is not recommended to drive even small loads without using proper driver circuit such as transistors. All port pins have internal selectable pull-up resistors. And finally, all pins have protection diodes to both VCC and GND rails. Each port of AVR consists of three registers DDRx, PORTx, and PINx (where x means port letter). DDRx register selects the direction of port pins. If logic one is written to DDRx then the port is configured to be as output. Zero means that the port is configured as an input. If DDRx is written zero and PORTx is written logic “1” then the port is configured as input with an internal pull-up resistor. Otherwise, if PORTx is written to zero, then the port is configured as input, but pins are set to tri-state, and you might need to connect external pull-up resistors. If PORTx is written to logic “1” and DDRx is set…

Continue reading

Why Using Ruby on Rails

Nowadays, many big and small companies prefer using Ruby on Rails when creating applications that are to be delivered on the web. It is not surprising, as Ruby on Rails offers lots of advantages over other web development frameworks. Lets have a closer look at the benefits of Ruby on Rails or Ruby, as it is usually called. This framework’s main advantage is that it makes the life of a web developer easier by allowing writing less code, which is achievable due to a leaner code base. Ruby on Rails is very easy to use. Besides, it gives speed and flexibility that no other scripting language or framework can give. Creating websites with Ruby on Rails is a lot faster and easier than with other web developing solutions. Generally, to develop and launch a website, the developer needs about twelve weeks. While using Ruby on Rails, a web developer needs six weeks to complete a similar project. The modular design of Ruby on Rails allows reusing earlier created elements rather than creating new ones. Making changes and adjustments is also a lot easier if a site is created with Ruby on Rails.

Continue reading

Agile Web Development with Ruby on Rails

Ruby on Rails (also known as RoR or simply Rails) is an object-oriented, multi-level, full-stack framework running via Ruby’s programming language. Many web developers choose to work in Ruby on Rails due to its numerous advantages. Why do developers love RoR? The best-known advantage of Ruby on Rails web development is the speed. A variety of handy instruments and Ruby’s support on the Rails community increase development speed by about 30-40%. With Ruby on Rails, you get excellent built-in testing, caching, localization, validation, and deployment tools. And that’s not it. You also get an opportunity to customize the routing and titles of the website sections so that your projects always have simple and beautiful URLs. The database migration process is perfect in Rails. The database structure always stays in the repository, and every change in structure gets instantly documented.

Continue reading

Reading serial data from chipKIT UNO32 using Python3 and pyserial

installing python3 - path variable

Python is great programming (scripting) language that is supported on all platforms. Embedded enthusiasts love it because of the variety of modules that connect things to the internet and other crazy stuff by writing only a few code lines. Today my interest was to read serial data using Python 3.3 and the pyserial module. Python 3.3 is still fresh, and there is a majority of modules that need to be ported from Python 2 to Python 3, but I hope soon they will here. The serial module seems to be working fine in Windows 7 x64, and I decided to share my experience. First of all download and install Python 3 (current release is Python 3.3) Just be sure to include “Add python.exe to Path” so you could run Python anywhere on your computer. We won’t go into details on how to set up this tool. It is pretty robust. After setup, python install is placed in C:\Python33. To test if things work OK open the command prompt and type python; you should see the python prompt:

Continue reading

Control LPT port under windows XP using Delphi

Another way of controlling the LPT port under Windows 2000 and XP is using the Delphi language. In this case, library, inpout32.dll, is used, which allows controlling LPT port registers. And now how to do this from the beginning. Start Borland Delphi 7.0 and make a simple form where you can enter Data to be sent to the port, Port Address, buttons for writing to and reading from a port. If you are familiar with building forms this should be ease task. Okay, now let’s start programming; first of all wee need to include inpout32.dll in the project. For this, Delphi has several ways, but let’s stay to the easiest one when the library is in the same directory, where the project is. The header in section uses we have to place function prototypes Out32 and Inp32 with special compiler directive external, saying where to find this function.

Continue reading

Controlling external devices using COM port communications programmed using VB language

There are a lot of Radio amateurs that want to control external devices using computer standard ports. One of them is the COM port. Everybody wants things to be easy as people doing electronics are more hardware people, not software. COM port is more often used than LPT because COM port is more resistive to bigger loads, and there are fewer chances of failing. So if you know Visual Basic a little bit, then this shouldn’t be tough to use the MSComm Control component, located in Project->Components. You should check box MSComm Control. Later you have to add this control to the form and write some code for it.

Continue reading