⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 picservo.lst

📁 Code ASM for PIC16F628. Use for CNC/Servo Motor. With simulatio in Proteus (7.0)
💻 LST
📖 第 1 页 / 共 5 页
字号:
                      00167 ;| Declare Variables 
                      00168 ;+-----------------------------------------------------------------------------
                      00169 
                      00170 ; We will have up to 4 servos connected, each one needs to store the
                      00171 ; number 4us loops for the postion and the number of loops for the
                      00172 ; offset. The values are ordered in memory one after the other to allow 
                      00173 ; the use of the indirect addressing to call a routine that will process 
                      00174 ; all servos. Because we are using the indirect addressing to access
                      00175 ; all the detail for the servo, we will need an extra value to specify
                      00176 ; the mask to use to set and clear the correct servo output.
                      00177 ;
                      00178 ; NOTE: These are assumed to start at the Ram_Base (0Ch) by the rest of
                      00179 ; the program so don't put any variables before these.
                      00180 ;
                      00181         
                      00182 ; Declare the start of RAM that we can use
  0000000C            00183 RamBase                         EQU             0x0C
                      00184 
                      00185         CBLOCK RamBase
  0000000C            00186         Servo0_Mask                             ; Mask for Servo 0 output
  0000000D            00187         Servo0_Offset                   ; loop count for Servo 0 offset
  0000000E            00188         Servo0_Position                 ; loop count for Servo 0 position
                      00189 
  0000000F            00190         Servo1_Mask                             ; Mask for Servo 1 output
  00000010            00191         Servo1_Offset                   ; loop count for Servo 1 offset
  00000011            00192         Servo1_Position                 ; loop count for Servo 1 position
                      00193 
  00000012            00194         Servo2_Mask                             ; Mask for Servo 2 output
  00000013            00195         Servo2_Offset                   ; loop count for Servo 2 offset
  00000014            00196         Servo2_Position                 ; loop count for Servo 2 position
                      00197 
  00000015            00198         Servo3_Mask                             ; Mask for Servo 3 output
  00000016            00199         Servo3_Offset                   ; loop count for Servo 3 offset
  00000017            00200         Servo3_Position                 ; loop count for Servo 3 position
                      00201 
  00000018            00202         Servo4_Mask                     ; Mask for Servo 4 output
  00000019            00203         Servo4_Offset                   ; loop count for Servo 4 offset
  0000001A            00204         Servo4_Position                 ; loop count for Servo 4 position
                      00205 
  0000001B            00206         Servo5_Mask                     ; Mask for Servo 5 output
  0000001C            00207         Servo5_Offset                   ; loop count for Servo 5 offset
  0000001D            00208         Servo5_Position                 ; loop count for Servo 5 position
                      00209 
MPASM  4.02 Released                             PICSERVO.ASM   12-31-2006  11:50:00         PAGE  5


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

  0000001E            00210         Servo6_Mask                     ; Mask for Servo 6 output
  0000001F            00211         Servo6_Offset                   ; loop count for Servo 6 offset
  00000020            00212         Servo6_Position                 ; loop count for Servo 6 position
                      00213 
  00000021            00214         Servo7_Mask                     ; Mask for Servo 7 output
  00000022            00215         Servo7_Offset                   ; loop count for Servo 7 offset
  00000023            00216         Servo7_Position                 ; loop count for Servo 7 position
                      00217 
  00000024            00218         Int_W_Save                              ; Interrupt W register Store
  00000025            00219         Int_STATUS_Save                 ; Interrupt STATUS register Store
                      00220 
  00000026            00221         Flags                                   ; eight flags, see the Flag_* macros
  00000027            00222         Enables                                 ; eight servo enable flags
                      00223 
  00000028            00224         LED_Drive_Count                 ; used to count the number of 20ms blocks to keep
                      00225                                                         ; the LED on to indicate a data byte was receive
                            d.
                      00226 
  00000029            00227         CurrentServoMask                ; the current servo mask
                      00228 
  0000002A            00229         DataByte                                ; somewhere to store a incoming data byte for processing
                      00230 
  0000002B            00231         Serial_CurrentByte              ; the current byte being received or transmitted
  0000002C            00232         Serial_LoopCount                ; the current bit loop counter
                      00233 
  0000002D            00234         Parser_Command                  ; the stored command
  0000002E            00235         Parser_Data                             ; the stored data byte
  0000002F            00236         Parser_Temp     
                      00237         ENDC
                      00238 
                      00239 ;+-----------------------------------------------------------------------------
                      00240 ;| Declare MACROs
                      00241 ;+-----------------------------------------------------------------------------
                      00242 
  0000006B            00243 RTCC_19msValue          EQU             107             ; leaves 148 'ticks' at 1:128 before the
                      00244                                                                         ; RTCC register clocks over and 
                            generates 
                      00245                                                                         ; an interrupt. ~19ms
                      00246 
  000000F7            00247 RTCC_1msValue           EQU             247             ; leaves 8 'ticks' at 1:128 before the
                      00248                                                                         ; RTCC register clocks over and 
                            generates
                      00249                                                                         ; an interrupt. ~1mS
                      00250 
  0000000A            00251 LED_Drive_Time          EQU             10              ; leave the LED on for approx 200ms
                      00252 #DEFINE LED_Drive                       PORTA,4
                      00253 
                      00254 #DEFINE Serial_TX                       PORTA,0
                      00255 #DEFINE Serial_RX                       PORTA,3
                      00256 #DEFINE Serial_CTS                      PORTA,2
                      00257 #DEFINE Serial_RTS                      PORTA,1
                      00258 
  00000067            00259 Serial_BitDelay         EQU             103
MPASM  4.02 Released                             PICSERVO.ASM   12-31-2006  11:50:00         PAGE  6


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

  00000034            00260 Serial_HalfBitDelay     EQU             52
                      00261 
                      00262 ; Flag Access macros
                      00263 #DEFINE Serial_ReceiveValid     Flags,0 ; set if the current byte received was valid
                      00264 
                      00265 #DEFINE Parser_WaitForData      Flags,1 ; If set the parser is waiting for a data byte
                      00266                                                                         ; for the current command
                      00267 
                      00268 #DEFINE Flag_ServoPulseSafe Flags,2     ; Set once about 2 bit times have expired since the
                      00269                                                                         ; CTS line was deactivated in pr
                            eperation for doing
                      00270                                                                         ; the servo pulses.
                      00271 
                      00272 #DEFINE Flag_WaitingForCTS      Flags,3 ; The CTS line was deactivated and we are waiting for
                      00273                                                                         ; about 2 bit times to make sure
                             we're not going to miss
                      00274                                                                         ; a data byte.
                      00275 
                      00276 #DEFINE Serial_RestoreCTS       Flags,4 ; The Serial Transmit routine needs to disable CTS when
                      00277                                                                         ; transmitting so it needs to re
                            member to restore it
                      00278 
                      00279 ; servo enable outputs. NOTE These MUST be sequential starting at bit 0 as 
                      00280 ; it is assumed in the parser when enabling and disabling servos
                      00281 #DEFINE Flag_Servo0_Active      Enables,0
                      00282 #DEFINE Flag_Servo1_Active      Enables,1
                      00283 #DEFINE Flag_Servo2_Active      Enables,2
                      00284 #DEFINE Flag_Servo3_Active      Enables,3
                      00285 #DEFINE Flag_Servo4_Active      Enables,4
                      00286 #DEFINE Flag_Servo5_Active      Enables,5
                      00287 #DEFINE Flag_Servo6_Active      Enables,6
                      00288 #DEFINE Flag_Servo7_Active      Enables,7
                      00289 
                      00290 ;+-----------------------------------------------------------------------------
                      00291 ;| Beginning of Program 
                      00292 ;+-----------------------------------------------------------------------------
0000                  00293         ORG                     0
0000   2868           00294         GOTO            Main                            ; Jump to the main entry point
                      00295 
                      00296 ;+-----------------------------------------------------------------------------
                      00297 ;| Beginning of Interrupt Routine 
                      00298 ;| Note that we jump to the interrupt routine so that we can place all our 
                      00299 ;| 'lookup' table at the beginning of the program memory to ensure that when
                      00300 ;| we do an ADD to the PCL register we aren't going to clock over the address
                      00301 ;| and thus stuffing up our instruction pointer
                      00302 ;+-----------------------------------------------------------------------------
0004                  00303         ORG                     4
0004   283A           00304         GOTO            Interrupt
                      00305 
                      00306 ;+-----------------------------------------------------------------------------
                      00307 ;| SUBROUTINE:  ParserChannelToBitMask
                      00308 ;| 
                      00309 ;| Take the channel number as a binary number in the W register and change it
MPASM  4.02 Released                             PICSERVO.ASM   12-31-2006  11:50:00         PAGE  7


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

                      00310 ;| to a bit mask so that bit 0 is set if W=0, bit 1 is set of W=1 etc.
                      00311 ;| This can then be used to alter output ports etc.
                      00312 ;| 
                      00313 ;| Valid range for W is 0 to 7
                      00314 ;+-----------------------------------------------------------------------------
0005                  00315 ParserChannelToBitMask
0005   3907           00316         ANDLW   07h                                             ; Ensure that there is a max of 7.
0006   0782           00317         ADDWF   PCL, f                                  ; Jump into the commands below to return
                      00318                                                                         ; the correct value
0007   3401 3402 3404 00319         DT              0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
       3408 3410 3420 
       3440 3480 
                      00320 
                      00321 ;+-----------------------------------------------------------------------------
                      00322 ;| SUBROUTINE: GetPWROnMsg
                      00323 ;| 
                      00324 ;| return the character at offset in the W register for the Power On Message
                      00325 ;| returns 0 if at the end of the string
                      00326 ;+-----------------------------------------------------------------------------
000F                  00327 GetPWROnMsg
000F   0782           00328         ADDWF   PCL, f
0010   3450 3449 3443 00329         DT              "PIC Servo Controller\r\n", 0
       3420 3453 3465 
       3472 3476 346F 
       3420 3443 346F 
       346E 3474 3472 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -