RADIANT INSTITUTE OF ENGINEERING AND            TECHNOLOGY              ABOHAR                          SUBMITTED BY:     ...
2
3
First of all I would like to thank almighty GOD who has given this wonderful gift of life tous. He is the one who is guidi...
Beri Institute of Technologies(BIT) is an organization which is established in thefield of Computer hardware sporte, Netwo...
6
7
1) Difference between microprocessors and microcontrollers2) Disadvantages of processors over controllers2) Embedded Syste...
 Interfacing LCD to AT89s52 Serial communication B/W AT89s52 & PC Interfacing of ADC(0804) with AT89s52 Microcontroller...
DIFFERENCE BETWEEN MICROPROCESSORS AND                 MICROCONTROLLERS   • A Microprocessor is a general purpose digital ...
DISADVANTAGES OF PROCESSORS OVERCONTROLLERS    • System designed using Microprocessors are bulky    • They are expensive t...
EMBEDDED SYSTEMS   An embedded system:   •    Employs a combination of software & hardware to perform a specific function....
•   ISP-Flash Programmer Version 3.0a -Hex File Downloader (Machine code gets      burned in controller) -For C Language:-...
Intel Corporation introduced an 8-bit microcontroller called 8051 in 1981 this controllerhad 128 bytes of RAM, 4k bytes of...
you on the first step of a smooth and cost-effective upgrade path - to the enhancedperformance of the 151 and 251 microcon...
16
Pin configuration of 8051           17
Description of ports There are four ports P0, P1, P2 and P3 each use 8 pins, making them 8-bit ports. All the ports upon R...
MOV A, #0FFH             ; A = FF hex                     MOV P0, A               ; make P0 an input port                 ...
55h & AAh             MOV A, #55H; A = 55 hex       BACK: MOV P1, A; send it to Port 1             ACALL DELAY ; call dela...
MOV R5, A              ; save it in register R5Port 2:-Port 2 occupies a total of 8 pins (pins 21- 28). It can be used as ...
accessing 64K bytes of external memory, it needs a path for the 16 bits of the address.While P0 provides the lower 8 bits ...
Single bit addressability of ports:-There are times that we need to access only 1 or 2 bits of the port instead of the ent...
AT89s52AT89S52 is an ATMEL controller with the core of Intel MCS-51. It has same pinconfiguration as give above.The AT89S5...
program memory to be reprogrammed in-system through an SPI serial interface orby a conventional nonvolatile memory program...
• Full Duplex UART Serial Channel• Low Power Idle and Power Down Modes• Interrupt Recovery From Power Down Mode• Watchdog ...
External Access Enable. EA must be strapped to GND in order to enable thedevice to fetch code from external program memory...
Timer and counter descriptionTimer 0 and 1:Timer 0 and Timer 1 in the AT89S52 operate the same way as Timer 0 and Timer1 i...
response to a 1-to-0 transition at its corresponding external input pin, T2. In thisfunction, the external input is sample...
User software should not write 1s to these bit positions, since they may be used infuture AT89 products. Timer 2 interrupt...
The global interrupt enable bit and the individual interrupt enable bits are in the IEregister. In addition, the individua...
{    P1_0=1;    delay(1000000);    delay(1000000);    delay(1000000);    delay(1000000);    P1_0=0;    delay(1000000);    ...
•    Programming and program test time is drastically reduced, this increases     efficiency.•    Keywords and operational...
Pins 1 & 2 are the power supply lines, Vss & Vdd. The Vdd pin should be connectedto the positive supply & Vss to the 0V su...
Three command control inputs. When this line is low, data bytes transferred tothe display are treated as commands, and dat...
CODE FOR INTERFACING OF LCD WITH AT89S52 MICROCONTROLLER       #include<at89s8252.h>#define lcdprt P0#define rs P1_2#defin...
void lcd_cmd(unsigned char a);    void display(unsigned char b);    void wait(void);    void init_lcd(void);    void clear...
wait();lcdprt=b;rs=1;en=1;en=0;}void wait(void){unsigned int count=300;while(count!=0){count--;}}void cursor_position(unsi...
{temp=digit/100;display(lkup_tb101[temp]);digit=digit-(temp*100);temp=digit/10;display(lkup_tb101[temp]);digit=digit-(temp...
digit=digit-(temp*100);temp=digit/10;display(lkup_tb101[temp]);digit=digit-(temp*10);temp=digit;display(lkup_tb101[temp]);...
display(o);                delay(0xffff);}                }       CODE FOR SERIAL PORT COMMUNICATION IN TRANSMIT MODE     ...
SCON=0x40;TR1=1;TH1=0xfd;}void transmit_serial(unsigned int a){int i;TI=0;for(i=0xffff;i>=0;i--);SBUF=a;}void main(void){i...
SCON=0x50;TR1=1;TH1=0xfd;}unsigned int receive(void){int i;RI=0;for(i=0xffff;i>=0;i--);return SBUF;}void main(void){int e;...
programmed by the system software so that normally no external logic is necessary tointerface peripheral devices or struct...
Ports A, B, and CThe 82C55A contains three 8-bit ports (A, B, and C). All can be configured in a widevariety of functional...
RESET is kept low to make all the ports the output ports. To do this, the pin isconnected to the pin of controller as show...
ADC0804  8-Bit μP Compatible D/A Converters with 8-                                 ChannelThe ADC0804 family is CMOS 8-Bi...
and permits offsetting the analog zero-input voltage value. In addition, the voltagereference input can be adjusted to all...
49
When interfacing is being done then                gets lowered then only it allows thecontroller to read the data, otherw...
lcdprt=a;      rs=0;      en=1; en=0;      }      void init_lcd(void){    lcd_cmd(0x3c);                lcd_cmd(0x0c);    ...
}    }                  void shift(void)                  {                  lcd_cmd(0x1c);                  }            ...
temp=digit/10;display(lkup_tb101[temp]);digit=digit-(temp*10);temp=digit;display(lkup_tb101[temp]);}if(digit>99&&digit<100...
display(lkup_tb101[temp]);                    digit=digit-(temp*100);                    temp=digit/10;                   ...
{unsigned int e;P2=0xff;init_lcd();init_sit();while(1){e=read_adc();cursor_position(0x00);delay(0xffff);disp_dec(e);}}unsi...
Real Time ClockThe DS12887 is real-time clocks (RTCs). The devices provide a real-timeclock/calendar, one time-of-day alar...
Pin diagramFeatures♦ RTC Counts Seconds, Minutes, Hours, Day, Date, Month, and Year with Leap Year Compensation Through 20...
♦ 114 Bytes of General-Purpose, Battery-Backed RAM (113 Bytes in the DS12C887 and DS12C887A)♦ Time-of-Day Alarm Once Per S...
To Update Set Bit is 1                         rb=0x80                                   59
CODE FOR INTERFACING OF RTC (DS12887) WITH ATs52MICROCONTROLLER#include<at89s8252.h>#define LCDPRT P2#define RS P1_2#defin...
unsigned int x;unsigned char sec;unsigned char hr;unsigned char minInit_lcd();for(x=0;x<10000;x++)T0M2delay_rtc();ds12887....
void bcdconv(unsigned int mb){unsigned int x;unsigned int y;x=mb&0x0f;x=x|0x30;y=mb&0xf0;y=y>>4;y=y|0x30;display(y);displa...
{    count--;    }} void Init_lcd(void) { lcd_cmd(0x3c); lcd_cmd(0x0c); lcd_cmd(0x06); lcd_cmd(0x01); } void clear_lcd(voi...
64
Detailed description of training project:For easy understanding I have divide my project into four sections:              ...
(iii)   input filter   (iv)    regulator   (v)     output filter   (vi)    output indication   (i)     Transformer:       ...
Well, we use microcontroller to control our hardware using programs which we makeaccording to our requirement. We have use...
code unsigned char name_arry2[]={"stop     $"};bit flag;unsigned char sec;void drive(void);void display_string(unsigned ch...
P2=0x00; cursor_position(0x00); display_string2(&name_arry2); delay(0xffff); delay(0xffff); delay(0xffff); delay(0xffff); ...
}          void display_string2(unsigned char *tp)    {     while(*tp!=$)   {       display(*tp);       tp=tp+1;       }  ...
} void clear_lcd(void){   lcd_cmd(0x01); }void delay (unsigned int i)  {  while (i!=0)  {   i--;   }}    void cursor_posit...
Upcoming SlideShare
Loading in …5
×

Embedded training report(mcs 51)

2,053 views
1,994 views

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,053
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
229
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Embedded training report(mcs 51)

  1. 1. RADIANT INSTITUTE OF ENGINEERING AND TECHNOLOGY ABOHAR SUBMITTED BY: NAME: Gurwinder Singh Branch : ECE Roll No.: 100930420230 1
  2. 2. 2
  3. 3. 3
  4. 4. First of all I would like to thank almighty GOD who has given this wonderful gift of life tous. He is the one who is guiding us in right direction to follow noble path of humanity. Inmy Six weeks industrial training it is a wonderful experience to be a part of Beri Instituteof Technology. Where I got the opportunity to work under brilliant minds. I owe my deepregards for the supporting and kind staff authorities who are helping me in my lean patchesduring these six weeks. The knowledge I am gaining through out my studies have thepractical implementation during this period. I am grateful to all the staff of BIT and fortheir timely support and sharing of their experience with me. I would like to express myheartiest concern for Er. Bikram Beri for his able guidance and for his inspiring attitude,praiseworthy attitude and honest support. Not to forget the pain staking efforts of ourcollege training and placement cell and specially my training and placement officerMr………….. Last but not the least I would express my utmost regards for the ECEdepartment of our Institute. 4
  5. 5. Beri Institute of Technologies(BIT) is an organization which is established in thefield of Computer hardware sporte, Network training and Embedded systems. We provideSupport and training in the field of networking solutions (LINUX) and embeddedsystems (Micro controller based design, Electronics system design).BIT also provide Technical Research & Development support and consultancy to someElectronics companies.THEIR TEAMPresently they have a strong technical team of certified professionals for catering to thesesolutions and have presence in Abohar and Punjab. They have skilled team of engineerswho are experienced in design, programming.Support Area (network solutions)a) LINUX / UNIX networksb) Radio Linksc) Security SolutionsDesign Services (Embedded systems)a) AVR familyb) MCS 51c) ELECTRONIC SYSTEM DESIGN 5
  6. 6. 6
  7. 7. 7
  8. 8. 1) Difference between microprocessors and microcontrollers2) Disadvantages of processors over controllers2) Embedded System using microcontrollers  Embedded System  Characteristics  History of 8051  Architecture  Pin configuration  AT89s52 • Block Diagram • Features • Pin description  On chip peripherals • Interrupts • Serial communication • Timer and counter  Advantages of C over Assembly language  Off chip peripherals • LCD (JHD162A) • RTC(DS12887) • ADC(ADC 0804) • 8255PPI 8
  9. 9.  Interfacing LCD to AT89s52 Serial communication B/W AT89s52 & PC Interfacing of ADC(0804) with AT89s52 Microcontroller Interfacing of RTC with AT89s52 Microcontroller Interfacing of 8255 with AT89s52 Microcontroller 9
  10. 10. DIFFERENCE BETWEEN MICROPROCESSORS AND MICROCONTROLLERS • A Microprocessor is a general purpose digital computer central processing unit(C.P.U) popularly known as CPU on the chip. The Microprocessors contain no RAM, no ROM, and no I/P O/P ports on the chip itself. • On the other hand a Microcontroller has a C.P.U(microprocessor) in addition to a fixed amount of RAM, ROM, I/O ports and a timer all on a single chip. • In order to make a Microprocessor functional we must add RAM, ROM, I/O Ports and timers externally to them,ie any amount of external memory can be added to it. • But in controllers there is a fixed amount of memory which makes them ideal for many applications. • The Microprocessors have many operational codes(opcodes) for moving data from external memory to the C.P.U • Whereas Microcontrollers may have one or two operational codes. 10
  11. 11. DISADVANTAGES OF PROCESSORS OVERCONTROLLERS • System designed using Microprocessors are bulky • They are expensive than Microcontrollers • We need to add some external devices such as PPI chip, Memory, Timer/counter chip, Interrupt controller chip,etc. to make it functional. 11
  12. 12. EMBEDDED SYSTEMS An embedded system: • Employs a combination of software & hardware to perform a specific function. • Is a part of a larger system which may not be a “computer”. • Works in a reactive & time constrained environment.CHARACTERISTICS:Single functioned • Executes a single program, repeatedly.Tightly-constrained • Low power, low cost, small, fast etc.Reactive & real time • Continually reacts to the changes in the system’s environment. • Must compute certain result in real-time without delayTools Used for Embedded System:For Assembly Language:- • 8051 Assembler cum Simulator 12
  13. 13. • ISP-Flash Programmer Version 3.0a -Hex File Downloader (Machine code gets burned in controller) -For C Language:- • Programming Environment- Programmers Notepad 2 • Small Device C Compiler • ISP-Flash Programmer Version 3.0a -Hex File Downloader (Machine code gets burned in controller)Embedded System Applications:- • Consumer electronics, e.g., cameras, cell phones etc. • Consumer products, e.g. washers, microwave ovens etc. • Automobiles (anti-lock braking, engine control etc.) • Industrial process controller & defense applications. • Computer/Communication products, e.g. printers, FAX machines etc. • Medical Equipments. • ATMs • Aircrafts • elevators MICROCONTROLLERSHistory of 8051 13
  14. 14. Intel Corporation introduced an 8-bit microcontroller called 8051 in 1981 this controllerhad 128 bytes of RAM, 4k bytes of on chip ROM, two timers, one serial port, and fourports all are on single chip. The 8051 is an 8 bit processor, meaning that the CPU canwork on only 8 bit data at a time. Data larger than 8 bits broken into 8 bit pieces to beprocessed by CPU. It has for I/O 8 bit wide.Features of the 8051:-Feature QuantityROM 4K bytesRAM 128 bytesTimer 2I/O pins 32Serial port 1Interrupt sources 68051 Architecture OverviewThe 8051 family is one of the most common microcontroller architectures usedworldwide.8051 based microcontrollers are offered in hundreds of variants from manydifferent silicon manufacturers.The 8051 is based on an 8-bit CISC core with Harvard architecture. Its an 8-bit CPU,optimized for control applications with extensive Boolean processing (single-bit logiccapabilities), 64K program and data memory address space and various on-chipperipherals.The 8051 microcontroller family offers developers a wide variety of high-integration andCost-effective solutions for virtually every basic embedded control application. Fromtraffic control equipment to input devices and computer networking products, 8051microcontrollers deliver high performance together with a choice of configurations andoptions matched to the special needs of each application. Whether its low poweroperation, higher frequency performance, expanded on-chip RAM, or an application-specific requirement, theres a version of the 8051 microcontroller thats right for the job.When its time to upgrade product features and functionality, the 8051 architecture puts 14
  15. 15. you on the first step of a smooth and cost-effective upgrade path - to the enhancedperformance of the 151 and 251 microcontrollers 15
  16. 16. 16
  17. 17. Pin configuration of 8051 17
  18. 18. Description of ports There are four ports P0, P1, P2 and P3 each use 8 pins, making them 8-bit ports. All the ports upon RESET are configured as output, ready to be used as output ports. To use any of these ports as an input port, it must be programmed.Port 0:- Port 0 occupies a total of 8 pins (pins 32-39) .It can be used for input or output.To use the pins of port 0 as both input and output ports, each pin must be connectedexternally 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 opencollector is used for TTL chips. With external pull-up resistors connected upon reset, port0 is configured as an output port. For example, the following code will continuously sendout to port 0 the alternating values 55H and AAH. MOV A, #55H BACK: MOV P0, A ACALL DELAY CAPL A SJMP BACKPort 0 as input: - With resistors connected to port 0, in order to make it an input, the portmust be programmed by writing 1 to all the bits. In the following code, port 0 is configuredfirst as an input port by writing 1s to it, and then data is received from the port and sent toP1. 18
  19. 19. MOV A, #0FFH ; A = FF hex MOV P0, A ; make P0 an input port BACK: MOV A, P0 ; get data from P0 MOV P1, A ; send it to port 1 SJMP BACKDual Role of Port 0:-Port 0 is also designated as AD0-AD7, allowing it to be used forboth address and data. When connecting an 8051/31 to an external memory, port 0provides both address and data. The 8051 multiplexes address and data through port 0 tosave pins. ALE indicates if P0 has address or data. When ALE = 0, it provides data D0-D7,but when ALE =1 it has address and data with the help of a 74LS373 latch.Port 1:- Port 1 occupies a total of 8 pins (pins 1 through 8). It can be used as input oroutput. In contrast to port 0, this port does not need any pull-up resistors since it alreadyhas pull-up resistors internally. Upon reset, Port 1 is configured as an output port. Forexample, the following code will continuously send out to port1 the alternating values 19
  20. 20. 55h & AAh MOV A, #55H; A = 55 hex BACK: MOV P1, A; send it to Port 1 ACALL DELAY ; call delay routine CPL A; make A=0SJMP BACKPort 1 as input:-To make port1 an input port, it must programmed as such by writing 1 toall its bits. In the following code port1 is configured first as an input port by writing 1’s toit, then data is received from the port and saved in R7 ,R6 & R5. MOV A, #0FFH ; A=FF HEX MOV P1, A ; make P1 an input port by writing all 1’s to it MOV A, P1 ; get data from P1 MOV R7, A ; save it in register R7 ACALL DELAY ; wait MOV A, P1 ; get another data from P1 MOV R6, A ; save it in register R6 ACALL DELAY ; wait MOV A, P1 ; get another data from 20
  21. 21. MOV R5, A ; save it in register R5Port 2:-Port 2 occupies a total of 8 pins (pins 21- 28). It can be used as input or output.Just like P1, P2 does not need any pull-up resistors since it already has pull-up resistorsinternally. Upon reset, Port 2 is configured as an output port. For example, the followingcode will send out continuously to port 2 the alternating values 55h and AAH. That is allthe bits of port 2 toggle continuously. MOV A, #55H ; A = 55 hex BACK: MOV P2, A ; send it to Port 2 ACALL DELAY ; call delay routine CPL A ; make A=0 SJMP BACKPort 2 as input: - To make port 2 an input, it must programmed as such by writing 1 to allits bits. In the following code, port 2 is configured first as an input port by writing 1’s to it.Then data is received from that port and is sent to P1 continuously. MOV A, #0FFH ; A=FF hex MOV P2, A ; make P2 an input port by writing all 1’s to it BACK: MOV A, P2 ; get data from P2 MOV P1, A ; send it to Port1 SJMP BACK ; keep doing thatDual role of port 2:- In systems based on the 8751, 8951, and DS5000, P2 is used assimple I/O. However, in 8031-based systems, port 2 must be used along with P0 to providethe 16-bit address for the external memory. As shown in pin configuration 8051, port 2 isalso designed as A8-A15, indicating the dual function. Since an 8031 is capable of 21
  22. 22. accessing 64K bytes of external memory, it needs a path for the 16 bits of the address.While P0 provides the lower 8 bits via A0-A7, it is the job of P2 to provide bits A8-A15 ofthe address. In other words, when 8031 is connected to external memory, P2 is used for theupper 8 bits of the 16 bit address, and it cannot be used for I/O.Port 3:- port 3 occupies a total of 8 pins, pins 10 through 17. It can be used as input oroutput. P3 does not need any pull-up resistors, the same as P1 and P2 did not. Althoughport 3 is configured as an output port upon reset. Port 3 has the additional function ofproviding some extremely important signals such as interrupts. This information appliesboth 8051 and 8031 chips. There functions are as follows:- P3.0 and P3.1 are used for the RxD and TxD serial communications signals. Bits P3.2and P3.3 are set aside for external interrupts. Bits P3.4 and P3.5 are used for timers 0 and1. Finally P3.6 and P3.7 are used to provide the WR and RD signals of external memoriesconnected in 8031 based systems. 22
  23. 23. Single bit addressability of ports:-There are times that we need to access only 1 or 2 bits of the port instead of the entire 8bits. A powerful feature of 8051 I/O ports is their capability to access individual bits of theport without altering the rest of the bits in that port.For example, the following code toggles the bit p1.2 continuously. BACK: CPL P1.2 ; complement p1.2 only ACALL DELAY SJMP BACK Notice that P1.2 is the third bit of P1, since the first bit is P1.0, the second bit is P1.1,and so on. Notices in example of those unused portions of port1 are undisturbed. Tablebellow shows the bits of 8051 I/O ports. This single bit addressability of I/O ports is one ofthe features of the 8051 microcontroller. 23
  24. 24. AT89s52AT89S52 is an ATMEL controller with the core of Intel MCS-51. It has same pinconfiguration as give above.The AT89S52 is a low-power, high-performance CMOS 8-bit microcomputer with8K bytes of Downloadable Flash programmable and erasable read only memoryand 2K bytes of EEPROM. The device is manufactured using Atmel’s high densitynonvolatile memory technology and is compatible with the industry standard80C51 instruction set and pin out. The on-chip Downloadable Flash allows the 24
  25. 25. program memory to be reprogrammed in-system through an SPI serial interface orby a conventional nonvolatile memory programmer. By combining a versatile 8-bitCPU with Downloadable Flash on a monolithic chip, the Atmel AT89S52 is apowerful microcomputer which provides a highly flexible and cost effective solutionto many embedded control applications. The AT89S52 provides the followingstandard features: 8K bytes of Downloadable Flash, 2K bytes of EEPROM, 256bytes of RAM, 32 I/O lines, programmable watchdog timer, two Data Pointers,three 16-bit timer/counters, a six-vector two-level interrupt, a full duplex serial port,on-chip oscillator, and clock circuitry. In addition, the AT89S52 is designed withstatic logic for operation down to zero frequency and supports two softwareselectable power saving modes. The Idle Mode stops the CPU while allowing theRAM, timer/counters, serial port, and interrupt system to continue functioning. ThePower down Mode saves the RAM contents but freezes the oscillator, disabling allother chip functions until the next interrupt or hardware reset.The Downloadable Flash can be changed a single byte at a time and is accessiblethrough the SPI serial interface. Holding RESET active forces the SPIbus into a serial programming interface and allows the program memory to bewritten to or read from unless Lock Bit 2 has been activated.Features• Compatible with MCS-51™Products• 8K bytes of In-System Reprogrammable Downloadable Flash Memory- SPI Serial Interface for Program Downloading- Endurance: 1,000 Write/Erase Cycles• 4.0V to 5.5V Operating Range• Fully Static Operation: 0 Hz to 33 MHz• Three-Level Program Memory Lock• 256 x 8 bit Internal RAM• 32 Programmable I/O Lines• Three 16 bit Timer/Counters• Eight Interrupt Sources 25
  26. 26. • Full Duplex UART Serial Channel• Low Power Idle and Power Down Modes• Interrupt Recovery From Power Down Mode• Watchdog Timer• Dual Data Pointer• Power off FlagRSTReset input. A high on this pin for two machine cycles while the oscillator isrunning resets the device.ALE/PROGAddress Latch Enable is an output pulse for latching the low byte of the addressduring accesses to external memory. This pin is also the program pulse input(PROG) during Flash programming. In normal operation, ALE is emitted at aconstant rate of 1/ 6 the oscillator frequency and may be used for external timingor clocking purposes. Note, however, that one ALE pulse is skipped during eachaccess to external data memory. If desired, ALE operation can be disabled bysetting bit 0 of SFR location 8EH. With the bit set, ALE is active only during aMOVX or MOVC instruction. Otherwise, the pin is weakly pulled high. Setting theALE-disable bit has no effect if the microcontroller is in external execution mode.PSENProgram Store Enable is the read strobe to external program memory. When theAT89S8252 is executing code from external program memory, PSEN is activatedtwice each machine cycle, except that two PSEN activations are skipped duringeach access to external data memory.EA/VPP 26
  27. 27. External Access Enable. EA must be strapped to GND in order to enable thedevice to fetch code from external program memory locations starting at 0000H upto FFFFH. Note, however, that if lock bit 1 is programmed, EA will be internallylatched on reset. EA should be strapped to VCC for internal program executions.This pin also receives the 12-volt programming enable voltage (VPP) during Flashprogramming when 12-volt programming is selectedXTAL1Input to the inverting oscillator amplifier and input to the internal clock operatingcircuit.XTAL2Output from the inverting oscillator amplifier. Circuit representing external crystal 27
  28. 28. Timer and counter descriptionTimer 0 and 1:Timer 0 and Timer 1 in the AT89S52 operate the same way as Timer 0 and Timer1 in the AT89C51, AT89C52 and “Timer/Counters.”Timer 2:Timer 2 is a 16 bit Timer/Counter that can operate as either a timer or an eventcounter. The type of operation is selected by bit C/T2 in the SFR T2CON (shownin Table 2). Timer 2 has three operating modes: capture, auto-reload (up or downcounting), and baud rate generator. The modes are selected by bits in T2CON, asshown in Table 8. Timer 2 consists of two 8-bit registers, TH2 and TL2. In theTimer function, the TL2 register is incremented every machine cycle. Since amachine cycle consists of 12 oscillator periods, the count rate is 1/12 of theoscillator frequency. In the Counter function, the register is incremented in 28
  29. 29. response to a 1-to-0 transition at its corresponding external input pin, T2. In thisfunction, the external input is sampled during S5P2 of every machine cycle. Whenthe samples show a high in one cycle and a low in the next cycle, the count isincremented. The new count value appears in the register during S3P1 of thecycle following the one in which the transition was detected. Since two machinecycles (24 oscillator periods) are required to recognize a 1-to-0 transition, themaximum count rate is 1/24 of the oscillator frequency. To ensure that a givenlevel is sampled at least once before it changes, the level should be held for atleast one full machine cycle Interrupts:The AT89S52 has a total of six interrupt vectors: two external interrupts (INT0 andINT1), three timer interrupts (Timers 0, 1, and 2), and the serial port interrupt.Each of these interrupt sources can be individually enabled or disabled by settingor clearing a bit in Special Function Register IE. IE also contains a global disablebit, EA, which disables all interrupts at once. In the AT89C51, bit position IE.5 isalso unimplemented. 29
  30. 30. User software should not write 1s to these bit positions, since they may be used infuture AT89 products. Timer 2 interrupt is generated by the logical OR of bits TF2and EXF2 in register T2CON. Neither of these flags is cleared by hardwarewhen the service routine is vectored to. In fact, the service routine may have todetermine whether it was TF2 or EXF2 that generated the interrupt, and that bitwill have to be cleared in software. The Timer 0 and Timer 1 flags, TF0 and TFI,are set at S5P2 of the cycle in which the timers overflow. The values are thenpolled by the circuitry in the next cycle. However, the Timer 2 flag, TF2, is set atS2P2 and is polled in the same cycle in which the timer overflows.Interrupt Registers: 30
  31. 31. The global interrupt enable bit and the individual interrupt enable bits are in the IEregister. In addition, the individual interrupt enable bit for the SPI is in the SPCRregister. Two priorities can be set for each of the sixinterrupt sources in the IP register.CODE FOR INTERRUPTS#include<at89s8252.h>void en_int(void);void delay(unsigned int i);void main (void){P1=0x00;INT0=0;en_int();}void en_int(void){EA=1;EX0=1;}void isr_intr (void) interrupt 0{ if(INT0==0) { while(1) 31
  32. 32. { P1_0=1; delay(1000000); delay(1000000); delay(1000000); delay(1000000); P1_0=0; delay(1000000); delay(1000000); delay(1000000); delay(1000000); }}}void delay(unsigned int i){ while(i!=0) { i--; } }Advantages of C over Assembly language programming• Knowledge of the processor instruction set is not required.• Details like register allocation and addressing of memory and data is managed by the compiler.• Programs get a formal structure and can be divided into separate functions. 32
  33. 33. • Programming and program test time is drastically reduced, this increases efficiency.• Keywords and operational functions can be used that come closer to how humans think.• The supplied and supported C libraries contain many standard routines such as numeric conversions.• Reusable code: Existing program parts can be more easily included into new programs, because of the comfortable modular program construction techniques.• The C language based on the ANSI standard is very portable. Existing programs can be quickly adapted to other processors as needed.Interfacing to LCD DisplayOn most displays, the pins are numbered on the LCD’s printed circuit board, but ifnot, it is quit easy to locate pin1. Since the pin is connected to ground, it often hasa thicker p.c.b. track connected to it, and it is generally connected to the metalwork at some point.The function of each of the connections is shown in the table below:- 33
  34. 34. Pins 1 & 2 are the power supply lines, Vss & Vdd. The Vdd pin should be connectedto the positive supply & Vss to the 0V supply or ground.Although the LCD module data sheets specify 5V D.C. supply (at only a fewmilliamps), supplies of 6V & 4.5V both work well, and even 3V is sufficient for somemodules. Consequently, these modules can be effectively and economically poweredby batteries.Pin 3 is a control pin, Vee, which is used to alter the contrast of the display. Ideally,these pin should be connected to a variable voltage supply. A preset potentiometerconnected between the power supply lines, with its wiper connected to the contrastpin is suitable in many cases, but be aware that some modules may require anegative potential; as low as 7V in some cases. For absolute simplicity, connectingthis pin to 0V will often suffice.Pin 4 is register select (RS) line. PIN NO. NAME FUNCTION 1 Vss Ground 2 Vdd +ve supply 3 Vee contrast 4 RS Register select 5 R/W Read/Write 6 E Enable 7 D0 Data Bit 0 8 D1 Data Bit 1 9 D2 Data Bit 2 10 D3 Data Bit 3 11 D4 Data Bit 4 12 D5 Data Bit 5 13 D6 Data Bit 6 14 D7 Data Bit 7 34
  35. 35. Three command control inputs. When this line is low, data bytes transferred tothe display are treated as commands, and data bytes read from the displayindicate its status. By setting the RS line high, character data can betransferred to and from the module.Pin 5 is (R/W) line. This line is pulled low in order to write commands orcharacter data to the module, or pulled high to read character data or statusinformation from its registers.Pin 6 is Enable (E) line. This input is used to initiate the actual transfer ofcommands or character data between the module and the data lines. Whenwriting to the display, data is transferred only on the high to low transition ofthis signal. However, when reading from the display, data will becomeavailable shortly after the low to high transition and remain available until thesignal falls low again.Pins 7 to 14 are the eight data bus lines (D0 to D7). Data can be transferred toand from the display, either as a single 8-bit byte or as two 4-bit “nibbles”. Inthe latter case, only the upper four data lines (D4 to D7) are used. This $-bitmode is beneficial when using a microcontroller, as fewer I/O lines arerequired. 35
  36. 36. CODE FOR INTERFACING OF LCD WITH AT89S52 MICROCONTROLLER #include<at89s8252.h>#define lcdprt P0#define rs P1_2#define en P1_3void delay(unsigned int i); 36
  37. 37. void lcd_cmd(unsigned char a); void display(unsigned char b); void wait(void); void init_lcd(void); void clear_lcd(void); void cursor_position(unsigned char c); void disp_hex(unsigned char digit); void disp_dec(unsigned int digit); code unsigned char lkup_tb101[16]={0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F}; //LCD ROUTINES// void lcd_cmd(unsigned char a) { wait(); lcdprt=a; rs=0; en=1; en=0; } void init_lcd(void) { lcd_cmd(0x3c); lcd_cmd(0x0c); lcd_cmd(0x06); lcd_cmd(0x01);} void clear_lcd(void){lcd_cmd(0x01);}void display(unsigned char b){ 37
  38. 38. wait();lcdprt=b;rs=1;en=1;en=0;}void wait(void){unsigned int count=300;while(count!=0){count--;}}void cursor_position(unsigned char c){lcd_cmd(c+0x80);}void disp_hex(unsigned char digit){unsigned char temp;temp=digit>>4;display(lkup_tb101[temp])temp=(digit&0x0f);display(lkup_tb101[temp]);}void disp_dec(unsigned int digit){unsigned int temp;if (digit<100){temp=digit/10;display(lkup_tb101[temp]);temp=digit-temp*10;display(lkup_tb101[temp]);}if(digit>99&&digit<1000) 38
  39. 39. {temp=digit/100;display(lkup_tb101[temp]);digit=digit-(temp*100);temp=digit/10;display(lkup_tb101[temp]);digit=digit-(temp*10);temp=digit;display(lkup_tb101[temp]);}if(digit>99&&digit<10000){temp=digit/100;display(lkup_tb101[temp]);digit=digit-(temp*1000);temp=digit/100;display(lkup_tb101[temp]);digit=digit-(temp*100);temp=digit/10;display(lkup_tb101[temp]);digit=digit-(temp*10);temp=digit;display(lkup_tb101[temp]);}if(digit>10000){temp=digit/10000;display(lkup_tb101[temp]);digit=digit-(temp*10000);temp=digit/1000;display(lkup_tb101[temp]);digit=digit-(temp*1000);temp=digit/100;display(lkup_tb101[temp]); 39
  40. 40. digit=digit-(temp*100);temp=digit/10;display(lkup_tb101[temp]);digit=digit-(temp*10);temp=digit;display(lkup_tb101[temp]); }}void delay(unsigned int i){while(i!=0){i--;} }void main(void){while(1){init_lcd();cursor_position(0x00);display(h);delay(0xffff);cursor_position(0x01);display(e);delay(0xffff); cursor_position(0x02);display(l);delay(0xffff); cursor_position(0x03);display(l);delay(0xffff); cursor_position(0x04); 40
  41. 41. display(o); delay(0xffff);} } CODE FOR SERIAL PORT COMMUNICATION IN TRANSMIT MODE #include<at89s8252.h> void init_sit(void) {TMOD=0x00; TMOD=0x20; 41
  42. 42. SCON=0x40;TR1=1;TH1=0xfd;}void transmit_serial(unsigned int a){int i;TI=0;for(i=0xffff;i>=0;i--);SBUF=a;}void main(void){init_sit();transmit_serial(0x01);}CODE FOR SERIAL PORT COMMUNICATION IN RECEIVE MODE#include<at89s8252.h>void init_sit(void){TMOD=0x00;TMOD=0x20; 42
  43. 43. SCON=0x50;TR1=1;TH1=0xfd;}unsigned int receive(void){int i;RI=0;for(i=0xffff;i>=0;i--);return SBUF;}void main(void){int e;init_lcd();clear_lcd();init_sit();e=receive();display(e);}82C55A FUNCTIONAL DESCRIPTIONThe 82C55A is a programmable peripheral interface device designed for use in Intelmicrocomputer systems.Its function is that of a general purpose I/O component to interface peripheral equipment tothe microcomputer system bus. The functional configuration of the 82C55A is 43
  44. 44. programmed by the system software so that normally no external logic is necessary tointerface peripheral devices or structuresPin DiagramData Bus BufferThis 3-state bidirectional 8-bit buffer is used to interface the 82C55A to the system databus. Data is transmitted or received by the buffer upon execution of input or outputinstructions by the CPU. Control words and status information are also transferred throughthe data bus buffer.Read/Write and Control LogicThe function of this block is to manage all of the internal and external transfers of bothData and Control or Status words. It accepts inputs from the CPU Address and Controlbusses and in turn, issues commands to both of the Control Groups. 44
  45. 45. Ports A, B, and CThe 82C55A contains three 8-bit ports (A, B, and C). All can be configured in a widevariety of functional characteristics by the system software but each has itsPort A:One 8-bit data output latch/buffer and one 8-bit input latch buffer. Both “pull-up and “pulldown buses hold devices are present on Port A.Port B:One 8-bit data input/output latch/buffer. Only “pull-up bus hold devices are present onPort B.Port C:One 8-bit data output latch/buffer and one 8-bit data input buffer (no latch for input). Thisport can be divided into two 4-bit ports under the mode control. Each 4-bit port contains a4-bit latch and it can be used for the control signal outputs and status signal inputs inconjunction with ports A and B. Only ``pull-up bus hold devices are present 45
  46. 46. RESET is kept low to make all the ports the output ports. To do this, the pin isconnected to the pin of controller as shown and the pin is then made to 1 and thento 0.PA, PB, PC become output ports.It has four registers Pa, Pb, Pc, CW 00, 01, 10, 11 46
  47. 47. ADC0804 8-Bit μP Compatible D/A Converters with 8- ChannelThe ADC0804 family is CMOS 8-Bit, successive-approximation A/D converterswhich use a modified potentiometric ladder and are designed to operate with the8080A control bus via three-state outputs. These converters appear to theprocessor as memory locations or I/O ports, and hence no interfacing logic isrequired. The differential analog voltage input has good common mode- rejection 47
  48. 48. and permits offsetting the analog zero-input voltage value. In addition, the voltagereference input can be adjusted to allow encoding any smaller analog voltagespan to the full 8 bits of resolution.Features• 80C48 and 80C80/85 Bus Compatible - No Interfacing Logic Required• Conversion Time < 100s• Easy Interface to Most Microprocessors• Differential Analog Voltage Inputs• TTL Compatible Inputs and Outputs• On-Chip Clock Generator• 0V to 5V Analog Voltage Input Range (Single + 5V Supply)• No Zero-Adjust RequiredPIN DIAGRAM 48
  49. 49. 49
  50. 50. When interfacing is being done then gets lowered then only it allows thecontroller to read the data, otherwise controller can not read the data. is always grounded. is software controlled.CODE FOR INTERFACING OF ADC(0804) WITH AT89S52MICROCONTROLLER #include<at89s8252.h> #define lcdprt P0 #define rs P1_2 #define en P1_3 unsigned char read_adc(void); unsigned char display_dec(unsigned char i); void init_sit(void); void transmit_serial(unsigned int a); void delay(unsigned int i); void lcd_cmd(unsigned char a); void display(unsigned char b); void wait(void); void init_lcd(void); void clear_lcd(void); void cursor_position(unsigned char c); void disp_hex(unsigned char digit); void disp_dec(unsigned int digit); void shift(void); code unsigned char lkup_tb101[16]={0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F}; //LCD ROUTINES// void lcd_cmd(unsigned char a) { wait(); 50
  51. 51. lcdprt=a; rs=0; en=1; en=0; } void init_lcd(void){ lcd_cmd(0x3c); lcd_cmd(0x0c); lcd_cmd(0x06); lcd_cmd(0x01); } void clear_lcd(void) { lcd_cmd(0x01); } void display(unsigned char b) { wait(); lcdprt=b; rs=1; en=1; en=0; } void wait(void) {unsigned int count=300; while(count!=0) {count--; 51
  52. 52. } } void shift(void) { lcd_cmd(0x1c); } void cursor_position(unsigned char c) {lcd_cmd(c+0x80); } void disp_hex(unsigned char digit) {unsigned char temp; temp=digit>>4; display(lkup_tb101[temp]); temp=(digit&0x0f); display(lkup_tb101[temp]); } void disp_dec(unsigned int digit) {unsigned int temp,temp1,temp2; if (digit<100) {temp1=digit/10; display(lkup_tb101[temp1]); temp2=digit-temp1*10; display(lkup_tb101[temp2]); transmit_serial(temp1*10+temp2);} if(digit>99&&digit<1000) {temp=digit/100;display(lkup_tb101[temp]); digit=digit-(temp*100); 52
  53. 53. temp=digit/10;display(lkup_tb101[temp]);digit=digit-(temp*10);temp=digit;display(lkup_tb101[temp]);}if(digit>99&&digit<10000){temp=digit/100;display(lkup_tb101[temp]);digit=digit-(temp*1000);temp=digit/100;display(lkup_tb101[temp]);digit=digit-(temp*100);temp=digit/10;display(lkup_tb101[temp]);digit=digit-(temp*10);temp=digit;display(lkup_tb101[temp]);}if(digit>10000){temp=digit/10000;display(lkup_tb101[temp]);digit=digit-(temp*10000);temp=digit/1000;display(lkup_tb101[temp]);digit=digit-(temp*1000);temp=digit/100; 53
  54. 54. display(lkup_tb101[temp]); digit=digit-(temp*100); temp=digit/10; display(lkup_tb101[temp]); digit=digit-(temp*10); temp=digit; display(lkup_tb101[temp]); }} void delay(unsigned int i) { while(i!=0) { i--; } } void init_sit(void) {TMOD=0x00; TMOD=0x20; SCON=0x40; TR1=1; TH1=0xfd; }void transmit_serial(unsigned int a){int i;TI=0;for(i=0xffff;i>=0;i--);SBUF=a;}void main(void) 54
  55. 55. {unsigned int e;P2=0xff;init_lcd();init_sit();while(1){e=read_adc();cursor_position(0x00);delay(0xffff);disp_dec(e);}}unsigned char read_adc(void){unsigned char n;P1_0=0; // SOC=0P1_0=1; // SOC=1while(P1_1==1) //while( EOC==1){n=P2;}return(n);} 55
  56. 56. Real Time ClockThe DS12887 is real-time clocks (RTCs). The devices provide a real-timeclock/calendar, one time-of-day alarm, three maskable interrupts with a commoninterrupt output, a programmable square wave, and 114 bytes of battery backedstatic. The DS12887 integrates a quartz crystal and lithium energy source into a24-pin encapsulated DIP package. The DS12C887 adds a century byte ataddress 32h. For all devices, the date at the end of the month is automaticallyadjusted for months with fewer than 31 days, including correction for leap years.The devices also operate in either 24-hour or 12-hour format with an AM/PMindicator. A precision temperature-compensated circuit monitors the status ofVcc. If a primary power failure is detected, the device automatically switches to abackup supply. A lithium coin-cell battery can be connected to the VBAT input pinon the DS12885 to maintain time and date operation when primary power isabsent. The device is accessed through a multiplexed byte-wide interface, whichsupports both Intel and Motorola mode 56
  57. 57. Pin diagramFeatures♦ RTC Counts Seconds, Minutes, Hours, Day, Date, Month, and Year with Leap Year Compensation Through 2099♦ Binary or BCD Time Representation♦ 12-Hour or 24-Hour Clock with AM and PM in 12-Hour Mode♦ Daylight Saving Time Option♦ Interfaced with Software as 128 RAM Locations♦ 14 Bytes of Clock and Control Registers 57
  58. 58. ♦ 114 Bytes of General-Purpose, Battery-Backed RAM (113 Bytes in the DS12C887 and DS12C887A)♦ Time-of-Day Alarm Once Per Second to Once Per Day♦ Periodic Rates from 122μs to 500ms♦ Programmable Square-Wave Output♦ Automatic Power-Fail Detect and Switch Circuitry♦ Optional 28-Pin PLCC Surface Mount Package or 32-Pin TQFP (DS12885♦ Optional Encapsulated DIP (EDIP) Package with Integrated Crystal and Battery(DS12887, DS12887A, DS12C887, DS12C887A)♦ Optional Industrial Temperature Range Available♦ Underwriters Laboratory (UL) RecognizedFOR REGISTER ra (To control RTC functions for some settings) UIP DV2 DV1 DV0 RS3 RS2 RS1 RS0 0 0 1 0 0 0 0 0 To initially start the oscillator. ra=0x20FOR REGISTER rb (To control RTC functions for some settings) SET PIE AIE UIE SQWE DM 24/12 DSE 1 0 0 0 0 0 0 0 DM=0(BCD) =1(HEXADECIMAL) Square Wave Alarm Interrupt Enable Periodic Interrupt Enab 58
  59. 59. To Update Set Bit is 1 rb=0x80 59
  60. 60. CODE FOR INTERFACING OF RTC (DS12887) WITH ATs52MICROCONTROLLER#include<at89s8252.h>#define LCDPRT P2#define RS P1_2#define EN P1_3void bcdconv(unsigned int mb);void T0M2delay_rtc(void);void init_rtc(void);void delay(unsigned int i);void lcd_cmd(unsigned char a);void display(unsigned char b);void wait(void);void Init_lcd(void);void clear_lcd(void);void cursor_position(unsigned char c);struct rtc{ unsigned char second; unsigned char sa; unsigned char minute; unsigned char ma; unsigned char hours; unsigned char ha; unsigned char dow; unsigned char dom; unsigned char month; unsigned char years; unsigned char ra; unsigned char rb; unsigned char rc; unsigned char rd;};xdata at 0x0000 struct rtc ds12887;void main(void){ 60
  61. 61. unsigned int x;unsigned char sec;unsigned char hr;unsigned char minInit_lcd();for(x=0;x<10000;x++)T0M2delay_rtc();ds12887.ra=0x20;ds12887.rb=0x81;ds12887.second=0x55;ds12887.minute=0x25;ds12887.hours=0x09;ds12887.dom=0x19;ds12887.month=0x10;ds12887.years=0x06;ds12887.rb=0x03;while(1){ sec=ds12887.second;cursor_position(0x00);bcdconv(sec);cursor_position(0x02);display(:);min=ds12887.minute;cursor_position(0x03);bcdconv(min);cursor_position(0x05);display(:); hr=ds12887.hours; cursor_position(0x06); bcdconv(hr);cursor_position(0x40);display(s);cursor_position(0x42);display(:);cursor_position(0x43);display(m);cursor_position(0x45);display(:);cursor_position(0x46);display(h);}} 61
  62. 62. void bcdconv(unsigned int mb){unsigned int x;unsigned int y;x=mb&0x0f;x=x|0x30;y=mb&0xf0;y=y>>4;y=y|0x30;display(y);display(x);}void T0M2delay_rtc(void){TMOD=TMOD&0xf0;TMOD=TMOD|0x02;TH0=0xEC; // 236 decimal value load in THOTR0=1;if(TF0==1){ TR0=0; TF0=0; }}void lcd_cmd(unsigned char a) { wait (); LCDPRT=a; RS=0; EN=1; EN=0; } void display(unsigned char b) { wait (); LCDPRT=b; RS=1; EN=1; EN=0; } void wait(void) { unsigned int count=300; while(count!=0) 62
  63. 63. { count--; }} void Init_lcd(void) { lcd_cmd(0x3c); lcd_cmd(0x0c); lcd_cmd(0x06); lcd_cmd(0x01); } void clear_lcd(void){ lcd_cmd(0x01); } void cursor_position(unsigned char c) { lcd_cmd(c+0x80); } 63
  64. 64. 64
  65. 65. Detailed description of training project:For easy understanding I have divide my project into four sections: Regulated power supply Microcontroller DC Motor drive AT89S52 LCD display Conveyor belt application(I) POWER SUPPLY SECTION: Initial stage of every electronic circuit is power supply system which provides requiredpower to drive the whole system. The specification of power supply depends on the powerrequirement and this requirement is determined by its rating. The main components used insupply system are: (i) transformer (ii) rectifier 65
  66. 66. (iii) input filter (iv) regulator (v) output filter (vi) output indication (i) Transformer: The main source of power supply is a transformer. The maximum outputpower of power supply is dependent on maximum output power of transformer .Wedetermine power from its current and voltage rating. e.g.: if there is a transformer of 12V,500mA then maximum power delivered by transformer is 6Watt.It means we can drive a load from this transformer up to 6w. In our project our maximumpower requirement is 1watt. So to provide this power we use 12V/250mA transformer. Themaximum output power of this transformer is 4watt.it means it can easily drive load up to4 watt. (ii) Rectifier: Rectifier is a circuit which is used to convert ac to dc. Every electroniccircuit requires a dc power supply for rectification. We have used four diodes. (iii) Input filter: After rectification we obtain dc supply from ac but it is not pure dc it mayhave some ac ripples .To reduce these ripples we use filters. It comprises of two filters –low frequency ripple filter and high frequency ripple filter. To reduce low frequencyripples we use electrolytic capacitor. The voltage rating of capacitor must be double fromincoming dc supply. It blocks dc and passes ripples to ground. (iv) Regulator: Regulator is a device which provides constant output voltage withvarying input voltage. There are two types of regulators-(a) Fixed voltage regulator(b) Adjustable regulatorWe have used fixed voltage regulator LM78XX last two digits signify output voltage. Thevoltage for our system is 5V that is why we have used 7805 regulator which provides 5Vfrom 12V dc. (v) Output filter: It is used to filter out output ripple if any. (vi) Output indication: We use LED to observe the functioning of our system. If the LEDglows it confirms proper functioning of our supply. (III) MICROCONTROLLER AND DISPLAY SECTION: We are all familiar with the term microcontroller and even havestudied it as part of our curriculum but the question is why we use microcontroller? 66
  67. 67. Well, we use microcontroller to control our hardware using programs which we makeaccording to our requirement. We have used MCS51 family microcontroller AT89S52. Wehave interfaced LCD with microcontroller to display the working action of our drive. Wehave connected LCD on port1 and we control the drive action of motor from port2. RS(P3.3) and EN (P3.4) pin of LCD are connected to port 3. Detailed description ofinterfacing of LCD with microcontroller has been explained in earlier section in detail. (IV) DC MOTOR DRIVE SECTION: We use dc motor drive to control direction of dc motor. it means atparticular time it will move in forward motion and at another particular time it will movein backward direction. The timing of this circuit is controlled by microcontroller. Tooperate dc motor we require dc voltage. When we give positive voltage to positiveterminal and negative voltage to negative terminal it moves clockwise i.e. forwarddirection and when we give positive voltage to negative terminal and negative voltage topositive terminal the motor moves in anticlockwise direction i.e. backward/reversedirection. This voltage is provided to the motor through drive section which comprises oftransistors. The switching action of these transistors is controlled by microcontroller. Wehave used four NPN transistors (BC547). Since the out put power of BC547 that is thetransistor is not sufficient to drive motor that is why we use a Darlington pair packageTIP127 (PNP) and TIP122 (NPN) with BC547 to increase the incoming power from theemitter of BC547. Hence sufficient power from TIP122 and TIP127 is easily provided tomotor. in our circuit transistor Q1,Q2,Q3,Q4 provide Vcc to motor and Q5,Q6,Q7,Q8provide ground to motor.WORKIN ACTION OF TRANSISTOR: When we give a base voltage to Q1 and Q8 they are set to onposition. Q1 provide Vcc and Q8 provide ground to DC motor and in this case motormoves clock wise. Q4 and Q7 are in off position. Similarly when we set Q4 and Q7 in onposition Q4 provide Vcc to motor and Q7 provide ground to motor. This configuration isopposite to previous configuration and in this case motor moves anti clock wise. since wehave used silicon transistor the need minimum .7 volt dc to get on and we are providing5volt as base voltage from microcontroller.(IV) CONVEYOR BELT APPLICATION USING DC MOTOR: Our project is a small model which depicts the transportation ofgoods from one place to another in production plant in industry.C CODING FOR CONTROLLING DRIVE ACCORDING TO APPLICATION# include<at89s8252.h>#define LCDPRT P1#define RS P3_3#define EN P3_4void lcd_cmd(unsigned char a);code unsigned char name_arry[]={"forward$"};code unsigned char name_arry1[]={"backward$"}; 67
  68. 68. code unsigned char name_arry2[]={"stop $"};bit flag;unsigned char sec;void drive(void);void display_string(unsigned char *sp);void display_string1(unsigned char *pp);void display_string2(unsigned char *tp);void delay(unsigned int i);void lcd_cmd(unsigned char a);void display(unsigned char b);void wait(void);void Init_lcd(void);void clear_lcd(void);void cursor_position(unsigned char c);void main(void){P2=0x00;Init_lcd(); drive(); } void drive(void) { while(1){ P2=0x00; cursor_position(0x00); display_string2(&name_arry2); delay(0xffff); delay(0xffff); delay(0xffff); delay(0xffff);delay(0xffff);delay(0xffff);delay(0xffff); P2=0x05; cursor_position(0x00); display_string(&name_arry); delay(0xffff); 68
  69. 69. P2=0x00; cursor_position(0x00); display_string2(&name_arry2); delay(0xffff); delay(0xffff); delay(0xffff); delay(0xffff); delay(0xffff); delay(0xffff); delay(0xffff); P2=0x0a; cursor_position(0x00); display_string1(&name_arry1); delay(0xffff); } }void display_string(unsigned char *sp) { while(*sp!=$) { display(*sp); sp=sp+1; } }void display_string1(unsigned char *pp) { while(*pp!=$) { display(*pp); pp=pp+1; } 69
  70. 70. } void display_string2(unsigned char *tp) { while(*tp!=$) { display(*tp); tp=tp+1; } }void lcd_cmd(unsigned char a) { wait (); LCDPRT=a; RS=0; EN=1; EN=0; } void display(unsigned char b) { wait (); LCDPRT=b; RS=1; EN=1; EN=0; } void wait(void) { unsigned int count=300; while(count!=0) { count--; } } void Init_lcd(void) { lcd_cmd(0x3c); lcd_cmd(0x0c); lcd_cmd(0x06); lcd_cmd(0x01); 70
  71. 71. } void clear_lcd(void){ lcd_cmd(0x01); }void delay (unsigned int i) { while (i!=0) { i--; }} void cursor_position(unsigned char c) { lcd_cmd(c+0x80); } 71

×