基于单片机的智能路灯控制系统.doc
《基于单片机的智能路灯控制系统.doc》由会员分享,可在线阅读,更多相关《基于单片机的智能路灯控制系统.doc(16页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、元件清单名称型号数量(个)单片机AT89S521RS-232标准串口设计的接口电路MAX2321串口DB91光耦MOC30521双电压比较器LM3931稳压管LM78051变压器220V转9V1二极管IN40072三极管90131可控硅BTA081LED灯发光二极管1灯泡220V 40W的白炽灯1滑动变阻器100K1光敏电阻LG44162电阻1001330110K51K1150K2电容103110421054电解电容10pF210uF11000uF/25F12200uF/25F1P1.01P1.12P1.23P1.34P1.45P1.5/MOSI6P1.6/MISO7P1.7/SCK8RST9
2、P3.0/RXD10P3.1/TXD11P3.2/INT012P3.3/INT113P3.4/T014P3.5/T115P3.6/WR16P3.7/RD17XTAL218XTAL119GND20A8/P2.021A9/P2.122A10/P2.223A11/P2.324A12/P2.425A13/P2.526A14/P2.627A15/P2.728PESN29ALE/PROG30EA/VPP31P0.7/AD732P0.6/AD633P0.5/AD534P0.4/AD435P0.3/AD336P0.2/AD237P0.1/AD138P0.0/AD039VCC40U1AT89S52D3IN400
3、7L1LEDR11KR21KC1104C2104C5104Vin1GND2Vout3U5LM7805R310KR8100R410KVCC213T1BTA081264U2MOC3052C10103R6330R7330VCC C1+1V+2C1-3C2+4C2-5V-6T2out7R2in8R2out9T2in10T1in11R1out12R1in13T1out14GND15VCC16U4MAX232C6105C7105C9105C8105162738495J1DB9VCCVCCR510KS1SW-PBVCCC1230pFC1330pF12J29VVCCOUTPUT A1IUTPUT A+2 IU
4、TPUT A-3GND4 IUTPUT B-5 IUTPUT B+6OUTPUT B7VCC8J3LM393R1010KR14150KR910KR11150KVCC12J4220VR13100KR15100KC31000uF/25VC42200uF/25VY111.0592MU3LAMPC1110uFQ190135VR16LRR12LR1234J5K1Private Declare Sub Sleep Lib Kernel32 (ByVal dwMilliseconds As Long)通信Dim commflag As BooleanDim commstr(0 To 3) As Byte灯泡
5、状态 true 亮 false 灭Dim lightstate As Boolean故障指示灯状态 true 亮 false 灭Dim errorledstate As Boolean联机指示Dim connection As BooleanDim config As String/当点击“联机”按钮时或动其他按钮时,如果计算机和硬件未连接,会出现”端口打开错误”的命令窗口;如果计算机和硬件连接了,会出现”系统已联机”的字样。Private Sub Command1_Click()On Error GoTo out If Not connection ThenMe.MSComm1mPort =
6、 Mebo1.ListIndex + 1 Me.MSComm1.PortOpen = True If Me.MSComm1.PortOpen = False Then MsgBox 端口打开错误, vbOKOnly, 错误 Else connection = Not connection Me.Label8.Caption = 系统已联机 Me.Label8.ForeColor = RGB(255, 0, 0) Memand1.Caption = 断开 commstr(0) = &HFF commstr(1) = &H1 commstr(2) = &H0 commstr(3) = commst
7、r(0) Xor commstr(1) Xor commstr(2) commflag = True Me.MSComm1.Output = commstr End If Else connection = Not connection Me.MSComm1.PortOpen = False Me.Label8.Caption = 系统未联机 Me.Label8.ForeColor = RGB(255, 255, 255) Memand1.Caption = 联机 lightstate = False errorledstate = False Me.lederror(0).FillColor
8、 = RGB(100, 100, 100)Me.ledstate(0).FillColor = RGB(100, 100, 100) End If GoTo out2out: MsgBox 端口打开错误, vbOKOnly, 错误out2:End SubPrivate Sub Form_Load()Dim timestr As StringMe.ledstate(0).FillColor = RGB(100, 100, 100)Me.lederror(0).FillColor = RGB(100, 100, 100)Me.Label3.Caption = Now()Mebo1.ListInde
9、x = 0/端口的参数设置串口MSComm1.Settings = 9600,n,8,1MSComm1.InputMode = 0 采用文本接收MSComm1.InBufferCount = 0 清空接受缓冲区MSComm1.OutBufferCount = 0 清空传输缓冲区MSComm1.RThreshold = 1 产生MSComm事件恢复时间config = App.Path + + config.iniOpen config For Input As #1 读取该汉字在16点阵字库中的原始字模Line Input #1, timestrMe.DTPicker1.Value = tim
10、estrLine Input #1, timestrMe.DTPicker2.Value = timestrClose #1清发送标志commflag = FalseMe.Text1.Text = Str(Me.UpDown1.Value)errorledstate = Falselightstate = Falseconnection = FalseEnd SubPrivate Sub Form_Unload(Cancel As Integer)保存时间Dim timestr As Stringconfig = App.Path + + config.iniOpen config For O
11、utput As #1 读取该汉字在16点阵字库中的原始字模Print #1, Me.DTPicker1.ValuePrint #1, Me.DTPicker2.ValueClose #1End Sub/当PC机发送“开灯”请求时,单片机回送“tuon”命令,开灯成功;当PC机发送“故障检测”请求时,单片机回送“trou”命令,说明灯泡故障,VB界面中的故障灯会亮,反之单片机回送“norm”命令,说明灯泡是好的,正常的,VB界面种的故障灯不会发生变化。Private Sub MSComm1_OnComm()Dim strBuff As StringSelect Case MSComm1mEve
12、nt Case 2 strBuff = MSComm1.Input If strBuff = ok Then commflag = False ElseIf strBuff = toff Then Me.ledstate(0).FillColor = RGB(100, 100, 100) lightstate = False commflag = False ElseIf strBuff = tuon Then Me.ledstate(0).FillColor = RGB(255, 0, 0) lightstate = True commflag = FalseElseIf strBuff =
13、 trou Then Me.lederror(0).FillColor = RGB(255, 0, 0) ElseIf strBuff = norm Then Me.lederror(0).FillColor = RGB(100, 100, 100) End IfEnd SelectEnd SubPrivate Sub Option1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If connection Then commstr(0) = &HFF commstr(1) = &H56 com
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 基于 单片机 智能 路灯 控制系统
限制150内