Digital Calulator Using 89C52 Micro Controller
Digital Calulator Using 89C52 Micro Controller
PROJEC T R E PORT
Command/Instruction Register Rs ......................................................... 4 Data Register R/W ................................................................................. 4 Pin configuration ................................................................................... 5 Programming the LCD ............................................................................ 5
y
Components:
We have implemented a digital calculator using an 89C52 microcontroller, with LCD display and Keypad Input. The calculator takes input from a 44 keypad and displays the results on the 16 2 LCD. The major components used are:
y y y y y
1. AT89C52:
The AT89C52 is a low-power, high-performance CMOS 8-bit microcomputer with 8K bytes of PEROM. The controller can be burned by any conventional burner, in our case it was burned using USBpro burner and its proprietary software. By combining a versatile 8-bit CPU with Flash on a monolithic chip, the Atmel AT89C52 is a powerful microcomputer which provides a highly-flexible and cost-effective solution to many embedded control applications. Clock is provided using one 1200MHz crystal and two 10uF Capacitors.
The pin configuration of 89C52 is as following:
2. 16
2 LCD:
We have used a 16 2 LCD, for the output. It can display 16 characters per line and there are 2 such lines. In this LCD each character is displayed in 5x7 pixel matrix. This LCD has two registers.
Command/Instruction Register Rs: It stores the command instructions given to the LCD. A command is an instruction given to LCD to do a predefined task like initializing, clearing the screen, setting the cursor position, controlling display etc. To send a command to LCD we have to simply float the Hex code of the instruction to the Command Register.
Data Register R/W: It stores the data to be displayed on the LCD. The data is the ASCII value of the character to be displayed on the LCD.
Pins 1 & 16 are Ground Pins 2 & 15 are VCC Pins 3, 4 & 5 are Register Select, Read/Write and Enable Respectively Pins 7-14 are Data Pins
Programming the LCD: To Read Data from the LCD, R/W = 1, RS = 0 and busy flag =1. Data pin8 (D7) of the LCD is busy flag.
To send data on the LCD, data is first written to the data pins with R/W = 0 (to specify the write operation) and RS = 1 (to select the data register). A high to low pulse is given at EN pin when data is sent. Each write operation is performed on the positive edge of the Enable signal. To send a command on the LCD, a particular command is first specified to the data pins with R/W = 0 (to specify the write operation) and RS = 0 (to select the command register). A high to low pulse is given at EN pin when data is sent.
3. 4 4 KEYPAD
We have used a 4 4 keypad to take the input. This keypad has 4 rows and 4 columns and a unique combination of one row and one column selects a particular key on the keypad. Rows and Columns are selected in active low. In our project we have used controllers port 1; pins 0-3 for rows and pins 4-7 for columns.
Working:
The first step in the project was the coding. The coding was done in C on keil.
1. Coding:
The code has following major sections: Port assignments: External devices were interface with the 89C52 microcontroller using port assignments. Each port is identified by assigning a variable to it. All keypad outputs (4 rows & 4 Columns) were assigned port 1 (pin 0-7). The LCD was interface with microcontroller using two ports: Data pins were assigned to port 2 (pins 0-7) RS, R/W & En were assigned to pins 3.4, 3.3 & 3.2 respectively on port 3 of the microcontroller. Functions: Different functions have been created to perform specific tasks:
y y y y y y y y
delay; function for delay. command; function to send commands to LCD. data_out; function to send data to the LCD. disp_string; function to write string on LCD. disp_char; function to display numbers on LCD; sends the ASCII values of characters. disp_number; function to display integers on LCD. initialize; function to initialize LCD read_port; function to read keypad
Various functions are made to display characters/numbers on LCD. There is a separate function for displaying Characters (disp_char) and to display two digit numbers such as 11,12, 13 etc, a separate function is defined that makes use of the remainder operation to extract digits one by one from the whole number. Apart from functions to initialize and clear the LCD and reading the keypad are also defined.
y Keypad Scanning: A function read_port scans the keypad using the row and column method described previously it scans first for the pressed row and then for the column and the simply sends the number to one of the functions that display them on the LCD. The scanned number is stored in data_in special function register.
The main function takes the input scanned from the keypad and just performs the basic calculator operations.
2. Simulation:
The code was verified by keil and a .hex file was created. The circuit was created on ISIS Proteus 7 and the .hex file was burned into the microcontroller and the simulation showed successful results and whole functionality of the calculator was implemented in the simulation.
Proteus Simulation
3. Hardware:
The same circuit was implemented on hardware on a PCB board. The layout was taken using proteus and printed on a circuit board. The LCD, Keypad and the Microcontroller were just plucked into their respective bases and the circuit was complete.
Conclusion:
Hence a Digital Arithmetic Calculator was implemented using AT989C52 microcontroller and it was interfaced with external peripherals like LCD and Keypad too. Our project finds its uses in school and academic work. It is very portable and can perform fast calculations at a very reasonable cost.
References:
1. Mr.Haris Anis 2. http://www.atmel.com/dyn/resources/prod_documents/doc0313.pdf 3. http://www.engineersgarage.com/microcontroller/8051projects/interface-lcdat89c51-circuit 4. www.botskool.com