5.3模拟多路开关5.2A/D转换及与单片机接口电路设计5.1MCS-51单片机第5章单片机及接口电路设计5.6ATmega128基础实例5.5AVR单片机开发工具(ATmega128)5.4AVR单片机简介(ATmega128)5.1MCS-51单片机5.1.1MCS-51单片机的引脚描述及片外总线结构图5-1MCS-51引脚图(1)主电源引脚Vcc和Vss。(2)外接晶体引脚XTAL1和XTAL2。(3)控制与其它电源复用引脚RST/VPD、ALE/、和/VPP。(4)输入/输出(I/O)引脚、PO、P1、P2、P3(共32根),其中,P3口(10脚~17脚)还用于专门功能,是复用双功能口。5.1.2MCS-51片内总体结构5.1.3MCS-51单片机基本外围电路1.MCS-51单片机上电复位电路2.MCS-51单片机时钟电路3.MCS-51单片机基本外围电路123456ABCD654321DCBATitleNumberRevisionSizeBDate:2-Oct-2008SheetofFile:E:\教学文件\机电一体化课程文件2008机制本部\MyDesign.ddbDrawnBy:EA/VP31X119X218RESET9RD17WR16INT012INT113T014T115P101P112P123P134P145P156P167P178P0039P0138P0237P0336P0435P0534P0633P0732P2021P2122P2223P2324P2425P2526P2627P2728PSEN29ALE/P30TXD11RXD10U189S51Y111.0592C130pC230pR1010k+C310uVCCVCCR3R4R5R6R7R2R1R0470*8D0D1D3D2D4D5D6D7VCCP10P11P12P13P14P15P16P17P10P11P12P13P14P15P16P1712345678161514131211109RP1470*8RSTVCC图5-6MCS-51单片机基本外围电路123456ABCD654321DCBATitleNumberRevisionSizeBDate:2-Oct-2008SheetofFile:E:\教学文件\机电一体化课程文件2008机制本部\MyDesign.ddbDrawnBy:EA/VP31X119X218RESET9RD17WR16INT012INT113T014T115P101P112P123P134P145P156P167P178P0039P0138P0237P0336P0435P0534P0633P0732P2021P2122P2223P2324P2425P2526P2627P2728PSEN29ALE/P30TXD11RXD10U189S51Y111.0592C130pC230pR1010k+C310uVCCVCCR3R4R5R6R7R2R1R0470*8D0D1D3D2D4D5D6D7VCCP10P11P12P13P14P15P16P17P10P11P12P13P14P15P16P1712345678161514131211109RP1470*8RSTVCC图5-7MCS-51单片机输入输出控制基本电路工作例程如下:#includeREGX51.H#includestdio.h#defineXTAL11.0592Mzunsignedintx,y;voidmain(void){x=P0;y=x;P1=y;}P0口作为输入,检测输入电平高低,P1口作为输出,控制LED亮灭。其工作过程为,检测P0口8个输入电平,再将P0口检测到的8个电平从P1口的8个引脚输出。5.1.4MCS-51单片机看门狗电路(MAX6814)随着单片机技术的发展和制造工艺的日益成熟,单片机的应用领域不断拓宽,但由于单片机自身的抗干扰能力较差,尤其是在一些条件比较恶劣、噪声大的场合常会出现单片机因受外界干扰而导致死机的现象,造成系统不能正常工作。设置看门狗是防止单片机死机提高单片机系统抗干扰性的一种重要途径。MAX6814是低功耗看门狗电路,该器件通过监视系统软件代码的运行错误提高系统的可靠性。(a)MAX6814芯片引脚图(b)电源上电和掉电时序图(c)看门狗工作时序图图5-8看门狗电路(MAX6814)该器件通过监视系统软件代码的运行错误提高系统的可靠性。当看门狗输入检测到一个瞬变沿WDI时,内部看门狗定时器被清零并重新启动,然后重新开始计时。如果看门狗定时器超过了看门狗超时周期(tWD=1.6s典型值),低电平有效、推挽式看门狗输出将被触发并维持一个看门狗脉冲(周期tPP=140ms最小值),向系统发出故障警报。WDO1234ABCD4321DCBATitleNumberRevisionSizeADate:21-Oct-2008SheetofFile:E:\教学文件\机电一体化课程文件2008机制本部\MyDesign.ddbDrawnBy:EA/VP31X119X218RESET9RD17WR16INT012INT113T014T115P101P112P123P134P145P156P167P178P0039P0138P0237P0336P0435P0534P0633P0732P2021P2122P2223P2324P2425P2526P2627P2728PSEN29ALE/P30TXD11RXD10U189S51Y112MHzCat130pCat230pVCCRXDTXDRSTP00P01P02P03P04P05P06P07P10P11P12P13P14P15P16P17P20P21P22P23P24P25P26P27MAX6814/WDOGNDN.CVCCWDIU?NOTVCC图5-9看门狗电路(MAX6814)在MCS-51单片机中的应用电路工作例程如下:#includeREGX51.H#includestdio.h#defineXTAL11.0592Mzunsignedintx,y,i;voidmain(void){for(;;){x=P0;y=5;……P17=0;/喂狗指令/P17=1;}}5.2A/D转换及与单片机接口电路设计传感器变送器A/DCPU电量模拟电压量数字量图传感器与微机的接口通道模拟数字转换电路称为A/D转换。AD571是10位逐次逼近式的单片集成A/D转换芯片。AD571将D/A转换电路、参考电压、时钟脉冲、比较器、逐次逼近寄存器及输比缓冲器集成在一个芯片上,并有三态输出,所以很容易与微处理器接口。图模拟量以数字量的表示A/D变换精度(分辨率):1LSBA/D变换位数:8位(低精度,1LSB=1/256),10位(常用,1LSB=1/1024),12位(常用,1LSB=1/4096),16位(高精度,1LSB=1/16384)A/D变换满度(模拟输入范围):0~5V,0~10V,-5~+5V等。A/D变换时间:从变换开始到变换结束的时间,各厂家采用的电路不同变换时间也不同。例1:10位A/D变换器满度0~5V,当VIN=2.3V时,变换值为多少?例2:10位A/D变换器满度-5~+5V,当VIN=2.3V时,变换值为多少?AD571转换器AN-IN:模拟电压输入端AN-GND:模拟地GND:电源地V-,V+:工作电源电压输入端(+15V,-15V)BIT1~BIT10:十位数据输出端BPLRof:单极性输入接地、双极性输入接高电平BL/CNV:接高电平不转换,接地启动转DRTrdy:转换结束时变为低电平转换时间:15μs~40μs,一般为25μs123456ABCD654321DCBATitleNumberRevisionSizeBDate:30-Sep-2010SheetofFile:E:\教学文件\机电一体化课程2010机制07\教案\MyDesign.ddbDrawnBy:GND16AN-IN13msBIT19BIT28AN-GND14BIT37BIT46BIT55BIT64BPLRof15BIT73BIT82BIT91lsb-1018+Vs10DATrdy17-Vs12BL&CNV11AD571AIN:模拟电压输入端AGND:模拟地GND:数字地V-,V+:工作电源电压输入端(+15V,-15V)BIT1~BIT10:十位数据输出端BPLRof:单极性输入接地、双极性输入接高电平B/C—(BLANK/CONVERT):接高电平不转换,接地启动转DATrdy:转换结束时变为低电平转换时间:15μs~40μs,一般为25μs计算下列输入电压时的数字输出值:AIN=2.1V(单极性输入)AIN=7.5V(单极性输入)AIN=-3.5V(双极性输入)AIN=2.5V(双极性输入)123456ABCD654321DCBATitleNumberRevisionSizeBDate:30-Sep-2010SheetofFile:E:\教学文件\机电一体化课程2010机制07\教案\MyDesign.ddbDrawnBy:GND16AN-IN13msBIT19BIT28AN-GND14BIT37BIT46BIT55BIT64BPLRof15BIT73BIT82BIT91lsb-1018+Vs10DATrdy17-Vs12BL&CNV11AD571+15V-15VCTRinAinAD571转换器应用电路123456ABCD654321DCBATitleNumberRevisionSizeBDate:2-Oct-2008SheetofFile:E:\教学文件\机电一体化课程文件2008机制本部\MyDesign.ddbDrawnBy:VCCRad5100Rad6100+12V-12VZ-REF-IN10lsbDB016DB117AN-GND9DB218DB319DB420BPLRof12DB521DB622DB72310Vspn13DB824DB92520Vspn14DB1026msb-1127REFout8STATUS28CS3+Vs7A0/SC4R/C5-Vs1112/82CE6VCC1U2AD1674A32674U7OP-07Z+Rad11KRad21K+12V-12VRad44.7KRad34.7KVCCEA/VP31X119X218RESET9RD17WR16INT012INT113T014T115P101P112P123P134P145P156P167P178P0039P0138P0237P0336P0435P0534P0633P0732P2021P2122P2223P2324P2425P2526P2627P2728PSEN29ALE/P30TXD11RXD10U189S51Y112MHzCat130pCat230pRat11kVCCVCCRXDTXDRSTP00P01P02P03P04P05P06P07P10P11P12P13CSA0R/-CSTATUSP14P15P16P17P20P21P22P23P24P25P26P27信号放大电路信号12位A/D转换电路+Cat34.7uP00P01P02P03P04P05P06P07P10P11P12P13P20P21P22123456ABCD654321DCBATitleNumberRevisionSizeBDate:2-Oct-2008SheetofFile:E:\教学文件\机电一体化课程文件2008机制本部\MyDesign.ddbDrawnBy:VCCRad5100Rad6100+12V-12VZ-REF-IN10lsbDB016DB117AN-GND9DB218DB319DB420BPLRof12DB521DB622DB72310Vspn13DB824DB92520Vspn14DB1026msb-1127REFout8STATUS28CS3+Vs7A0/SC4R/C5-Vs1112/82CE6VCC1U2AD1674A32674U7OP-07Z+Rad1