summaryrefslogtreecommitdiff
path: root/trunk/darwin/firmware/PIC/devices/stepmotor/stepmotorz-stepmotor1.asm
blob: 7634afcab9533f85c994bc7d8693f00deb79d3e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
;--------------------------------------------------------
; File Created by SDCC : free open source ANSI-C Compiler
; Version 2.7.4 #4943 (Oct 27 2007) (UNIX)
; This file was generated Fri Jun 13 14:34:02 2008
;--------------------------------------------------------
; PIC port for the 14-bit core
;--------------------------------------------------------
;	.module stepmotor1
	list	p=16f648a
	radix dec
	include "p16f648a.inc"
;--------------------------------------------------------
; config word 
;--------------------------------------------------------
	__config 0x3f10
;--------------------------------------------------------
; external declarations
;--------------------------------------------------------
	extern	_init2
	extern	_timerTick
	extern	_processCommand
	extern	_syncStrobe
	extern	_setPower
	extern	_flashLED
	extern	_LEDon
	extern	_setFlash
	extern	_uartTransmit
	extern	_sendReply
	extern	_sendMessage
	extern	_sendDataByte
	extern	_endMessage
	extern	_sendMessageISR
	extern	_sendDataByteISR
	extern	_endMessageISR
	extern	_releaseLock
	extern	_serialInterruptHandler
	extern	_packetReady
	extern	_uartNotifyReceive
	extern	_serial_init
	extern	_delay_10us
	extern	_clearwdt
	extern	_CCP1CON_bits
	extern	_CMCON_bits
	extern	_EECON1_bits
	extern	_INTCON_bits
	extern	_OPTION_REG_bits
	extern	_PCON_bits
	extern	_PIE1_bits
	extern	_PIR1_bits
	extern	_PORTA_bits
	extern	_PORTB_bits
	extern	_RCSTA_bits
	extern	_STATUS_bits
	extern	_T1CON_bits
	extern	_T2CON_bits
	extern	_TRISA_bits
	extern	_TRISB_bits
	extern	_TXSTA_bits
	extern	_VRCON_bits
	extern	_syncEnabled
	extern	_syncCounter
	extern	_buffer
	extern	_serialStatus
	extern	_INDF
	extern	_TMR0
	extern	_PCL
	extern	_STATUS
	extern	_FSR
	extern	_PORTA
	extern	_PORTB
	extern	_PCLATH
	extern	_INTCON
	extern	_PIR1
	extern	_TMR1L
	extern	_TMR1H
	extern	_T1CON
	extern	_TMR2
	extern	_T2CON
	extern	_CCPR1L
	extern	_CCPR1H
	extern	_CCP1CON
	extern	_RCSTA
	extern	_TXREG
	extern	_RCREG
	extern	_CMCON
	extern	_OPTION_REG
	extern	_TRISA
	extern	_TRISB
	extern	_PIE1
	extern	_PCON
	extern	_PR2
	extern	_TXSTA
	extern	_SPBRG
	extern	_EEDATA
	extern	_EEADR
	extern	_EECON1
	extern	_EECON2
	extern	_VRCON
	extern	___sdcc_saved_fsr
	extern	__sdcc_gsinit_startup
;--------------------------------------------------------
; global declarations
;--------------------------------------------------------
	global	_init1
	global	_main
	global	_deviceAddress

	global PSAVE
	global SSAVE
	global WSAVE
	global STK12
	global STK11
	global STK10
	global STK09
	global STK08
	global STK07
	global STK06
	global STK05
	global STK04
	global STK03
	global STK02
	global STK01
	global STK00

sharebank udata_ovr 0x0070
PSAVE	res 1
SSAVE	res 1
WSAVE	res 1
STK12	res 1
STK11	res 1
STK10	res 1
STK09	res 1
STK08	res 1
STK07	res 1
STK06	res 1
STK05	res 1
STK04	res 1
STK03	res 1
STK02	res 1
STK01	res 1
STK00	res 1

;--------------------------------------------------------
; global definitions
;--------------------------------------------------------
;--------------------------------------------------------
; absolute symbol definitions
;--------------------------------------------------------
;--------------------------------------------------------
; compiler-defined variables
;--------------------------------------------------------
UDL_stepmotor1_0	udata
r0x1001	res	1
r0x1002	res	1
;--------------------------------------------------------
; initialized data
;--------------------------------------------------------

ID_stepmotor1_0	idata
_deviceAddress
	db	0x04

;--------------------------------------------------------
; overlayable items in internal ram 
;--------------------------------------------------------
;	udata_ovr
;--------------------------------------------------------
; reset vector 
;--------------------------------------------------------
STARTUP	code
	nop
	pagesel __sdcc_gsinit_startup
	goto	__sdcc_gsinit_startup
;--------------------------------------------------------
; interrupt and initialization code
;--------------------------------------------------------
c_interrupt	code	0x4
__sdcc_interrupt
;***
;  pBlock Stats: dbName = I
;***
;entry:  _isr	;Function start
; 0 exit points
;functions called:
;   _serialInterruptHandler
;   _timerTick
;   _serialInterruptHandler
;   _timerTick
;; Starting pCode block
_isr	;Function start
; 0 exit points
;	.line	48; "stepmotor1.c"	static void isr() interrupt 0 {
	MOVWF	WSAVE
	SWAPF	STATUS,W
	CLRF	STATUS
	MOVWF	SSAVE
	MOVF	PCLATH,W
	CLRF	PCLATH
	MOVWF	PSAVE
	MOVF	FSR,W
	BANKSEL	___sdcc_saved_fsr
	MOVWF	___sdcc_saved_fsr
;	.line	49; "stepmotor1.c"	serialInterruptHandler();
	PAGESEL	_serialInterruptHandler
	CALL	_serialInterruptHandler
	PAGESEL	$
;	.line	51; "stepmotor1.c"	if (TMR1IF) {
	BANKSEL	_PIR1_bits
	BTFSS	_PIR1_bits,0
	GOTO	_00107_DS_
;	.line	52; "stepmotor1.c"	timerTick();
	PAGESEL	_timerTick
	CALL	_timerTick
	PAGESEL	$
;	.line	53; "stepmotor1.c"	TMR1IF = 0;
	BANKSEL	_PIR1_bits
	BCF	_PIR1_bits,0
_00107_DS_
	BANKSEL	___sdcc_saved_fsr
	MOVF	___sdcc_saved_fsr,W
	MOVWF	FSR
	MOVF	PSAVE,W
	MOVWF	PCLATH
	CLRF	STATUS
	SWAPF	SSAVE,W
	MOVWF	STATUS
	SWAPF	WSAVE,F
	SWAPF	WSAVE,W
END_OF_INTERRUPT
	RETFIE	

;--------------------------------------------------------
; code
;--------------------------------------------------------
code_stepmotor1	code
;***
;  pBlock Stats: dbName = M
;***
;entry:  _main	;Function start
; 2 exit points
;has an exit
;functions called:
;   _init1
;   _init2
;   _serial_init
;   _uartTransmit
;   _packetReady
;   _processCommand
;   _releaseLock
;   _syncStrobe
;   _clearwdt
;   _init1
;   _init2
;   _serial_init
;   _uartTransmit
;   _packetReady
;   _processCommand
;   _releaseLock
;   _syncStrobe
;   _clearwdt
;2 compiler assigned registers:
;   r0x1001
;   r0x1002
;; Starting pCode block
_main	;Function start
; 2 exit points
;	.line	123; "stepmotor1.c"	byte syncEnabled = 0;
	BANKSEL	r0x1001
	CLRF	r0x1001
;	.line	125; "stepmotor1.c"	init1();
	CALL	_init1
;	.line	126; "stepmotor1.c"	init2();
	PAGESEL	_init2
	CALL	_init2
	PAGESEL	$
;	.line	127; "stepmotor1.c"	serial_init();
	PAGESEL	_serial_init
	CALL	_serial_init
	PAGESEL	$
;	.line	130; "stepmotor1.c"	GIE=0;
	BANKSEL	_INTCON_bits
	BCF	_INTCON_bits,7
;	.line	131; "stepmotor1.c"	uartTransmit(0);
	MOVLW	0x00
	PAGESEL	_uartTransmit
	CALL	_uartTransmit
	PAGESEL	$
;	.line	132; "stepmotor1.c"	GIE=1;
	BANKSEL	_INTCON_bits
	BSF	_INTCON_bits,7
;	.line	134; "stepmotor1.c"	if (SYNCA) // Only enable if SYNCA is by default high
	BTFSS	_PORTA_bits,1
	GOTO	_00127_DS_
;	.line	135; "stepmotor1.c"	syncEnabled = 1;
	MOVLW	0x01
	BANKSEL	r0x1001
	MOVWF	r0x1001
_00127_DS_
;	.line	138; "stepmotor1.c"	if (packetReady()) {
	PAGESEL	_packetReady
	CALL	_packetReady
	PAGESEL	$
	BANKSEL	r0x1002
	MOVWF	r0x1002
	MOVF	r0x1002,W
	BTFSC	STATUS,2
	GOTO	_00119_DS_
;	.line	139; "stepmotor1.c"	processCommand();
	PAGESEL	_processCommand
	CALL	_processCommand
	PAGESEL	$
;	.line	140; "stepmotor1.c"	releaseLock();
	PAGESEL	_releaseLock
	CALL	_releaseLock
	PAGESEL	$
_00119_DS_
;	.line	142; "stepmotor1.c"	if (syncEnabled && !SYNCA) {
	MOVLW	0x00
	BANKSEL	r0x1001
	IORWF	r0x1001,W
	BTFSC	STATUS,2
	GOTO	_00124_DS_
	BANKSEL	_PORTA_bits
	BTFSC	_PORTA_bits,1
	GOTO	_00124_DS_
_00120_DS_
;	.line	145; "stepmotor1.c"	while(!SYNCA)
	BANKSEL	_PORTA_bits
	BTFSS	_PORTA_bits,1
	GOTO	_00120_DS_
;	.line	147; "stepmotor1.c"	syncStrobe();
	PAGESEL	_syncStrobe
	CALL	_syncStrobe
	PAGESEL	$
_00124_DS_
;	.line	149; "stepmotor1.c"	clearwdt();
	PAGESEL	_clearwdt
	CALL	_clearwdt
	PAGESEL	$
	GOTO	_00127_DS_
	RETURN	
; exit point of _main

;***
;  pBlock Stats: dbName = C
;***
;entry:  _init1	;Function start
; 2 exit points
;has an exit
;; Starting pCode block
_init1	;Function start
; 2 exit points
;	.line	60; "stepmotor1.c"	OPTION_REG = BIN(01011111); // Disable TMR0 on RA4, 1:128 WDT, pullups on
	MOVLW	0x5f
	BANKSEL	_OPTION_REG
	MOVWF	_OPTION_REG
;	.line	61; "stepmotor1.c"	CMCON = 0xff;               // Comparator module defaults
	MOVLW	0xff
	BANKSEL	_CMCON
	MOVWF	_CMCON
;	.line	63; "stepmotor1.c"	TRISA = BIN(00101010);      // Port A outputs except 1,3 (sync) and 5 (Max)
	MOVLW	0x2a
	BANKSEL	_TRISA
	MOVWF	_TRISA
;	.line	72; "stepmotor1.c"	TRISB = BIN(00000011);      // Port B 0,1 input, 2-7 outputs
	MOVLW	0x03
	MOVWF	_TRISB
;	.line	89; "stepmotor1.c"	PIE1 = BIN(00000000);       // All peripheral interrupts initially disabled
	CLRF	_PIE1
;	.line	90; "stepmotor1.c"	INTCON = BIN(00000000);     // Interrupts disabled
	BANKSEL	_INTCON
	CLRF	_INTCON
;	.line	91; "stepmotor1.c"	PIR1 = 0;                   // Clear peripheral interrupt flags
	CLRF	_PIR1
;	.line	92; "stepmotor1.c"	SPBRG = 12;                 // 12 = 19200 (actually 19230) baud @ 4MHz
	MOVLW	0x0c
	BANKSEL	_SPBRG
	MOVWF	_SPBRG
;	.line	94; "stepmotor1.c"	TXSTA = BIN(00000100);      // 8 bit high speed 
	MOVLW	0x04
	MOVWF	_TXSTA
;	.line	95; "stepmotor1.c"	RCSTA = BIN(10000000);      // Enable port for 8 bit receive
	MOVLW	0x80
	BANKSEL	_RCSTA
	MOVWF	_RCSTA
;	.line	97; "stepmotor1.c"	PORTB = PULLUPS;      // Turn on pullups for B0,3
	MOVLW	0x01
	MOVWF	_PORTB
;	.line	99; "stepmotor1.c"	RCIE = 1;  // Enable receive interrupts
	BANKSEL	_PIE1_bits
	BSF	_PIE1_bits,5
;	.line	100; "stepmotor1.c"	CREN = 1;  // Start reception
	BANKSEL	_RCSTA_bits
	BSF	_RCSTA_bits,4
;	.line	102; "stepmotor1.c"	TXEN = 1;  // Enable transmit
	BANKSEL	_TXSTA_bits
	BSF	_TXSTA_bits,5
;	.line	103; "stepmotor1.c"	PEIE = 1;  // Peripheral interrupts on
	BANKSEL	_INTCON_bits
	BSF	_INTCON_bits,6
;	.line	104; "stepmotor1.c"	GIE = 1;   // Now turn on interrupts
	BSF	_INTCON_bits,7
;	.line	106; "stepmotor1.c"	PORTB = 0;
	CLRF	_PORTB
;	.line	107; "stepmotor1.c"	PORTA = 0;
	CLRF	_PORTA
;	.line	109; "stepmotor1.c"	TMR1IE = 0;
	BANKSEL	_PIE1_bits
	BCF	_PIE1_bits,0
;	.line	111; "stepmotor1.c"	TMR2 = 0;
	BANKSEL	_TMR2
	CLRF	_TMR2
;	.line	112; "stepmotor1.c"	CCPR1L = 4;  // Default power-up current limiting (25%)
	MOVLW	0x04
	MOVWF	_CCPR1L
;	.line	113; "stepmotor1.c"	PR2 = 16;
	MOVLW	0x10
	BANKSEL	_PR2
	MOVWF	_PR2
;	.line	114; "stepmotor1.c"	CCP1CON = BIN(00001100);   // PWM mode
	MOVLW	0x0c
	BANKSEL	_CCP1CON
	MOVWF	_CCP1CON
;	.line	115; "stepmotor1.c"	T2CON = BIN(00000100);     // Start timer 1:1 prescale, 1:1 postscale
	MOVLW	0x04
	MOVWF	_T2CON
;	.line	117; "stepmotor1.c"	T1CON = BIN(00000000);  // Timer 1 in clock mode with 1:1 scale
	CLRF	_T1CON
;	.line	118; "stepmotor1.c"	TMR1IE = 1;  // Enable timer interrupt
	BANKSEL	_PIE1_bits
	BSF	_PIE1_bits,0
	RETURN	
; exit point of _init1


;	code size estimation:
;	   94+   47 =   141 instructions (  376 byte)

	end