Sunday, December 07, 2014

Create Musical Tone Using PIC Microcontroller[Step by Step ]

In this tutorial , i will show how to create melody using microcontroller and in this tutorial i will use pic18f2550 microcontroller .So let's create a project in proteus .

Proteus Project :

Please follow the instructions given below :

Now pick pic18f2550, sounder, crystal,22pf capacitor,VDD and ground according to the instructions given below :


Now complete the circuit as given below :


MikroC Code :


Now  we need the source code .So create a project in MikroC and follow the instructions given below:

Source Code :


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


void Tone1() {
  Sound_Play(659, 250);   // Frequency = 659Hz, duration = 250ms
}

void Tone2() {
  Sound_Play(698, 250);   // Frequency = 698Hz, duration = 250ms
}

void Tone3() {
  Sound_Play(784, 250);   // Frequency = 784Hz, duration = 250ms
}

void Melody() {           // Plays the melody "Yellow house"
  Tone1(); Tone2(); Tone3(); Tone3();
  Tone1(); Tone2(); Tone3(); Tone3();
  Tone1(); Tone2(); Tone3();
  Tone1(); Tone2(); Tone3(); Tone3();
  Tone1(); Tone2(); Tone3();
  Tone3(); Tone3(); Tone2(); Tone2(); Tone1();
}

void ToneA() {
  Sound_Play( 880, 50);
}
void ToneC() {
  Sound_Play(1046, 50);
}
void ToneE() {
  Sound_Play(1318, 50);
}

void main() {
    ADCON1=0x0F;   //disable adc
    CMCON=7;         //disable comparator



  Sound_Init(&PORTC,0);
  Sound_Play(880, 1000);             // Play sound at 880Hz for 1 second

  while (1) {
  ToneA();
  delay_ms(100);
  ToneC();
   delay_ms(100);
  ToneE();
   delay_ms(100);
  Melody();


  }
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


Now follow the next instructions .
.
Now just run the project.

Thank You!

Matrix [4x4] Keypad interfacing with PIC Microcontroller [ PIC18f2550 ] in Proteus [Step by Step]




 Matrix [4x4] Keypad  interfacing with PIC Microcontroller [ PIC18f2550 ] in Proteus [Step by Step]
 Matrix [4x4] Keypad  interfacing with PIC Microcontroller [ PIC18f2550 ] in Proteus [Step by Step]


Basically a matrix keypad[ 4x4] can be compared as a keyboard of microcontroller .The keypad contains 16 buttons .Internal architecture of keypad described below :
 Matrix [4x4] Keypad  interfacing with PIC Microcontroller [ PIC18f2550 ] in Proteus [Step by Step]
Taken from Internet

You can see  the button's structure  .Here each row is connected with ground through 10k ohm resistor . Now consider that A=1, B=0,C=0,D=0 and column A get +5v .At this situation , if you press   button[A,E]  , the E link get +5v .In this way for button[A,F] , F=+5v or 1, button[A,G] , G=1, button[A,H] , H= 1.
Listen , if we can make ABCD(1000) ,ABCD(0100),ABCD(0010), ABCD(0001) through a loop . Now any button  pressed  , we can uniquely identify the button .In this way the matrix keypad works .

Now Create a project in Proteus :

Proteus Project :

Please follow the steps




I am just trying to make easy for beginner .Now follow the instruction for pick parts from library .




Now pick  PIC18F4550  microcontroller , 22pf capacitor ,crystal , LCD DISPLAY [LM016L] , keypad  from proteus library .Now see the complete circuit given below :
 Matrix [4x4] Keypad  interfacing with PIC Microcontroller [ PIC18f2550 ] in Proteus [Step by Step]
 Matrix [4x4] Keypad  interfacing with PIC Microcontroller [ PIC18f2550 ] in Proteus [Step by Step]

Here i have connected each column with +5v instead of GND and now i am going to provide (1000) ,(0100),(0010),(0001) in each row respectively .So if any button  is pressed we get 0 according to this.
Now We have completed the Circuit and create a project in MikroC .

MikroC Project :

If  you are a beginner , please follow the steps given below :

Source Code :

  


  sbit LCD_RS at RB7_bit;  
  sbit LCD_EN at RB6_bit;  
  sbit LCD_D4 at RB5_bit;  
  sbit LCD_D5 at RB4_bit;  
  sbit LCD_D6 at RB3_bit;  
  sbit LCD_D7 at RB2_bit;  
  sbit LCD_RS_Direction at TRISB7_bit;  
  sbit LCD_EN_Direction at TRISB6_bit;  
  sbit LCD_D4_Direction at TRISB5_bit;  
  sbit LCD_D5_Direction at TRISB4_bit;  
  sbit LCD_D6_Direction at TRISB3_bit;  
  sbit LCD_D7_Direction at TRISB2_bit;  
  // End LCD module connections  
  char ch[]="   ";  
  int j=0,ak=0,i=0;  
  void main() {  
  ADCON1=0x0F;  
  CMCON=7;  
  TRISA.F0=1;  
  TRISA.F1=1;  
  TRISA.F2=1;  
  TRISA.F3=1;  
  TRISC.F0=0;  
  TRISC.F1=0;  
  TRISC.F2=0;  
   TRISC.F4=0;  
  Lcd_Init();  
   Lcd_Cmd(_LCD_CLEAR);    // Clear display  
  Lcd_Cmd(_LCD_CURSOR_OFF);  
  delay_ms(200);  
  j=0;  
   while(1){  
    PORTC=0x00;  
    LCD_Out(1,1,"Matrix Keypad");  
    ak=5;  
    delay_ms(200);  
   while (ak==5){  
  PORTC=0x01;       //  
  if(PORTA.F0==1 & PORTA.F1==0 & PORTA.F2==0 & PORTA.F3==0) {  
   ak=2;  
   Lcd_Chr(2,4,'7');  
    ch[j]='7';  
   j++;  
  }  
  if(PORTA.F0==0 & PORTA.F1==1 & PORTA.F2==0 & PORTA.F3==0) {  
   Lcd_Chr(2,4,'4');  
   ak=2;  
    ch[j]='4';  
   j++;  
  }  
  if(PORTA.F0==0 & PORTA.F1==0 & PORTA.F2==1 & PORTA.F3==0) {  
  Lcd_Chr(2,4,'1');  
      ch[j]='1';  
   ak=2;  
   j++;  
  }  
   if(PORTA.F0==0 & PORTA.F1==0 & PORTA.F2==0 & PORTA.F3==1) {  
     Lcd_Chr(2,4,'C');  
    ch[j]='C';  
   ak=2;  
   j++;  
  }  
   PORTC=0x02;  
   if(PORTA.F0==1 & PORTA.F1==0 & PORTA.F2==0 & PORTA.F3==0) {  
   Lcd_Chr(2,4,'8');  
  ch[j]='8';  
   ak=2;  
   j++;  
  }  
  if(PORTA.F0==0 & PORTA.F1==1 & PORTA.F2==0 & PORTA.F3==0) {  
   Lcd_Chr(2,4,'5');  
  ch[j]='5';  
   ak=2;  
   j++;  
  }  
  if(PORTA.F0==0 & PORTA.F1==0 & PORTA.F2==1 & PORTA.F3==0) {  
   Lcd_Chr(2,4,'2');  
  ch[j]='2';  
   ak=2;  
   j++;  
  }  
   if(PORTA.F0==0 & PORTA.F1==0 & PORTA.F2==0 & PORTA.F3==1) {  
    Lcd_Chr(2,4,'0');  
   ch[j]='0';  
   ak=2;  
   j++;  
  }  
  /////////////////////////  
  PORTC=0x04;        //  
   if(PORTA.F0==1 & PORTA.F1==0 & PORTA.F2==0 & PORTA.F3==0) {  
   Lcd_Chr(2,4,'9');  
  ch[j]='9';  
   ak=2;  
   j++;  
  }  
  if(PORTA.F0==0 & PORTA.F1==1 & PORTA.F2==0 & PORTA.F3==0) {  
    Lcd_Chr(2,4,'6');  
   ch[j]='6';  
   ak=2;  
   j++;  
  }  
  if(PORTA.F0==0 & PORTA.F1==0 & PORTA.F2==1 & PORTA.F3==0) {  
    Lcd_Chr(2,4,'3');  
    ch[j]='3';  
   ak=2;  
   j++;  
  }  
   if(PORTA.F0==0 & PORTA.F1==0 & PORTA.F2==0 & PORTA.F3==1) {  
    Lcd_Chr(2,4,'=');  
    ch[j]='=';  
   ak=2;  
   j++;  
  }  
   /////////////////////////  
  PORTC=0x10;        //  
   if(PORTA.F0==1 & PORTA.F1==0 & PORTA.F2==0 & PORTA.F3==0) {  
   Lcd_Chr(2,4,'/');  
  ch[j]='/';  
   ak=2;  
   j++;  
  }  
  if(PORTA.F0==0 & PORTA.F1==1 & PORTA.F2==0 & PORTA.F3==0) {  
    Lcd_Chr(2,4,'*');  
   ch[j]='*';  
   ak=2;  
   j++;  
  }  
  if(PORTA.F0==0 & PORTA.F1==0 & PORTA.F2==1 & PORTA.F3==0) {  
    Lcd_Chr(2,4,'-');  
    ch[j]='-';  
   ak=2;  
   j++;  
  }  
   if(PORTA.F0==0 & PORTA.F1==0 & PORTA.F2==0 & PORTA.F3==1) {  
    Lcd_Chr(2,4,'+');  
    ch[j]='+';  
   ak=2;  
   j++;  
  }  
  }  
   }  
  }  




 Now follow the instructions, how to create .hex file and save .


 Now go to Proteus and Run the Project .



 Matrix [4x4] Keypad  interfacing with PIC Microcontroller [ PIC18f2550 ] in Proteus [Step by Step]

 In this way you will able to interface Keypad with Microcontroller .

Result Video :



Download This Project(Google Drive)


Thank You!



Saturday, December 06, 2014

Lcd 16x2 Scrolling Display Using PIC Microcontroller [Step by Step]



In this tutorial , i will show how to make a Scrolling Display using LCD and PIC18F2550 .
Generally LCD display has 16 pins . 16x2 means the display has 12 columns and 2 rows .

The picture given below shows about rows and columns .
 Lcd_Cmd(_LCD_SHIFT_RIGHT);
Lcd 16x2 Scrolling Display Using PIC Microcontroller



The picture given below discuss about each pin .
Lcd 16x2 Scrolling Display Using PIC Microcontroller

 Proteus Project :

Now we are going to create a new project in Proteus and follow instructions given below :


Lcd 16x2 Scrolling Display Using PIC Microcontroller








According to instruction pick from library 'pic18f2550' , crystal, 22pf capacitor, 5Kohm variable resistor ,power and ground. For lcd display please type "LM016L" on keywords .
In this tutorial we will use 4 data pin [D4-D7] .Now complete the circuit as given below :
Lcd 16x2 Scrolling Display Using PIC Microcontroller [Step by Step]


We have completed the circuit .Now we need the source hex file .So create a new project in MikroC and follow the instructions:

MikroC Source Code :






Required MikroC LCD Library Functions :

1.Lcd_Init   :  Initializes Lcd module.
2.Lcd_Out  :  Prints text on Lcd starting from specified position. Both string variables and literals can be passed as a text.
Parameters :
  1. row: starting position row number
  2. column: starting position column number
  3. text: text to be written

3.Lcd_Cmd :   Sends command to Lcd.
a)     Lcd_Cmd(_LCD_SHIFT_RIGHT)  :This function is used for shifting on the right hand side .
          Lcd_Cmd(_LCD_SHIFT_RIGHT);
 Lcd_Cmd(_LCD_SHIFT_RIGHT);

b)     Lcd_Cmd(_LCD_SHIFT_LEFT)  :This function is used for shifting on the left hand side.
c)     Lcd_Cmd(_LCD_CURSOR_OFF) : This function is used for setting the cursor off .
d)     Lcd_Cmd(_LCD_CLEAR) :To Clear the lcd .
 Lcd_Cmd(_LCD_SHIFT_RIGHT);
 Lcd_Cmd(_LCD_SHIFT_RIGHT);

Source Code :

  // 
 sbit LCD_RS at RB7_bit;  
 sbit LCD_EN at RB6_bit;  
 sbit LCD_D4 at RB5_bit;  
 sbit LCD_D5 at RB4_bit;  
 sbit LCD_D6 at RB3_bit;  
 sbit LCD_D7 at RB2_bit;  
 sbit LCD_RS_Direction at TRISB7_bit;  
 sbit LCD_EN_Direction at TRISB6_bit;  
 sbit LCD_D4_Direction at TRISB5_bit;  
 sbit LCD_D5_Direction at TRISB4_bit;  
 sbit LCD_D6_Direction at TRISB3_bit;  
 sbit LCD_D7_Direction at TRISB2_bit;  
 // End LCD module connections  
  char txt1[]=" Moving Right";  
  char txt2[]="  Moving Left";  
  int i=0,j=0;  
 void main() {  
  ADCON1=0x0F;  
  CMCON=7;  
  Lcd_Init();  
   Lcd_Cmd(_LCD_CLEAR);        // Clear display  
  Lcd_Cmd(_LCD_CURSOR_OFF);  
    while(1){  
    for(i=0;i<20;i++){  
   Lcd_Out(1,1,txt1);  
     Lcd_Cmd(_LCD_SHIFT_RIGHT);  
      delay_ms(200);  
     }  
       Lcd_Cmd(_LCD_CLEAR);  
     for(j=0;j<20;j++){  
   Lcd_Out(2,1,txt2);  
     Lcd_Cmd(_LCD_SHIFT_LEFT);  
      delay_ms(200);  
     }  
  }  
 }  


//////////////////////////////////////////////////////


 Now create a hex file with MikroC .Please follow the instructions :

Now go to the hardware and make double click on the Microcontroller  .Please follow the instructions:




Lcd 16x2 Scrolling Display Using PIC Microcontroller [Step by Step]

Lcd 16x2 Scrolling Display Using PIC Microcontroller [Step by Step]
Lcd 16x2 Scrolling Display Using PIC Microcontroller [Step by Step]

I was just trying to make something good for beginner .If i made something wrong ,forgive me .

Thank You !


Friday, December 05, 2014

Push Button Interfacing with PIC Microcontroller [Step by Step]


Basically computer system works on 0 and 1. Here 0 for GND and 1  for VDD. Consider, we have a resistor which is connected with vdd. So at this state the resistor gets '1'. Now connect a push button's one end at the point resistor connected with vdd and another end with ground. In this condition if we press the button , the resistor achieve 0. It is the main theme.
Now we are going to interface push button with Microcontroller and in this tutorial  i am going to use microcontroller PIC 18F2550 .


Proteus Circuit : 

Create a new project  in Proteus and follow the instructions .I am just trying to make easy for every one  .




If  you completed those steps, then pick from library  ' pic18f2550' , crystal, 22pf capacitor, 10kohm resistor,5Kohm variable resistor ,power, ground , push button and LCD display( "LM016L" Model  ) according to the instructions given below .

If you got all parts , you can complete the circuit as given below :

[Note : If you don't know how to interface LCD  with microcontroller , please follow this tutorial  ] 


In this circuit , we added resistors one end with PORTC and another end added with VDD. Push button's one end connected with PORTC and atother with GND. In this condition pressing the button will make enable 0 state .

Now we need the Source code for this microcontroller .So Create a new Project in MikroC  and follow the instructions :

 

MikroC Code :


Source Code :

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

sbit LCD_RS at LATB7_bit;
sbit LCD_EN at LATB6_bit;
sbit LCD_D4 at LATB5_bit;
sbit LCD_D5 at LATB4_bit;
sbit LCD_D6 at LATB3_bit;
sbit LCD_D7 at LATB2_bit;

sbit LCD_RS_Direction at TRISB7_bit;
sbit LCD_EN_Direction at TRISB6_bit;
sbit LCD_D4_Direction at TRISB5_bit;
sbit LCD_D5_Direction at TRISB4_bit;
sbit LCD_D6_Direction at TRISB3_bit;
sbit LCD_D7_Direction at TRISB2_bit;
// End Lcd module connections



void main(){
   TRISC.F0=1;
   TRISC.F1=1;
  ADCON1=0x0F;              //Disable Analog to Digital Converter
  CMCON=7;                    // Disable Comperator

  Lcd_Init();                        // Initialize Lcd
      while(1){
  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
  Lcd_Out(1,1,"Microcontroller");
  Lcd_Out(2,4,"Tutorial");                         // Write text in first row
  delay_ms(400);
  if(PORTC.F0==0){
     Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
  Lcd_Out(1,1,"Button_1");
  Lcd_Out(2,4,"PORTC.F0");                         // Write text in first row
  delay_ms(400);
  }
      if(PORTC.F1==0){
     Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
  Lcd_Out(1,1,"Button_2");
  Lcd_Out(2,4,"PORTC.F1");                         // Write text in first row
  delay_ms(400);
  }
  }
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Look at Here :
  TRISC.F0=1;
  TRISC.F1=1;
Here we selected the RESISTER for PORTC. We are using button that means we are providing input for the Microcontroller. As we like to get input from button, we have to define  TRISC.F0=1. Here 1 for input and 0 for output. If we consider TRISC.F0=0, the RC0 port becomes output port.

  if(PORTC.F0==0)
  if(PORTC.F1==0)
Here  PORTC.F0 or RC0 and PORTC.F0 or RC1 ports are always remaining with +5v. If you press  button, the current pass through the button. Because the current will get easy way to meet with ground. At this situation the RC port will get 0. So when we press button, the RC ports get 0. As it gets 0, we can  use this in programming logic and we did it.


Now write the source code on mikroC and create .hex file according to the instructions given below :
Now go to Proteus circuit and make a double click on microcontroller to load the .hex file .Please look at the picture given below :

See  result here :


For Button_1
For Button_2


Thank You!

Share and Bookmark this Blog

Tags

: (1) 18F2550 (1) 36KHz (3) and (1) Based (1) battery (1) Bipolar (1) Blinking (1) blinks (1) Bluetooth (1) bluetooth device interfacing (1) bluetooth module (1) button (1) circuit (1) clock (1) control (1) crystal oscillator (3) Db9 (1) DC Motor (2) digital (2) Digital Voting Machine (1) digital voting machine using pic (1) display (2) DS1307 (1) electronic (1) embedded c programming tutorial (11) embedded c tutorial (11) experiment kit (4) external interrupt (4) flash (1) flashing (1) Gas Leakage detector (1) HC-06 (1) home (1) how (1) How to (10) i2c tutorial (1) in (1) indicator (1) infrared Connection (3) interface (8) interfacing (3) Interrupt (3) Introduction (1) IR Connection (3) IR Receiver (4) IR Transmitter (4) key pad (1) keypad (1) lavel (1) Lcd 16x2 (2) lcd 2x16 (2) led (1) lm35 (2) LPG (1) machine (1) make (1) Make bootloader (1) making (1) matrix (1) max232 (1) membrane keyboard (1) meter (2) Micocontroller (1) microchip (4) microchip pic (2) microchips (3) microcontroller (9) microcontroller based (3) microcontroller programming (3) Microcontroller Project (4) Microcontroller Projects (1) microcontroller_project (2) microcontrollers (4) Microprocessor (2) mikroC (5) mikroc code to start and stopstart and stop dc motor (1) mikroc pro for pic (2) Motion detector (1) MQ-9 Gas Sensor (1) musical (1) NEC Protocol (4) pcb (5) PIC (3) pic controller (11) pic microcontroller (11) pic microcontroller tutorial (11) pic programming (1) pic programming in c (12) pic proteus (1) Pic Tutorial (12) pic18 (2) pic18f2550 (11) picmicrocontroller (4) picRFモジュール (1) PIR Motion Sensor (1) printed circuit board (1) proteus (6) pulse width modulation (1) push (1) push button (1) PWM (1) real (1) rf transmitter (3) Rs 232 (1) Rs232 (1) scroll (1) scrolling (1) Serial communication (1) Serial Connection (1) Serial Port (1) serial port rs232 (1) Servo Motembedded c programming tutorial (1) simulation (2) Soil Moisture Meter (1) speed control (1) step by step (7) step bystep (1) Stepper Motor (2) text (2) Thief Detector (1) time (1) timer (4) timer0 (4) tone (1) TSOP38236 Receiver (4) tutorial (2) Unipolar (1) USART Connection (1) USB (1) usb 1.0 (1) USB bootloadere (1) USB HID (1) using (9) voltmeter (1) voting (1) water level indicator (3) with (2) work (1)

Live Traffic Feed


Live Traffic Feed
Live Traffic Feed

Comment Option isn't working properly

Comment option isn't working properly. If you have anything to say, you are requested to use the "Contact Form" below here.

Leave Your Message Here

Name

Email *

Message *

Google+ Followers

Like on Facebook