Subversion Repositories svn.mios

Rev

Rev 1 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
44 tk 1
; $Id: j5_dout.inc 44 2008-01-30 21:39:30Z tk $
1 tk 2
;
3
; Using J5 as DOUT
4
;
5
; This include file provides following functions:
6
;    o J5_DOUT_Init:    initializes the J5 port
7
;    o J5_DOUT_Set:     user function to set all pins at J5 at once
8
;    o J5_DOUT_PinSet:  user function to set a single pin of J5
9
;
10
; ==========================================================================
11
;
12
;  Copyright 1998-2007 Thorsten Klose (tk@midibox.org)
13
;  Licensed for personal non-commercial use only.
14
;  All other rights reserved.
15
;
16
; ==========================================================================
17
 
18
;; --------------------------------------------------------------------------
19
;;  FUNCTION: J5_DOUT_Init
20
;;  DESCRIPTION: This function initializes J5 as digital output
21
;;     Pin #0: RA.0
22
;;     Pin #1: RA.1
23
;;     Pin #2: RA.2
24
;;     Pin #3: RA.3
25
;;     Pin #4: RA.5
26
;;     Pin #5: RE.0
27
;;     Pin #6: RE.1
28
;;     Pin #7: RE.2
29
;;  IN:   -
30
;;  OUT:  -
31
;;  USES: -
32
;; --------------------------------------------------------------------------
33
 
34
J5_DOUT_Init
35
	;; disable the ADC which allocates the analog pins
36
#if PIC_DERIVATIVE_NEW_ADC == 0 ; PIC18F452
37
	movlw	0x07
38
#else
39
	movlw	0x0f		; all newer PIC18F derivatives (like PIC18F4685)
40
#endif
41
	movwf	ADCON1
42
 
43
	;; turn on the output driver of PORTA and PORTE
44
	;; (note: if you want to use some of them as input instead, just set the appr. line to "bsf TRISx, x"
45
	bcf	TRISA, 0	; Pin RA.0 = output
46
	bcf	TRISA, 1	; Pin RA.1 = output
47
	bcf	TRISA, 2	; Pin RA.2 = output
48
	bcf	TRISA, 3	; Pin RA.3 = output
49
	bcf	TRISA, 5	; Pin RA.5 = output
50
	bcf	TRISE, 0	; Pin RE.0 = output
51
	bcf	TRISE, 1	; Pin RE.1 = output
52
	bcf	TRISE, 2	; Pin RE.2 = output
53
 
54
	return
55
 
56
;; --------------------------------------------------------------------------
57
;;  FUNCTION: J5_DOUT_Set
58
;;  DESCRIPTION: This function sets all pins of J5 at once
59
;;  IN:   pin values in WREG
60
;;  OUT:  -
61
;;  USES: -
62
;; --------------------------------------------------------------------------
63
J5_DOUT_Set
64
	;; temporary store values in MIOS_PARAMETER1
65
	movwf	MIOS_PARAMETER1
66
 
67
	;; copy values into SFRs
68
 
69
	;; MIOS_PARAMETER1[3..0] -> PORTA[3..0]
70
	;; MIOS_PARAMETER1[4] -> PORTA[5]
71
	;; (make it clean, avoid spikes!)
72
	movf	LATA, W
73
	andlw	0xd0
74
	movwf	MIOS_PARAMETER2
75
	movf	MIOS_PARAMETER1, W
76
	andlw	0x0f
77
	iorwf	MIOS_PARAMETER2, W
78
	btfsc	MIOS_PARAMETER1, 4
79
	iorlw	0x20
80
	movwf	LATA
81
 
82
	;; MIOS_PARAMETER1[7..5] -> PORTE[2..0] (make it clean, avoid spikes!)
83
	movf	LATE, W
84
	andlw	0xf8
85
	movwf	MIOS_PARAMETER2
86
	swapf	MIOS_PARAMETER1, W
87
	rrf	WREG, W
88
	andlw	0x07
89
	iorwf	MIOS_PARAMETER2, W
90
	movwf	LATE
91
 
92
	return
93
 
94
;; --------------------------------------------------------------------------
95
;;  FUNCTION: J5_DOUT_PinSet
96
;;  DESCRIPTION: This function sets a single pin of J5
97
;;  IN:   pin number in WREG, pin value in MIOS_PARAMETER1
98
;;  OUT:  -
99
;;  USES: -
100
;; --------------------------------------------------------------------------
101
J5_DOUT_PinSet
102
	;; make it superfast: branch depending on WREG
103
	BRA_IFSET WREG, 2, ACCESS, J5_DOUT_PinSet_4567
104
J5_DOUT_PinSet_0123
105
	BRA_IFSET WREG, 1, ACCESS, J5_DOUT_PinSet_23
106
J5_DOUT_PinSet_01
107
	BRA_IFSET WREG, 0, ACCESS, J5_DOUT_PinSet_1
108
J5_DOUT_PinSet_0
109
	btfsc	MIOS_PARAMETER1, 0		; set A.0
110
	bsf	LATA, 0
111
	btfss	MIOS_PARAMETER1, 0
112
	bcf	LATA, 0
113
	return
114
 
115
J5_DOUT_PinSet_1
116
	btfsc	MIOS_PARAMETER1, 0		; set A.1
117
	bsf	LATA, 1
118
	btfss	MIOS_PARAMETER1, 0
119
	bcf	LATA, 1
120
	return
121
 
122
J5_DOUT_PinSet_23
123
	BRA_IFSET WREG, 0, ACCESS, J5_DOUT_PinSet_3
124
J5_DOUT_PinSet_2
125
	btfsc	MIOS_PARAMETER1, 0		; set A.2
126
	bsf	LATA, 2
127
	btfss	MIOS_PARAMETER1, 0
128
	bcf	LATA, 2
129
	return
130
 
131
J5_DOUT_PinSet_3
132
	btfsc	MIOS_PARAMETER1, 0		; set A.3
133
	bsf	LATA, 3
134
	btfss	MIOS_PARAMETER1, 0
135
	bcf	LATA, 3
136
	return
137
 
138
J5_DOUT_PinSet_4567
139
	BRA_IFSET WREG, 1, ACCESS, J5_DOUT_PinSet_67
140
J5_DOUT_PinSet_45
141
	BRA_IFSET WREG, 0, ACCESS, J5_DOUT_PinSet_5
142
J5_DOUT_PinSet_4
143
	btfsc	MIOS_PARAMETER1, 0		; set A.5
144
	bsf	LATA, 5
145
	btfss	MIOS_PARAMETER1, 0
146
	bcf	LATA, 5
147
	return
148
 
149
J5_DOUT_PinSet_5
150
	btfsc	MIOS_PARAMETER1, 0		; set E.0
151
	bsf	LATE, 0
152
	btfss	MIOS_PARAMETER1, 0
153
	bcf	LATE, 0
154
	return
155
 
156
J5_DOUT_PinSet_67
157
	BRA_IFSET WREG, 0, ACCESS, J5_DOUT_PinSet_7
158
J5_DOUT_PinSet_6
159
	btfsc	MIOS_PARAMETER1, 0		; set E.1
160
	bsf	LATE, 1
161
	btfss	MIOS_PARAMETER1, 0
162
	bcf	LATE, 1
163
	return
164
 
165
J5_DOUT_PinSet_7
166
	btfsc	MIOS_PARAMETER1, 0		; set E.2
167
	bsf	LATE, 2
168
	btfss	MIOS_PARAMETER1, 0
169
	bcf	LATE, 2
170
	return
171