Docsity

It is a project report, Study Guides, Projects, Research of Microcontrollers

Partial preview of the text

Download It is a project report and more Study Guides, Projects, Research Microcontrollers in PDF only on Docsity!

Microcontrollers

& Embedded Systems

(MTS -331)

DE-43 Mechatronics

Syndicate – C

Project Report

AT89C51 Development Board with 4 Modes

Names of Members:

1. NC Ahmed Saeed

Reg # 374405

2. NC Mohammad Bin Tila

Reg # 388525

Submitted to: LD Muhammad Qasim

Table of Contents

  • List of Figures
  • Abstract
    1. INTRODUCTION AND BACKGROUND .................................................................................
    • 1.1 Microcontrollers for Everyday Problem Solving
  • 1.2 The Assembly Language: - 1.2.1 Historical Overview - 1.2.2 Benefits and Drawbacks - 1.2.3 Applications of Assembly Language ................................................................................... - 1.2.4 Assembly Language and Microcontrollers
    • 1.3 The AT89C51 Microcontroller
      • 1.3.1 Historical Background .........................................................................................................
      • 1.3.2 Specifications and Capabilities
      • 1.3.3 Uses and Applications ..........................................................................................................
      • 1.3.4 Benefits of AT89C51
      • 1.3.5 Architecture Overview
      • 1.3.6 Programming Commands and Syntax
    1. CIRCUIT HARDWARE
    • 2.1 Development Board
      • 2.1.1 Crytal Circuit: ....................................................................................................................
      • 2.1.2 Reset and Power Circuits
    • 2.2 Switch board
    1. CIRCUIT SOFTWARE ..............................................................................................................
    • 3.1 Mode
    • 3.2 Mode
    • 3.3 Mode
    • 3.4 Mode
  • Conclusion: ..........................................................................................................................................
  • References and Bibliography
  • Figure 1: 8051 Block structure diagram List of Figures
  • Figure 2: AT89C51 controller (L) and pinout (R)
  • crystal circuits (below) Figure 3: Proteus Schematic for the development board (above), closeups of the rest, power, and
  • Figure 4: Bill of material for the development board
  • Figure 5: witch board PCB (left) and layout (right)
  • (bottom) Figure 6: PCB Schematic for main board (top), PCB model (center) and Physical PCB with controller
  • Figure 7: Switchboard proteus schematic
  • Figure 8: Mode 1 with a negative and overflowing value (P3.2 and P3.3 ON)
  • Figure 9: Even value output in mode 2, P2 is active
  • Figure 10: 87F displayed on Port 0 after conversion
  • Figure 11: Generating PWM on port

Abstract

This is a report for the project of the course MTS-331 Microcontrollers and embedded systems. The goal of the project was to create a generic development board to be used with AT89C51 Microcontrollers as well as to code 4 separate usage modes for it in order to learn about the different capabilities and usages of the 8051 series of microcontrollers as well as the assembly coding language. Both the development board and the program modes were successfully implemented and tested on a self-fabricated PCB board.

Drawbacks:

● Steep Learning Curve : Learning assembly language can be challenging, as it requires a deep understanding of the underlying hardware architecture. ● Portability Issues: Code written in assembly language is often specific to a particular CPU architecture, limiting its portability across different platforms. ● Debugging Complexity: Debugging assembly code can be intricate, as errors may directly impact hardware functionality, and tools for debugging may be limited compared to higher-level languages.

1.2.3 Applications of Assembly Language

Assembly language is commonly employed in scenarios where low-level control over hardware is crucial. One notable application is the programming of microcontrollers, which are embedded into a wide range of electronic devices.

1.2.4 Assembly Language and Microcontrollers

Microcontrollers are integrated circuits designed for specific tasks within electronic systems. Assembly language is particularly well-suited for programming microcontrollers due to the following reasons:

● Real-time Control: Microcontrollers often require real-time control over peripherals and sensors, which can be efficiently achieved through the direct manipulation of hardware registers provided by assembly language. ● Resource Optimization: In resource-constrained environments, such as those found in many microcontroller applications, assembly language allows for precise control over memory and processing resources, resulting in optimized code. ● Minimal Overhead: Microcontrollers typically have limited processing power, and assembly language minimizes the overhead associated with high-level language compilers, allowing for more efficient code execution.[3]

1.3 The AT89C51 Microcontroller

The AT89C51 microcontroller is a key member of the 8051-microcontroller family, widely recognized for its versatility and reliability in embedded systems.

1.3.1 Historical Background

The AT89C51 is based on the 8051 architecture, which was first introduced by Intel in 1980. Over the years, the 8051-microcontroller family has gained widespread adoption due to its robust design, broad industry support, and compatibility with various programming languages, including assembly and C.[4]

1.3.2 Specifications and Capabilities

Clock Frequency: Typically operates at frequencies ranging from 1 MHz to 24 MHz.

Memory: Features 4 KB of Flash memory for program storage and 128 bytes of RAM for data storage.

I/O Ports : Four parallel I/O ports (P0, P1, P2, and P3) provide general-purpose digital I/O capabilities.

Peripheral Integration: The AT89C51 integrates various peripherals such as timers, counters, and serial communication ports, enhancing its suitability for diverse applications.

Timers/Counters: It features two 16-bit timers/counters, labeled as Timer 0 and Timer 1. These timers are crucial for various timing and control applications.

Serial Communication: The AT89C51 supports full-duplex UART (Universal Asynchronous Receiver/Transmitter) for serial communication.

Interrupts: It supports both external and internal interrupts to handle real-time events efficiently.

On-Chip Oscillator and Clock Circuitry: The microcontroller has an on-chip oscillator and clock circuitry, reducing the need for external components.

Supply Voltage: The typical operating voltage is in the range of 4.0 to 5.5 volts.

Development Tools: ATMEL provides a range of development tools, including assemblers, compilers, and debuggers, to facilitate software development for the AT89C51.[5]

1.3.3 Uses and Applications

The AT89C51 microcontroller finds application in a broad range of embedded systems, including but not limited to:

Industrial Automation: Control systems for manufacturing processes and machinery.

1.3.6 Programming Commands and Syntax

ORG 0H ; Set the origin address to 0 MOV A, #55H ; Load the value 55H into register A MOV P1, A ; Move the value in A to Port 1 END ; END operation ● ORG: Sets the origin address for the program. ● MOV: Moves data between registers or memory locations. ● A: Accumulator register. ● P1: Port 1 of the microcontroller. ● END: End of code

These assembly language commands illustrate the basic syntax for programming the AT89C51 microcontroller.

2. CIRCUIT HARDWARE

The hardware for the project involves two printed circuit boards. The main board houses an 8051 microcontroller along with a series of LED bars and their controllers and resistor pack. There are also pins available to take outputs and inputs from the ports which can be done through the second PCB which is a board housing Dipswitches which can be used as inputs when connected to the main board. The layouts for the boards are further explained below.

2.1 Development Board

The schematic and bill of materials for the main board are shown below.

Crystal: The crystal itself is the key component. It is a piece of quartz or other piezoelectric material that exhibits a predictable and stable resonant frequency. In this case it is a 12 MHz crystal.

Two Capacitors (Load Capacitors): The crystal requires a capacitive load to operate properly. Two capacitors are connected to the crystal, one on each side. These capacitors are often referred to as load capacitors. The capacitors help set the resonance frequency of the crystal and stabilize the oscillation. The crystal circuit is connected to the XTAL 1 and XTAL 2 pins of the controller.

The basic operation of the crystal oscillator involves the crystal vibrating at its resonant frequency. The feedback network amplifies the signal, and the crystal provides a precise frequency reference. The capacitors are critical in providing the necessary capacitance for the crystal to operate within its specified range. The values of the capacitors are chosen based on the characteristics of the crystal and the requirements of the oscillator circuit. The correct capacitance values are crucial for ensuring stable and accurate oscillation.

2.1.2 Reset and Power Circuits

These are rather simple circuits with single set tasks, the rest circuit contains a button and a bypass capacitor which can be connected to the res pin of the 8051 in order to be able to reset it. The power circuit controls the flow of power to the entire system; hence it has a 7805-voltage regulator IC to ensure safe operation of the system when externally powered. It also has an LED to indicate whether the board is on or not.

2.2 Switch board

The switch board is a small PCB board with a series of Dipswitches that is used to give inputs to port 1 on the main board as well ss to act as the external interrupt provider for the P3.0 and

P3.1 pins. This board has its own voltage regulator as well.

3. CIRCUIT SOFTWARE

The software portion of the project was divided into 4 modes, which were activated using the external interrupt pins. Namely, mode 1, 2, 3, 4. The code below shows how pins 3.0 and 3. are checked every time the code is ran to activate the 4 modes as required by the user.

3.1 Mode 1

Mode 1 basically solves a quadratic equation to calculate the height attained by the ball when it is thrown up with some initial velocity. This common equation of motion is used for this purpose.

H = Vi t + Â― gt^2

The value of the time will be taken from the user on port 1, with g taken as -10 and Vi taken as 100. The low byte of the height is displayed on port 0 and the high bite on port 2 for exactly 1.5 seconds. If the value of distance exceeds 2 bytes, P3.2 is set and if it is negative

3.3 Mode 3

In this mode, a temperature conversion I to be done from Celsius to Fahrenheit. The Celsius temperature is taken from the user on port 1 and then converted to Fahrenheit and displayed on port 0 in packed BCD. The conversion Is done using the formula,

F = 9/5 C + 32

If the resulting Fahrenheit value is less than 99, the values on port 0 will blink, whereas if the value exceeds 99F, the lights on port 2 will blink instead. This code, given at the end, first takes the input and checks whether the result is going to be higher than 99F (which is done by making sure that the input is equal to or greater than 38C), if so, port 2 will blink. If not, then the conversion will take place, the centigrade value is first multiplied by 9, leading to a 2–4-byte number, which is then stored at successive memory locations so it can be divided by 5 in parts. After the division, the result is combined back into a byte, 32 is added to it, and it is divided by 10 to convert t into packed BCD after which it is displayed at port 0 with a blink.

3.4 Mode 4

The last mode requires the controller to generate a PWM signal with duty cycle of given input, which is a digital binary number on port 1, and then display it on port 2 with a frequency of 80Hz. This code, given at the end, first pushes all the registers to the stack, it then checks the input and makes sure it is not 0 or 255 as these would result in constant values and not PWM signals. For the other values, the timer is set up along with constants. For 80 HZ the timer is always loaded with 53036, and depending on P1, a value is added to it. E.g. if P1 is 1, then 255-1 = 254 is added, however, this is always done with the constant value of 49 (1250 Ξs) along with it to ensure correct PWM. The correct PWM after calculations is displayed on port 2 and the values are popped back into the stack at the end.