Rs232 Serial Communication Projects:A Simple Calculator Program Using the RS232 Port

PROJECT 24 – A Simple Calculator Program Using the RS232 Port

Function

This is a simple calculator project based upon the 89C51 type microcontroller. The microcontroller is connected to an RS232 serial terminal. The user can perform simple addition, subtraction, multiplication, and division of numbers using the microcontroller.

Circuit Diagram

This project is based upon the 89C51 microcontroller. This is a 40-pin device which is software compatible with the 89C2051 microcontroller. The 89C51 contains a 4 Kbyte flash program memory, 128 bytes of RAM, 32 program- mable input/output lines, and six interrupt sources.

The circuit diagram of this project is shown in Fig. 6.10. A 12 MHz crystal and two capacitors are connected to pins 18 and 19 of the microcontroller. Reset input is connected to a capacitor and a resistor. Transmit output (TXD) and receive input (RXD) of the device are connected to a MAX232 type RS232 converter IC. EA is the external program enable pin and this pin should be connected to +5 V for internal program executions.

Program Description

The program operates as a simple calculator. When power is applied to the microcontroller, a menu is displayed on the user’s terminal and the user is prompted toenter twonumbers and the operation tobe performed. A typical dialogue is given below (note that the characters typed by the user are underlined for clarity):

Rs232-Serial-Communication-Projects-[12]

Rs232-Serial-Communication-Projects-Rs232-Serial-Communication-Projects-[10]

Program Listing

The program listing is given in Fig. 6.11. The serial port is initialized by the function serial_init. The program then prints a heading and a menu using the built-in function printf. The user is prompted to enter the numbers and the operation to be performed. The first number is stored in variable numl using the built-in function scanf. The second number is stored in variable num2. The operation to be performed is stored in variable oper.A switch statement is then used to select the required operation. The result of the calculation is stored in variable result and this is then displayed using a printf function. The program repeats forever unless stopped by the user.

Components Required

The following components will be required for this project:

Rs232-Serial-Communication-Projects-[3]Rs232-Serial-Communication-Projects-[13]Rs232-Serial-Communication-Projects-[16]

Leave a comment

Your email address will not be published. Required fields are marked *