on Monday, 30 September 2013
BREADBOARD: Breadboard is used to test whether our circuit is working correctly or not. In order to know whether our circuit is working correctly or not we cannot always use PCB and solder all our components and check it, its time consuming as well as economical to do so. Whatever may be the circuit we will first test it on Breadboard and then if we get desired result only then we solder it on PCB.
How it looks:
breadboard

You can see holes on the breadboard in which we insert our component pins. It consists of two rails top rail and bottom rail and middle area. In top and bottom rail, all rows are interconnected and in middle part all the columns are connected.Look at the below fig to know in which fashion they are interconnected. 

breadboard internal wiring

Dark spots indicates the connected area. Its little difficult to describe in words, so check the video below to understand it better with simple example circuit. 





AUTHOR: YOUSTRON SIC


LED: LED (Light Emitting Diode) is the most useful component which is used as light source. I think everyone knows about it so, no need to explain it again. 
How it looks: You can see different color variants of led's in the image below.
leds










Symbol:
led symbol







How to check polarities of an LED: 




led pins

Method 1: Its very easy to know which terminal is +ve and which one is -ve. The terminal which is longer is the +ve terminal and which is shorter is -ve terminal. 
Method 2: If in case both the terminals are same, then look inside the led one which is thin is the +ve and     other one is -ve.
Method 3: If you cant find which one is thin, then use multimeter to check its polarities. Set the multimeter     in 'Continuity mode' touch the positive probe to one terminal and COM probe of multimeter to other         terminal of Led, if LED lights up then the corresponding pin is +ve and -ve. If it dint lights up then                   interchange the probes surely it will light up and corresponding pin is +ve and -ve. Even it dint lights up           then your LED is damaged one.


TACT SWITCH: 

It consists of 4 pins lets say A,B,C,D. Two pins will be internally connected.To know which two pins are connected internally we use multimeter. Set in 'continuity mode' and touch the pins, at which contact we get beep sound they both are one pair. For example we find A&B are one pair and C&D are another pair, lets say A&B=a and C&D=b. Look at the below picture to understand.
switch on and off tutorial

When we press the switch, 'a' and 'b' will be shorted, when we left the switch it comes to its previous positions. 





PIEZO BUZZER: Buzzer is used to produce beep sound. Black wire is the -ve terminal and Red wire is +ve terminal. Operating voltage is around 1-30V i.e you can connect voltage source in this range, in general we use 5v or 9v.

buzzer
In our next post we will look at how to use Bread board and wire few basic circuits on it. 
AUTHOR: YOUSTRON SIC




In our previous posts we have seen Resistor and its color coding, Capacitor and finding its value, in this post we will look at Diode and Transistor.

DIODE: Diode is a two terminal device which helps the current to flow in one direction i.e zero resistance(ideally) in that direction, and high resistance(infinite ideally) in other direction.
How it looks:
diode
 Look at one end which is coated with silver color, it is the -ve terminal of the diode and remaining one is the +ve terminal.




Symbol:
diode symbol
Look at the symbol beside in which --l> shows that flow of electrons in that direction during forward bias and |-- shows it halts(stops) the flow of electrons if it is reverse bias.







Its clear to us except forward and reverse bias. Yes, we will know what actually mean by forward bias and reverse bias is about...
I will not go in depth to explain forward bias and reverse bias with the fermi levels and all that, but just in lay man way.

Forward Bias: 

forward bias
If the positive terminal of the diode(p type) is connected to the +ve side of the battery and -ve terminal(N type) of the diode is connected to the -ve side of the battery then it is called forward bias.


Reverse Bias:
reverse bias
If the positive terminal of the diode(p type) is connected to the -ve side of the battery and -ve terminal(N type) of the diode is connected to the +ve side of the battery then it is called Reverse bias.



TRANSISTOR: Transistor is a three terminal device which is most useful component in electronics, which is used to amplify signal or acts like a switch.
How it looks:
transistor
 Image shown beside is one type of transistor, you will find many variants depending upon its type.





Transistors are of different types, if i start explaining each of them this whole blog will not be enough. So, i will only deal with basic most frequently used type of transistor i.e BJT (Bipolar Junction Transistor) type.

Bipolar Junction Transistor(BJT) have three terminals Emitter, Base and Collector. BJT is divided into two types
  1. NPN Transistor
  2. PNP Transistor
1.NPN TRANSISTOR: From its name we can easily say that Emitter is of N-type , Base is of P-type and Collector is of N-type. Look at the symbol below


npn
NPN transistor will be ON i.e current flows from Collector to Emitter when base is 'high' relative to emitter.

2.PNP TRANSISTOR: Emitter and Collector is of P-type and Base is of N-type.

pnp
PNP transistor will be ON i.e current flows from Collector to Emitter when base is 'low' relative to emitter.

How to find the Emitter , Base and Collector terminals of the Transistor:
Look at the video below to identify the pins of the transistor and its type.




AUTHOR: YOUSTRON SIC
on Sunday, 29 September 2013
In our previous post we have seen the Resistor and its color coding to find its value, in this post we will look at one of the basic component which is essential to know in order to deal with the projects we are going to deal further.
Capacitor: Capacitor is used to store electric charge in the form of electric field.
Practical Example:
When we switch off our Ceiling fan, is it stops as soon we switch OFF's the switch? Obviously it will rotate for few seconds and stops, right.
Why it is so? Its because if it stops at that high speed the high possibility of burning coil(winding) inside that fan.
Now what helps that fan to stop slowly ? Answer is 'Capacitor' , in general technicians call it as 'condenser' . When switch is ON that capacitor charges and as soon as the switch is OFF it discharges exponentially and provide electric charge to that fan and this makes fan to rotate slowly and when capacitor totally discharges, fan will stop rotating.
Just lift your head up towards your ceiling fan,  you will find a white cylinder shape device, its capacitor.




How it looks:
capacitor explanation
Picture which is shown beside is the Electrolytic Capacitor.
We have various varieties of capacitors in the market. Just google as capacitors then you will find the most general capacitors available in the market.
The terminal which is long is the +ve and which is smaller is -ve. You can even find the -ve symbol on the capacitor.
Disc capacitor will not have any polarity, i.e we can use any terminal as +ve or -ve.



Symbol:
capacitor symbol







To know the value of the capacitor you can check on the capacitor which will be written. In some cases you will find some code rather than the capacitor value, use the below table to trace its value.
capacitor chart
I will end up here, in our next post we will look at another important component.

AUTHOR: YOUSTRON SIC




This is the first post of the section 'Hardware Basics', in this post we will look at few basic components we use frequently in our projects.

Resistor: Resistor is a two terminal component used almost in all the electronic devices, it resists the flow of current. Depending upon its value they resists(opposes) the flow of current.
Analogy: Speed breakers on road which resists the speed of vehicle, in the same way resistors resists the flow of current.
How it looks:
To know the value of the resister we should know how to read the colors which is printed on it.We will look how to 'color code' next.






Symbol: 
You can observe the symbol which is similar to "speed breaker of road" ;-)




COLOR CODING:
Every resistor printed with  different color bands and every color have its predefined value, to know the value of the resistor we should know color coding.

Step1: Find the silver or gold color on the resistor, it will be last color of the resistor(so check both the ends to find it), now hold its adjacent terminal with your left hand. It looks something like...

resistor color coding example

Step2: Looking from right, note the colors one after the other(numbered as 1,2,3 so on..)

Step3: Every color will have corresponding value(look at the below table). Calculate the value of register by

                     First color second color third color so on.. X 10^ last color(color before the silver color)


resistor color coding






Example 1:
resistor color coding example


 First color is Brown , next color red, next color black , next color black, next color silver or gold.

Values Brown=1, Red=2, Black=0, again Black=0

                 120x10^0 =120 (ohm) 


Example 2:
resistor color coding example

Colors: Brown, black, orange

Brown=1, black=0, orange=3

10x10^3 = 10,000 = 10k ohm


Example 3:
resistor color coding example


Red=2, Red=2, Black=0
22x10^0 =220 ohm






Example 4:

resistor color coding example

violet=7 , green=5 , black=0
75x10^0= 750 ohm

Example 5:

resistor color coding example

100x10^0=1000=1k ohm


Tip to remember colors in order:
Just remember this phrase 

BB ROY  Great Britain has Very Good Wife 

B-Black=0
B-Brown=1
R-Red=2
O-Orange=3
Y-Yellow=4
G-Green=5
B-Blue=6
V-Violet=7
G-Gray=8
W-White=9

In our next post we will look at other components :-) 

AUTHOR: YOUSTRON SIC


on Friday, 27 September 2013
In this post we will have an overview of C functions and Arrays.As i said you before that this is not a tutorial section but just an overview.

FUNCTIONS:

Functions are the section of code which is written to perform specifically defined action. They are usually created when a single operation is performed in different parts of the main program.

The general syntax is

type name( parameter 1, parameter 2,....)
{
          Function body;
}

Type= The type of data which is going to returned by the function.
Name= Name of the function.
Parameter 1, 2,etc = Arguments of the function.

Example:

int Add(int a, int b)
{
   return ( a+ b);
}

This function is an add function. When this function is called it will return the addition result and the result is of integer type.

Function Without Returning Value:
It is not necessary that the function should return some value. Sometime we dont need any value to be returned.

Void name ( parameters)
{
       Function body


Example:

Void interrupt( )
{
   x++; 
}
This function dont return any value just it will executes the 'functional body' and returns back to its main control.

LIBRARY FUNCTIONS IN MIKROC :

MikroC compiler offers many useful functions which can be used for fast programming. To know all the verity of functions check the 'help' section of your compiler. Following is the list of libraries it offers

LCD LIBRARY
UART LIBRARY
I2C LIBRARY
CAN LIBRARY
SPI LIBRARY
CAN LIBRARY
USB LIBRARY
ETHERNET LIBRARY
PS2 LIBRARY
RS-485 LIBRARY
Many more....

But remember that using the Library functions always kills your creative thinking and programming skills. So, i suggest you to use function as least as possible. 

We only use few library functions in our programming, other than that we make our programming library free.






ARRAYS: 

Its easy for anyone to declare variables which are limited , but if we want to declare many variables then its difficult. i.e its easy to declare 5 or 10 variables independently but if we want to declare 20 or more variables we cant, so in this case we use ARRAYS. 
Arrays are the data items of similar data type.
For example we want to declare int type individual 30 variables then its an issue, but we can declare using array in the simplest way example "variable_name[30] " . 

DECLARATION: Single dimensional array can be declared as  

type name [ size ] 

Example:
double somename [ 30 ]

INITIALIZATION: 
we can initialize as 
type name[size] = { data} ;

Example:
int xyz[5]={1,2,3,4,5};
or
int xyz[]={1,2,3,4,5};

Note it is not necessary to give 'size' . If we omit size then it automatically allocates its size. 
We will full-stop the C programming section with this post. When we deal with project programming then its easy for you to understand all of these concepts. 


AUTHOR: YOUSTRON SIC




on Wednesday, 25 September 2013
In this post we will look at the 2 types of control handling statements and they are
  • Selection Statements
  • Iteration Statements
Now let us see one after the other, but note that this is just an overview of C but not in depth explanation which i have said you in my previous post.  

SELECTION STATEMENTS:

There are two types of Selection statements, they are
  • IF
  • SWITCH 
IF Statement:
General format of the the statement is 

if(expression)
 {
    Statements;
 }
else
{
   Statements; 
 }

If there is only one Statement in the flower brackets { , }  then they can be neglected. 'Else' is optional. 
Example:
If 'x' is greater than 10 then increment 'y' or else increment 'z' 

if(x>10)
{
  y++;
}
else
{
  z++;
}

we can write this as below
if(x>10) y++;
else
z++; 

SWITCH Statement:
If we want to compare many conditions then we will use "Switch statement".

Switch(condition)
{
              case condition1;
                      statements;
                      break;
              case condition2;
                      statements;
                      break;
              case condition3;
                      statements;
                      break;
              .............................
             .............................
              default:
                     Statements;
}

Example:
Take the decision depends on the value stored in the variable 'xyz' , if it is 1 then store A=20 , if it is 6 then store A=50 , if it is 8 then store A=60 , if non of these then store A=0.

Switch(xyz)
{
                   Case 1:
                         A=20; break;
                   Case 6: 
                         A=50;break;
                   Case 8:
                         A=60;break;
                    default:
                          A=0;
}






ITERATION STATEMENTS:

They are also called as loop statements used for repeating the same statement for predefined number of times. We will look at these statements which are supported by MikroC.
  • For Statement
  • while Statement
  • do Statement
  • goto Statement
FOR Statement:
The syntax of FOR statement is 
for(initial expression;condition;increment expression)
{
    statements;
}

Example:  Repeating a loop for 10 times 
for(i=1;i<=10;i++)
{
   statements;
}

If we want to repeat the loop for infinite number of times then 
for(;;)
{
     statements;
}

WHILE STATEMENT:
This is the simplest form of 'for' statement. Look at the syntax below
While(condition)
{
      Statements;
}

For example if we want to repeat the loop for 10 times then 
x=0
While(x<10)
{
       statements;
       x++;
}

If we want infinite loop using 'while' then 
While(1)
{
    statements;
}

DO WHILE STATEMENT:
It is similar to that of 'While' statement but here the condition is checked after the execution of the statements.
do
{
    statements;
}while(condition)

GOTO STATEMENT:
First let us look at the syntax 

goto label;

The control will be shifted to the 'label' in the program. 
Let us look at a simple example

Loop:
          statements;
           x+ +;
if(x<100) goto Loop;
If  x<100 is satisfied then control will be shifted to the label "Loop" . 

AUTHOR: YOUSTRON SIC

on Monday, 23 September 2013
This post is just an overview on the various operators which are supported by MikroC . Have a look one after the other.

  • Arithmetic Operators
  • Relational Operators
  • Logical Operators
  • Bitwise Operators
  • Assignment Operators
  • Conditional Operators
  • Preprocessor Operators
ARITHMETIC OPERATORS: 
Arithmetic operators are similar to that of C language and look the table given below which are self explanatory. 

OPERATOR
OPERATION
+
Addition
-
Subtraction
*
Multiplication
/
Division
%
Integer division (Remainder)
++
Auto increment
--
Auto decrement
 They are used to perform the arithmetic operations.


RELATIONAL OPERATORS: 

OPERATOR
OPERATION
==
Equal to
!=
Not equal to
> 
Greater than
< 
Less than
>=
Greater than or equal to
<=
Less than or equal to

To compare any two variables these operators are used.




LOGICAL OPERATORS:

OPERATOR
OPERATION
&&
AND
||
OR
!
NOT

Logical operators are used to check the statements and take corresponding step.
For example if we want to check two variable conditions i.e if A and B are true then do some C in this case we use AND operator. Ether A is true or B is true then do some C then OR operator is used. If A is not true then do some C then we use NOT operator.

BITWISE OPERATORS:

OPERATOR
OPERATION
&
Bitwise AND
|
Bitwise OR
^
Bitwise EXOR
~
Bitwise Complement
<< 
Shift Left
>> 
Shift Right
Bit wise operators are used to perform the bitwise operations. It is similar to that of instructions ANL , ORL, etc which we have seen in Assembly language before.

ASSIGNMENT OPERATOR: 
Simplest assignment operator is equal to = 
Other assignment operators supported by mikroC are shown below

+= , - = , * = , / = , so on...

 CONDITIONAL OPERATOR: 

Result = Exp1? Exp2 : Exp3

If Expression1 is true then Result = Exp2 , if Expression1 is false then Result = Exp3 

PREPROCESSOR OPERATOR: 
Preprocessor commands which are supported by mikroC are 

#define             #undef
#if                    #elif             #endif
#ifdef               #ifndef
#error
#line
Only few of them will be used in our programming , we will look at that instant. 

AUTHOR: YOUSTRON SIC

In this post we will look at the mikroC variable names and its types and its predefined memory.

VARIABLE NAMES:
Rules for the variable names in mikroC is similar to C language, check the points which are given below.

  • Variable names can begin with an alphabetical characters or with underscore character i.e it can be any characters a to z and A to Z, the digits 0 to 9, and underscore " _ " .
  • Each variable name should be unique with 31 characters at most.
  • Variable names can be mixed with upper and lower case characters.
  • Names which are reserved for the compiler cannot be used. 
One important different between normal C and MikroC is that MikroC is not case sensitive i.e upper and lower case characters are considered one and the same. Look at the names below all of them are considered as same.

Name                    nAme                        naMe                          namE


VARIABLE TYPES:
MikroC supports the variable types which are shown below , if you want to know more then just go to the 'help' section of your MikroC compiler.

Asm
do
if
static
auto
double
int
struct
break
else
long
switch
case
enum
register
typedef
char
extern
return
union
const
float
short
unsigned
continue
for
signed
void
default
goto
Size of
Volatile and while






 Let us see few important types which we are going to use frequently in our programming. 

Unsigned Char or Unsigned short int :
The range of the type is 0 to 255 i.e it is of 8 bits i.e the variables of this type cannot hold the value which is more than 8 bits i.e more than 255 .
Declaration is something like this shown below 

unsigned char variable_name  ; 
or
char variable_name;

Example: unsigned char xyz; 
xyz variable can hold upto 8bit length. 

Signed char or signed short int :
They are also 8 bits but they are signed character variable i.e range from -128 to +127. 

Signed char variable_name;
or
Short variable_name;
or
short int variable_name;

Example: signed char abc ; 
              or you can declare as " signed char abc=-20 ;" 

Signed int: 
It is of 16 bits i.e -32768 to +32767
int variable_name;

Unsigned int:
It is also of 16bit wide ranges from 0 to 65535.
Unsigned int variable_name;

Signed long int:
It is of 32bits ranges from -2147483648 to + 2147483647. 
Signed long variable_name; 

Unsigned long int:
It is also of 32 bits ranges from 0 to 4294967295.
Unsigned long variable_name;

Double or long double:
To represent the floating point numbers we use double or long double types they ranges from + or - 1.17549435082E-38 to + or - 6.80564774407E38.

From the above which i have mentioned "unsigned char, int" are used frequently in our programming.
AUTHOR: YOUSTRON SIC


Before we start our topic i want to make you few points clear. First thing i want to make you clear is that, this is not the C tutorial section to learn  C programming  language, here you will only learn how to program the PIC microcontroller using MikroC compiler. So before you go further to read my posts first get basics of C language from any source. You have many tutorials on net and you need not to be an expert in C but just learn the syntax and few basic programs and come here.

There are several compilers available for the PIC microcontroller. They are almost similar but little change in their library functions and other features. Some of the famous compilers are 

  • MikroC
  • CCS
  • Hitech C



Is it different to program for different compilers ? Answer is yes, but differ in least, the basic C programming is the same but if you are including library functions then you need to know what are the library functions offering by that particular compiler, check the 'help' section of your compiler to know all the library functions.
After compiling, various files will be generated, but we only concern with the file with extension .hex , because we burn or load this file into our microcontroller.

As we use PIC microcontroller and MikroC compiler, so we only concern with it. We look at structure of mikroC program,libraries and other features...

Look at the general structure below

Void main( )
{
   Program statement;  // comments
   .
   .
   .
}


All the statements will be in between parenthesis i.e { } and every program statement should be terminated with ; and comments should be after // . Its all similar to C language.
Let us look at simple example of blinking LEDs which are connected to Portb of PIC microcontroller.

Void main( )
{
TRISB=0;                     //PORTB as output
  while(1)                              //loop forever
  {
      PORTB=0b00000000; // All leds are off i.e 0
      Delay_Ms(1000);         // 1000 Milli sec delay i.e 1sec delay
      PORTB=0b11111111;// ON all the leds connected to portb
      Delay_Ms(1000);        // 1sec delay
   }
}

led blinking program



  • Here 0b00000000 is binary value.Portb have 8 pins so each bit value corresponds to each pin. i.e right most bit lsb 0 is portb.0 next bit portb.1 , next bit portb.2 and so on upto portb.7. When we make pin 0 then  the led connected to it will be in OFF state, when portb=1 then ON state. 
  • Delay_Ms( ) is the mikroC library function to generate the delay. We have generated 1000ms i.e 1sec delay between OFF and ON.

Note this is just an example program which is intended to show you the structure, we will look more deeply as our topics go further.

Download the mikroC for PIC software from this link
http://www.mikroe.com/mikroc/pic/