![]() |
|
Tài trợ cho PIC Vietnam |
Cơ bản về vi điều khiển và PIC Những bài hướng dẫn cơ bản nhất để làm quen với vi điều khiển PIC |
![]() |
|
Ðiều Chỉnh | Xếp Bài |
|
![]() |
#1 | |
Đệ tử 1 túi
Tham gia ngày: Mar 2006
Bài gửi: 23
: |
Trích:
Đó là do giá trị của prescale em đặt là 16, nếu em đặt là 32 thì nó sẽ bằng (với cùng loại crystal 8Mhz) |
|
![]() |
![]() |
![]() |
#2 | |
Trưởng lão PIC bang
|
Trích:
Trong cả hai công thức tính PR2 và PWM Duty Cycle thì đều có mặt TMR2 prescale value, em đổi TMR2 prescale value thì vẫn có tỷ lệ giữa giá trị đặt vào CCPR1L:CCP1Con<5:4> và giá trị đặt vào PR2 như vậy. Suy nghĩ lại xem. Thân, À, đối với những đoạn code em post lên thì nên đưa nó vào trong khung định dạng cho code (khi em dán code vào thì chọn đoạn code đó, rồi nhấn vào cái nút có hình # ở thanh công cụ đó).
__________________
Biển học mênh mông, sức người có hạn. Đang gặp vấn đề cần được giúp đỡ? Hãy dành ra vài phút đọc luồng sau: http://www.picvietnam.com/forum/showthread.php?t=1263 thay đổi nội dung bởi: namqn, 20-04-2006 lúc 12:19 AM. |
|
![]() |
![]() |
![]() |
#3 |
Đệ tử 1 túi
Tham gia ngày: Mar 2006
Bài gửi: 23
: |
hê hê, xin lỗi mọi người nghe... Đoạn code của em
Code:
org 0x0000 goto start ; case1 equ 0x20 ;PORTA value = 000 -> the robot is in the air ; case2 equ 0x21 ;PORTA value = 001 -> left hand side ; case3 equ 0x22 ;PORTA value = 011 -> completely in left hand side ; case4 equ 0x23 ;PORTA value = 100 -> right hand side ; case5 equ 0x24 ;PORTA value = 101 -> center the line ; case6 equ 0x25 ;PORTA value = 110 -> completely in right hand side ; case7 equ 0x26 ;PORTA value = 111 -> start movlw d'124' ;set period for PWM=1000Hz movwf PR2 movlw b'00000111' ;set prescale = 1:16 and enable TIMER2 movwf T2CON bcf TRISC, CCP1 bcf TRISB, CCP2 clrf PORTB ;initialize PORTB, PORTA clrf TRISB clrf PORTA clrf PORTD clrf TRISD ;R_led off <=> PORTB = 11111110 ;C_led off <=> PORTB = 11111101 ;L_led off <=> PORTB = 11111011 ;configure PORTA movlw b'00000110' ;set all PORTAs as digital input movwf ADCON1 movlw 0xff movwf TRISA ;set portA as input movf PORTA,0 ;read from PORTA and store it to W_reg movwf PORTB loop movf PORTA,0 movwf PORTB goto case2 s1 ;special case of robot when it turning right and get out of the line movlw b'00000000' cpfseq PORTA ;if equal skip goto loop ;if equal goto case1 call RIGHT_WHEEL_FAST call LEFT_WHEEL_SLOW goto loop s2 ;special case of robot when it turning left and get out of the line movlw b'00000000' cpfseq PORTA ;if equal skip goto loop ;if equal goto case1 call LEFT_WHEEL_FAST call RIGHT_WHEEL_SLOW goto loop ;s3 ;robot will stop while it follow the center and suddenly did not sence anything ; movlw b'00000111' ; cpfseq PORTA ;if equal skip ; goto loop ;if equal goto case1 ; call LEFT_WHEEL_STOP ; call RIGHT_WHEEL_STOP case2 ;in left hand side movlw b'00000001' cpfseq PORTA ;if equal skip goto case3 call LEFT_WHEEL_FAST call RIGHT_WHEEL_NORM goto loop case3 ;completely in left hand side movlw b'00000011' cpfseq PORTA goto case4 call LEFT_WHEEL_FAST call RIGHT_WHEEL_SLOW goto s2 case4 ;right hand side movlw b'00000100' cpfseq PORTA goto case5 call RIGHT_WHEEL_FAST call LEFT_WHEEL_NORM goto loop case5 ;center movlw b'00000101' cpfseq PORTA goto case6 call RIGHT_WHEEL_NORM call LEFT_WHEEL_NORM goto loop case6 ;completely in right hand side movlw b'00000110' cpfseq PORTA goto loop call RIGHT_WHEEL_FAST call LEFT_WHEEL_SLOW goto s1 |
![]() |
![]() |
![]() |
|
|