The important aspect of every learning is to induce curiosity and doing something meaningful to satisfy that.With the help of that curiosity, I'm here making a volume adjuster program which resembles the same in most devices but not that much, Here the default volume will be 10.Maximum volume will be 20 as well as the minimum volume will be 5.
Well, here I'm using Proteus 8 Professional for stimulation and Mikro C Pro Plus 2012 as Embedded Compiler for programming the microcontroller because I've already ran out of hardware and money :).
Step 1: Things You will need
Since this is a fully software stimulated program, You will need not more than the following softwares:
1.Proteus 8 (Any build or Version).
2.Mikro C (Any build or Version).
Step 2: The Connections.
Open Proteus. In the Component Mode, select Pick from devices and search and double click the following components:
1.LM016L (16x2 AlphaNumeric Display LCD)
2.PIC16F877A Microcontroller (Here i am going with 16F877A as it is the most common PIC Microcontroller)
3.A Resistor or POT(Value = 10k Ohms).
4. SW_ROT_3 switch
Here we'll use the inbuilt crystal with the default frequency 8MHz.
I have used the SW_ROT_3 switch to avoid floating point errors.
I made a 4-bit connection to LCD as it is more than enough for this program.
Do the Following Connections:
1.Place the PIC16F877A
2.On the right side of it place the LCD Display.
3.In the LCD, connect VSS to gnd, VDD to +5V and RW , D0,D1,D2,D3 to ground(since its a 4 bit connection) . VEE is connected to +5V via a 10K ohms resistor.
4.We are going to use portB in PIC to control LCD. so, connect RB1,RB2,RB4,RB5,RB6,RB7 to RS,E,D4,D5,D6,D7 in the LCD respectively.
5.Connect the SW_ROT_3 switches as shown.
Step 3: The coding part(With Mikro C)
The most important part and the most frustrating part is the coding part. This code is no complex . This is a very simple code. Though it appears as more complex, appearances are deceptive:).
Open MikroC. Create a new project and select P16F877A microcontroller with frequency 8Mhz. name the project as 'Volume Adjuster' and include all library files in it. If you don't wanna include all library files, then include and in your program.Just copy and paste the code in Mikro C
//AN ARTICLE BY TheEffectiver.
// specify what pins will be used as what. THis bit of code is necessary.
sbit LCD_RS at RB1_bit;
sbit LCD_EN at RB2_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D4 at RB4_bit;
// End specification for pins
// specify the pin directions
sbit LCD_RS_Direction at TRISB1_bit;
sbit LCD_EN_Direction at TRISB2_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End of LCD Pin direction
TRISC.TRISC1 = 1; // sets RC1 in input mode (for increasing the volume)
TRISC.TRISC2 = 1; //sets Rc2 in imput mode(for decreasing the volume)
PORTC = 0x00; //sets all the input pins to logic low(or zero volt)
Lcd_Init(); // to initialize the lcd
Lcd_Cmd(_LCD_CLEAR); // Clear the display of lcd
Lcd_Cmd(_LCD_CURSOR_OFF); // Turn cursor off since it appears in the lcd screen
/*Lcd_Out(row number,column number,text);*/
Lcd_Out(1,1,"Volume Adjuster");//Display the program name
Delay_ms(1000);//give a delay of 1 second
Lcd_Cmd(_LCD_CLEAR); // clear all the rows of lcd screen
Lcd_Out(1,1,"Volume:"); //display volume in first row
intTostr(Volume,Vol);//convert int to string(char array) since Lcd_Out only displays string
Lcd_Out(2,1,Vol); //display the converted string
while(1)//The endless loop begins
if(PORTC.RC1==1) //checks for input
while(PORTC.RC1==1);//stays here till the input becomes zero
Volume++; //increases the volume
if(Volume==maxvol) //checks if volume is maximum volume
Lcd_Cmd(_LCD_CLEAR); //clears the screen
Lcd_Out(2,1,"MAX VOLUME"); //displays maximum volume in second row
Delay_ms(1000); //gives a delay
Lcd_Out(2,1," "); //clears the second row(there are 16 blank characters in this string)
Volume--;//Decreases the volume since the volume is maximum
//The above applies for the remaining section
//Display the final results
And build the project by pressing ctrl+F9
mikro c will produce the hex file for you.
make sure you save the project and know the path of the hex file.
Volume Adjuster.c2 KB
Volume Adjuster.hex4 KB
Step 4: The Final PartThank god.. we have finished all the irritating parts and came to the end.Here is what you have to do
1.In proteus, double click or right click the PIC microcontroller and select edit properties.
2.In the program file text box, click the folder icon and select the .hex file that mikro c generated for you.
3.Click OK and start the stimulation.
4.To increase the volume, adjust the SW1 switch.
5.To decrease the volume, adjust the SW2 switch.
Thats it.. You have made a Volume Adjuster.. Hatz off..
Your feedback is important. Please give your feedback.
-->>AN ARTICLE BY TheEffectiver<<--