SHOW:
|
|
- or go back to the newest paste.
| 1 | ; | |
| 2 | ; book scanner za kiber pipu 15.11.12. | |
| 3 | ; | |
| 4 | ; ____ ____ | |
| 5 | ; MCLR | \__/ | B7 PGD | |
| 6 | ; LM in A0 | | B6 PGC | |
| 7 | ; tranz out A1 | | B5 out cw/ccw | |
| 8 | ; out A2 | | B4 out -Full Power | |
| 9 | ; test key in A3 | | B3 out EXP0 | |
| 10 | ; in A4 | | B2 in KEY | |
| 11 | ; mot clk out A5 | 2525 | B1 in HALL | |
| 12 | ; Vss | | B0 LM in | |
| 13 | ; 16 MHz Osc | | Vdd | |
| 14 | ; 16 MHz Osc | | Vss | |
| 15 | ; LED out C0 | | C7 RXD | |
| 16 | ; EXP2 out C1 | | C6 TXD | |
| 17 | ; in C2 | | C5 out EXP1 | |
| 18 | ; in C3 |____________| C4 out | |
| 19 | ; | |
| 20 | ||
| 21 | LIST P=18F2525 | |
| 22 | #include <P18F2525.INC> | |
| 23 | ||
| 24 | #define motclock lata,5 | |
| 25 | #define cwccw latb,5 | |
| 26 | #define motpower latb,4 | |
| 27 | #define led lata,2 | |
| 28 | #define click0 latc,5 ; (uostravanje) | |
| 29 | #define click1 latc,5 ; (camera 1) | |
| 30 | #define click2 latc,1 ; (camera 2) | |
| 31 | #define hilite2 latc,0 | |
| 32 | #define key porta,3 | |
| 33 | #define extkey portb,2 | |
| 34 | #define hall portb,1 | |
| 35 | ||
| 36 | config osc = HS | |
| 37 | config fcmen = off | |
| 38 | config ieso = off | |
| 39 | config pwrt = on | |
| 40 | config borv = 1 | |
| 41 | config wdt = off | |
| 42 | config mclre = on | |
| 43 | config lpt1osc = off | |
| 44 | config pbaden = off | |
| 45 | config stvren = on | |
| 46 | config lvp = off | |
| 47 | config xinst = off | |
| 48 | config debug = off | |
| 49 | config cp0 = off | |
| 50 | config cp1 = off | |
| 51 | config cp2 = off | |
| 52 | config cpb = off | |
| 53 | config cpd = off | |
| 54 | config wrt0 = on | |
| 55 | config wrt1 = on | |
| 56 | config wrt2 = on | |
| 57 | config wrtb = on | |
| 58 | config wrtc = on | |
| 59 | config wrtd = off | |
| 60 | config ebtr0 = off | |
| 61 | config ebtr1 = off | |
| 62 | config ebtr2 = off | |
| 63 | config ebtrb = off | |
| 64 | ||
| 65 | CBLOCK 0 | |
| 66 | inner | |
| 67 | outer | |
| 68 | keyrotor | |
| 69 | stepcount | |
| 70 | liftcount | |
| 71 | speedbyte | |
| 72 | ||
| 73 | ENDC | |
| 74 | ||
| 75 | ;____________________________________________________MACROS | |
| 76 | ||
| 77 | gore macro | |
| 78 | bcf cwccw | |
| 79 | endm | |
| 80 | ||
| 81 | dole macro | |
| 82 | bsf cwccw | |
| 83 | endm | |
| 84 | ||
| 85 | weak macro | |
| 86 | bsf motpower ; low power | |
| 87 | endm | |
| 88 | ||
| 89 | strong macro | |
| 90 | bcf motpower ; high power | |
| 91 | endm | |
| 92 | ||
| 93 | ifhallon macro | |
| 94 | btfss hall | |
| 95 | endm | |
| 96 | ||
| 97 | ifhalloff macro | |
| 98 | btfsc hall | |
| 99 | endm | |
| 100 | ||
| 101 | defspeed macro | |
| 102 | movlw .56 | |
| 103 | movwf speedbyte | |
| 104 | endm | |
| 105 | ||
| 106 | speed macro speedvalue | |
| 107 | movlw speedvalue | |
| 108 | movwf speedbyte | |
| 109 | endm | |
| 110 | ||
| 111 | ifz macro | |
| 112 | btfsc status,z | |
| 113 | endm | |
| 114 | ||
| 115 | ifnz macro | |
| 116 | btfss status,z | |
| 117 | endm | |
| 118 | ||
| 119 | ifc macro | |
| 120 | btfsc status,c | |
| 121 | endm | |
| 122 | ||
| 123 | ifnc macro | |
| 124 | btfss status,c | |
| 125 | endm | |
| 126 | ||
| 127 | ;********************************************************************************* | |
| 128 | ;********************************************************************************* | |
| 129 | ;**************** ***************** | |
| 130 | ;**************** M A I N ***************** | |
| 131 | ;**************** ***************** | |
| 132 | ;********************************************************************************* | |
| 133 | ;********************************************************************************* | |
| 134 | ||
| 135 | ||
| 136 | org 0 | |
| 137 | ||
| 138 | movlw 0fh | |
| 139 | movwf adcon1 | |
| 140 | movlw 7 | |
| 141 | movwf cmcon | |
| 142 | ||
| 143 | movlw b'00000000' | |
| 144 | movwf porta | |
| 145 | movlw b'00000000' | |
| 146 | movwf portb | |
| 147 | movlw b'00000000' | |
| 148 | movwf portc | |
| 149 | movlw B'011001' | |
| 150 | movwf trisa | |
| 151 | movlw B'00000111' | |
| 152 | movwf trisb | |
| 153 | movlw B'10001100' | |
| 154 | movwf trisc | |
| 155 | ; ___ clear ram bank 0-3 | |
| 156 | lfsr fsr0,0 | |
| 157 | goclr1k | |
| 158 | clrf postinc0 | |
| 159 | btfss fsr0h,2 | |
| 160 | goto goclr1k | |
| 161 | ||
| 162 | ;****************************************************************************** | |
| 163 | ;****************************************************************************** | |
| 164 | ;** ** | |
| 165 | ;** F A R M ** | |
| 166 | ;** ** | |
| 167 | ;****************************************************************************** | |
| 168 | ;****************************************************************************** | |
| 169 | ||
| 170 | ; jedan step motora je 0,153 mm | |
| 171 | bcf led | |
| 172 | call home | |
| 173 | ifc | |
| 174 | goto goerror | |
| 175 | farm | |
| 176 | defspeed | |
| 177 | bcf led | |
| 178 | weak | |
| 179 | dole | |
| 180 | call waitkey | |
| 181 | ||
| 182 | strong | |
| 183 | call slowstart | |
| 184 | movlw .123 | |
| 185 | movwf liftcount | |
| 186 | move_down ; \ u ovoj petlji ide nadole | |
| 187 | call mm2 | |
| 188 | decfsz liftcount,f | |
| 189 | bra move_down ; / u ovoj petlji ide nadole | |
| 190 | ||
| 191 | btfsc extkey | |
| 192 | bra otp1 | |
| 193 | ; still down mode | |
| 194 | waitjust | |
| 195 | call timing0 | |
| 196 | weak | |
| 197 | gore | |
| 198 | bsf hilite2 | |
| 199 | bcf status,c | |
| 200 | btfsc extkey | |
| 201 | bsf status,c | |
| 202 | rlcf keyrotor | |
| 203 | movf keyrotor,w | |
| 204 | xorlw b'11111110' | |
| 205 | bnz waitjust | |
| 206 | bra goup | |
| 207 | otp1 | |
| 208 | call timing2 | |
| 209 | weak | |
| 210 | gore | |
| 211 | bsf hilite2 | |
| 212 | movlw 0 | |
| 213 | call timing3 | |
| 214 | ||
| 215 | bsf click0 | |
| 216 | bsf click1 | |
| 217 | call timing3 | |
| 218 | bsf click2 | |
| 219 | call timing3 | |
| 220 | call timing3 | |
| 221 | call timing3 | |
| 222 | call timing3 | |
| 223 | call timing3 | |
| 224 | call timing3 | |
| 225 | call timing3 | |
| 226 | call timing3 | |
| 227 | bcf click0 | |
| 228 | bcf click1 | |
| 229 | call timing3 | |
| 230 | bcf click2 | |
| 231 | call timing3 | |
| 232 | call timing3 | |
| 233 | call timing3 | |
| 234 | call timing3 | |
| 235 | call timing3 | |
| 236 | call timing3 | |
| 237 | call timing3 | |
| 238 | goup | |
| 239 | bcf hilite2 | |
| 240 | call home ; ide nagore | |
| 241 | ifc | |
| 242 | goto goerror | |
| 243 | call timing2 | |
| 244 | bra farm | |
| 245 | ;------------------------------- | |
| 246 | ||
| 247 | showhall | |
| 248 | ifhallon | |
| 249 | bsf led | |
| 250 | ifhalloff | |
| 251 | bcf led | |
| 252 | return | |
| 253 | ||
| 254 | ;------- | |
| 255 | mm2 ; napravi 13 koraka (2 mm) | |
| 256 | movlw .13 ; za 2 mm | |
| 257 | movwf stepcount | |
| 258 | gost20 | |
| 259 | btg motclock | |
| 260 | call timing | |
| 261 | btg motclock | |
| 262 | call timing | |
| 263 | decfsz stepcount,f | |
| 264 | bra gost20 | |
| 265 | return | |
| 266 | ;------- | |
| 267 | timing0 | |
| 268 | movlw .5 | |
| 269 | movwf outer | |
| 270 | bra gostep | |
| 271 | timing2 | |
| 272 | movlw .200 | |
| 273 | movwf outer | |
| 274 | bra gostep | |
| 275 | timing | |
| 276 | movf speedbyte,w | |
| 277 | movwf outer | |
| 278 | gostep2 | |
| 279 | movlw .6 | |
| 280 | movwf inner | |
| 281 | gostep | |
| 282 | decfsz inner,f | |
| 283 | bra gostep | |
| 284 | decfsz outer,f | |
| 285 | bra gostep2 | |
| 286 | return | |
| 287 | ;------- | |
| 288 | timing3 ; dugi tajming, period w | |
| 289 | movwf outer | |
| 290 | gostep3 | |
| 291 | nop | |
| 292 | nop | |
| 293 | nop | |
| 294 | nop | |
| 295 | nop | |
| 296 | decfsz inner,f | |
| 297 | bra gostep3 | |
| 298 | decfsz outer,f | |
| 299 | bra gostep3 | |
| 300 | return | |
| 301 | ||
| 302 | ;------- | |
| 303 | waitkey | |
| 304 | btfss extkey | |
| 305 | return | |
| 306 | btfss key | |
| 307 | return | |
| 308 | bra waitkey | |
| 309 | ;------------------------------- | |
| 310 | ||
| 311 | home | |
| 312 | strong | |
| 313 | defspeed | |
| 314 | ifhalloff | |
| 315 | bra samogore | |
| 316 | ; prvo ide dole da se otkaci od halla | |
| 317 | dole | |
| 318 | call slowstart | |
| 319 | movlw .3 ; za 20 mm | |
| 320 | call gosteps2 | |
| 321 | call slowstop | |
| 322 | ifhallon | |
| 323 | goto errhome | |
| 324 | movlw .200 | |
| 325 | call timing3 | |
| 326 | samogore ; ide gore do halla, error ako ga nije nasao | |
| 327 | gore | |
| 328 | call slowstart_long | |
| 329 | defspeed | |
| 330 | movlw .150 ; za 300 mm max posle kojih prijavljuje gresku | |
| 331 | call gosteps | |
| 332 | bc errhome | |
| 333 | slowstop ; sad ide jos usporeno | |
| 334 | speed 90 | |
| 335 | movlw 1 ; jos 2 mm | |
| 336 | call gosteps2 | |
| 337 | speed 160 | |
| 338 | movlw 1 ; jos 2 mm | |
| 339 | call gosteps2 | |
| 340 | speed 200 | |
| 341 | movlw 1 ; jos 2 mm | |
| 342 | call gosteps2 | |
| 343 | bcf status,c ; NC = no error | |
| 344 | return | |
| 345 | errhome | |
| 346 | bsf status,c ; C = error | |
| 347 | return | |
| 348 | ;------- | |
| 349 | ||
| 350 | slowstart | |
| 351 | speed 200 | |
| 352 | movlw 1 ; jos 2 mm | |
| 353 | call gosteps2 | |
| 354 | speed 160 | |
| 355 | movlw 2 ; jos 2 mm | |
| 356 | call gosteps2 | |
| 357 | speed 90 | |
| 358 | movlw 3 ; jos 2 mm | |
| 359 | call gosteps2 | |
| 360 | defspeed | |
| 361 | return | |
| 362 | ||
| 363 | slowstart_long | |
| 364 | speed 160 | |
| 365 | movlw 8 ; x 2 mm | |
| 366 | call gosteps2 | |
| 367 | speed 120 | |
| 368 | movlw 1 ; x 2 mm | |
| 369 | call gosteps2 | |
| 370 | speed 90 | |
| 371 | movlw 1 ; x 2 mm | |
| 372 | call gosteps2 | |
| 373 | defspeed | |
| 374 | return | |
| 375 | ||
| 376 | ||
| 377 | ;------- | |
| 378 | ||
| 379 | gosteps ; napravi w*2mm, stop and clr C if hall low | |
| 380 | strong | |
| 381 | movwf liftcount | |
| 382 | godns | |
| 383 | call mm2 | |
| 384 | ifhallon | |
| 385 | bra foundhall | |
| 386 | decfsz liftcount,f | |
| 387 | bra godns | |
| 388 | bsf status,c ; set C, error (nije nasao hall) | |
| 389 | return | |
| 390 | foundhall | |
| 391 | bcf status,c ; clr C, nasao hall | |
| 392 | return | |
| 393 | ;------- | |
| 394 | ||
| 395 | gosteps2 ; samo napravi w*2mm bezuslovno | |
| 396 | strong | |
| 397 | movwf liftcount | |
| 398 | godns2 | |
| 399 | call mm2 | |
| 400 | decfsz liftcount,f | |
| 401 | bra godns2 | |
| 402 | return | |
| 403 | ||
| 404 | ;------------------------------ | |
| 405 | ||
| 406 | goerror ; samo blinka led do beskraja | |
| 407 | weak | |
| 408 | btg led | |
| 409 | clrf wreg | |
| 410 | call timing3 | |
| 411 | bra goerror | |
| 412 | ||
| 413 | ;------------------------------ | |
| 414 | END |