Professional Documents
Culture Documents
Lovely Professional University Jalandhar Delhi G. T Road (NH-1) Phagwara, Punjab, 144402, India
2013
ACKNOWLEDGEMENT
It was highly educative and interactive to take training at Lovely professional university, Phagwara, Punjab. A person technically lacks without having practical knowledge but here it was a good chance for learning and practicing new things to update our self. In a fully equipped environment and well experienced trainers, it was a qualitative program for being known with engineering requirements. Trainers guided me very well and updated me with all the valuable information regarding my course and latest technology. I am highly thankful to the respected Training and Placement Officer and respected Head of Department of Electronics and Communication Department Mr. Mayank Gupta for allowing me to join Lovely Professional University and motivating me to do the right things. I would also like to thanks Mr. Dusyant Singh ,Mr. Bharat Sanchlecha and Mr. Swapnil Bhargav for their precious guidance in field of microcontrollers and interfacing circuits and devices and also sorting out our problems. I would also like to thank my parents and my friends who encouraged me all the time while I was taking my projects and training in order to complete it successfully.
CANDIDATE/S DECLARATION
I hereby certify that the work, which is being presented in the Training report entitled Embedded System, in partial fulfillment of the requirement for the award of the Degree of Bachelor of Technology submitted to the institution is an authentic record of my own work carried out during the period 03 June,2013 to 12 July,2013 under the supervision of Mr. Dusyant Singh ,Mr. Bharat Sanchlecha , Mr.Swapnil Bhargav. I also cited the reference about the texts/figures/tables from where they have been taken.
Date:
This is to certify that the above statement made by the candidate is correct to the best of my /our knowledge.
Date:
Signature Supervisor
OBJECTIVE OF TRAINING/PROJECT Main objectives and goal of this training are as follows:-
To enhance my skills in Embedded System Design using 8051 microcontroller. To have a practical approach to Digital and Analog electronics. To implement theoretical knowledge in practical world example using hardware and software like Kiel and proteus. To prepare an individual project in embedded system.
TABLE OF CONTENTS
Chapter 1- Institute Profile Chapter 2- Introduction to embedded systems Chapter 3-Characteristics of Embedded Systems Chapter 4- Processors in Embedded System
4.1 Microcontroller vs. Microprocessor 4.2 Microcontroller Families
9 10-11 11 11-13
13-16
17-19
19-37
7.4 Instructions that affects Flags 7.5 I/O PROGRAMMING 7.6 TIMERS AND COUNTERS 7.7 Serial Port Communication in 8051 microcontroller 7.8 INTERUPTS
37-44
44-49
Chapter 10 References
50
TABLE OF FIGURES
Figure 5.1 - Pin Diagram of 8051 Microcontroller Figure 6.1- Block Diagram of 8051 microcontroller Figure 6.2- Register Bank Architecture Figure 6.3- Register Bank Selection
Figure7.1-RAM Memory Location Figure 7.2: Program Status Word Figure 7.3: Port 0 Figure 7.4: Tmer Register Figure 7.5:TMOD Register Figure 7.6:TCON Register Figure 7.7: Serial And Parallel Communication Figure 7.8: SCON Register Figure 7.9:Intrupts in 8051 Figure 7.10: Interrupt Enable Register Figure 8.1: LED Interfacing Figure 8.2: Typical Seven Segment Figure 8.3: Seven Segment Interfacing Figure 8.4: DC Motor Interfacing Figure 9.1:Stepper Motor Figure 9.2: Transistor BC547 Figure 9.3: AT89C51 microcontroller
LIST OF TABLES
Table 4.1: Difference between Microcontroller and Microprocessor Table 7.1: Addressing Modes Table 7.2:Arithematic Operatons Table 7.3: Logical Operations Table 7.4: Data Transfer Operations Table 7.5: Bitwise Operations Table 7.6: Branching Operations Table 7.7:Instructions Effecting Flags Table 7.8:Dual Functionality of Port 3 Table 8.1: Command to LCD Instruction Register
Lovely Professional University (LPU) is a private semi-residential university created under the state government private university act. LPU claims to be the largest private university in India in terms of number of students on a single campus and is situated on 600+ acres of green area on NH-1 at the entry of Jalandhar city.]The university has more than 25,000 students from 26 states and 16 countries. It is recognized by UGC under Section 2(f) of UGC Act 1956. The Lovely Faculty of Technology and Sciences was ranked 2 on the CSR-GHRDC Engineering Colleges Survey 2011. It was ranked 29. Lovely Professional University was declared as the Best ICT Enabled University of the Year by the Ministry of Communications and IT, Government of India
Occasion was the 7th e-INDIA Awards at Gandhinagar, Gujarat, India Award conferred on Lovely Professional University for having 'the Best University Management System' The e-INDIA award is the India's largest ICT event.
SiliconIndia.com ranked Lovel y Professional University among top 4 Best private Universities of India.
SiliconIndia.com is Indias largest professional News and Media Company. LPU got a "Punjab Gaurav Award" in the First Annual Corporate Summit 2012 organized by All India Technical and Management Association (AITMA).Excellency Hon'ble Governor Punjab Sh. Shivraj Patil bestowed 'Punjab Gaurav Award' upon LPU Chancellor.
LPU stared training on Embedded System by best of its Embedded system faculty member of university.
Students were selected by an online Examination conducted by University itself on basics of Microprocessor 8085, Microcontroller 8051, Digital Electronics, Analog and Liner ICs. Top 50 students were selected among third year students of ECE department.
10
home automation products, like thermostats, air conditioners, sprinklers, and security monitoring systems handheld calculators household appliances, including microwave ovens, washing machines, television sets medical equipment handheld computers videogame consoles
11
computer market, many different basic CPU architectures are used, since software is customdeveloped for an application and is not a commodity product installed by the end user. RISC as well as non-RISC processors are found. Word lengths vary from 4-bit to 64-bits and beyond, although the most typical remain 8/16-bit.
Microprocessors
1. A Microprocessor is an IC which has only the CPU inside them i.e. only the processing powers such as Intels Pentium 1,2,3,4, core 2 duo, i3, i5 etc. 2. Microprocessor find applications where tasks are unspecific like developing software, games, websites, photo editing, creating documents etc.
3. In such cases the relationship between input and output is not defined. They need high amount of resources like RAM, ROM, I/O ports etc. So needs external RAM, ROM and Memory. 4. Themicroprocessor operates above 1GHz as they perform complex tasks.
5.The microcontroller is designed for embedded 5.The microprocessors are used in personal applications. Microcontrollers are used in computers or other general purpose automatically controlled products and devices, applications such as for laptops and heavy such as automobile engine control systems, applications where complexity is more and implantable medical devices, remote controls, memory requirements are high. office machines, appliances, power tools, toys and other embedded systems. Table 4.1: Difference Between Microcontroller and Microprocessor So microcontrollers are more preferred over microprocessors for embedded applications because of the simplicity in design and cheaper availability. The system design using microcontroller cost much cheaper than the microprocessors design because memory, RAM, and ROM is built-in in a microcontroller as compared to microprocessor in which external memory and RAM and ROM are to interfaced with it.
12
PIC- Programmable Interface Controller is usually referred as PIC. They are slightly older than 8051 microcontrollers but excel cause of their small low pin count devices. They perform well and are affordable. The Microchip technology fabricated the single chip microcontroller PIC with Harvard architecture. The programming part is very tedious and hence it is not recommended for beginners.
AVR (Advanced Version RISC) - In 1996, Atmel fabricated this single chip microcontroller with a modified Harvard Architecture. This chip is loaded with C- compiler, Free IDE and many more features. This microcontroller is a bit difficult for the starters to handle.
5.1 AT89C51
AT89C51 is an 8-bit, 40 pin microcontroller that belongs to Atmel's 8051 family. ATMEL 89C51 has 4KB of Flash programmable and erasable read only memory (PEROM) and 128 bytes of RAM. It can be erased and program to a maximum of 1000 times. In 40 pin AT89C51, there are four ports designated as P1, P2, P3 and P0. All these ports are 8-bit bi-directional ports, i.e., they can be used as both input and output ports. Except P0 which needs external pull-ups, rest of the ports have internal pull-ups. When 1s are written to these port pins,
13
they are pulled high by the internal pull-ups and can be used as inputs. These ports are also bit addressable and so their bits can also be accessed individually.
5.1.1 Salient Features of AT89C51-
4K Bytes of In-System Reprogrammable Flash Memory Fully Static Operation: 0 Hz to 24 MHz Three-level Program Memory Lock 28 x 8-bit Internal RAM 32 Programmable I/O Lines Two 16-bit Timer/Counters Six Interrupt Sources Programmable Serial Channel Low-power Idle and Power-down Modes 40-pin DIP
14
Figure 5.1: Pin Diagram of 8051 microcontroller 5.1.3 Pin Description of AT89C51 Pins 1-8 (Port 1) - Each of these pins can be configured as an input or an output. Pin 9 (Reset) - A logic one on this pin disables the microcontroller and clears the contents of most registers. In other words, the positive voltage on this pin resets the microcontroller. By applying logic zero to this pin, the program starts execution from the beginning.
15
Pins 10- 17 (Port 3) -Similar to port 1, each of these pins can serve as general input or output. Besides, all of them have alternative functions: Pin 10 (RXD) - Serial asynchronous communication input or Serial synchronous communication output. Pin 11(TXD) - Serial asynchronous communication output or Serial synchronous communication clock output. Pin 12 (INT 0) - Interrupt 0 input. Pin 13(INT 1) - Interrupt 1 input. Pin 14(T0) - Counter 0 clock input. Pin 15(T1) - Counter 1 clock input. Pin 16(WR) -Write to external (additional) RAM. Pin 17 (RD) -Read from external RAM. Pin 18 and 19(X1, X2) - Internal oscillator input and output. A quartz crystal which specifies operating frequency is usually connected to these pins. Instead of it, miniature ceramics resonators can also be used for frequency stability. Later versions of microcontrollers operate at a frequency of 0 Hz up to over 50 Hz. Pin 20 (GND) - Ground. Used to provide earth to microcontroller circuit. Pin 21-28 (Port 2) - If there is no intention to use external memory then these port pins are configured as general inputs/outputs. In case external memory is used, the higher address byte, i.e. addresses A8-A15 will appear on this port. Even though memory with capacity of 64Kb is not used, which means that not all eight port bits are used for its addressing, the rest of them are not available as inputs/outputs. Pin 29 (PSEN) - If external ROM is used for storing program then a logic zero (0) appears on it every time the microcontroller reads a byte from memory. Pin 30 (ALE) - Prior to reading from external memory, the microcontroller puts the lower address byte (A0-A7) on P0 and activates the ALE output. After receiving signal from the ALE pin, the external register memorizes the state of P0 and uses it as a memory chip address. Immediately after that, the ALU pin is returned its previous logic state and P0 is now used as a Data Bus. As seen, port data multiplexing is performed by means of only one additional (and cheap) integrated circuit. In other words, this port is used for both data and address transmission. Pin 31 (EA) - By applying logic zero to this pin, P2 and P3 are used for data and address transmission with no regard to whether there is internal memory or not. It means that even there is a program written to the microcontroller, it will not be executed. Instead, the program written to external ROM will be executed. By applying logic one to the EA pin, the microcontroller will use both memories, first internal then external (if exists).
16
Pin 32-39 (Port 0) - Similar to P2, if external memory is not used, these pins can be used as general inputs/outputs. Otherwise, P0 is configured as address output (A0-A7) when the ALE pin is driven high (1) or as data output (Data Bus) when the ALE pin is driven low (0). Pin 40 (Vcc) - +5V power supply.
Figure 6.1: Block Diagram of 8051 microcontroller Address bus-For a device (memory or I/O) to be recognized by the CPU, it must be assigned an address. The address assigned to a given device must be unique. The CPU puts the address on the address bus, and the decoding circuitry finds the device.
17
Data bus-The CPU either gets data from the device or sends data to it. Control bus-Provides read or write signals to the device to indicate if the CPU is asking for information or sending it information .
Figure 6.2: Register Bank Architecture Generally for normal operations, Register bank Bank0 is set by default. But we can switch to other banks by using PSW Commands.
18
Figure 6.3: Register Bank Selection 6.2.1 SFRs (Special Function Register) - These Registers are in extra 128 bytes of the memory. This part of memory is not user accessible and these registers are used for special purposes. These registers range from 80h to FFH. There are a total of only 21 SFRs in this range and all other addresses from 80h to FFH are invalid and there use can cause errors and not valuable results. Some of the SFRs are TCON, SBUF, ACC, B, SCON, TMOD SP, P0, PSW, TL0, and TL1. These all the registers have some specific function that has to be performed after they are programmed. (i) Bit Addressable SFR with byte address SP Stack printer 81H DPTR Data pointer 2 bytes DPL Low byte 82H DPH High byte 83H TMOD Timer mode control 89H TH0 Timer 0 Higher order bytes 8CH TL0 Timer 0 Low order bytes 8AH TH1 Timer 1 High bytes = 80H TL1 Timer 1 Low order byte = 86H SBUF Serial data buffer = 99H PCON Power control 87H. 6.2.2 DPTR - Data Pointer in 8051 16 bit register; it is divided into two parts DPH and DPL. DPH for Higher order 8 bits, DPL for lower order 8 bits. DPTR, DPH, DPL these all are SFRs in 8051.
19
[Label:] mnemonic [operands] [; comment] Mnemonics -Assembly level instructions are called mnemonic like MOV R5 Operands -On which the operation is performed. Example: Loop: MOV R1, #25H ; transfer 25H into R1
The Two instructions which are used to start and terminate program are ORG -This instruction indicate the origin of program, Example- ORG 3000H means program starts from 3000H location. this instruction hasnt take any memory space. It is used to show the starting address of program. END - This instruction show the END of program or it is used to terminate the program. Example: ORG 0H Again: MOV R5, # 25H ADD A, R5 SJMP Again END
; start compiler from 0h address ; transfer 25H to R5 ; Add the R5 with Accumulator ; jump to the location again ; end the program.
20
The instruction transfers the accumulator content into the R0register. The register bank (Bank 0, 1, 2 or 3) must be specified prior to this instruction. In the Register Addressing mode, the instruction involves transfer of information between registers. The accumulator is referred to as the A register.
Direct Addressing Mode- This mode allows you to specify the operand by giving its actual
memory address (typically specified in hexadecimal format) or by giving its abbreviated name (e.g. P3).Used for SFR accesses Example: MOV A, P3 ; Transfer the contents of Port 3 to the accumulator MOV A, 020H ; Transfer the contents of RAM location 20H to the accumulator.
Indirect Addressing Mode-In the Indirect Addressing mode, a register is used to hold the
effective address of the operand. This register, which holds the address, is called the pointer register and is said to point to the operand. Only registers R0, R1 and DPTR can be used as pointer registers. R0 and R1 registers can hold an 8-bit address whereas DPTR can hold a 16-bit address. DPTR is useful in accessing operands which are in the external memory. Examples: MOV @R0, A ; Store the content of accumulator into the memory location pointed to by the contents of register R0. R0 could have an 8-bit address, such as 60H. MOVX A, @DPTR ; Transfer the contents from the memory location pointed to by DPTR into the accumulator. DPTR could have a 16-bit address, such as 1234H.
Immediate Addressing Mode-In the Immediate Constant Addressing mode, the source
operand is an 8- or 16-bit constant value. This constant is specified in the instruction itself (rather than in a register or a memory location). The destination register should hold the same data size which is specified by the source operand. Examples: ADD A, #030H; Add 8-bit value of 30H to the accumulator register (which is an 8-bit register).
MOV DPTR, #0FE00H; Move 16-bit data constant FE00H into the 16-bit Data Pointer
Register.
Indexed Addressing Mode- The Indexed addressing is useful when there is a need to
retrieve data from a look-up table (LUT). A 16-bit register (data pointer) holds the base address and the accumulator holds an 8-bit displacement or index value. The sum of these two registers forms the effective address for a JMP or MOVC instruction. Example: MOV A, #08H ; Offset from table start
21
; Table start address ; Gets target value from the table starts address + offset
Arithmetic Instructions of 8051 are shown as follows [@ RI] implies contents of memory location pointed to by R0 or R1. Rn refers to registers R0-R7 of the currently selected register bank.
22
Table 7.2:Arithematic Operaton Logical Instructions-Logical instructions perform standard Boolean operations such as AND, OR, XOR, NOT (compliment). Other logical operations are clear accumulator, rotate accumulator left and right, and swap nibbles in accumulator. Examples: ANL A, #02H; Mask bit 1 ORL TCON, A; TCON=TCON OR A
23
Table 7.3:Logical Operation Data Transfer Instructions- Data transfer instructions can be used to transfer data between an internal RAM location and an SFR location without going through the accumulator. It is also possible to transfer data between the internal and external RAM by using indirect addressing. The upper 128 bytes of data RAM are accessed only by indirect addressing and the SFRs are accessed only by direct addressing.
24
Bitwise Instructions-The Boolean Variable operations include set, clear, as well as and, or and complement instructions. Also included are bitlevel moves or conditional jump instructions. All bit accesses use direct addressing. Examples:
Start Timer0.
25
The following table contains all the Boolean Variable Instructions of 8051 microcontroller.
Branching Instructions- Program branching instructions are used to control the flow of program execution. Some instructions provide decision making capabilities before transferring control to other parts of the program e.g. conditional and unconditional branches. the following table contains all the branching instructions
26
instruction was execute. 3. The PSW3 and PSW4 are designed as RS0 and RS1, and are used to change the bank. The two unused bits are user-definable.
PSW 7 PSW 0
PSW 6
PSW 5
PSW 4
PSW 3
PSW 2
PSW 1
CY
AC
F0
RS1
RS0
OV
--------- P
Figure 7.2: Program Status Word CYACF0 (-----) RS1 RS0 OV F0 (-----) P PSW.7- Carry flag. PSW.6- Auxiliary Carry flag. PSW.5- Available to the user for general purpose PSW.4 - Register Bank selector bit 1. PSW.3 -Register Bank selector bit 0. PSW.2 -Overflow flag. PSW.1- User definable bit. PSW.0- Parity flag. Set/cleared by hardware each.
28
CJNE
To use any of these ports as an input port, it must be programmed. 7.5.1 Port 0 It can be used for input or output; each pin must be connected externally to a 10K ohm pull-up resistor. This is due to the fact that P0 is an open drain, unlike P1, P2, and P3. Open drain is a term used for MOS chips in the same way that open collector is used for TTL chips.
29
Figure 7.3: Port 0 Port 0 is also designated as AD0-AD7, allowing it to be used for both address and data.
7.5.2 Port 1 Port 1 can be used as input or output. In contrast to port 0, this port does not need any pull-up resistors since it already has pullup resistors internally. Upon reset, port 1 is configured as an input port. To make port 1 an input port, it must be programmed as such by writing 1 to all its bits.
7.5.3 Port 2 Port 2 can be used as input or output. Just like P1, port 2 does not need any pull-up resistors since it already has pull-up resistors internally. Upon reset, port 2 is configured as an input portP0.4. Port 2 is also designated as A8 A15, indicating its dual function .Port 0 provides the lower 8 bits via A0 A7.
7.5.3 Port 3 Port 3 can be used as input or output. Port 3 does not need any pull-up resistors. Port 3 is configured as an input port upon reset; this is not the way it is most commonly used. Port 3 has the additional function of providing some extremely important signals
30
Int0 P3.3 P3.4 P3.5 P3.6 Wr P3.7 Rd Table 7.8:Dual Functionality of Port 3 17 Int1 T0 T1 13 14 15 16 Read/ Write Signals Timers External Interrupts
31
(i)
TMOD Register
It is used to set the various timer operation mode. TMOD is an 8-bit register where the lower 4 bits are set aside for timer 0 and the upper 4 bits are set aside for timer 1. MSB LSB
Gate
C/T Timer 1
M0
M1
GATE
C/T Timer 0
M0
MI
Figure 7.5:TMOD Register GATE: To start and stop the timer GATE=1 _HW control: is enabled only while INTx pin is 1and TRx control pin (in TCON) is set. GATE=0 _SW control (used frequently) C/T: Timer or counter selection C/T = 0 _Timer (input from internal system clock) the crystal (1/12) is used to trigger the timer. C/T = 1 _Counter (input from Tx input pin)
32
M1 and M0: Mode selection for timer and counter Mode M1 M0 0 1 2 3 0 0 1 1 0 1 0 1 13-bit timer/counter mode 16-bit timer/counter mode 8-bit auto reload timer/counter mode split timer/counter mode
TF1
TF0
TR1
TR0
IE1
IE0
IT1
IT0
Figure 7.6:TCON Register TF1: Timer 1 overflows flag TF1=1: Timer/counter 1 overflows. TF1=0: processor vectors to the interrupt services. TR1: Timer 1 run control bit TR1=1: turn Timer 1 ON TR1=0: turn Timer 1 OFF IE1: External interrupt 1 edge flag IE1=1: external interrupt is detected. IE1=0: when interrupt is processed. IT1: Interrupt 1 type control bit IT1=1: falling edge. IT1=0: low level triggered external interrupt. Gate=0, SETB TR1 _Run Timer 1 SETB TR0 _Run Timer 0 Gate=0, CLR TR1 _OFF Timer 1 CLR TR0 _OFF Timer 0
Timer Mode 0
Mode 0: 13-bit Timer/counter mode 0000 ~ 1FFFH
Timer Mode 2
Mode 2: 8-bit auto reload Timer/counter mode (00 ~ FFH). In auto reload, TH is loaded with the initial count and a copy of it is given to TL. This reloading leaves TH unchanged still holding a copy of original values. This mode has many applications, including setting the baud rate in serial communication.
33
Mode 2 Programming 8 bit - 00 ~FFH TH copy to TL Start SETB TR0, or TR1 TL increased FFH (OV monitoring) TH reloads to TL.
7.6.2 Counters
Counter is used to count input pulses. C/T=0: As Time, using 8051s crystal as the source ofthe frequency. C/T=1: As counter, a pulse outside of the 8051 that increments the TH and TL register. When the C/T=1, the counter counts up as pulses are fed from Pins P3.4 (for counter 0) or P3.5 (for counter 1).
Serial data communication uses two methods Synchronous method transfers a block of data at a time Asynchronous method transfers a single byte at a time
34
It is possible to write software to use either of these methods, but the programs can be tedious and long There are special IC chips made by many manufacturers for serial communications UART (universal asynchronous Receiver transmitter) USART (universal synchronous-asynchronous Receiver-transmitter) The rate of data transfer in serial data communication is stated in bps (bits per second). Another widely used terminology for bps is baud rate.
Figure 7.8: SCON Register RI (Receive Interrupt Flag)-Set by hardware on receiving. Must be cleared by software TI (Transmit Interrupt Flag) -Set by hardware on transmitted, must clear by hardware RB8 (Receive bit 8) Mode 2,3 : copy of bit 8 Mode 1 & SM2 clear : copy of stop bit TB8 Transmit bit 8- The 9th data bit of mode 2, 3. Set or clear by software REN Receive Enable- Set by software to enable reception, if is cleared reception will be blocked. SM2 Serial Mode (bit 2) -Use in mode 2, 3 for multiprocessor communications. SM1 & SM0 Serial Mode (bit 6 & 7) Operating modes Mode 0 Mode 1 Mode 2 Mode 3 8-bit shift register, f/12 1Mbit with 12 MHz Oscillator Frequency 8-bit UART, variable baud rate 9-bit UART, f/64 or f/32 187.5K and 375K with 12MHz Oscillator Frequency 9-bit UART, variable baud rate.
7.7.2 SBUF
35
These are two separate data buffers for transmit and receive. The register SBUF is used to hold both the transmitter and receiver serial port data. To transmit the data, load SBUF register with data. MOV SBUF, source When transmission is complete the TI bit will be set in the SCON register. When a data frame is received the RI bit in SCON is set high. The received data may then be loaded from SBUF MOV destination, SBUF Data reception is double buffered.
7.7.3 SMOD
Addition bit to double baud speed.
7.8 INTERUPTS
An interrupt is an external or internal event that interrupts the microcontroller to inform it that a device needs its service. The advantage of interrupts is that the microcontroller can serve many devices. Each device can get the attention of the microcontroller based on the assigned priority. The microcontroller can also ignore (mask) a device request for service. 7.8.1 Hardware and Software interrupt The interrupts in a controller can be either hardware or software. If the interrupts are generated by the controllers inbuilt devices, like timer interrupts; or by the interfaced devices, they are called the hardware interrupts. If the interrupts are generated by a piece of code, they are termed as software interrupts. The 8051 controller has six hardware interrupts of which five are available to the programmer. 1. RESET Interrupt - This is also known as Power on Reset (POR). When the RESET interrupt is received, the controller restarts executing code from 0000H location. This is an interrupt which is not available to or, better to say, need not be available to the programmer. 2. Timer interrupts - Each Timer is associated with a Timer interrupt. A timer interrupt notifies the microcontroller that the corresponding Timer has finished counting. Therefore these are two interrupts for the timers. 3. External interrupts - There are two external interrupts EX0 and EX1 to serve external devices. Both these interrupts are active low. In AT89C51, P3.2 (INT0) and P3.3 (INT1) pins are
36
available for external interrupts 0 and 1 respectively. An external interrupt notifies the microcontroller that an external device needs its service. 4. Serial interrupt - This interrupt is used for serial communication. When enabled, it notifies the controller whether a byte has been received or transmitted.
The interrupts must be enabled by software in order for the microcontroller to respond to them. Interrupt Enable Register- There is a register called IE (interrupt enable) that is responsible for enabling (unmasking) and disabling (masking) the interrupts.
IE.7 IE.0 EA
IE.6
IE.5
IE.4
IE.3
IE.2
IE.1
--------
ET2
ES
ET1
EX1
ET0
EX0
Figure 7.10: Interrupt Enable Register To enable any of the interrupts, first the EA bit must be set to 1. After that the bits corresponding to the desired interrupts are enabled. ET0, ET1 and ET2 bits are used to enable the Timer Interrupts 0, 1 and 2, respectively. In AT89C51, there are only two timers, so ET2 is not used. EX0 and EX1 are used to enable the external interrupts 0 and 1. ES is used for serial interrupt.
37
EA bit acts as a lock bit. If any of the interrupt bits are enabled but EA bit is not set, the interrupt will not function. By default all the interrupts are in disabled mode.
38
39
Figure 8.2:Typical Seven Segment Display CodeORG 000H MOV DPTR,#300H MOV R0, #0AH LABEL: CLR A MOVC A,@A+DPTR MOV P1, A ACALL DELAY DJNZ R0,LABEL SJMP START DELAY: MOV R4, #05H WAIT1: MOV R3, #00H WAIT2: MOV R2, #00H WAIT3: DJNZ R2,WAIT3 DJNZ R3,WAIT2 DJNZ R4,WAIT1 RET ORG 300H Mydata DB: 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH END START:
40
Code-
41
42
43
Figure 8.5: DC Motor Interfacing CodeSTART: ORG 00H CLR P1.2 CLR P1.1 SETB P1.0 ACALL DELAY CLR P1.2 SETB P1.1 CLR P1.0 MOV R4, #0FH MOV R3, #00H MOV R2, #00H DJNZ R2, WAIT3 DJNZ R3, WAIT2 DJNZ R4, WAIT1 RET END
;clockwise ;anticlockwise
44
CONTROLING A STEPPER MOTOR MOVEMENT USING BUTTONS 9.1: Project Description: My project is basically controlling a single stepper motor in
different movements using different buttons .It has to make choice according to buttons pressed, they send them in different subroutines in order to move differently.
9.2: Components: 9.2.1:- Stepper Motor :It is type which can be rotated in steps not contineousaly.
9.2.2: Transistor BC547: BC547 is an NPN bi-polar junction transistor. A transistor, stands
for transfer of resistance, is commonly used to amplify current.
45
Figure 9.2:BC547 Transistor 9.2.3: AT89C51 Microcontroller: AT89C51 is an 8-bit microcontroller and belongs to Atmel's 8051 family.
46
unsigned char ch; label:ch=P1; ch=ch&0x07; switch(ch) { case 0: { P2 = 0xcc; Msdelay(); P2 = 0x66; Msdelay(); P2 = 0x33; Msdelay(); P2 = 0x99; Msdelay();
47
case 2: { P2=0xcc; Msdelay(); break; } case 3: { P2=0x99; Msdelay(); P2=0x33; Msdelay(); P2=0x66; Msdelay();
48
49
REFERENCES
I. II. III. IV. V. VI. VII. VIII. The MAZIDI BOOKS ENGINEERSGARAGE.COM WIKIPEDIA.ORG ATMEL.COM DATASHEETS.COM CIRCUITSTODAY.COM PDFs FROM VARIOUS SITES GOOGLE.COM
50