Vous êtes sur la page 1sur 51

SIX WEEKS INDUSTRIAL TRAINING REPORT

Submitted for partial fulfillment of award of

BACHELOR OF ELECTRONICS & COMMUNICATION ENGINEERING

Submitted by:
Manoj Sethi Uni.Roll No:100230492505 College Roll No: ECE/71/09 3rd Year ECE

Table of Contents
Preface 1

Acknowledgement ....3 Microcontroller Pin Configuration Reset Circuit Ram Architecture 8 Register Banks ..9 Bit Memory .9 Special Function Register Memory ..9 Registers. 10 Microcontroller VS Microprocessor .12 Bus 13 Serial Communication 14 Interfacing 2 7 4 6

Seven Segment Display.. ..18 Liquid Crystal Display(LCD) .. .20 DC Motor.. .24 Stepper Motor.. .25 Project Description and Coding Basic Overview of Digital Clock.. 29 Coding in Assembly Language.. ..32 Advantages of C Language over Assembly Language.. 34 Coding in C Language.. ..35 Circuit Diagram.. 39

PREFACE
This training report is all about the embedded systems and its application in various fields of real world. We are living in the Embedded World. We are surrounded with many embedded products and our daily life largely depends on the proper functioning of these gadgets.
3

Television, Radio, CD player, Washing Machine or Microwave Oven in our kitchen, Card readers, Access Controllers, Palm devices of our work space enable us to do many of our tasks very effectively. Apart from all these, many controllers embedded in our car take care of car operations between the bumpers. All kinds of magazines and journals regularly dish out details about latest technologies, new devices, fast applications which make us believe that our basic survival is controlled by these embedded products. Now we can agree to the fact that these embedded products have successfully invaded into our world. What is this Embedded System? Theoretically, an embedded controller is a combination of piece of microprocessor based hardware and the suitable software to undertake a specific task. I have made a Project based on Microcontroller that is a Digital Clock. This training report covers all about the microcontroller and project description. In this project I have implemented the Digital Clock that is describing a small application of microcontroller.

ACKNOWLEDGEMENT
I Manoj Sethi, Bachelors Student of DAV Institute of Engineering and Technology, Jalandhar, majoring in Electronics and Communication Engineering express my heartfelt thanks to our Training and Placement Officers for Providing us their valuable guidance & sharp vision to undertake this six week industrial training. Training in an institute like Labs&Racks which is fuelled with individuals with so much zest and energy, teaming up to form a formidable forcem was in itself a trye learning experience which is goung to help us immensely in our career. There is no substitute of teamwork, this is one of the best lesson I learnt during our training in Labs&Racks institute I would like to thank and express my gratitude towards the personalities who have helped me a lot to undertake and complete this training. First and formost I express my gratitude towards Mr. Gaurav Garg for his support during my Training. He provided me valuable guidance and technical skill without which this training would not have been possible. Special thanks to the talented people at Labs&Racks to all of them and to each one individually. They were growing the source of inspiration for us throughout the development process of this Project

I am deeply indebted to my HOD Mrs. Neeru Malhotra whose help, stimulating suggestions and encouragements was always with me. Manoj Sethi

MICROCONTROLLERS
Introduction
Circumstances that we find ourselves in today in the field of microcontrollers had their beginnings in the development of technology of integrated circuits. This development has made it possible to store hundreds of thousands of transistors into one chip. That was a prerequisite for production of microprocessors, and the first computers were made by adding external peripherals such as memory, inputoutput lines, timers and other. Further increasing of the volume of the package resulted in creation of integrated circuits. These integrated circuits contained both processor and peripherals. That is how the first chip containing a microcomputer, or what would later be known as a microcontroller came about. Definition of a Microcontroller Microcontroller, as the name suggests, are small controllers. They are like single chip computers that are often embedded into other systems to function as processing/controlling unit. For example, the remote control you are using probably has microcontrollers inside that do decoding and other controlling functions. They are also used in automobiles, washing machines, microwave ovens, toys ... etc, where automation is needed. The key features of microcontrollers include: 1. High Integration of Functionality
7

Microcontrollers sometimes are called single-chip computers because they have on-chip memory and I/O circuitry and other circuitries that enable them to function as small standalone computers without other supporting circuitry. 3. Field Programmability, Flexibility 4. Microcontrollers often use EEPROM or EPROM as their storage device to allow field programmability so they are flexible to use. Once the program is tested to be correct then large quantities of microcontrollers can be programmed to be used in embedded systems. 5. Easy to Use
2.

Assembly language is often used in microcontrollers and since they usually follow RISC architecture, the instruction set is small. The development package of microcontrollers often includes an assembler, a simulator, a programmer to "burn" the chip and a demonstration board. Some packages include a high level language compiler such as a C compiler and more sophisticated libraries. Most microcontrollers will also combine other devices such as: 1. A Timer module to allow the microcontroller to perform tasks for certain time periods. 2. A serial I/O port to allow data to flow between the microcontroller and other devices such as a PC or another microcontroller. 3. An ADC to allow the microcontroller to accept analogue input data for processing.

Figure 1: Showing a typical microcontroller device and its different subunits

PIN CONFIGURATION

Figure 2 Pin configuration of Microcontroller We have 4 ports in 8051 micro controller. They are port0, port1, port2, port3 which can be accessed as i/o ports. The pins of the micro controller are explained below. RXD: It receives data in serial communication. TXD: It transmits data in serial communication. INT0: External interrupt for timer 0. INT1: External interrupt for timer1 T0: Timer0. T1: Timer1. RD: To read into external memory. WR: To write into external memory. XTAL1 & XTAL2: To connect the crystal oscillator. ALE: Address latch enable which is used to access the address locations from external memory.

10

PSEN: Program store enable which is used for storing programming code into the external memory. EA: External Access: 64 KB of ROM is the limit for external memory. RESET CIRCUIT

Figure3 : Reset circuit of microcontroller Capacitor is storing charge permanently until we use it. Crystal Oscillator is used to generate a carrier signal with stable frequency. With the help of this oscillator we will deduce the execution speed in terms of bytes/ sec.It
11

generates 12 clock pulses /machine cycle. Capacitors provide charge for crystal oscillator. If we are not connecting any external memory to micro controller, EA is connected to Vcc in case of 8051.

RAM ARCHITECTURE

Figure 4: Ram Architecture

12

The 8051 has a bank of 128 bytes of Internal RAM. This Internal RAM is found on-chip on the 8051 so it is the fastest RAM available, and it is also the most flexible in terms of reading, writing, and modifying its contents. Internal RAM is volatile, so when the 8051 is reset this memory is cleared. The 128 bytes of internal ram is subdivided as shown on the memory map. The first 8 bytes (00h - 07h) are "register bank 0". These alternative register banks are located in internal RAM in addresses 08h through 1Fh.Bit memory actually resides in internal RAM, from addresses 20h through 2Fh. The 80 bytes remaining of Internal RAM, from addresses 30h through 7Fh, may be used by user variables that need to be accessed frequently or at high-speed. This area is also utilized by the microcontroller as a storage area for the operating stack.

Register Banks The 8051 uses 8 "R" registers which are used in many of its instructions. These "R" registers are numbered from 0 through 7 (R0, R1, R2, R3, R4, R5, R6, and R7).These registers are generally used to assist in manipulating values and moving data from one memory location to another. The concept of register banks adds a great level of flexibility to the 8051. Bit Memory The 8051, being a communication oriented microcontroller, gives the user the ability to access a number of bit variables. These variables may be either 1 or 0. There are 128 bit
13

variables available to the user, numbered 00h through 7Fh. The user may make use of these variables with commands such as SETB and CLR. It is important to note that Bit Memory is really a part of Internal RAM. In fact, the 128 bit variables occupy the 16 bytes of Internal RAM from 20h through 2Fh. Special Function Register (SFR) Memory Special Function Registers (SFRs) are areas of memory that control specific functionality of the 8051 processor. For example, four SFRs permit access to the 8051s 32 input/output lines. Another SFR allows a program to read or write to the 8051s serial port. SFR is a part of Internal Memory. This is not the case. When using this method of memory access (its called direct address), any instruction that has an address of 00h through 7Fh refers to an Internal RAM memory address; any instruction with an address of 80h through FFh refers to an SFR control register.

Registers
The Accumulator
14

The Accumulator, as its name suggests, is used as a general register to accumulate the results of a large number of instructions. It can hold an 8-bit (1-byte) value and is the most versatile register The "R" registers The "R" registers are a set of eight registers that are named R0, R1, etc. up to and including R7. These registers are used as auxiliary registers in many operations. The "B" Register The "B" register is very similar to the Accumulator in the sense that it may hold an 8-bit (1-byte) value. The "B" register is only used by two 8051 instructions: MUL AB and DIV AB. The Data Pointer (DPTR) The Data Pointer (DPTR) is the 8051s only user-accessible 16-bit (2-byte) register. The Accumulator, "R" registers, and "B" register are all 1-byte values. DPTR, as the name suggests, is used to point to data. It is used by a number of commands which allow the 8051 to access external memory. The Program Counter (PC) The Program Counter (PC) is a 2-byte address which tells the 8051 where the next instruction to execute is found in memory. When the 8051 is initialized PC always starts at 0000h and is incremented each time an instruction is executed.
15

The Stack Pointer (SP) The Stack Pointer, like all registers except DPTR and PC, may hold an 8-bit (1-byte) value. The Stack Pointer is used to indicate where the next value to be removed from the stack should be Addressing Modes An "addressing mode" refers to how you are addressing a given memory location. The addressing modes are as follows, With an example of each: Immediate Addressing MOV A, #20h Direct Addressing MOV A, #30h Indirect Addressing MOV A, @R0 External Direct MOVX A, @DPTR Code Indirect MOVC A, @A+DPTR Each of these flexibility. Interrupts An interrupt is a special feature which allows the 8051 to provide the illusion of "multitasking," although in reality the 8051 is only doing one thing at a time. Timers
16

addressing

modes

provides

important

Timers are one of the categories of hardware time delays. Time delays are used to keep a system into halting System or sleepy mode. We have two timers-timer0, timer1.Hardware time delays are used to generate exact time delays.

Microcontrollers versus Microprocessors


Microcontroller differs from a microprocessor in many ways. First and the most important is its functionality. In order for a microprocessor to be used, other components such as memory, or components for receiving and sending data must be added to it. In short that means that microprocessor is the very heart of the computer. On the other hand, microcontroller is designed to be all of that in one. No other external components are needed for its application because all necessary peripherals are already built into it. Thus, we save the time and space needed to construct devices. Central Processing Unit Let add 3 more memory locations to a specific block that will have a built in capability to multiply, divide, subtract, and move its contents from one memory location onto another. The part we just added in is called "central processing unit" (CPU). Its memory locations are called registers.
17

Figure 5: Simplified central processing unit with three registers Registers are therefore memory locations whose role is to help with performing various mathematical operations or any other operations with data wherever data can be found. Look at the current situation. We have two independent entities (memory and CPU) which are interconnected, and thus any exchange of data is hindered, as well as its functionality. If, for example, we wish to add the contents of two memory locations and return the result again back to memory, we would need a connection between memory and CPU. Simply stated, we must have some "way" through data goes from one block to another. Bus That "way" is called "bus". Physically, it represents a group of 8, 16, or more wires. There are two types of buses: address and data bus. The first one consists of as many lines as the amount of memory we wish to address and the other one is as wide as data, in our case 8 bits or the connection line. First one serves to transmit address from CPU memory, and the second to connect all blocks inside the microcontroller.
18

Figure 6: Showing connection between memory and central unit using buses

As far as functionality, the situation has improved, but a new problem has also appeared, we have a unit that's capable of working by itself, but which does not have any contact with the outside world, or with us! In order to remove this deficiency, let's add a block which contains several memory locations whose one end is connected to the data bus, and the other has connection with the output lines on the microcontroller which can be seen as pins on the electronic component.

Input-output unit
19

Those locations we've just added are called "ports". There are several types of ports: input, output or bidirectional ports. When working with ports, first of all it is necessary to choose which port we need to work with, and then to send data to, or take it from the port.

Figure 7: Simplified input-output unit communicating with external world When working with it the port acts like a memory location. Something is simply being writteninto or read from it, and it could be noticed on the pins of the microcontroller.

20

Serial communication Beside stated above we've added to the already existing unit the possibility of communication with an outside world. However, this way of communicating has its drawbacks. One of the basic drawbacks is the number of lines which need to be used in order to transfer data. What if it is being transferred to a distance of several kilometers? The number of lines times number of kilometers doesn't promise the economy of the project. It leaves us having to reduce the number of lines in such a way that we don't lessen its functionality. Suppose we are working with three lines only, and that one line is used for sending data, other for receiving, and the third one is used as a reference line for both the input and the output side. In order for this to work, we need to set the rules of exchange of data. These rules are called protocol. Protocol is therefore defined in advance so there wouldn't be any misunderstanding between the sides that are communicating with each other. For example, if one man is speaking in French, and the other in English, it is highly unlikely that they will quickly and effectively understand each other. Let's suppose we have the following protocol. The logical unit "1" is set up on the transmitting line until transfer begins. Once the transfer starts, we lower the transmission line to logical "0" for a period of time (which we will designate as T), so the receiving side will know that it is receiving data, and so it will activate its mechanism for reception. Let's go back now to the transmission side and start putting logic zeros and ones onto the transmitter line in the order from a bit of the lowest value to a bit of the highest
21

value. Let each bit stay on line for a time period which is equal to T, and in the end, or after the 8th bit, let us bring the logical unit "1" back on the line which will mark the end of the transmission of one data. The protocol we've just described is called in professional literature NRZ (Non-Return to Zero).

Figure 8: Serial unit sending data through three lines only As we have separate lines for receiving and sending, it is possible to receive and send data (info.) at the same time. So called full-duplex mode block which enables this way of communication is called a serial communication block. Unlike the parallel transmission, data moves here bit by bit, or in a series of bits what defines the term serial communication comes from. After the reception of data we need to read it from the receiving location and store it in memory as opposed to sending where the process is reversed. Data goes from memory through the bus to the sending location, and then to the receiving unit according to the protocol. Timer unit Since we have the serial communication explained, we can receive, send and process data.

22

Figure 9: Timer unit generating signals in regular time intervals However, in order to utilize it in industry we need a few additionally blocks. One of those is the timer block which is significant to us because it can give us information about time, duration, protocol etc. The basic unit of the timer is a free-run counter which is in fact a register whose numeric value increments by one in even intervals, so that by taking its value during periods T1 and T2 and on the basis of their difference we can determine how much time has elapsed. This is a very important part of the microcontroller whose understanding requires most of our time.

Figure 10: Physical configuration of the interior of a microcontroller

23

Figure 11: Microcontroller outline with basic elements and internal connections For a real application, a microcontroller alone is not enough. Beside a microcontroller, we need a program that would be executed, and a few more elements which make up interface logic towards the elements of regulation (which will be discussed next).

24

INTERFACING
Seven Segment Display The seven segment display is one of the commonly used display devices in the world of electronics. Easy of operation and good visual indication has made their use in low cost circuits e.g. counter and speedometer and even in costly devices e.g. power system static protective relays. Seven segment display is a great utility at low cost. Seven segment display is collection of seven led. In a simple LED package, each LED is typically connected with one terminal to its own pin on the outside of the package and the other LED terminal connected in common with all other LEDs in the device and brought out to a shared pin. This shared pin will then make up all of the cathodes (negative terminals) OR all of the anodes (positive terminals) of the LEDs in the device; and so will be either a "Common Cathode" or "Common Anode" device depending how it is constructed.

How to display digits on seven segment display Apply proper polarity to common pin. Make the required segment pin low or high depending on the type of display. You can refer the table given below to send respective hex value for displaying numbers from 0 to 9.
25

Interfacing seven segment display to microcontroller In early days to drive the seven segment decoder was used with it and the BCD was send to the decoder IC. But the microcontroller has eliminated the use of decoder as already decoded data is sent to the seven segment display. Common anode display are most suitable for interfacing with 8051 since 8051 port pins can sink current better than sourcing it. Connect the a to g pins and dot pin of seven segment display to the 8-bit port of microcontroller Now send the respective hex data to display specific number on seven segment display on that port. Give some delay and repeat the process if you want to display another digit. Change the value of resistor to obtain required contrast Circuit Diagram

26

27

LCD INTERFACING LCD stands for Liquid Crystal Display. The most commonly used LCDs found in the market today are 1 Line, 2 Line or 4 Line LCDs which have only 1 controller and support at most of 80 characters.

The LCD discussed in this section has 14 pins. The function of each pin is given in table.

Vcc, Vss, and VEE: While Vcc and Vss provide +5V and ground, respectively, VEE is used for controlling LCD contrast. RS register select:
28

There are two very important registers inside the LCD. The RS pin is used for their selection as follows. If RS = 0, the instruction command code register is selected, allowing the user to send a command such as clear display, cursor at home, etc. If RS = 1 the data register is selected, allowing the user to send data to be displayed on the LCD. R/W read/write: R/W input allows the user to write information to the LCD or read information from it. R/W = 1 when reading; R/W =0 when writing. E enable: The enable pin is used by the LCD to latch information presented to its data pins. When data is supplied to data pins, a high to low pulse must be applied to this pin in order for the LCD to latch in the data present at the data pins. This pulse must be a minimum of 450 ns wide. D0 D7: The 8 bit data pins, D0 D7, are used to send information to the LCD or read the contents of the LCDs internal registers. To display letters and numbers, we send ASCII codes for the letters A Z, a z, and numbers 0 9 to these pins while making RS = 1. There are also instructions command codes that can be sent to the LCD to clear the display or force the cursor to the home position or blink the cursor. Table below lists the instruction command codes.

29

LCD Commands table We also use RS = 0 to check the busy flag bit to see if the LCD is ready to receive information. The busy flag is D7 and can be read when R/W =1 and RS = 0, as follows: if R/W =1, RS =0. When D7 = 1(busy flag = 1), the LCD busy taking care of internal operations and will not accept any new information. When D7 = 0, the LCD is ready to receive new information. Note: It is recommended to check the busy flag before writing any data to the LCD. DDRAM - Display Data RAM Display data RAM (DDRAM) stores display data represented in 8-bit character codes. Its extended capacity is 80 X 8 bits, or 80 characters. The area in display data RAM (DDRAM) that is not used for display can be used as general data RAM. So whatever you send on the DDRAM is actually displayed on the LCD.

30

BF - Busy Flag Busy Flag is a status indicator flag for LCD. When we send a command or data to the LCD for processing, this flag is set (i.e. BF =1) and as soon as the instruction is executed successfully this flag is cleared (BF = 0). This is helpful in producing and exact amount of delay. For the LCD processing. To read Busy Flag, the condition RS = 0 and R/W = 1 must be met and The MSB of the LCD data bus (D7) act as busy flag. When BF = 1 means LCD is busy and will not accept next command or data and BF = 0 means LCD is ready for the next command or data to process. Instruction Register (IR) and Data Register (DR) There are two 8-bit registers controller Instruction and Data register. Instruction register corresponds to the register where you send commands to LCD e.g. LCD shift command, LCD clear, LCD address etc. and Data register is used for storing data which is to be displayed on LCD. When send the enable signal of the LCD is asserted, the data on the pins is latched in to the data register and data is then moved automatically to the DDRAM and hence is displayed on the LCD.

Commands and Instruction set Only the instruction register (IR) and the data register (DR) of the LCD can be controlled by the MCU. Before starting the internal operation of the LCD, control information is temporarily stored into these registers to allow interfacing with various MCUs, which operate at different speeds, or
31

various peripheral control devices. The internal operation of the LCD is determined by signals sent from the MCU. Sending Commands to LCD To send commands we simply need to select the command register. Everything is same as we have done in the initialization routine. But we will summarize the common steps and put them in a single subroutine. Following are the steps: 1. Move data to LCD port 2. Select command register 3. Select write operation 4. Send enable signal 5. Wait for LCD to process the command

DC MOTOR INTERFACING
32

This section begins with an overview of the basic operation of DC motors. Then we describe how to interface a DC motor to the 8051. Finally, we use Assembly and C language programs to demonstrate the concept of pulse width modulation (PWM) and show how to control the speed and direction of a DC motor. DC motors A direct current (DC) motor is another widely used device that translates electrical pulses into mechanical movement. In the DC motor we have only + and leads. Connecting them to a DC voltage source moves the motor in one direction. By reversing the polarity, the DC motor will move in the opposite direction. One can easily experiment with the DC motor. For example, small fans used in many motherboards to cool the CPU are run by DC motors. By connecting their leads to the + and voltage source, the DC motor moves. While a stepper motor moves in steps of 1 to 15 degrees, the DC motor moves continuously. In a stepper motor, if we know the starting position we can easily count the number of steps the motor has moved and calculate the final position of the motor. This is not possible in a DC motor. The maximum speed of a DC motor is indicated in rpm and is given in the data sheet. The DC motor has two rpms: no-load and loaded. The manufacturers data sheet gives the no-load rpm. The no-load rpm can be from a few thousand to tens of thousands. The rpm is reduced when moving a load and it decreases as the load is increased. For example, a drill turning a screw has a much lower rpm speed than when it is in the no-load situation. DC motors also have voltage and current ratings. The nominal voltage is the voltage for that motor under normal conditions, and can be from 1 to 150V, depending on the motor. As we increase the voltage, the rpm goes up. The current rating is the current consumption when the nominal voltage is applied with no load, and can be from 25mA to a few amps. As the load increases, the rpm is decreased, unless the current or voltage provided to the
33

motor is increased, which in turn increases the torque. With a fixed voltage, as the load increases, the current (power) consumption of a DC motor is increased. If we overload the motor it will stall, and that can damage the motor due to the heat generated by high current consumption.

Stepper Motor A stepper motor is a brushless, synchronous electric motor that converts electrical pulses into mechanical movement. Every revolution of the stepper motor is divided into a discrete number of steps, and the motor must be sent a separate pulse for each step. Since each pulse causes the motor to rotate a precise angle, the motors position can be controlled without any feedback mechanism. As the electrical pulses increase in frequency, the step movement changes into continuous rotation, with the speed of rotation directly proportional to the frequency of the pulses. Step motors are used every day in both industrial and commercial applications because of their low cost, high reliability, high torque at low speeds and a simple, rugged construction that operates in almost any environment. Unipolar stepper motor The unipolar stepper motor has five or six wires and four coils (actually two coils divided by center connections on each coil). The center connections of the coils are tied together and used as the power connection. They are called unipolar steppers because power always comes in on this one pole.

34

Unipolar Stepper Motor Windings

Bipolar stepper motor The bipolar stepper motor usually has four wires coming out of it. Unlike unipolar steppers, bipolar steppers have no common center connection. They have two independent sets of coils instead. You can distinguish them from unipolar steppers by measuring the resistance between the wires. You should find two pairs of wires with equal resistance. If youve got the leads of your meter connected to two wires that are not connected, you should see infinite resistance.

Bipolar Stepper Motor windings

Stepper Motor interfacing with Microcontrollers Stepper motors can be used in various areas of microcontroller projects such as making robots, robotic arm, automatic door lock system etc.Here,I will discuss different controlling types (Half step and Full step), Interfacing Techniques (using L293D or ULN2003) to control stepper motor. Step Sequence Stepper motors can be driven in two different patterns or sqeunces. namely, Full Step Sequence Half Step Sequence Full Step Sequence

35

In the full step sequence, two coils are energized at the same time and motor shaft rotates. The order in which coils has to be energized is given in the table below.

Full Step Sequence Half Step Sequence In Half mode step sequence, motor step angle reduces to half the angle in full mode. So the angualar resolution is also increased i.e. it becomes double the angular resolution in full mode. Also in half mode sequence the number of steps gets doubled as that of full mode. Half mode is usually preffered over full mode.

Step Angle Step angle of the stepper motor is defined as the angle traversed by the motor in one step. To calculate step angle,simply divide 360 by number of steps a motor takes to complete one revolution. As we have seen that in half mode, the number of steps taken by the motor to complete one revolution gets doubled, so step angle reduces to half.
36

As in above examples, Stepper Motor rotating in full mode takes 4 steps to complete a revolution, So step angle can be calculated as Step Angle = 360 / 4 = 90 and in case of half mode step angle gets half so 45. So this way we can calculate step angle for any stepper motor. Usually step angle is given in the spec sheet of the stepper motor you are using. Knowing stepper motors step angle helps you calibrate the rotation of motor also to helps you move the motor to correct angular position.

37

Basic Overview of Digital Clock


A digital clock is a type of clock that displays the time digitally, i.e. in cyphers, as opposed to an analog clock, where the time is displayed by hands. Digital clocks are often associated with electronic drives, but the "digital" description refers only to the display, not to the drive mechanism. (Both analog and digital clocks can be driven either mechanically or electronically, but "clockwork" mechanisms with digital displays are rare.) The biggest digital clock is the Lichtzeitpegel ("Light Time Level") on the television tower Rheinturm Dsseldorf, Germany. History Perhaps the earliest digital timepieces were Plato clocks. These spring-wound pieces consisted of a glass cylinder with a column inside, affixed to which were small digital cards with numbers printed on them, which flipped as time passed. The Plato clocks were introduced at the St. Louis World Fair in 1904, produced by Ansonia Clock Company. Eugene Fitch of New York patented the clock design in 1903. Josef Pallweber, a Swiss timepiece maker born in Salzburg, Austria, created and produced a mechanic-digital clock model in 1956. The earliest patent for a digital clock was held in the United States by D.E Protzmann and others. Dated October 23, 1956, this patent describes a digital alarm clock. D.E Protzmann and his associates also patented another digital clock in 1970, which was said to use a minimal amount of moving parts. Two side-plates held digital numerals between them, while an electric motor and cam gear outside controlled movement. In 1970, the first digital wristwatch with an LED display was mass-produced. Called the Pulsar, and produced by the Hamilton Watch Company, this watch was hinted at two
38

years prior when the same company created a prototype digital watch for Kubrick's 2001: A Space Odyssey. Throughout the 1970s, despite the initial hefty cost of digital watches, the popularity of said devices steadily rose. Construction Digital clocks typically use the 50 or 60 hertz oscillation of AC power or a 32,768 hertz crystal oscillator as in a quartz clock to keep time. Most digital clocks display the hour of the day in 24 hour format; in the United States and a few other countries, a more commonly used hour sequence is 12 hour format (with some indication of AM or PM). Some clocks can display either time mode according to the owner's preference. Emulations of analog-style faces often use an LCD screen, and these are also sometimes described as "digital". Displays

A digital clock's display changing numbers.

An LCD battery operated clock without alarm. To represent the time, most digital clocks use a sevensegment LED, VFD, or LCD display for each of four digits. They generally also include other elements to indicate whether the time is AM or PM, whether or not an alarm is set, and so on. Setting

39

Some people find difficulty in setting the time in some designs of digital clocks. Therefore in electronic devices where the clock is not a critical function, often they are not set at all, displaying the default after powered on, 00:00 or 12:00. Since they run on electricity, digital clocks must be reset every time the power is cut off. This is a particular problem with alarm clocks that have no "battery" backup, because even a very brief power outage during the night usually results in the clock failing to trigger the alarm in the morning. To reduce the problem, many devices designed to operate on household electricity incorporate a battery backup to maintain the time during power outages and during times of disconnection from the power supply. More recently, some devices incorporate a method for automatically setting the time, such as using a broadcast radio time signal from an atomic clock, getting the time from an existing satellite television or computer connection, or by being set at the factory and then maintaining the time from then on with a quartz movement powered by an internal rechargeable battery. Uses

A digital clock built into an oven.

Because digital clocks can be very small and inexpensive devices that enhance the popularity of product designs, they are often incorporated into all kinds of devices such as cars, radios, televisions, microwave ovens, standard ovens, computers and cell phones. Sometimes their usefulness is disputed: a
40

common complaint is that when time has to be set to Daylight Saving Time, many household clocks have to be readjusted. The incorporation of automatic synchronisation by a radio time signal is reducing this problem.

41

Programming of Digital Clock In Assembly Language


ORG 00H MOV P2,#38H ACALL COMMAND MOV P2,#0EH ACALL COMMAND MOV P2,#01H ACALL COMMAND MOV R1,#1EH MOV @R1,#'0' INC R1 MOV @R1,#'1' INC R1 MOV @R1,#'2' INC R1 MOV @R1,#'3' INC R1 MOV @R1,#'4' INC R1 MOV @R1,#'5' INC R1 MOV @R1,#'6' INC R1 MOV @R1,#'7' INC R1 MOV @R1,#'8' INC R1 MOV @R1,#'9' CLR PSW.4 SETB PSW.3 MOV R1,#1EH MOV R4,#05H LOOPM1:MOV P2,#8BH ACALL COMMAND MOV P2,@R1 ACALL DETA INC R1 MOV R7,#0AH MOV R0,#1EH
42

LOOPM0: MOV P2,#8CH ACALL COMMAND MOV P2,@R0 ACALL DETA INC R0 CLR PSW.3 CLR PSW.4 MOV R6,#05H MOV R0,#1EH MOV P2,#8DH ACALL COMMAND MOV P2,':' ACALL DETA LOOPS1: MOV P2,#8EH ACALL COMMAND MOV P2,@R0 ACALL DETA INC R0 MOV R5,#0AH MOV R1,#1EH LOOPS0: MOV P2,#8FH ACALL COMMAND MOV P2,@R1 ACALL DETA ACALL DELAY INC R1 DJNZ R5,LOOPS0 DJNZ R6,LOOPS1 DJNZ R7,LOOPM0 DJNZ R4,LOOPM1 ORG 2AH COMMAND: MOV P2,A CLR P3.0 CLR P3.1 SETB P3.2 ACALL DELAY CLR P3.2
43

RET DETA: MOV P2,A SETB P3.0 CLR P3.1 SETB P3.2 ACALL DELAY CLR P3.2 RET ORG 4CH DELAY:MOV R2,#100 DELAY1:MOV TMOD,#10H MOV TH1,#0DBH MOV TL1,#0FFH SETB TR1 BACK: JNB TF1,BACK CLR TR1 CLR TF1 DJNZ R2,DELAY1 RET END

This is the Code For the Digital Clock in Assembly Language but Coding in Assembly Language has one disadvantage over the C Language. In Assembly Language we cannot set the time easily as we have to use the registers and have to use the address locations which we have assigned to the numerics. But in C Language we are not in concern with the address location and registers. Advantages of C over Assembly Using a high-level language like C has many advantages over assembly language programming: Knowledge of the processor instruction set is not required. A rudimentary knowledge of the memory architecture of the 8051 is desirable, but is not necessary. Details like register allocation and addressing modes are managed entirely by the compiler.
44

The ability to combine variable selection with specific operations improves program readability. Keywords and operational functions that more nearly resemble the human thought process can be used. Program development and debugging times are dramatically reduced when compared to assembly language programming. The supplied library files provide many standard routines (such as formatted output, data conversions, and floating-point arithmetic) that may be incorporated into your application. Existing programs can be reused in new programs by utilizing the modular programming techniques available with C. The C language is a very portable and popular language. C compilers can be obtained for almost all target systems. This means that existing program software investments can be quickly and easily converted from or adapted to other processors or environments.

45

Programming For Digital Clock in C Language


#include<reg51.h> sbit swt1=P1^0; sbit swt2=P1^1; sbit swt3=P1^2; sbit swt4=P1^3; sbit swt5=P1^4; sbit swt6=P1^5; void alarm(); void delay(); void command(); void deta(); void timeset(); int sec0,sec1,min0,min1,hr0,hr1; int almhr0,almhr1,almmin0,almmin1; char array[]={'0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; void main() { //char array[]={'0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; P1=0; P2=0x38; command(); P2=0x0e; command(); P2=0x01; command(); for(hr0=0;hr0<=2;hr0++) { P2=0x88; command(); P2=array[hr0]; deta(); for(hr1=0;hr1<=9;hr1++) { P2=0x89; command(); P2=array[hr1]; deta(); P2=':'; deta();
46

for(min0=0;min0<=5;min0++) { P2=0x8b; command(); P2=array[min0]; deta(); delay(); for(min1=0;min1<=9;min1++) { P2=0x8c; command(); P2=array[min1]; deta(); P2=':'; deta(); if((hr0==almhr0)&&(hr1==almhr1)&&(min0==almmin0)&&(min 1==almmin1)) { P0=0x01; } for(sec0=0;sec0<=5;sec0++) { P2=0x8e; command(); P2=array[sec0]; deta(); delay(); for(sec1=0;sec1<=9;sec1++) { if(swt1==1) { alarm(); } if(swt6==1) { timeset(); } P2=0x8f; command(); P2=array[sec1]; deta();
47

delay(); } } } } } } } void deta() { P3=0x03; delay(); delay(); P3=0x01; } void command() { P3=0x02; delay(); delay(); P3=0; } void delay() { int j; for(j=0;j<=32000;j++); } void alarm() { int a; char array1[]={"alarm" }; P2=0xc4; command(); for(a=0;a<=4;a++) { P2=array1[a]; deta(); } while(swt1==1) { if(swt2==1)
48

{ ++almhr0; if(almhr0>2) { almhr0=0; } P2=0xca; command(); P2=array[almhr0]; deta(); } if(swt3==1) { ++almhr1; if(almhr1>9) { almhr1=0; } P2=0xcb; command(); P2=array[almhr1]; deta(); } P2=0xcc; command(); P2=':'; deta(); if(swt4==1) { ++almmin0; if(almmin0>5) { almmin0=0; } P2=0xcd; command(); P2=array[almmin0]; deta(); } if(swt5==1) {
49

++almmin1; if(almmin1>9) { almmin1=0; } P2=0xce; command(); P2=array[almmin1]; deta(); } } } void timeset() { while(swt6==1) { if(swt2==1) { ++min1; P2=0x8c; command(); P2=array[min1]; deta();} if(swt3==1) { ++min0; P2=0x8b; command(); P2=array[min0]; deta(); } if(swt4==1) { ++hr1; P2=0x89; command(); P2=array[hr1]; deta(); } if(swt5==1) {
50

++hr0; P2=0x88; command(); P2=array[hr0]; deta(); } } }

This is the Code for Digital Clock in C Language including the Time Setting and the Alarm. Circuit Diagram:-

51

Vous aimerez peut-être aussi