;chuong trinh dieu khien dong co khong dong bo 3 pha ;viet cho vi dieu khien 8051 ;thuc hien truyen thong noi tiep UART voi may tinh ;toc do truyen 9600, khong kiem tra chan le, 8 bit du lieu, 1 bit dung ;thach anh su dung la 11,0592Mhz ; ;dinh nghia cac chan vao ra quay_thuan equ p1.0 ;chan dieu khien quay thuan quay_nguoc equ p1.1 ;chan dieu khien quay nguoc cam_bien equ p3.4 ;chan nhan xung dem tu encoder ;su dung encoder E6B2-C cua OMRON chon ty le 100 xung tren 1 vong ; org 0 jmp main ; khai bao dia chi vector ngat noi tiep org 23h jnb ri,thoat_ngat ;kiem tra ngat nhan mov a,sbuf ;doc ky tu nhan duoc vao A cjne a,'1',so_sanh_tiep1 ;kiem tra xem ky tu nhan duoc co phai la tin hieu chon quay thuan clr quay_nguoc setb quay_thuan ;chon quay thuan jmp thoat_ngat so_sanh_tiep1: cjne a,'2',so_sanh_tiep2 ;kiem tra xem ky tu nhan duoc co phai la tin hieu chon quay nguoc clr quay_thuan setb quay_nguoc ;chon quay nguoc jmp thoat_ngat so_sanh_tiep2: cjne a,'0',thoat_ngat ;kiem tra xem ky tu nhan duoc co phai la tin hieu chon dung clr quay_thuan clr quay_nguoc ;chon dung quay thoat_ngat: reti ; bat dau chuong trinh chinh main: mov ie,#10010000b ;cho phep ngat noi tiep ;thiet lap khung du lieu noi tiep MOV TMOD,#20h ;Timer 1 in Auto-reload mode MOV TH1,#0FDh ;Reload value for 9600 baud @ 11.059 Mhz SETB TR1 ;Turn on timer 1 mov scon,#50h ;cho phep nhan du lieu noi tiep ; clr quay_thuan ;dung dong co clr quay_nguoc mov tmod,#00100101b ;chon timer 0 mode 16 bit o che do bo dem setb tr0 ;khoi dong timer0 lap: mov a,tl0 ;doc xung dem vao a mov b,#100 div ab ;chia cho 100 jb ti,$ ;cho truyen mov a,sbuf ;truyen di clr ti ;xoa co truyen jmp lap end Private Sub Command2_Click() Text2.Text = "DõNG" COM.Output = "0" 'gui so 0 chon dung End Sub Private Sub Command3_Click() Text2.Text = "QUAY THUËN" COM.Output = "1" 'gui so 1 chon quay thuan End Sub Private Sub Command4_Click() Text2.Text = "QUAY NG¦îC" COM.Output = "2" 'gui so 2 chon quay nguoc End Sub Private Sub Command5_Click() COM.PortOpen = False 'CHON DONG CONG COM End End Sub Private Sub Form_Load() 'THIET LAP THONG SO CHO CONG NOI TIEP' 'TOC DO TRUYEN LA 9600' '8 BIT DU LIEU, 1 BIT DUNG, KHONG KIEM TRA CHAN LE' 'SU DUNG CONG COM1' COM.CommPort = 1 'CHON CONG NOI TIEP 1 COM.Settings = "9600,n,8,1" 'thiet lap toc do 9600,khong kiem tra chan le, 8 bit du lieu, 1 bit dung COM.PortOpen = True 'chon mo cong COM Text2.Text = "DõNG" End Sub Private Sub MSComm1_OnComm() End Sub XTAL2 18 XTAL1 19 ALE 30 EA 31 PSEN 29 RST 9 P0.0/AD0 39 P0.1/AD1 38 P0.2/AD2 37 P0.3/AD3 36 P0.4/AD4 35 P0.5/AD5 34 P0.6/AD6 33 P0.7/AD7 32 P1.0 1 P1.1 2 P1.2 3 P1.3 4 P1.4 5 P1.5 6 P1.6 7 P1.7 8 P3.0/RXD 10 P3.1/TXD 11 P3.2/INT0 12 P3.3/INT1 13 P3.4/T0 14 P3.7/RD 17 P3.6/WR 16 P3.5/T1 15 P2.7/A15 28 P2.0/A8 21 P2.1/A9 22 P2.2/A10 23 P2.3/A11 24 P2.4/A12 25 P2.5/A13 26 P2.6/A14 27 U1 AT89C51 1 6 2 7 3 8 4 9 5 J1 CONN-D9F T1IN 11 R1OUT 12 T2IN 10 R2OUT 9 T1OUT 14 R1IN 13 T2OUT 7 R2IN 8 C2+ 4 C2- 5 C1+ 1 C1- 3 VS+ 2 VS- 6 U2 MAX232 C1 1uF C2 1uF C3 1uF C4 1uF C5 33p X1 CRYSTAL FREQ=11.0592Mhz C6 33p C7 10uF R1 8.2K Q1 2N2369 D1 LED-RED D2 LED-RED Q2 2N2369 XTAL2 18 XTAL1 19 ALE 30 EA 31 PSEN 29 RST 9 P0.0/AD0 39 P0.1/AD1 38 P0.2/AD2 37 P0.3/AD3 36 P0.4/AD4 35 P0.5/AD5 34 P0.6/AD6 33 P0.7/AD7 32 P1.0 1 P1.1 2 P1.2 3 P1.3 4 P1.4 5 P1.5 6 P1.6 7 P1.7 8 P3.0/RXD 10 P3.1/TXD 11 P3.2/INT0 12 P3.3/INT1 13 P3.4/T0 14 P3.7/RD 17 P3.6/WR 16 P3.5/T1 15 P2.7/A15 28 P2.0/A8 21 P2.1/A9 22 P2.2/A10 23 P2.3/A11 24 P2.4/A12 25 P2.5/A13 26 P2.6/A14 27 U1 AT89C51 1 6 2 7 3 8 4 9 5 J1 CONN-D9F T1IN 11 R1OUT 12 T2IN 10 R2OUT 9 T1OUT 14 R1IN 13 T2OUT 7 R2IN 8 C2+ 4 C2- 5 C1+ 1 C1- 3 VS+ 2 VS- 6 U2 MAX232 C1 1uF C2 1uF C3 1uF C4 1uF C5 33p X1 CRYSTAL FREQ=11.0592Mhz C6 33p C7 10uF R1 8.2K D2 LED-RED RLQT RLQN R2 10k R3 10k D3 10MQ100NTR 12VDC 12VDC . Sub XTAL2 18 XTAL1 19 ALE 30 EA 31 PSEN 29 RST 9 P0.0/AD0 39 P0.1/AD1 38 P0.2/AD2 37 P0 .3/ AD3 36 P0.4/AD4 35 P0.5/AD5 34 P0.6/AD6 33 P0.7/AD7 32 P1.0 1 P1.1 2 P1.2 3 P1 .3 4 P1.4 5 P1.5 6 P1.6 7 P1.7 8 P3.0/RXD 10 P3.1/TXD 11 P3.2/INT0 12 P3 .3/ INT1 13 P3.4/T0 14 P3.7/RD 17 P3.6/WR 16 P3.5/T1 15 P2.7/A15 28 P2.0/A8 21 P2.1/A9 22 P2.2/A10 23 P2 .3/ A11 24 P2.4/A12 25 P2.5/A 13 26 P2.6/A14 27 U1 AT89C51 1 6 2 7 3 8 4 9 5 J1 CONN-D9F T1IN 11 R1OUT 12 T2IN 10 R2OUT 9 T1OUT 14 R1IN 13 T2OUT 7 R2IN 8 C2+ 4 C2- 5 C1+ 1 C1- 3 VS+ 2 VS- 6 U2 MAX 232 C1 1uF C2 1uF C3 1uF C4 1uF C5 33 p X1 CRYSTAL FREQ=11.0592Mhz C6 33 p C7 10uF R1 8.2K Q1 2N 236 9 D1 LED-RED D2 LED-RED Q2 2N 236 9 XTAL2 18 XTAL1 19 ALE 30 EA 31 PSEN 29 RST 9 P0.0/AD0 39 P0.1/AD1 38 P0.2/AD2 37 P0 .3/ AD3 36 P0.4/AD4 35 P0.5/AD5 34 P0.6/AD6 33 P0.7/AD7 32 P1.0 1 P1.1 2 P1.2 3 P1 .3 4 P1.4 5 P1.5 6 P1.6 7 P1.7 8 P3.0/RXD 10 P3.1/TXD 11 P3.2/INT0 12 P3 .3/ INT1 13 P3.4/T0 14 P3.7/RD 17 P3.6/WR 16 P3.5/T1 15 P2.7/A15 28 P2.0/A8 21 P2.1/A9 22 P2.2/A10 23 P2 .3/ A11 24 P2.4/A12 25 P2.5/A 13 26 P2.6/A14 27 U1 AT89C51 1 6 2 7 3 8 4 9 5 J1 CONN-D9F T1IN 11 R1OUT 12 T2IN 10 R2OUT 9 T1OUT 14 R1IN 13 T2OUT 7 R2IN 8 C2+ 4 C2- 5 C1+ 1 C1- 3 VS+ 2 VS- 6 U2 MAX 232 C1 1uF C2 1uF C3 1uF C4 1uF C5 33 p X1 CRYSTAL FREQ=11.0592Mhz C6 33 p C7 10uF R1 8.2K D2 LED-RED RLQT RLQN R2 10k R3 10k D3 10MQ100NTR 12VDC 12VDC . Sub XTAL2 18 XTAL1 19 ALE 30 EA 31 PSEN 29 RST 9 P0.0/AD0 39 P0.1/AD1 38 P0.2/AD2 37 P0 .3/ AD3 36 P0.4/AD4 35 P0.5/AD5 34 P0.6/AD6 33 P0.7/AD7 32 P1.0 1 P1.1 2 P1.2 3 P1 .3 4 P1.4 5 P1.5 6 P1.6 7 P1.7 8 P3.0/RXD 10 P3.1/TXD 11 P3.2/INT0 12 P3 .3/ INT1 13 P3.4/T0 14 P3.7/RD 17 P3.6/WR 16 P3.5/T1 15 P2.7/A15 28 P2.0/A8 21 P2.1/A9 22 P2.2/A10 23 P2 .3/ A11 24 P2.4/A12 25 P2.5/A 13 26 P2.6/A14 27 U1 AT89C51 1 6 2 7 3 8 4 9 5 J1 CONN-D9F T1IN 11 R1OUT 12 T2IN 10 R2OUT 9 T1OUT 14 R1IN 13 T2OUT 7 R2IN 8 C2+ 4 C2- 5 C1+ 1 C1- 3 VS+ 2 VS- 6 U2 MAX 232 C1 1uF C2 1uF C3 1uF C4 1uF C5 33 p X1 CRYSTAL FREQ=11.0592Mhz C6 33 p C7 10uF R1 8.2K Q1 2N 236 9 D1 LED-RED D2 LED-RED Q2 2N 236 9 XTAL2 18 XTAL1 19 ALE 30 EA 31 PSEN 29 RST 9 P0.0/AD0 39 P0.1/AD1 38 P0.2/AD2 37 P0 .3/ AD3 36 P0.4/AD4 35 P0.5/AD5 34 P0.6/AD6 33 P0.7/AD7 32 P1.0 1 P1.1 2 P1.2 3 P1 .3 4 P1.4 5 P1.5 6 P1.6 7 P1.7 8 P3.0/RXD 10 P3.1/TXD 11 P3.2/INT0 12 P3 .3/ INT1 13 P3.4/T0 14 P3.7/RD 17 P3.6/WR 16 P3.5/T1 15 P2.7/A15 28 P2.0/A8 21 P2.1/A9 22 P2.2/A10 23 P2 .3/ A11 24 P2.4/A12 25 P2.5/A 13 26 P2.6/A14 27 U1 AT89C51 1 6 2 7 3 8 4 9 5 J1 CONN-D9F T1IN 11 R1OUT 12 T2IN 10 R2OUT 9 T1OUT 14 R1IN 13 T2OUT 7 R2IN 8 C2+ 4 C2- 5 C1+ 1 C1- 3 VS+ 2 VS- 6 U2 MAX 232 C1 1uF C2 1uF C3 1uF C4 1uF C5 33 p X1 CRYSTAL FREQ=11.0592Mhz C6 33 p C7 10uF R1 8.2K D2 LED-RED RLQT RLQN R2 10k R3 10k D3 10MQ100NTR 12VDC 12VDC . ;chuong trinh dieu khien dong co khong dong bo 3 pha ;viet cho vi dieu khien 8051 ;thuc hien truyen thong noi tiep UART voi may tinh ;toc do truyen 9600, khong kiem tra chan