Thông báo

Collapse
No announcement yet.

Điều khiển Robot từ xa bằng máy tính

Collapse
X
 
  • Lọc
  • Giờ
  • Show
Clear All
new posts

  • #76
    tài liệu của bạn tôi nhớ em hữu ích thật, thank nhá ^^
    Nhận thiết kế và làm mạch in đồ án điện tử:
    Nick:doandientu
    Mail:
    Phone: 0904078671 (A.Danh)
    Add:18 - Phan Chu Trinh - Q.9
    Web: my.opera.com/doandientu

    Comment


    • #77
      Trên đây là một ví dụ viết cho giao tiếp từ máy tính xuống chip ...
      __________________________________________
      Private Sub Form_Load()

      With MSComm1
      .Settings = "9600,N,8,1"
      .CommPort = 1
      .RThreshold = 1
      .SThreshold = 0
      .InputMode = comInputModeText
      .InputLen = 0
      .Handshaking = comNone
      .InBufferSize = 1024
      .OutBufferSize = 1024
      If .PortOpen = False Then
      .PortOpen = True
      End If

      End With
      End Sub
      _________________________________________
      Private Sub MSComm1_OnComm()
      'Text2.SetFocus
      'Text2.text = ""
      Dim buffer As Variant
      If MSComm1.CommEvent = comEvReceive Then
      Text1.Text = MSComm1.Input
      End If
      End Sub
      ______________________________________
      ( Cái đoạn này có nghĩa là khi check vào ô R trên giao diện 3D máy tính thì robot sẽ rẽ phải...!!!)
      Private Sub Option1_Click()
      STATE_object_rotate_z car_handle, -7, OBJECT_SPACE
      'MSComm1.Output = "R"
      Text2.SetFocus
      End Sub
      _________________________________(còn nữa mà dài lắm....)
      from: toinhoem1001@yahoo.com
      add: công ty LLP, 204 nguyễn đình chính,phú nhuận,tphcm
      Last edited by toinhoem1001; 08-10-2009, 12:21.
      Nuôi con trẻ tại :
      Culi Manager tại :

      Comment


      • #78
        nếu muốn sử dụng kiểu truyền 1bit có thể xem cái này :
        __________________________________________________ __________________________________

        ;********************* chuong trinh viet cho remote tot nghiep *************
        ;******************* thuc thi chuong trinh ngay 26/4/2009 ******************
        ;************** designer : Nguyen hung thuong _ lop tu dong 04d2a **********
        ;*********** ^!^ my address : toinhoem1001@yahoo.com (0987876770) ^!^ ******
        $include 8051.mc
        ;************* dinh cac dia chi bit su dung trong chuong trinh *************
        ;************* dia chi cac kenh truyen *************************************
        kenh_1 bit p0.7
        kenh_2 bit p0.6
        kenh_3 bit p0.5
        kenh_4 bit p0.4
        ;****************** dia chi cac nut nhan dc su dung ***********************
        toi bit p3.0
        lui bit p3.1
        trai bit p3.2
        phai bit p3.3
        nang bit p3.4
        ha bit p3.5
        kep bit p3.6
        nha bit p3.7
        truot bit p0.0 ;**** truot lui ***
        auto_manu bit p0.1
        tang_toc bit p0.2 ;**** truot toi ***
        reset_auto bit p0.3
        ;******************** cac thanh ghi trung gian *******************************
        thoi_gian_tre data 2fh
        ;******************** phan thuc thi chuong trinh ****************************
        org 0h
        jmp main
        org 03h
        jmp ex0_isr
        org 0bh
        jmp t0_isr
        org 13h
        jmp ex1_isr
        org 1bh
        jmp t1_isr
        ;******************* than chuong trinh chinh *********************************
        main:
        Mov p0,#0ffh
        mov p3,#0ffh
        mov p2,#0h
        mov tmod,#11h
        mov ie,#10000000b
        setb tf0
        setb tf1
        mov thoi_gian_tre,#3
        start:
        Jb auto_manu,chuong_trinh_tu_dong
        jmp chuong_trinh_bang_tay
        jmp start
        ;****************** chuong trinh ngat thuc thi khi robot hoat dong **********
        ;******************** ngat ngoai o ******************************************
        ex0_isr:
        Reti
        ;************************ ngat timer 0 **************************************
        t0_isr:
        Clr tr0
        mov th0,#0ffh ;0feh
        mov tl0,#18h ;00c
        setb tr0
        mov p2,#0h
        reti
        ;************************* ngat ngoai 1 *************************************
        ex1_isr:
        Reti
        ;************************** ngat timer1 *************************************
        t1_isr:
        Clr tr1
        mov th1,#0h ;0feh
        mov tl1,#0h ;00c
        setb tr1
        mov p2,#0ffh
        reti
        ;***************** cac chuong trinh con co ban ******************************
        chuong_trinh_tu_dong:
        Mov p0,#0fh
        mov p2,#0ffh
        jmp $
        ret
        chuong_trinh_bang_tay:
        Kt_nut_toi:
        Jb toi,kt_nut_lui
        mov r0,#5
        xac_nhan_nut_toi:
        Djnz r0,xac_nhan_nut_toi
        lcall chay_toi
        jnb toi,kt_nut_toi
        mov p2,#0ffh
        mov p0,#0fh
        lcall delay_50ms
        ret
        kt_nut_lui:
        Jb lui,kt_nut_trai
        mov r0,#5
        xac_nhan_nut_lui:
        Djnz r0,xac_nhan_nut_lui
        lcall chay_lui
        jnb lui,kt_nut_lui
        mov p2,#0ffh
        mov p0,#00fh
        ret
        kt_nut_trai:
        Jb trai,kt_nut_phai
        mov r0,#5
        xac_nhan_nut_trai:
        Djnz r0,xac_nhan_nut_trai
        lcall re_trai
        jnb trai,kt_nut_trai
        mov p2,#0ffh
        mov p0,#00fh
        ret
        kt_nut_phai:
        Jb phai,kt_nut_nang
        mov r0,#5
        xac_nhan_nut_phai:
        Djnz r0,xac_nhan_nut_phai
        lcall re_phai
        jnb phai,kt_nut_phai
        mov p2,#0ffh
        mov p0,#00fh
        ret
        kt_nut_nang:
        Jb nang,kt_nut_ha
        mov r0,#5
        xac_nhan_nut_nang:
        Djnz r0,xac_nhan_nut_nang
        lcall nang
        jnb nang,kt_nut_nang
        mov p2,#0ffh
        mov p0,#00fh
        ret
        kt_nut_ha:
        Jb ha,kt_nut_kep
        mov r0,#5
        xac_nhan_nut_ha:
        Djnz r0,xac_nhan_nut_ha
        lcall ha_xuong
        jnb ha,kt_nut_ha
        mov p2,#0ffh
        mov p0,#00fh
        ret
        kt_nut_kep:
        Jb kep,kt_nut_nha
        mov r0,#5
        xac_nhan_nut_kep:
        Djnz r0,xac_nhan_nut_kep
        lcall kep
        jnb kep,kt_nut_kep
        mov p2,#0ffh
        mov p0,#00fh
        ret
        kt_nut_nha:
        Jb nha,kt_truot_toi
        mov r0,#5
        xac_nhan_nut_nha:
        Djnz r0,xac_nhan_nut_nha
        lcall nha
        jnb nha,kt_nut_nha
        mov p2,#0ffh
        mov p0,#00fh
        ret
        kt_truot_toi:
        Jb tang_toc,kt_truot_lui
        mov r0,#5
        xac_nhan_truot_toi:
        Djnz r0,xac_nhan_truot_toi
        lcall truot_toi
        jnb tang_toc,kt_truot_toi
        mov p2,#0h
        mov p0,#0fh
        ret
        kt_truot_lui:
        Jb truot,kt_nut_reset_robot_tu_dong
        mov r0,#5
        xac_nhan_truot_lui:
        Djnz r0,xac_nhan_truot_lui
        lcall truot_lui
        jnb truot,kt_truot_lui
        mov p2,#0h
        mov p0,#0fh
        ret
        kt_nut_reset_robot_tu_dong:
        Jb reset_auto,thoat_chuong_trinh
        mov r0,#10
        xac_nhan_nut_reset_auto:
        Djnz r0,xac_nhan_nut_reset_auto
        lcall reset_robot
        jnb reset_auto,kt_nut_reset_robot_tu_dong
        xoa_reset:
        Mov p2,#00000001b
        mov p0,#01111111b
        mov thoi_gian_tre,#2
        lcall delay_300ms
        mov a,p3
        cjne a,#11111111b,thoat_reset
        jmp xoa_reset
        thoat_reset:
        Ret
        thoat_chuong_trinh:
        Jmp chuong_trinh_bang_tay
        ;************************** chuong trinh con nho *********************************
        chay_toi:
        Mov p2,#0h
        mov p0,#01111111b
        lcall delay_50ms
        ret
        chay_lui:
        Mov p2,#0h
        mov p0,#10111111b
        lcall delay_50ms
        ret
        re_trai:
        Mov p2,#0h
        mov p0,#11011111b
        lcall delay_50ms
        ret
        re_phai:
        Mov p2,#0h
        mov p0,#11101111b
        lcall delay_50ms
        ret
        nang:
        Mov p2,#0h
        mov p0,#00111111b
        lcall delay_50ms
        ret
        ha_xuong:
        Mov p2,#0h
        mov p0,#01011111b
        lcall delay_50ms
        ret
        kep:
        Mov p2,#0h
        mov p0,#01101111b
        lcall delay_50ms
        ret
        nha:
        Mov p2,#0h
        mov p0,#10011111b
        lcall delay_50ms
        ret
        truot_toi:
        Mov p2,#0h
        mov p0,#11001111b
        lcall delay_50ms
        ret
        truot_lui:
        Mov p2,#0h
        mov p0,#00011111b
        lcall delay_50ms
        ret
        tang_toc:
        Mov p2,#0h
        mov p0,#00101111b
        lcall delay_50ms
        ret
        giam_toc:
        Mov p2,#0h
        mov p0,#10001111b
        lcall delay_50ms
        ret
        reset_robot:
        Mov r1,#5
        mov p2,#00000001b
        mov a,#00011111b
        reset_5lan:
        Rrc a
        mov p0,a
        lcall delay_50ms
        djnz r1,reset_5lan
        ret
        ;***************************** ham tao thoi gian tre *********************************
        delay_50ms:
        De_1:
        Mov r6,#5
        de_2:
        Mov r7,#250
        djnz r7,$
        djnz r6,de_2
        mov r6,#0
        ret
        delay_100ms:
        De_3:
        Mov r6,#255
        de_4:
        Mov r7,#255
        djnz r7,$
        djnz r6,de_4
        ret
        delay_10ms:
        De_16:
        Mov r6,#2
        de_17:
        Mov r7,#250
        djnz r7,$
        djnz r6,de_17
        ret

        delay_300ms:
        De_20:
        Mov r6,#250
        de_21:
        Mov r7,#250
        djnz r7,$
        djnz r6,de_21
        djnz thoi_gian_tre,de_20
        ret
        Last edited by toinhoem1001; 09-10-2009, 13:11.
        Nuôi con trẻ tại :
        Culi Manager tại :

        Comment


        • #79
          nếu muốn sử dụn kiểu truyền nhận 1byte có thể tham khảo đoạn code của mình xem :
          __________________________________________________ ________________________
          ;*************** NGAY THUC THI CHUONG TRINH 17/3/2009 ***************
          ;********* DESIGNER NGUYEN HUNG THUONG_04D2A ******************
          ;********** CHUONG TRINH VIET CHO MACH RF TOT NGHIEP ***********
          ;************** GVHD : LAM TANG DUC ****************************
          $INCLUDE 8051.MC
          ;******************** DINH DIA CHI BIT VA DIA CHI O NHO DUNG CHO CHUONG TRINH *****
          ;*********************** KENH TRUYEN DU LIEU PHAT *********************************
          TX BIT P0.0
          ;********************** NUT NHAN CHON KENH TRUYEN *********************************
          SW1 BIT P1.0
          SW2 BIT P1.1
          SW3 BIT P1.2
          ;********************** DIA CHI CAC O NHO CAN DUNG ********************************
          DATA DATA 2FH
          ;********************* GIAI THUAT CUA CHUONG TRINH *******************************
          ;/1.PHAT CHUOI XUNG 1,0 TRONG KHOANG 30MS DE CHUAN BI CHO PHAN THU KIP HIEU VA NHAN
          ;/2.NGHI KHOANG THOI GIAN 1MS DE DONG BO MAY THU VA MAY PHAT
          ;/3.CAI DU LIEU MONG MUON VAO ---> MA HOA SANG MA MANCHESTER, NEU LA 1 -->10,NEU LA
          ;/0 --> 01, PHAT LAN LUOT CHO HET 8BIT DU LIEU
          ;4.PHAT XUNG CHOT KET THUC CHU TRINH PHAT. TRE KHOANG THOI GIAN CHO BO THU
          ;*************^!^ CHUONG TRINH CHINH ^!^ *****************************************
          ORG 0H
          JMP MAIN
          ORG 03H
          JMP EX0_ISR
          ORG 0BH
          JMP T0_ISR
          ORG 13H
          JMP EX1_ISR
          ORG 1BH
          JMP T1_ISR
          ORG 23H
          JMP COMMUNICATION
          ; ***************** BAT DAU VAO CHUONG TRINH CHINH *******************************
          MAIN:
          MOV P0,#0FFH
          MOV P1,#0FFH
          MOV TMOD,#00000001B ;********** TIMER 0 CHE DO 1(16BIT) *********
          MOV TH0,#0FEH
          MOV TL0,#4DH
          MOV IE,#10000000B
          START:
          LCALL KT_NUT_NHAN
          LCALL CHUAN_BI_PHAT_DU_LIEU
          LCALL TO_MANCHESTER
          LCALL KET_THUC_PHAT
          RET
          ;***************** NGAT NGOAI 0 (EX0_ISR) ****************************************
          EX0_ISR:
          RET
          ;***************** NGAT TIMER 0 (T0_ISR) *****************************************
          T0_ISR:
          RET
          ;***************** NGAT NGOAI 1 (EX1_ISR) ****************************************
          EX1_ISR:
          RET
          ;****************** NGAT TIMER 1 (T1_ISR) ***************************************
          T1_ISR:
          RET
          ;********************* NGAT TRUYEN THONG NOI TIEP *******************************
          COMMUNICATION:
          RET
          ;******************* CAC CHUONG TRINH CON ***************************************
          ;**********^^^^^!! KIEM TRA CAC KENH TRUYEN DUOC NHAN !!^^^^^********************
          KT_NUT-NHAN:
          MOV R0,#50
          KT_NUT1:
          JB SW1,KT_NUT2
          DJNZ R0,KT_NUT1 ;*****XAC NHAN PHAI NUT 1 DUOC NHAN ? ***
          LCALL CHUONG_TRINH1 ; ******** TRUYEN KENH 1 *****************
          RET
          KT_NUT2:
          JB SW2,KT_NUT3
          DJNZ R0,KT_NUT2 ;******** XAC NHAN NUT 2 DUOC NHAN ? ****
          LCALL CHUONG_TRINH2 ;********* TRUYEN KENH 2 *****************
          RET
          KT_NUT3:
          JB SW3,THOAT_KT_NUT_NHAN
          DJNZ R0,KT_NUT3 ;********* XAC NHAN NUT 3 DUOC NHAN ? ***
          LCALL CHUONG_TRINH3 ;********* TRUYEN KENH 3 *****************
          RET
          THOAT_KT_NUT_NHAN:
          RET
          ;***************** NOI DUNG CUA TUNG KENH TRUYEN DUOC CHON *********************
          CHUONG_TRINH1:
          MOV DATA,#10011001B
          RET
          CHUONG_TRINH2:
          MOV DATA,#11111111B
          RET
          CHUONG_TRINH3:
          MOV DATA,#00000000B
          RET
          ;***************** BUOC CHUAN BI DUNG DE DONG BO 2 DU LIEU THU VA PHAT *********
          ;/ PHAT LIEN TUC CHUOI XUNG 0,1 TRONG KHOANG 40MS ******************************
          CHUAN_BI_PHAT_DU_LIEU:
          MOV R0,#35 ;*** PHAT KHOANG 35 LAN *************************
          PHAT_MOI:
          SETB TX
          LCALL DELAY_400uS
          CLR TX
          LCALL DELAY_400uS
          DJNZ R0,PHAT_MOI
          LCALL DELAY_1mS ;*** DOI DONG BO CHO BO THU ********************
          RET
          ;***************** DOI SANG MA MANCHESTER DE TRUYEN DU LIEU ********************
          TO_MANCHESTER:
          MOV R0,#8 ;********** DICH BIT 8 LAN *****************************
          DICH_BIT:
          MOV A,DATA
          ANL A,#10000000B
          CJNE A,#10000000B,BIT_0
          CALL BIT_1
          MOV A,DATA
          RL A
          MOV DATA,A
          DJNZ R0,DICH_BIT
          RET
          BIT_0: ;*********** NEU LA BIT 0 ----> 01 **********************
          CLR TX
          LCALL DELAY_400uS
          SETB TX
          LCALL DELAY_400uS
          RET
          BIT_1: ;********** NEU LA BIT 1 ----> 10 ***********************
          SETB TX
          LCALL DELAY_400uS
          CLR TX
          LCALL DELAY_400uS
          RET
          ;***************** PHAT XUNG KET THUC QUA TRINH PHAT DU LIEU **************
          KET_THUC_PHAT:
          SETB TX
          LCALL DELAY_400uS
          CLR TX
          LCALL DELAY_400uS
          LCALL DELAY_5mS ; ********** DOI BO THU XU LI XONG ************
          RET
          ;**************** HAM TAO THOI GIAN TRE CHO QUA TRINH TRUYEN DU LIEU *****
          DELAY_400uS:
          CLR TF0
          SETB TR0
          JNB TF0,$
          CLR TR0
          RET
          DELAY_1mS:
          MOV R0,#3
          TINH_DELAY1ms:
          LCALL DELAY_400uS
          DJNZ R0,TINH_DELAY1ms
          RET
          DELAY_5mS:
          MOV R0,#12
          TINH_DELAY5mS:
          LCALL DELAY_400mS
          DJNZ R0,TINH_DELAY5mS
          RET


          __________________________________________________ _______
          Nuôi con trẻ tại :
          Culi Manager tại :

          Comment


          • #80
            tạ ơn chúa, đỡ phải tìm lòi con mặt

            Comment


            • #81
              ảnh dành cho điều khiển đơn bit,có thể lập trình được. Cái này sài gòn bán không quá 100k cho 2 modul thu phát. Mình đem ra độ cái chuông nhấn từ xa cho khách hàng. Bề ngoài xù xì thế chứ bỏ trong hôp oai ra phết...
              Attached Files
              Nuôi con trẻ tại :
              Culi Manager tại :

              Comment


              • #82
                Chương trình này viết cho robot thực thi các hành động :

                Nếu có gì phải quấy mong các cao thủ võ lâm chỉ bảo thêm.....
                __________________________________________________ ________________________
                ;********************** CHUONG TRINH TU DONG DANH CHO ROBOT TOT NGHIEP ******************
                ;******************** DE TAI NCKH *****************************
                ;***********************LOP TU DONG *******************
                ;******************** MY ADDRESS : TOINHOEM1001@YAHOO.COM _ TEL : 0987876770 ***********
                ;***************** CHUONG TRINH THUC THI NGAY 2/5/2009 **********************************
                $INCLUDE 8051.MC
                ;****************** DINH DIA CHI TRONG CHUONG TRINH *************************************
                ;******** CHUONG TRINH SU DUNG 5 DONG CO,TOI DA CO THE DUNG 10 DONG CO TU 2 PORT P2,P3***
                L_MOTOR BIT P3.6
                L_ROLE BIT P3.7
                R_MOTOR BIT P3.4
                R_ROLE BIT P3.5
                DC_HA BIT P2.7 ;*** ROLE *******
                DC_NANG BIT P2.6
                DC_NHA BIT P2.1 ;*** ROLE *****
                DC_KEP BIT P2.0
                DC_TRUOT_TOI BIT P2.3 ;*** ROLE ******
                DC_TRUOT_LUI BIT P2.2
                ROLE_DC_DU_PHONG BIT P2.5
                DC_DU_PHONG BIT P2.4
                ;**************** CAM BIEN CUA ROBOT ************************
                CB_1 BIT P0.0
                CB_2 BIT P0.1
                CB_3 BIT P0.2
                CB_4 BIT P0.3
                CB_5 BIT P0.4
                CB_6 BIT P0.5
                CB_7 BIT P0.6
                CB_8 BIT P0.7
                ;************ DIA CHI KENH TRUYEN TU REMOTE TU XA TOI ROBOT ****************************
                KENH_1 BIT P1.0
                KENH_2 BIT P1.1
                KENH_3 BIT P1.2
                KENH_4 BIT P1.3
                ;********* DIA CHI CONG TAC GIOI HAN HANH TRINH ROBOT ***********************************
                CTHT_HA BIT P1.4
                CTHT_NANG BIT P1.5
                CTHT_TRUOT_TOI BIT P1.6
                CTHT_TRUOT_LUI BIT P1.7
                ;************ DIA CHI CHO ENCODER VA CAM BIEN CONG NGHIEP *******************************
                R_ENCODER BIT P3.2
                RE_ENCODER BIT IE.0
                CBCN BIT P3.3
                ;************** CAC THANH GHI DA CHUC NANG DUNG TRONG CHUONG TRINH **********************
                THOI_GIAN_TRE DATA 2FH
                SO_VACH DATA 2EH
                KT_VAN_TOC DATA 2DH
                TOCDO_R DATA 2CH
                TOCDO_L DATA 2BH
                KT_LO_TRINH DATA 2AH
                TONG_CB DATA 29H
                TOC_DO_RE_TRAI DATA 28H
                TOC_DO_RE_PHAI DATA 27H
                GIA_TRI_DAT DATA 26H
                GIA_TRI_DAT_EN DATA 25H
                R_ENCODER_THAP DATA 24H
                R_ENCODER_CAO DATA 23H
                ;***************** CO NHO CHO THANH GHI NOI *****************
                NHO_A DATA 21H
                NHO_C BIT 20.1H
                CO_ENCODER BIT 20.2H
                ;**************** CAC THANH GHI GIA TRI VAN TOC 2 BANH XE ***
                ;^^^^^^^^^^^^^^^^^^^^ RIGHT SPEED ^^^^^^^^^^^^^^^^^^^^^^^^^^^
                RS_1 DATA 38H
                RS_2 DATA 39H
                RS_3 DATA 3AH
                RS_4 DATA 3BH
                RS_5 DATA 3CH
                RS_6 DATA 3DH
                RS_7 DATA 3EH
                RS_8 DATA 3FH
                ;^^^^^^^^^^^^^^^^^^^^^ LEFT SPEED ^^^^^^^^^^^^^^^^^^^^^^^^^^^

                LS_1 DATA 40H
                LS_2 DATA 41H
                LS_3 DATA 42H
                LS_4 DATA 43H
                LS_5 DATA 44H
                LS_6 DATA 45H
                LS_7 DATA 46H
                LS_8 DATA 49H
                ;****************** PHAN DANH CHO CHUONG TRINH ******************************************
                ORG 0H
                JMP MAIN
                ORG 03H
                JMP EX0_ISR
                ORG 0BH
                JMP T0_ISR
                ORG 13H
                JMP EX1_ISR
                ORG 1BH
                JMP T1_ISR
                MAIN:
                MOV P2,#0FFH
                MOV P0,#0FFH
                MOV P1,#0FFH
                MOV P3,#0FFH
                MOV TMOD,#11H
                MOV IE,#10000000B
                SETB TF0
                MOV R0,#255
                MOV R3,#100
                MOV R4,#255
                START:
                LCALL KT_NUT_NHAN
                JMP START
                ;****************** CHUONG TRINH NGAT THUC THI KHI ROBOT HOAT DONG **********
                ;******************** NGAT NGOAI O ******************************************
                EX0_ISR:
                MOV NHO_C,C
                MOV A,R_ENCODER_THAP
                CJNE A,#0,GIAM_BYTE_THAP
                MOV A,R_ENCODER_CAO
                CJNE A,#0,GIAM_BYTE_CAO
                CLR RE_ENCODER
                SETB CO_ENCODER
                JMP THOAT_EX0
                GIAM_BYTE_CAO:
                DEC R_ENCODER_CAO
                MOV R_ENCODER_THAP,#255
                JMP THOAT_EX0
                GIAM_BYTE_THAP:
                DEC R_ENCODER_THAP
                THOAT_EX0:
                MOV C,RE_ENCODER
                RETI
                ;************************ NGAT TIMER 0 **************************************
                T0_ISR:
                CLR TR0
                MOV TH0,#0FFH ;0FEH
                MOV TL0,#18H ;00C
                SETB TR0
                LCALL BAM_XUNG
                RETI
                ;************************* NGAT NGOAI 1 *************************************
                EX1_ISR:
                RETI
                ;************************** NGAT TIMER1 *************************************
                T1_ISR:
                CLR TR1
                MOV TH1,#0FCH ;0FEH
                MOV TL1,#18H ;00C
                SETB TR1
                LCALL DEM_VACH_NGANG
                LCALL DO_DUONG
                RETI
                ;******************** CHUONG TRINH CON **************************************
                KT_NUT_NHAN:
                MOV A,P1
                LCALL DELAY_50MS
                ANL A,#00001111B
                DUNG_ROBOT_REMOTE:
                CJNE A,#00000000B,KT_CHAY_TOI
                LCALL DUNG_ROBOT
                RET
                KT_CHAY_TOI:
                CJNE A,#00000001B,KT_CHAY_LUI
                MOV TOCDO_R,#25
                MOV TOCDO_L,#35
                LCALL VAN_TOC_TRUNG_BINH
                MOV KT_VAN_TOC,#2
                LCALL LO_TRINH
                MOV IE,#10001000B
                SETB TF1
                JMP $
                RET
                KT_CHAY_LUI:
                CJNE A,#00000010B,KT_RE_TRAI
                CLR R_ROLE
                CLR L_ROLE
                LCALL DELAY_50MS
                LUI:
                MOV TOCDO_L,#250
                MOV TOCDO_R,#1
                MOV GIA_TRI_DAT,#200
                SETB IE.1
                JB P1.1,LUI
                CLR IE.1
                LCALL DUNG_ROBOT
                LCALL DELAY_50MS
                RET
                KT_RE_TRAI:
                CJNE A,#00000100B,KT_RE_PHAI
                MOV TOCDO_L,#0
                MOV TOCDO_R,#1
                MOV GIA_TRI_DAT,#250
                SETB IE.1
                JB P1.2,KT_RE_TRAI
                CLR IE.1
                LCALL DUNG_ROBOT
                LCALL DELAY_50MS
                RET
                KT_RE_PHAI:
                CJNE A,#00001000B,KT_NANG
                MOV TOCDO_L,#100
                MOV TOCDO_R,#0
                MOV GIA_TRI_DAT,#250
                SETB IE.1
                JB P1.3,KT_RE_PHAI
                CLR IE.1
                LCALL DUNG_ROBOT
                LCALL DELAY_50MS
                RET
                KT_NANG:
                CJNE A,#00000011B,KT_HA
                LCALL NANG
                JB P1.0,KT_NANG
                LCALL DUNG_NANG_HA
                LCALL DELAY_50MS
                RET
                KT_HA:
                CJNE A,#00000101B,KT_KEP
                LCALL HA_XUONG
                JB P1.2,KT_HA
                LCALL DUNG_NANG_HA
                LCALL DELAY_50MS
                RET
                KT_KEP:
                CJNE A,#00001001B,KT_NHA
                LCALL KEP
                JB P1.3,KT_KEP
                LCALL DUNG_KEP_NHA
                LCALL DELAY_50MS
                RET
                KT_NHA:
                CJNE A,#00000110B,KT_TRUOT_LUI
                LCALL NHA
                JB P1.2,KT_NHA
                LCALL DUNG_KEP_NHA
                LCALL DELAY_50MS
                RET
                KT_TRUOT_LUI:
                CJNE A,#00000111B,KT_TRUOT_TOI
                LCALL TRUOT_LUI
                JB P1.2,KT_TRUOT_LUI
                LCALL DUNG_TRUOT
                LCALL DELAY_50MS
                RET
                KT_TRUOT_TOI:
                CJNE A,#00000011B,THOAT_KT
                LCALL TRUOT_TOI
                JB P1.1,KT_TRUOT_TOI
                LCALL DUNG_TRUOT
                LCALL DELAY_50MS
                RET
                THOAT_KT:
                RET
                ;**************** CHUONG TRINH CON BAM XUNG DIEU KHIEN TOC DO 2 DONG CO BANH XE ******
                BAM_XUNG:
                DJNZ R0,DIEU_XUNG_CAP1
                MOV R0,#GIA_TRI_DAT
                DIEU_XUNG_CAP1:
                MOV R1,TOCDO_L
                CJNE R1,#0,KHONG_LECH_TRAI
                SETB L_MOTOR
                SJMP TIEP
                KHONG_LECH_TRAI:
                CLR L_MOTOR
                DJNZ R3,KHONG_LECH_TRAI
                MOV R3,#250
                DEC R1
                MOV TOCDO_L,R1
                TIEP:
                MOV R2,TOCDO_R
                CJNE R2,#0,KHONG_LECH_PHAI
                SETB R_MOTOR
                DJNZ R4,$
                MOV R4,#110
                RET
                KHONG_LECH_PHAI:
                CLR R_MOTOR
                DEC R2
                MOV TOCDO_R,R2
                RET
                ;**************************** THAO TAC ROBOT ******************************************
                NANG:
                JNB CTHT_NANG,DUNG_NANG_HA
                CLR DC_NANG
                MOV THOI_GIAN_TRE,#2
                LCALL DELAY_300MS
                LCALL DUNG_NANG_HA
                RET
                HA_XUONG:
                JNB CTHT_HA,DUNG_NANG_HA
                CLR DC_NANG
                CLR DC_HA
                MOV THOI_GIAN_TRE,#2
                LCALL DELAY_300MS
                LCALL DUNG_NANG_HA
                LCALL DELAY_50MS
                RET
                DUNG_NANG_HA:
                SETB DC_NANG
                SETB DC_HA
                LCALL DELAY_50MS
                RET
                KEP:
                CLR DC_KEP
                MOV THOI_GIAN_TRE,#2
                LCALL DELAY_300MS
                LCALL DUNG_KEP_NHA
                RET
                NHA:
                CLR DC_KEP
                CLR DC_NHA
                MOV THOI_GIAN_TRE,#2
                LCALL DELAY_300MS
                LCALL DUNG_KEP_NHA
                RET
                DUNG_KEP_NHA:
                SETB DC_KEP
                SETB DC_NHA
                LCALL DELAY_50MS
                RET
                DUNG_ROBOT:
                SETB R_MOTOR
                SETB L_MOTOR
                SETB R_ROLE
                SETB L_ROLE
                RET
                TRUOT_LUI:
                JNB CTHT_TRUOT_LUI,DUNG_TRUOT
                CLR DC_TRUOT_LUI
                MOV THOI_GIAN_TRE,#2
                LCALL DELAY_300MS
                LCALL DUNG_TRUOT
                LCALL DELAY_50MS
                RET
                TRUOT_TOI:
                JNB CTHT_TRUOT_TOI,DUNG_TRUOT
                CLR DC_TRUOT_TOI
                LCALL DELAY_50MS
                CLR DC_TRUOT_LUI
                MOV THOI_GIAN_TRE,#2
                LCALL DELAY_300MS
                LCALL DUNG_TRUOT
                LCALL DELAY_50MS
                RET
                DUNG_TRUOT:
                SETB DC_TRUOT_LUI
                SETB DC_TRUOT_TOI
                LCALL DELAY_50MS
                RET
                KHOI_DONG:
                SETB IP.0
                SETB RE_ENCODER
                MOV R_ENCODER_CAO,#HIGH(10000)
                MOV R_ENCODER_THAP,#LOW(25500)
                MOV C,RE_ENCODER
                CHO:
                MOV TOCDO_L,#100
                MOV TOCDO_R,#1
                SETB IP.1
                SETB IE.1
                JC CHO
                MOV IP,#0H
                LCALL DUNG_ROBOT
                RET
                RE_TRAI_ENCODER:
                SETB IP.0
                SETB RE_ENCODER
                MOV R_ENCODER_CAO,#HIGH(10000)
                MOV R_ENCODER_THAP,#LOW(25500)
                MOV C,RE_ENCODER
                CHO_RE_TRAI:
                MOV TOCDO_L,#0
                MOV TOCDO_R,#1
                MOV GIA_TRI_DAT,#250
                SETB IP.1
                SETB IE.1
                JC CHO_RE_TRAI
                MOV IP,#0H
                CLR IE.1
                LCALL DUNG_ROBOT
                LCALL DELAY_50MS
                RET
                RE_PHAI_ENCODER:
                SETB IP.0
                SETB RE_ENCODER
                MOV R_ENCODER_CAO,#HIGH(10000)
                MOV R_ENCODER_THAP,#LOW(25500)
                MOV C,RE_ENCODER
                CHO_RE_PHAI:
                MOV TOCDO_L,#100
                MOV TOCDO_R,#0
                MOV GIA_TRI_DAT,#250
                SETB IP.1
                SETB IE.1
                JC CHO_RE_PHAI
                MOV IP,#0H
                CLR IE.1
                LCALL DUNG_ROBOT
                LCALL DELAY_50MS
                RET
                ;******************CHUONG TRINH CON DO DUONG*****************
                DO_DUONG:
                DJNZ R0,DIEU_XUNG
                MOV A,KT_VAN_TOC
                CJNE A,#0,TRUNG_BINH
                NHANH:
                MOV R0,#50 ;50
                LCALL VAN_TOC_MAX
                JMP CHAY
                TRUNG_BINH:
                CJNE A,#1,CHAM
                MOV R0,#255 ;50
                LCALL VAN_TOC_TRUNG_BINH
                JMP CHAY
                CHAM:
                MOV R0,#120 ;180
                LCALL VAN_TOC_CHAM
                CHAY:
                LCALL QUET_CAM_BIEN
                DIEU_XUNG:
                MOV R1,TOCDO_L
                CJNE R1,#0,KHONG_LECH_TRAI1
                SETB L_MOTOR
                SJMP TIEP1
                KHONG_LECH_TRAI1:
                CLR L_MOTOR
                DEC R1
                MOV TOCDO_L,R1
                TIEP1:
                MOV R2,TOCDO_R
                CJNE R2,#0,KHONG_LECH_PHAI1
                SETB R_MOTOR
                DJNZ R4,$
                MOV R4,#250
                RET
                KHONG_LECH_PHAI1:
                CLR R_MOTOR
                DEC R2
                MOV TOCDO_R,R2
                RET

                ;*******************QUET CAMBIEN***********
                QUET_CAM_BIEN:
                MOV A,P0
                CJNE A,#00000000B,STEP0
                NGANG_VACH:
                MOV TOCDO_L,LS_1
                MOV TOCDO_R,RS_5
                RET
                STEP0:
                CJNE A,#11100111B,STEP1
                CHAY_THANG:
                MOV TOCDO_L,LS_1
                MOV TOCDO_R,RS_5
                RET
                STEP1:
                CJNE A,#11110111B,STEP2
                LECH_PHAI_MUC1:
                MOV TOCDO_L,LS_3
                MOV TOCDO_R,RS_5
                RET
                STEP2:
                CJNE A,#11110011B,STEP3
                LECH_PHAI_MUC2:
                MOV TOCDO_L,LS_2
                MOV TOCDO_R,RS_4
                RET
                STEP3:
                CJNE A,#11111011B,STEP4
                LECH_PHAI_MUC3:
                MOV TOCDO_L,LS_3
                MOV TOCDO_R,RS_3
                RET
                STEP4:
                CJNE A,#11111001B,STEP5
                LECH_PHAI_MUC4:
                MOV TOCDO_L,LS_5
                MOV TOCDO_R,RS_3
                RET
                STEP5:
                CJNE A,#11111101B,STEP6
                LECH_PHAI_MUC5:
                MOV TOCDO_L,LS_6
                MOV TOCDO_R,RS_3
                RET
                STEP6:
                CJNE A,#11111100B,STEP7
                LECH_PHAI_MUC6:
                MOV TOCDO_L,LS_6
                MOV TOCDO_R,RS_2
                RET
                STEP7:
                CJNE A,#11111110B,STEP8
                LECH_PHAI_MUC7:
                MOV TOCDO_L,LS_7
                MOV TOCDO_R,RS_2
                RET
                STEP8:
                CJNE A,#11101111B,STEP9
                LECH_TRAI_MUC1:
                MOV TOCDO_L,LS_1
                MOV TOCDO_R,RS_5
                RET
                STEP9:
                CJNE A,#11001111B,STEP10
                LECH_TRAI_MUC2:
                MOV TOCDO_L,LS_2
                MOV TOCDO_R,RS_5
                RET
                STEP10:
                CJNE A,#11011111B,STEP11
                LECH_TRAI_MUC3:
                MOV TOCDO_L,LS_1
                MOV TOCDO_R,RS_6
                RET
                STEP11:
                CJNE A,#10011111B,STEP12
                LECH_TRAI_MUC4:
                MOV TOCDO_L,LS_1
                MOV TOCDO_R,RS_5
                RET
                STEP12:
                CJNE A,#10111111B,STEP13
                LECH_TRAI_MUC5:
                MOV TOCDO_L,LS_2
                MOV TOCDO_R,RS_6
                RET
                STEP13:
                CJNE A,#00111111B,STEP14
                LECH_TRAI_MUC6:
                MOV TOCDO_L,LS_1
                MOV TOCDO_R,RS_7
                RET
                STEP14:
                CJNE A,#01111111B,STEP15
                LECH_TRAI_MUC7:
                MOV TOCDO_L,LS_1
                MOV TOCDO_R,RS_7
                RET
                STEP15:
                MOV TOCDO_L,LS_1
                MOV TOCDO_R,RS_4
                RET
                ;******************CHUONG TRINH CON DEM VACH*******
                DEM_VACH_NGANG:
                KT_VACH_NGANG:
                MOV TONG_CB,#0
                KT_CB2:
                JB CB_2,KT_CB7
                INC TONG_CB
                KT_CB7:
                JB CB_7,KT_CB8
                INC TONG_CB
                KT_CB8:
                JB CB_8,KT_VACH
                INC TONG_CB
                KT_VACH:
                MOV R2,TONG_CB
                MOV TONG_CB,#0
                CJNE R2,#3,THOAT
                CHO_DEM:
                MOV TOCDO_R,#40 ;100;150
                MOV TOCDO_L,#20 ;70;170
                LCALL DO_DUONG
                JNB CB_7,CHO_DEM
                DEM:
                INC SO_VACH
                MOV A,SO_VACH
                CALL LO_TRINH
                CJNE A,#0,THAO_TAC1
                MOV KT_VAN_TOC,#2 ;*******CHAY CHAM DO DUONG ***********
                RET
                THOAT:
                RET
                THAO_TAC1: ;*********CHAY NHANH DO DUONG****
                CJNE A,#1,THAO_TAC2
                MOV KT_VAN_TOC,#0
                RET
                THAO_TAC2: ;********CHAY TRUNG BINH*******
                CJNE A,#2,THAO_TAC3
                MOV KT_VAN_TOC,#1
                RET
                THAO_TAC3:
                LCALL DUNG_ROBOT
                JMP $
                RET
                ;********************* CHAY THANG VACH *********************
                LO_TRINH:
                MOVC A,@A+PC
                RET
                DB 0,0,6
                ;***************** CAC HAM VAN TOC DO DUONG******************
                ;***************** HAM VAN TOC MAX***************************
                VAN_TOC_MAX:
                MOV RS_1,#190
                MOV RS_2,#100
                MOV RS_3,#80 ;70
                MOV RS_4,#55 ;45
                MOV RS_5,#45 ;25
                MOV RS_6,#15 ;8
                MOV RS_7,#0

                MOV LS_1,#255
                MOV LS_2,#220
                MOV LS_3,#200
                MOV LS_4,#190
                MOV LS_5,#170
                MOV LS_6,#130
                MOV LS_7,#0
                RET

                ;****************HAM VAN TOC TRUNG BINH********************
                VAN_TOC_TRUNG_BINH:
                MOV RS_1,#15
                MOV RS_2,#10
                MOV RS_3,#8
                MOV RS_4,#5
                MOV RS_5,#3
                MOV RS_6,#0
                MOV RS_7,#0

                MOV LS_1,#200
                MOV LS_2,#140
                MOV LS_3,#130
                MOV LS_4,#120
                MOV LS_5,#80
                MOV LS_6,#70
                MOV LS_7,#0
                RET

                ;*****************HAM VAN TOC CHAM************************
                VAN_TOC_CHAM:
                MOV RS_1,#40 ;40
                MOV RS_2,#38 ;38
                MOV RS_3,#35 ;35
                MOV RS_4,#30 ;30
                MOV RS_5,#25 ;25
                MOV RS_6,#10 ;10
                MOV RS_7,#0

                MOV LS_1,#40 ;40
                MOV LS_2,#35 ;35
                MOV LS_3,#30 ;30
                MOV LS_4,#25 ;25
                MOV LS_5,#20 ;20
                MOV LS_6,#10 ;10
                MOV LS_7,#0
                RET

                ;*********************** CHUONG TRINH CON TAO THOI GIAN TRE ***************************
                DELAY_50MS:
                DE_1:
                MOV R6,#100
                DE_2:
                MOV R7,#250
                DJNZ R7,$
                DJNZ R6,DE_2
                MOV R6,#0
                RET
                DELAY_100MS:
                DE_3:
                MOV R6,#255
                DE_4:
                MOV R7,#255
                DJNZ R7,$
                DJNZ R6,DE_4
                RET

                DELAY_05MS:
                DE_6:
                MOV R6,#1
                DE_7:
                MOV R7,#250
                DJNZ R7,$
                DJNZ R6,DE_7
                RET
                DELAY_1MS:
                DE_8:
                MOV R6,#2
                DE_9:
                MOV R7,#250
                DJNZ R7,$
                DJNZ R6,DE_9
                RET
                DELAY_2MS:
                DE_10:
                MOV R6,#4
                DE_11:
                MOV R7,#250
                DJNZ R7,$
                DJNZ R6,DE_11
                RET
                DELAY_5MS:
                DE_12:
                MOV R6,#10
                DE_13:
                MOV R7,#250
                DJNZ R7,$
                DJNZ R6,DE_13
                RET
                DELAY_3MS:
                DE_18:
                MOV R6,#6
                DE_19:
                MOV R7,#250
                DJNZ R7,$
                DJNZ R6,DE_19
                RET

                DELAY_10MS:
                DE_16:
                MOV R6,#20
                DE_17:
                MOV R7,#250
                DJNZ R7,$
                DJNZ R6,DE_17
                RET

                DELAY_20MS:
                DE_14:
                MOV R6,#40
                DE_15:
                MOV R7,#250
                DJNZ R7,$
                DJNZ R6,DE_13
                RET
                DELAY_300MS:
                DE_20:
                MOV R6,#250
                DE_21:
                MOV R7,#250
                DJNZ R7,$
                DJNZ R6,DE_21
                DJNZ THOI_GIAN_TRE,DE_20
                RET


                __________________________________________________ __________________
                công ty llp,204,nguyễn đình chính,phú nhuận
                cellphone: 0987876770
                Nuôi con trẻ tại :
                Culi Manager tại :

                Comment


                • #83
                  phần này viết cho remote điều khiển robot nếu nó vượt xa khỏi máy tính :
                  __________________________________________________ _____________
                  ;********************* CHUONG TRINH VIET CHO REMOTE TOT NGHIEP *************
                  ;******************* THUC THI CHUONG TRINH NGAY 26/4/2009 ******************
                  ;************** DESIGNER : NGUYEN HUNG THUONG _ LOP TU DONG 04D2A **********
                  ;*********** ^!^ MY ADDRESS : TOINHOEM1001@YAHOO.COM (0987876770) ^!^ ******
                  $INCLUDE 8051.MC
                  ;************* DINH CAC DIA CHI BIT SU DUNG TRONG CHUONG TRINH *************
                  ;************* DIA CHI CAC KENH TRUYEN *************************************
                  KENH_1 BIT P0.7
                  KENH_2 BIT P0.6
                  KENH_3 BIT P0.5
                  KENH_4 BIT P0.4
                  ;****************** DIA CHI CAC NUT NHAN DC SU DUNG ***********************
                  TOI BIT P3.0
                  LUI BIT P3.1
                  TRAI BIT P3.2
                  PHAI BIT P3.3
                  NANG BIT P3.4
                  HA BIT P3.5
                  KEP BIT P3.6
                  NHA BIT P3.7
                  TRUOT BIT P0.0 ;**** TRUOT LUI ***
                  AUTO_MANU BIT P0.1
                  TANG_TOC BIT P0.2 ;**** TRUOT TOI ***
                  RESET_AUTO BIT P0.3
                  ;******************** CAC THANH GHI TRUNG GIAN *******************************
                  THOI_GIAN_TRE DATA 2FH
                  ;******************** PHAN THUC THI CHUONG TRINH ****************************
                  ORG 0H
                  JMP MAIN
                  ORG 03H
                  JMP EX0_ISR
                  ORG 0BH
                  JMP T0_ISR
                  ORG 13H
                  JMP EX1_ISR
                  ORG 1BH
                  JMP T1_ISR
                  ;******************* THAN CHUONG TRINH CHINH *********************************
                  MAIN:
                  MOV P0,#0FFH
                  MOV P3,#0FFH
                  MOV P2,#0H
                  MOV TMOD,#11H
                  MOV IE,#10000000B
                  SETB TF0
                  SETB TF1
                  MOV THOI_GIAN_TRE,#3
                  START:
                  JB AUTO_MANU,CHUONG_TRINH_TU_DONG
                  JMP CHUONG_TRINH_BANG_TAY
                  JMP START
                  ;****************** CHUONG TRINH NGAT THUC THI KHI ROBOT HOAT DONG **********
                  ;******************** NGAT NGOAI O ******************************************
                  EX0_ISR:
                  RETI
                  ;************************ NGAT TIMER 0 **************************************
                  T0_ISR:
                  CLR TR0
                  MOV TH0,#0FFH ;0FEH
                  MOV TL0,#18H ;00C
                  SETB TR0
                  MOV P2,#0H
                  RETI
                  ;************************* NGAT NGOAI 1 *************************************
                  EX1_ISR:
                  RETI
                  ;************************** NGAT TIMER1 *************************************
                  T1_ISR:
                  CLR TR1
                  MOV TH1,#0H ;0FEH
                  MOV TL1,#0H ;00C
                  SETB TR1
                  MOV P2,#0FFH
                  RETI
                  ;***************** CAC CHUONG TRINH CON CO BAN ******************************
                  CHUONG_TRINH_TU_DONG:
                  MOV P0,#0FH
                  MOV P2,#0FFH
                  JMP $
                  RET
                  CHUONG_TRINH_BANG_TAY:
                  KT_NUT_TOI:
                  JB TOI,KT_NUT_LUI
                  MOV R0,#5
                  XAC_NHAN_NUT_TOI:
                  DJNZ R0,XAC_NHAN_NUT_TOI
                  LCALL CHAY_TOI
                  JNB TOI,KT_NUT_TOI
                  MOV P2,#0FFH
                  MOV P0,#0FH
                  LCALL DELAY_50MS
                  RET
                  KT_NUT_LUI:
                  JB LUI,KT_NUT_TRAI
                  MOV R0,#5
                  XAC_NHAN_NUT_LUI:
                  DJNZ R0,XAC_NHAN_NUT_LUI
                  LCALL CHAY_LUI
                  JNB LUI,KT_NUT_LUI
                  MOV P2,#0FFH
                  MOV P0,#00FH
                  RET
                  KT_NUT_TRAI:
                  JB TRAI,KT_NUT_PHAI
                  MOV R0,#5
                  XAC_NHAN_NUT_TRAI:
                  DJNZ R0,XAC_NHAN_NUT_TRAI
                  LCALL RE_TRAI
                  JNB TRAI,KT_NUT_TRAI
                  MOV P2,#0FFH
                  MOV P0,#00FH
                  RET
                  KT_NUT_PHAI:
                  JB PHAI,KT_NUT_NANG
                  MOV R0,#5
                  XAC_NHAN_NUT_PHAI:
                  DJNZ R0,XAC_NHAN_NUT_PHAI
                  LCALL RE_PHAI
                  JNB PHAI,KT_NUT_PHAI
                  MOV P2,#0FFH
                  MOV P0,#00FH
                  RET
                  KT_NUT_NANG:
                  JB NANG,KT_NUT_HA
                  MOV R0,#5
                  XAC_NHAN_NUT_NANG:
                  DJNZ R0,XAC_NHAN_NUT_NANG
                  LCALL NANG
                  JNB NANG,KT_NUT_NANG
                  MOV P2,#0FFH
                  MOV P0,#00FH
                  RET
                  KT_NUT_HA:
                  JB HA,KT_NUT_KEP
                  MOV R0,#5
                  XAC_NHAN_NUT_HA:
                  DJNZ R0,XAC_NHAN_NUT_HA
                  LCALL HA_XUONG
                  JNB HA,KT_NUT_HA
                  MOV P2,#0FFH
                  MOV P0,#00FH
                  RET
                  KT_NUT_KEP:
                  JB KEP,KT_NUT_NHA
                  MOV R0,#5
                  XAC_NHAN_NUT_KEP:
                  DJNZ R0,XAC_NHAN_NUT_KEP
                  LCALL KEP
                  JNB KEP,KT_NUT_KEP
                  MOV P2,#0FFH
                  MOV P0,#00FH
                  RET
                  KT_NUT_NHA:
                  JB NHA,KT_TRUOT_TOI
                  MOV R0,#5
                  XAC_NHAN_NUT_NHA:
                  DJNZ R0,XAC_NHAN_NUT_NHA
                  LCALL NHA
                  JNB NHA,KT_NUT_NHA
                  MOV P2,#0FFH
                  MOV P0,#00FH
                  RET
                  KT_TRUOT_TOI:
                  JB TANG_TOC,KT_TRUOT_LUI
                  MOV R0,#5
                  XAC_NHAN_TRUOT_TOI:
                  DJNZ R0,XAC_NHAN_TRUOT_TOI
                  LCALL TRUOT_TOI
                  JNB TANG_TOC,KT_TRUOT_TOI
                  MOV P2,#0H
                  MOV P0,#0FH
                  RET
                  KT_TRUOT_LUI:
                  JB TRUOT,KT_NUT_RESET_ROBOT_TU_DONG
                  MOV R0,#5
                  XAC_NHAN_TRUOT_LUI:
                  DJNZ R0,XAC_NHAN_TRUOT_LUI
                  LCALL TRUOT_LUI
                  JNB TRUOT,KT_TRUOT_LUI
                  MOV P2,#0H
                  MOV P0,#0FH
                  RET
                  KT_NUT_RESET_ROBOT_TU_DONG:
                  JB RESET_AUTO,THOAT_CHUONG_TRINH
                  MOV R0,#10
                  XAC_NHAN_NUT_RESET_AUTO:
                  DJNZ R0,XAC_NHAN_NUT_RESET_AUTO
                  LCALL RESET_ROBOT
                  JNB RESET_AUTO,KT_NUT_RESET_ROBOT_TU_DONG
                  XOA_RESET:
                  MOV P2,#00000001B
                  MOV P0,#01111111B
                  MOV THOI_GIAN_TRE,#2
                  LCALL DELAY_300MS
                  MOV A,P3
                  CJNE A,#11111111B,THOAT_RESET
                  JMP XOA_RESET
                  THOAT_RESET:
                  RET
                  THOAT_CHUONG_TRINH:
                  JMP CHUONG_TRINH_BANG_TAY
                  ;************************** CHUONG TRINH CON NHO *********************************
                  CHAY_TOI:
                  MOV P2,#0H
                  MOV P0,#01111111B
                  LCALL DELAY_50MS
                  RET
                  CHAY_LUI:
                  MOV P2,#0H
                  MOV P0,#10111111B
                  LCALL DELAY_50MS
                  RET
                  RE_TRAI:
                  MOV P2,#0H
                  MOV P0,#11011111B
                  LCALL DELAY_50MS
                  RET
                  RE_PHAI:
                  MOV P2,#0H
                  MOV P0,#11101111B
                  LCALL DELAY_50MS
                  RET
                  NANG:
                  MOV P2,#0H
                  MOV P0,#00111111B
                  LCALL DELAY_50MS
                  RET
                  HA_XUONG:
                  MOV P2,#0H
                  MOV P0,#01011111B
                  LCALL DELAY_50MS
                  RET
                  KEP:
                  MOV P2,#0H
                  MOV P0,#01101111B
                  LCALL DELAY_50MS
                  RET
                  NHA:
                  MOV P2,#0H
                  MOV P0,#10011111B
                  LCALL DELAY_50MS
                  RET
                  TRUOT_TOI:
                  MOV P2,#0H
                  MOV P0,#11001111B
                  LCALL DELAY_50MS
                  RET
                  TRUOT_LUI:
                  MOV P2,#0H
                  MOV P0,#00011111B
                  LCALL DELAY_50MS
                  RET
                  TANG_TOC:
                  MOV P2,#0H
                  MOV P0,#00101111B
                  LCALL DELAY_50MS
                  RET
                  GIAM_TOC:
                  MOV P2,#0H
                  MOV P0,#10001111B
                  LCALL DELAY_50MS
                  RET
                  RESET_ROBOT:
                  MOV R1,#5
                  MOV P2,#00000001B
                  MOV A,#00011111B
                  RESET_5LAN:
                  RRC A
                  MOV P0,A
                  LCALL DELAY_50MS
                  DJNZ R1,RESET_5LAN
                  RET
                  ;***************************** HAM TAO THOI GIAN TRE *********************************
                  DELAY_50MS:
                  DE_1:
                  MOV R6,#5
                  DE_2:
                  MOV R7,#250
                  DJNZ R7,$
                  DJNZ R6,DE_2
                  MOV R6,#0
                  RET
                  DELAY_100MS:
                  DE_3:
                  MOV R6,#255
                  DE_4:
                  MOV R7,#255
                  DJNZ R7,$
                  DJNZ R6,DE_4
                  RET
                  DELAY_10MS:
                  DE_16:
                  MOV R6,#2
                  DE_17:
                  MOV R7,#250
                  DJNZ R7,$
                  DJNZ R6,DE_17
                  RET

                  DELAY_300MS:
                  DE_20:
                  MOV R6,#250
                  DE_21:
                  MOV R7,#250
                  DJNZ R7,$
                  DJNZ R6,DE_21
                  DJNZ THOI_GIAN_TRE,DE_20
                  RET
                  __________________________________________________ __________
                  Nuôi con trẻ tại :
                  Culi Manager tại :

                  Comment


                  • #84
                    nhieu qua, phải từ từ mới đọc hết đc

                    Comment


                    • #85
                      chang ai reply lai chan qua nhi?
                      Nuôi con trẻ tại :
                      Culi Manager tại :

                      Comment


                      • #86
                        bài "sử dụng kiểu truyền 1bit" bị thiếu các lện call để gọi chương trình con (Kt_nut_toi; kt_nut_lui; kt_nut_trai; kt_nut_phai; kt_nut_nang; kt_nut_ha; kt_nut_kep; kt_nut_nha; kt_truot_toi; kt_truot_lui; kt_nut_reset_robot_tu_dong) phải không anh?
                        Last edited by hammecuala; 20-10-2009, 21:05.

                        Comment


                        • #87
                          123456768901
                          Last edited by hammecuala; 21-10-2009, 08:38.

                          Comment


                          • #88
                            bài "sử dụng kiểu truyền 1bit" thì 4 bit cao của P0 là kênh 1,2,3,4 có chức năng để làm gì vậy. Và port2 để làm gì vậy?

                            Comment


                            • #89
                              bài "truyền nhận 1 Byte" , trong chương trình chính Main thì đáng lẽ phải gọi ch tr con chuyển mã LCALL TO_MANCHESTER trước rồi mới gọi LCALL CHUAN_BI_PHAT_DU_LIEU và LCALL KET_THUC_PHAT . Nếu kg thì lần phát đầu tiên sẽ kg có dữ liệu hoặc dữ liệu bị sai thì robot sẽ hoạt động lung tung (xin chỉ giáo)

                              Comment


                              • #90
                                không phải như thế đâu?ví dụ thế này nhé....khi nào biết bộ phát bắt đầu phát và bộ thu bắt đầu thu và thu như thế nào đó là vấn đề đặt ra?...để đồng bộ tín hiệu thu và phát thì ta phải qui định:ví dụ thời gian này tao chuẩn bị bắt đầu phát nè...lo mà chuẩn bị thu đi...khi nào tao hô 1.2.3 thì là lúc tao phát đó nha...???đó cũng chính là lí do ta phải phát xung chuẩn bị trước rồi mới phát dữ liệu sau...kết thúc chuỗi xung bắt đầu cũng chính là lúc dữ liệu chuẩn bị đẩy qua bộ thu đó.
                                __________________________________________________ __

                                Liên hệ : thuongnh@ntc.com.vn
                                Công ty TNHH NTC - FC1 Floor, 268 To Hien Thanh Street, District 10
                                Ho Chi Minh City, Vietnam
                                mob : 0987876770
                                Nuôi con trẻ tại :
                                Culi Manager tại :

                                Comment

                                Về tác giả

                                Collapse

                                toinhoem1001 Tìm hiểu thêm về toinhoem1001

                                Bài viết mới nhất

                                Collapse

                                Đang tải...
                                X