What is the reason for explicitly declaring L or UL to long values?

If we donot declare a value explicitly then it uses the first data type available for it.

Some examples:

int a = 2; //  2’s data type is int.

long a = 2; // 2’s data type is int.

In both the above cases there will not be any problem.

but what if,,,

unsigned long long a = 21< 36;

as in the above case 1 has int type but we are trying to shift it 36 bits left, and as we all know an int is not that long, so it will overflow.

That’s the reason it’s a good practice to write,

unsigned long long a = 1ULL <  36;

Using Macros to clear and set a bit

There are many ways to clear and set a bit in a variable. But not all the ways are fast and efficient. The quickest way to do this is by shifting 1 or 0 to the bit you want to set or clear respectively.

To set a bit:

#define setBit(var, bit) (var |= 1 << bit)

To clear a bit:

#define clearBit(var, bit) (var &= ~(1 << bit))

you can compile this code and check the output:

#include <stdio.h>

#define setBit(var, bit) (var |= 1 << bit)
#define clearBit(var, bit) (var &= ~(1 << bit))

int main()
{
int a = 2;

printf(“Before setting bit 1: %d\n”, a);
setBit(a, 0);
printf(“After setting bit 1: %d\n”, a);

printf(“Before Clearing bit 1: %d\n”, a);
clearBit(a, 1);
printf(“After Clearing bit 1: %d\n”, a);

return 0;
}

output can be seen in the picture below:

AVR ATmega8 LED Blinking

The first step and the easiest way to start AVR ATmega8 is to use its feature to control I/O pin available to control your connected devices.

By learning these easy steps you will be able to make any useful application in the end.

Components Used:
1. ATmega8 Controller
2. LEDs – Light Emitting Diodes

3. Resistance – 220 ohm
4. Power – 5V supply or Battery
5. PCB and Soldering Items or Breadboard and Connecting wires

All these things are required if you love to make hardware to enhance your hardware skills, but if you want to give it a first try without hardware, you can use simulator (Proteus).

Circuit Diagram , Program Code and Simulation file will be provided to you.

Circuit-

Circuit

You can use any number of LEDs up to 23, because we have 23 I/O pins on ATmega8. Here I have just connected 3 LEDs for demonstration purpose. You can also use different color LEDs to make your hardware look attractive and have fun by making different colorful patterns.

Introduction to AVR

AVR (Advance virtual RISC) is manufactured by ATMEL. Commonly used in various applications for advancement in the traditional systems and to meet the requirement of future. We are using micro-controllers in every electronics or any semi-electronics machines to reduce human interference and labor work.
We have ATmega8, ATmega16, ATmega32 and ATmega128 commonly used controllers, first we are starting with ATmega8.

Features:

  • High Performance, Low-power 8-bit Microcontroller
  • 8KB Flash Memory
  • 512 Bytes EEPROM
  • 1KB SRAM
  • 2 Timer 8bit
  • 1 Timer 16bit
  • Real Time Counter with separate Oscillator
  • 3 PWM Channels
  • 8 ADC Channels in TQFP 10-bit Accuracy
  • 6 ADC Channels in DIP 10-bit Accuracy
  • I2C
  • USART
  • SPI
  • Watchdog
  • Analog Comparator
  • Brown Out Detection
  • Internal up to 8MHz / External Oscillator up to 16 MHz
  • External Interrupts
  • 5 Sleep Modes
  • 23 In-Out Pins
  • Operating Voltage 2.7-5.5V (ATmega8L)
  • Operating Voltage 4.5-5.5V (ATmega8)
  • Operating Current (Active) 3.6mA at 4 MHZ
  • 28 PIN IC

Start with ‘VIM’

From now on that’s your blackboard !!

If you are a newbie to Linux (or Ubuntu) . . .

Open Terminal from Dashboard or better use the shortcut Ctrl+Alt+T

After opening Terminal, the first we will do is – Installing VIM

That’s quite easy job…believe me !

Just type the following command:

sudo apt-get install vim

It will take some time and you will get your own blackboard…

Follow the simple steps below to create your first file in Linux (It’s even simpler than making paper aeroplane):

  1. Open a new file (.c file) by typing vim helloworld.c
  2. Press ‘I” to enter into the insert mode
  3. Start with your program
  4. Press ‘Esc’ key to get out of the insert mode
  5. Save the program by typing on the screen- :wq! (colon wq exclamation mark)
  6. Now it’s time to compile your program:

        gcc –o helloworld helloworld.c

,where gcc is your GNU C Compiler; -o will create object file; in the next field type the name of your object file, give it any name, but we prefer to give it the same name as your .c file; the last field is the name of your .c file

Shell, Kernel and Terminal

Shell

It is basically a command line interpreter and an interface between user and Unix kernel  . You can write various commands in it which can further perform various tasks. Job of the shell is, suppose you want to print a document then you will give a command to the shell. Shell will then interprets the command and translate into something which kernel can understand.

Kernel

Unix Kernel is basically a program which manages system resources and hardware. Its central core of the operating system. The kernel’s job in this case will be, it will take instructions from the shell and will further translate into a language which a printer can understand and thus the job is done.

So if we have to get something done, we have to instruct the shell to instruct the kernel to execute whatever we wish to do.

Terminal

Now how do we access to shell???

Linux is Everywhere

Whether you know this or not, but Linux is everywhere. We use Linux everyday.

  • Over 850,000 android phones running Linux activate every single day,compare that to just 30,000 windows phone
  • Nearly 700,000 T.V. sold everyday, most of them are Linux-based
  • 8 out of 10 financial trades are powered by Linux
  • 9 out of 10 world’s super computer run Linux
  • Google, Twitter, Facebook and Amazon are all powered by Linux

So, how is Linux developed to achieve all of this???

Linux is built collaboratively across companies, geographies , and markets. Result in the LARGEST collaborative development project in the history of computing. Since 2005, about 8,000 developers from almost 800 companies contributed to the Linux kernel.  This contribution results in 15 million lines of code. 1.5 million lines of code written in the last couple of years.

It’s not only about the how many lines are there in code. It’s not just about the sheer number of lines and code. It’s also about how quickly Linux is developed and released. For eg, a major new kernel comes out every 2-3 months. Compare this to years for competing operating systems.

Say “Hello” to the “World” of Linux !!!

It was august of 1991, and a 20 year old science student Linus Torvalds sat down on his computer and made a post on computer “Hello everybody out there… I’m doing a free operating system(just a hobby, won’t be anything big”. This open source project quickly spread around the globe and developers from all over the world, contributed with their codes. Linus named his OS kernal- Linux and showed a Penguin as its mascot and named it “Tux”. He soon made a very important decision, he chose GPL licence. Linux along with GPL  licence revolutionize the entire industry. It gave,

  • Freedom to use software for any purpose
  • Freedom to change the software to suit your needs
  • Freedom to share the software with friends and neighbors, and
  • Freedom to share the changes you make

Companies built business around Linux. Red hat is the first Linux based company.  IBM spent a  billion dollars to improve and advertise Linux. Soon, Linux was knocking out industry heavy-weights. In short, Linux, revolutionized computing.