《单片机原理与接口技术 (2).pdf》由会员分享,可在线阅读,更多相关《单片机原理与接口技术 (2).pdf(17页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、1PQFP/TQFP12345678910113332313029282726252423P1.5P1.6P1.7RST(RXD)P3.0NC(TXD)P3.1(INT0)P3.2(INT1)P3.3(T0)P3.4(T1)P3.5PO.4(AD4)P0.5(AD5)P0.6(AD6)P0.7(AD7)EA/VPPNCALE/PROGPSENP2.7(A15)P2.6(A14)P2.5(A13)44434241403938373635341213141516171819202122(WR)P3.6(RD)P3.7XTAL2XTAL1GNDGND(A8)P2.0(A9)P2.1(A10)P2.2
2、(A11)P2.3(A12)P2.4P1.4P1.3P1.2 P1.1(T2 EX)P1.0(T2)NCVCCP0.0(AD0)P0.1(AD1)P0.2(AD2)P0.3(AD3)FeaturesCompatible with MCS-51 Products4K Bytes of In-System Reprogrammable Flash Memory Endurance:1,000 Write/Erase CyclesFully Static Operation:0 Hz to 24 MHzThree-level Program Memory Lock128 x 8-bit Intern
3、al RAM32 Programmable I/O LinesTwo 16-bit Timer/CountersSix Interrupt SourcesProgrammable Serial ChannelLow-power Idle and Power-down ModesDescriptionThe AT89C51 is a low-power,high-performance CMOS 8-bit microcomputer with 4Kbytes of Flash programmable and erasable read only memory(PEROM).The devic
4、eis manufactured using Atmels high-density nonvolatile memory technology and iscompatible with the industry-standard MCS-51 instruction set and pinout.The on-chipFlash allows the program memory to be reprogrammed in-system or by a conven-tional nonvolatile memory programmer.By combining a versatile
5、8-bit CPU with Flashon a monolithic chip,the Atmel AT89C51 is a powerful microcomputer which providesa highly-flexible and cost-effective solution to many embedded control applications.PDIP12345678910111213141516171819204039383736353433323130292827262524232221 P1.0 P1.1P1.2P1.3P1.4P1.5P1.6P1.7RST(RX
6、D)P3.0(TXD)P3.1(INT0)P3.2(INT1)P3.3(T0)P3.4(T1)P3.5(WR)P3.6(RD)P3.7XTAL2XTAL1GNDVCCP0.0(AD0)P0.1(AD1)P0.2(AD2)P0.3(AD3)P0.4(AD4)P0.5(AD5)P0.6(AD6)P0.7(AD7)EA/VPPALE/PROGPSENP2.7(A15)P2.6(A14)P2.5(A13)P2.4(A12)P2.3(A11)P2.2(A10)P2.1(A9)P2.0(A8)Rev.0265G02/008-bit Microcontroller with 4K Bytes FlashAT
7、89C51Not Recommended for New Designs.Use AT89S51.Pin ConfigurationsPLCC78910111213141516173938373635343332313029P1.5P1.6P1.7RST(RXD)P3.0NC(TXD)P3.1(INT0)P3.2(INT1)P3.3(T0)P3.4(T1)P3.5PO.4(AD4)P0.5(AD5)P0.6(AD6)P0.7(AD7)EA/VPPNCALE/PROGPSENP2.7(A15)P2.6(A14)P2.5(A13)6543214443424140181920212223242526
8、2728(WR)P3.6(RD)P3.7XTAL2XTAL1GNDNC(A8)P2.0(A9)P2.1(A10)P2.2(A11)P2.3(A12)P2.4P1.4P1.3P1.2 P1.1P1.0NCVCCP0.0(AD0)P0.1(AD1)P0.2(AD2)P0.3(AD3)AT89C512Block DiagramPORT 2 DRIVERSPORT 2LATCHP2.0-P2.7FLASHPORT 0LATCHRAMPROGRAMADDRESSREGISTERBUFFERPCINCREMENTERPROGRAMCOUNTERDPTRRAM ADDR.REGISTERINSTRUCTIO
9、NREGISTERBREGISTERINTERRUPT,SERIAL PORT,AND TIMER BLOCKSSTACKPOINTERACCTMP2TMP1ALUPSWTIMINGANDCONTROLPORT 3LATCHPORT 3 DRIVERSP3.0-P3.7PORT 1LATCHPORT 1 DRIVERSP1.0-P1.7OSCGNDVCCPSENALE/PROGEA/VPPRSTPORT 0 DRIVERSP0.0-P0.7AT89C513The AT89C51 provides the following standard features:4Kbytes of Flash,
10、128 bytes of RAM,32 I/O lines,two 16-bittimer/counters,a five vector two-level interrupt architecture,a full duplex serial port,on-chip oscillator and clock cir-cuitry.In addition,the AT89C51 is designed with static logicfor operation down to zero frequency and supports twosoftware selectable power
11、saving modes.The Idle Modestops the CPU while allowing the RAM,timer/counters,serial port and interrupt system to continue functioning.ThePower-down Mode saves the RAM contents but freezesthe oscillator disabling all other chip functions until the nexthardware reset.Pin DescriptionVCCSupply voltage.
12、GNDGround.Port 0Port 0 is an 8-bit open-drain bi-directional I/O port.As anoutput port,each pin can sink eight TTL inputs.When 1sare written to port 0 pins,the pins can be used as high-impedance inputs.Port 0 may also be configured to be the multiplexed low-order address/data bus during accesses to
13、external pro-gram and data memory.In this mode P0 has internalpullups.Port 0 also receives the code bytes during Flash program-ming,and outputs the code bytes during programverification.External pullups are required during programverification.Port 1Port 1 is an 8-bit bi-directional I/O port with int
14、ernal pullups.The Port 1 output buffers can sink/source four TTL inputs.When 1s are written to Port 1 pins they are pulled high bythe internal pullups and can be used as inputs.As inputs,Port 1 pins that are externally being pulled low will sourcecurrent(IIL)because of the internal pullups.Port 1 al
15、so receives the low-order address bytes duringFlash programming and verification.Port 2Port 2 is an 8-bit bi-directional I/O port with internal pullups.The Port 2 output buffers can sink/source four TTL inputs.When 1s are written to Port 2 pins they are pulled high bythe internal pullups and can be
16、used as inputs.As inputs,Port 2 pins that are externally being pulled low will sourcecurrent(IIL)because of the internal pullups.Port 2 emits the high-order address byte during fetchesfrom external program memory and during accesses toexternal data memory that use 16-bit addresses(MOVX DPTR).In this
17、 application,it uses strong internal pullupswhen emitting 1s.During accesses to external data mem-ory that use 8-bit addresses(MOVX RI),Port 2 emits thecontents of the P2 Special Function Register.Port 2 also receives the high-order address bits and somecontrol signals during Flash programming and v
18、erification.Port 3Port 3 is an 8-bit bi-directional I/O port with internal pullups.The Port 3 output buffers can sink/source four TTL inputs.When 1s are written to Port 3 pins they are pulled high bythe internal pullups and can be used as inputs.As inputs,Port 3 pins that are externally being pulled
19、 low will sourcecurrent(IIL)because of the pullups.Port 3 also serves the functions of various special featuresof the AT89C51 as listed below:Port 3 also receives some control signals for Flash pro-gramming and verification.RSTReset input.A high on this pin for two machine cycles whilethe oscillator
20、 is running resets the device.ALE/PROGAddress Latch Enable output pulse for latching the low byteof the address during accesses to external memory.Thispin is also the program pulse input(PROG)during Flashprogramming.In normal operation ALE is emitted at a constant rate of 1/6the oscillator frequency
21、,and may be used for external tim-ing or clocking purposes.Note,however,that one ALEPort PinAlternate FunctionsP3.0RXD(serial input port)P3.1TXD(serial output port)P3.2INT0(external interrupt 0)P3.3INT1(external interrupt 1)P3.4T0(timer 0 external input)P3.5T1(timer 1 external input)P3.6WR(external
22、data memory write strobe)P3.7RD(external data memory read strobe)AT89C514pulse is skipped during each access to external DataMemory.If desired,ALE operation can be disabled by setting bit 0 ofSFR location 8EH.With the bit set,ALE is active only dur-ing a MOVX or MOVC instruction.Otherwise,the pin is
23、weakly pulled high.Setting the ALE-disable bit has noeffect if the microcontroller is in external execution mode.PSENProgram Store Enable is the read strobe to external pro-gram memory.When the AT89C51 is executing code from external pro-gram memory,PSEN is activated twice each machinecycle,except t
24、hat two PSEN activations are skipped duringeach access to external data memory.EA/VPPExternal Access Enable.EA must be strapped to GND inorder to enable the device to fetch code from external pro-gram memory locations starting at 0000H up to FFFFH.Note,however,that if lock bit 1 is programmed,EA wil
25、l beinternally latched on reset.EA should be strapped to VCC for internal programexecutions.This pin also receives the 12-volt programming enable volt-age(VPP)during Flash programming,for parts that require12-volt VPP.XTAL1Input to the inverting oscillator amplifier and input to theinternal clock op
26、erating circuit.XTAL2Output from the inverting oscillator amplifier.Oscillator Characteristics XTAL1 and XTAL2 are the input and output,respectively,of an inverting amplifier which can be configured for use asan on-chip oscillator,as shown in Figure 1.Either a quartzcrystal or ceramic resonator may
27、be used.To drive thedevice from an external clock source,XTAL2 should be leftunconnected while XTAL1 is driven as shown in Figure 2.There are no requirements on the duty cycle of the externalclock signal,since the input to the internal clocking circuitryis through a divide-by-two flip-flop,but minim
28、um and maxi-mum voltage high and low time specifications must beobserved.Idle Mode In idle mode,the CPU puts itself to sleep while all the on-chip peripherals remain active.The mode is invoked bysoftware.The content of the on-chip RAM and all the spe-cial functions registers remain unchanged during
29、thismode.The idle mode can be terminated by any enabledinterrupt or by a hardware reset.It should be noted that when idle is terminated by a hardware reset,the device normally resumes program execu-tion,from where it left off,up to two machine cycles beforethe internal reset algorithm takes control.
30、On-chip hardwareinhibits access to internal RAM in this event,but access tothe port pins is not inhibited.To eliminate the possibility ofan unexpected write to a port pin when Idle is terminated byreset,the instruction following the one that invokes Idleshould not be one that writes to a port pin or
31、 to externalmemory.Figure 1.Oscillator ConnectionsNote:C1,C2=30 pF 10 pF for Crystals=40 pF 10 pF for Ceramic ResonatorsC2XTAL2GNDXTAL1C1Status of External Pins During Idle and Power-down ModesModeProgram MemoryALEPSENPORT0PORT1PORT2PORT3IdleInternal11DataDataDataDataIdleExternal11FloatDataAddressDa
32、taPower-downInternal00DataDataDataDataPower-downExternal00FloatDataDataDataAT89C515Figure 2.External Clock Drive ConfigurationPower-down Mode In the power-down mode,the oscillator is stopped,and theinstruction that invokes power-down is the last instructionexecuted.The on-chip RAM and Special Functi
33、on Regis-ters retain their values until the power-down mode isterminated.The only exit from power-down is a hardwarereset.Reset redefines the SFRs but does not change theon-chip RAM.The reset should not be activated before VCCis restored to its normal operating level and must be heldactive long enou
34、gh to allow the oscillator to restart andstabilize.Program Memory Lock Bits On the chip are three lock bits which can be left unpro-grammed(U)or can be programmed(P)to obtain theadditional features listed in the table below.When lock bit 1 is programmed,the logic level at the EA pinis sampled and la
35、tched during reset.If the device is pow-ered up without a reset,the latch initializes to a randomvalue,and holds that value until reset is activated.It is nec-essary that the latched value of EA be in agreement withthe current logic level at that pin in order for the device tofunction properly.Lock
36、Bit Protection ModesProgram Lock BitsProtection TypeLB1LB2LB31UUUNo program lock features2PUUMOVC instructions executed from external program memory are disabled from fetching code bytes from internal memory,EA is sampled and latched on reset,and further programming of the Flash is disabled3PPUSame
37、as mode 2,also verify is disabled4PPPSame as mode 3,also external execution is disabledAT89C516Programming the Flash The AT89C51 is normally shipped with the on-chip Flashmemory array in the erased state(that is,contents=FFH)and ready to be programmed.The programming interfaceaccepts either a high-v
38、oltage(12-volt)or a low-voltage(VCC)program enable signal.The low-voltage program-ming mode provides a convenient way to program theAT89C51 inside the users system,while the high-voltageprogramming mode is compatible with conventional third-party Flash or EPROM programmers.The AT89C51 is shipped wit
39、h either the high-voltage orlow-voltage programming mode enabled.The respectivetop-side marking and device signature codes are listed inthe following table.The AT89C51 code memory array is programmed byte-by-byte in either programming mode.To program any non-blank byte in the on-chip Flash Memory,th
40、e entire memorymust be erased using the Chip Erase Mode.Programming Algorithm:Before programming theAT89C51,the address,data and control signals should beset up according to the Flash programming mode table andFigure 3 and Figure 4.To program the AT89C51,take thefollowing steps.1.Input the desired m
41、emory location on the address lines.2.Input the appropriate data byte on the data lines.3.Activate the correct combination of control signals.4.Raise EA/VPP to 12V for the high-voltage program-ming mode.5.Pulse ALE/PROG once to program a byte in the Flash array or the lock bits.The byte-write cycle
42、is self-timed and typically takes no more than 1.5 ms.Repeat steps 1 through 5,changing the address and data for the entire array or until the end of the object file is reached.Data Polling:The AT89C51 features Data Polling to indi-cate the end of a write cycle.During a write cycle,anattempted read
43、of the last byte written will result in the com-plement of the written datum on PO.7.Once the write cyclehas been completed,true data are valid on all outputs,andthe next cycle may begin.Data Polling may begin any timeafter a write cycle has been initiated.Ready/Busy:The progress of byte programming
44、 can alsobe monitored by the RDY/BSY output signal.P3.4 is pulledlow after ALE goes high during programming to indicateBUSY.P3.4 is pulled high again when programming isdone to indicate READY.Program Verify:If lock bits LB1 and LB2 have not beenprogrammed,the programmed code data can be read backvia
45、 the address and data lines for verification.The lock bitscannot be verified directly.Verification of the lock bits isachieved by observing that their features are enabled.Chip Erase:The entire Flash array is erased electricallyby using the proper combination of control signals and byholding ALE/PRO
46、G low for 10 ms.The code array is writtenwith all“1”s.The chip erase operation must be executedbefore the code memory can be re-programmed.Reading the Signature Bytes:The signature bytes areread by the same procedure as a normal verification oflocations 030H,031H,and 032H,except that P3.6 andP3.7 mu
47、st be pulled to a logic low.The values returned areas follows.(030H)=1EH indicates manufactured by Atmel(031H)=51H indicates 89C51(032H)=FFH indicates 12V programming(032H)=05H indicates 5V programmingProgramming InterfaceEvery code byte in the Flash array can be written and theentire array can be e
48、rased by using the appropriate combi-nation of control signals.The write operation cycle is self-timed and once initiated,will automatically time itself tocompletion.All major programming vendors offer worldwide support forthe Atmel microcontroller series.Please contact your localprogramming vendor
49、for the appropriate software revision.VPP=12VVPP=5VTop-side MarkAT89C51xxxxyywwAT89C51xxxx-5yywwSignature(030H)=1EH(031H)=51H(032H)=F FH(030H)=1EH(031H)=51H(032H)=05HAT89C517Note:1.Chip Erase requires a 10 ms PROG pulse.Figure 3.Programming the FlashFigure 4.Verifying the FlashFlash Programming Mode
50、sModeRSTPSENALE/PROGEA/VPPP2.6P2.7P3.6P3.7Write Code DataHL H/12VLHHHRead Code DataHLHHLLHHWrite LockBit-1HLH/12VHHHHBit-2HLH/12VHHLLBit-3HLH/12VHLHLChip EraseHLH/12VHLLLRead Signature ByteHLHHLLLL(1)P1P2.6P3.6P2.0-P2.3A0-A7ADDR.OOOOH/OFFFHTSEE FLASHPROGRAMMINGMODESABLE3-24 MHzA8-A11P0+5VP2.7PGMDATA