Tag: code

Writing Better Embedded Firmware

Co-operative multitasking I think this is the most simple, organized and suitable way to write code for real-time embedded systems. This is simple state machine based model which responds well in real-time. In this case I am using PIC32MX340F512L MCU, you can adopt this code for your favorite microcontroller.

First we write a simple main function where other functions will be called:

// main.c file
// add pic32 lib
#include
 
// prototype the functions
void blinky_init(void);
void blinky(void);
void button_init(void);
void button(void);
 
int main (void)
{
	// initialize the apps
	blinky_init();
	button_init();
	// ....
 
	// run the app(s)
	while (1)
	{
		blinky();
		button();
		// ....
	}
}

In above code snippet we have added processor related libraries, declared the prototypes of the functions which we are going to use and then started the main function. In the main function, we have first initialized the peripherals which we are going to use. In this case only two types, an LED and a push button. The main operations of the peripherals are handled in the blinky(); and button(); functions. Now we look at these functions: (continue reading…)

Share

Getting Started with Stellaris Microcontrollers

Stellaris is micro-controller series by TI. It was first introduced by LuminaryMicro, an independent company which was later acquired by TI. It was the first Cortex-M3 based MCU offering which caught-up the attention. Here is a brief tutorial to get started and creating the very first project in Keil uV4 and using StellarisWare library suite. Following is the step by step procedure. You can download the source code at the end of this post. In my case, am using EKK-LM3S8962 demo kit.

Step-1: Create new project

Getting started with stellaris

Step-2: Select the device

Getting started with stellaris

Step-3: Add startup code

Getting started with stellaris

Step-4: Add a file to source group

Getting started with stellaris

Step-5: Select the c source file this time

Getting started with stellaris

Step-6: Goto project options

Getting started with stellaris

Step-7: Check the crystal frequency from target tab

Getting started with stellaris

Step-8: Choose the debugger from debug tab

Getting started with stellaris

Step-9: Choose driver for flash programming from utilities tab

Getting started with stellaris

Step-10: Choose preprocessor for the part and include path from the c/c++ tab
I have created the new project in the same directory as the stellariware example code i.e, “C:\StellarisWare\boards\ek-lm3s8962″
Getting started with stellaris

Step-11: Linker settings

Getting started with stellaris

Step-12: Add some more files

Getting started with stellaris

Step-13: This time the library files

Getting started with stellaris

Step-14: Write the code in the *.c file

Getting started with stellaris

Download Files:

Share

RS232 interface with C#

A simple program in C# to send/receive data to PC serial port.

Download Files:

Share

PICC Serial Port

I had coded CCS PICC IDE for sometime. It’s good IDE and very powerful compiler. Only “drawback” is the money you need to pay for the said tools. Attached is simple serial port routine in PICC.

Download Files:

Share

  • Follow

  • Just a Moment Please

    About You
    What defines you the best...
  • Disclaimer

    The information on this website is based on my personal views which may differ from my employer(s). The free material here to download is the work I have done in my free time and, though may seem resembling, does not belong to my current or previous employer(s). It is solely my own intellectual property.
  • Copyright © Electrodesigns.net 2011-12
    iDream theme by Templates Next | Powered by WordPress