Sunday, 22 February 2015

Making a Digital Clock Using Timer,16x2 LCD and 8051/89c51

Digital Clock Using Timer with 8051/89c51

Here I am writing program of Digital Clock using timer for 8051/89c51 microcontroller. To understand complete code of Digital Clock using timer you must have to look at the connection diagram first which is shown in image below :-


In this connection diagram i have only connect the 16x2 LCD with 8051/89c51 microcontroller to display time. Here you can see that LCD is connected in 4-bit mode.

Now I’ll explain you the digital clock program. The main file of Digital Clock program is shown in image which is given below:-  


As you can see in the main program firstly I have initialize the Timer 1 through which I have generated 50 msec interrupt. So for more explanation about Timer 1 interrupt generation you can see my earlier post “Timer 1interrupt in 8051”.Then after I have initialized the LCD and send the command 0x80 to display text from 1st position of first line on LCD. After that I have write the text “Format : HH:MM:SS” on LCD .For more explanation to display text on LCD you can see my earlier post “LCD interfacing with 8051 using 4 datalines”.

Now after entering in while loop I have display time in Hour, Minute and Second format. This Time’s Hours, minutes and seconds is managed in Timer 1 interrupt. Which you can see in interrupt function which is shown in image below:-


Here in this interrupt function firstly I have increment msec counter. when this msec counter gets equal to 20 then I have increment sec counter because it is a 50 msec interrupt and 50x20 =1000 msec (1 sec) also I have make msec counter 0. So when sec counter gets equal to 60 then I have increment min counter and when min counter gets equal to 60  than I have increment hour Counter. In this manner we can manage seconds, minutes and hours. This Time will start from 0 when Microcontroller gets start.

Here in this program one more thing which you have to see that I have used a function name “variable_lcd_diaplay” through which I have display variable on LCD is shown in image below:- 

          
In this function firstly I have break a variable and the 1s digit and 10s digit is taken in different –different variable which are a and b. Then after both variable is converted into ASCII by adding 48. After that these ASCII values has been displayed on LCD by using “LCD_write_data” function.

After completion of program the LCD display will looks like as per the image given below:-



Download Link

To download complete code of Digital Clock Using Timer you can click here. If you are unable to download the complete code than you can leave your email id in comment section and i’ll send you the complete code.





Thursday, 12 February 2015

8051 Development Board Schematic

8051 Development Board Schematic


Here we have following sections:-

1) POWER SUPPLY :- this a 5V power supply circuit to provide a filtered power to MCU and other peripherals. input of this supply is available through adaptor of 8-16 AC or Dc.

2) SPI-ADC :- this a advanced MCP300Spi communicated Analogue to digital converter for two channels to sense analog inputs voltages via SPI.

3) DC MOTOR INTERFACE :- Dc motor interface circuit for communicating a dc motor application.

4) UART/USB :- this a combo circuit which can be used as uart and used as Usb communication since USB communication feature is not available in 8051 a special IC CP2103 is used to convert the uart signal to USB.

5) LCD INTERFACING :- Here we have designed a LCD interfacing circuit which can be used to display parameters. this circuit is configurable for all 16x1 ,16x2,16x4 Lcd's.

6) LED 's :- This section is used to play with general purpose Led for indications.

7) GPIO's :- This section is used to play with general purpose input outputs for indications and interrupts handlings.

8) RESET :- here we have a reset section which is used to reset the embedded software.

8051 Development Board Schematic

Please share your feedbacks if you have any doubts regarding any of the hardware and software part for the above.

we are happy to help you :)


Tuesday, 10 February 2015

How to scrolling Text on 16x2 LCD.

Moving Text On 16x2 LCD USING 8051/AT 89C51

Here in this post I’ll explain you that how we can scroll text message on 16x2 LCD. If you are new to embedded programming then I’ll suggest you that first read my older post which is “How to interface 16x2 LCD”  so that you can understand this post completely.

Before explaining you about the program I’ll show you the connection diagram first so that you can have a clear picture of about circuit that I have used in my program. Now here in below image you can see the connection diagram of 16x2 LCD to 8051 Microcontroller.

   
I feel that from above picture the connection between 8051 microcontroller and 16x2 LCD is clear.
Now I will explain you that how can we move the text on 16x2 LCD. You can see the main program file of my program in image given below:- 


Here in the program which is shown in above image firstly I have initialized the 16x2 LCD and then I write my name and my Profession on first line of LCD which is “VAIBHAV SINGHAL (Firmware Developer )” after that I have write my blog URL on Second Line of LCD which is “www.embeddedsolutions4u.blogspot.com”.

After displaying data on LCD the only thing that I did to keep this text moving is sending the command of 0x1c for shifting display right and put 500 millisecond delay. So from LCD right shift command and 500 millisecond delay the text will start moving on 16x2 LCD after every 500 millisecond.
       
Note :-
·         Also read my older post “How to interface 16x2 LCD” to understand this post completely.

Download Link :-
·         To download complete code of “Moving text on 16x2 LCD” click here. If you are unable to download the complete code please drop your email-id in comment section so that I can send the complete code to you.



Wednesday, 28 January 2015

How to interface 20x4 LCD Diaplay using 8051/AT89c51 with 4 data lines

20x4 LCD Interfacing Using 8051/89c51 with 4-data lines

Here I am writing program to interface 20x4 LCD using 8051/AT89c51 Microcontroller with using only 4 data lines. For interfacing a LCD you must have some idea about LCD Pins. The LCD which is normally available in market is of 16-pin.LCD pin description is explained below:-

PIN NUMBER
SYMBOL
FUNCTION
1.
VSS
GROUND
2.
VDD
+5V
3.
VEE
Contrast Adjustment
4.
RS
Register Selection Signal
5.
R/W
H/L , Read/write Signal
6.
E
H->L,  Enable Signal
7.
D0
H/L ,Data Bus Line
8.
D1
H/L ,Data Bus Line
9.
D2
H/L ,Data Bus Line
10.
D3
H/L ,Data Bus Line
11.
D4
H/L ,Data Bus Line
12.
D5
H/L ,Data Bus Line
13.
D6
H/L ,Data Bus Line
14.
D7
H/L ,Data Bus Line
15.
A/VEE
Backlight Anode
16.
K
Backlight cathode

As per the pin details of LCD explained in above table the important pin used to display character on LCD are RS,R/W,E and data lines (D0-D7) .Through RS pin we can select the LCD data register or LCD command register. If RS pin is HIGH then data register is selected or if RS pin is LOW then command register is selected. R/W is for selecting read or write operation if R/W pin is HIGH then read operation is selected if R/W pin is LOW then write operation is selected. Enable pin is to enabling data reception. Pin D0 to D7 are data lines through which LCD received command or data in 8-bit format.

Now to interfacing LCD on 4 data lines i have connected higher 4-bit of Port1 (i.e. P1.4 – P1.7) to higher the 4 data lines (i.e. D4-D7) you can see Connection diagram used to interface LCD using 4 data lines is given in below image:-



Now you can see in the connection diagram that RS is connected to P2.0 and R/W pin is ground for Write operation and Enable (E) pin is connected to P2.1.Also considered that higher 4 data lines are connected to higher 4 bit of port 1.
In this Program I have print my name (VAIBHAV SINGHAL) in first line and my profession   (i.e. FIRMWARE DEVELOPER) in second line and my blog url in 3rd and 4th line (i.e www.embeddedsolutions4u.blogspot.com). The main file of program is shown in below image:-


In the image of above program you can see I have first initialized the LCD by sending commands 0x02 to reset LCD,0x28 for 2 lines and 5x7 matrix and also for selecting LCD in 4- bit mode,0x0C to ON the display,0x01 to clear LCD screen and 0x06 for cursor increment. After initializing LCD i have write command 0x80 to start writing from 1 position of first line and send my name then send command 0xC0 to write data from 1 position of second line i have wrote my profession then after I have send command 0x94 to write data from 1 position of third line and I have print www.embeddedsolution then after I have send command 0xD4 to write data from  1 position of fourth line and I have print s4u.blogspot.com.
Now in above program I have used to functions one to write command and the other is to send string on LCD. Definition of both function is given in image below:-


In above image you can see both functions. In “LCD_write_command” function register firstly I have selected the command register by putting RS pin LOW and then after I have pull low higher 4 bit of port1 which is connected to data lines and then I have put higher 4 bit of data and then enables data reception by putting Enable pin high for very short time after that I have put zero to data lines and then after ihave send the lower 4 bit to data lines.
 In “LCD_Send_String” function I have send complete string to LCD by using “LCD_write_data” function. Full details of this function is given in image below:- 


The “LCD_write_data” function is same as of “LCD_write_command” function except that I have select data register in this function by putting RS pin high.           
This is all about to write characters on 20x4 LCD by using 4 data lines. After installing program in 8051/89c51 the data which’ll show on 20x4 LCD is given in below image :-


Download Link

To download complete code of 20x4 LCD interfacing using 8051/89c51 with 4-data lines click here.if you are unable to download then please share you email id and your requirement in comment section.



Tuesday, 27 January 2015

How to Display custom character on 16x2 LCD.

Displaying Custom character on 16x2 LCD

Here I am explaining how to display custom character on 16x2 LCD display. In alphanumeric 16x2 LCD display 64 bytes of CG (character generator) RAM is available to create custom character. Address of CG RAM is starts from 64 and ends to 127. Each character consists 8 bit so maximum 8 custom characters can be stored in CG RAM.

Now in my code firstly I have generated 8 custom characters and put it into CG RAM of LCD .Then after I have display these 8 characters starting from 1 position of first line with single space between each character.

Main Program to display custom character on 16x2 LCD with 5x7 pixels is given in images below :-



In above image you can see that I have created a array which contains 56 digit. So here first 7 digits is for first custom character which is a Bell then next 7 digits is for second custom character which is Heart then next 7 digits is for third custom character which is Smile then next 7 digits is for fourth custom character which is Symbol of Music then next 28 digits is for 4 Hindi Characters .You will say how I will explain in detail but first look on image given below which contain the main code:-


The code shown in image above is complete code of creating 8 custom character and display all these on 16x2 LCD.
So Here I will only explain how I create my first character Bell and display it on LCD the rest you’ll automatically understand.

Creating Custom Character:-

In above code after initializing LCD I have used a For loop for creating 8 custom character in that loop when we enter first time we’ll send a command 64 on LCD which is base address of CG RAM. Then I have send first 7 data using loop which are 4,14,14,14,31,0,4 to create Bell.

How this data creating Bell is a question? Answer of this question you will found below:-

16   8     4    2     1





    





























  
The above Figure shows the 5x7 pixel of LCD Block .Which pixel we wants to put ON we can do it with code. First I have send data 4 which is to ON 3rd  pixel of first row and then I have send 14,14,14 which put ON 2,3,4 pixel of 2,3,4 row and then I have send 31 to ON all 5 pixels of 5th row then 0 to OFF all 5 pixels of 6th row then after 4 to ON 3rd  pixel of seventh row. In this manner the picture which comes out is of Bell. So in this manner you can generate your own custom character.

Displaying Custom Character :-

After Creating all 8 characters I have display all these character using a for loop .In that loop first I have send command of start_add which is 0x80 to display character from 1 position of first line of 16x2 LCD. Then I have display the custom character which I have put in CG RAM for Ex I have put Bell on address 64-71. To characters which we have put in CG RAM can be display by sending data 0 for location 64, 1 for location 72 and …………….7 for location 120.

Through the above code the character that I have created is given in Image below:-


Read This :-
Before Reading this post First read How to display character on 16x2 LCD from my earlier post.

Download Link:-

To Download Complete code please click here. If you are unable to download this code then please give your email id in comment section.