1 | ;------------------------------------------------------------------------------
|
2 | ; PROCESSOR DECLARATION
|
3 | ;------------------------------------------------------------------------------
|
4 | LIST P=12F675 ; list directive to define processor
|
5 | #INCLUDE <P12F675.INC> ; processor specific variable definitions
|
6 |
|
7 | ;------------------------------------------------------------------------------
|
8 | ; CONFIGURATION WORD SETUP
|
9 | ;------------------------------------------------------------------------------
|
10 | __CONFIG _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT
|
11 |
|
12 | ;------------------------------------------------------------------------------
|
13 | ; VARIABLE DEFINITIONS
|
14 | ;------------------------------------------------------------------------------
|
15 | ; example of using Shared Uninitialized Data Section
|
16 | INT_VAR UDATA_SHR 0x20
|
17 | W_TEMP RES 1 ; variable used for context saving
|
18 | STATUS_TEMP RES 1 ; variable used for context saving
|
19 | ; für waitwx:
|
20 | anzmin RES 1
|
21 | anzs RES 1
|
22 | anzds RES 1
|
23 | anzms RES 1
|
24 | msconst RES 1
|
25 | flags RES 1
|
26 | puls RES 1
|
27 |
|
28 | ;------------------------------------------------------------------------------
|
29 | ; Definitionen:
|
30 | ;------------------------------------------------------------------------------
|
31 | #define servo GPIO,5
|
32 | #define taster GPIO,0
|
33 | #define rechtsLauf GPIO,1
|
34 | #define wartePulsDauer flags,0
|
35 |
|
36 |
|
37 | ;------------------------------------------------------------------------------
|
38 | ; EEPROM INITIALIZATION
|
39 | ; The 12F675 has 128 bytes of non-volatile EEPROM, starting at address 0x2100
|
40 | ;------------------------------------------------------------------------------
|
41 | ;DATAEE CODE 0x2100
|
42 | ; DE "MCHP" ; Place 'M' 'C' 'H' 'P' at address 0,1,2,3
|
43 |
|
44 |
|
45 | ;------------------------------------------------------------------------------
|
46 | ; OSCILLATOR CALIBRATION VALUE
|
47 | ; Internal RC calibration value is placed at location 0x3FF by Microchip as
|
48 | ; a 0xADDLW K instruction, where the K is a literal value to be loaded into
|
49 | ; the OSCCAL register.
|
50 | ;------------------------------------------------------------------------------
|
51 | OSC CODE 0x03FF
|
52 |
|
53 | ;------------------------------------------------------------------------------
|
54 | ; RESET VECTOR
|
55 | ;------------------------------------------------------------------------------
|
56 | RESET_VECTOR CODE 0x0000 ; processor reset vector
|
57 | GOTO INIT ; go to beginning of program
|
58 |
|
59 |
|
60 |
|
61 | ;------------------------------------------------------------------------------
|
62 | ; INTERRUPT SERVICE ROUTINE
|
63 | ;------------------------------------------------------------------------------
|
64 | INT_VECTOR CODE 0x0004 ; interrupt vector location
|
65 | MOVWF W_TEMP ; save off current W register contents
|
66 | MOVF STATUS,w ; move status register into W register
|
67 | MOVWF STATUS_TEMP ; save off contents of STATUS register
|
68 |
|
69 | ; isr code can go here or be located as a call subroutine elsewhere
|
70 | btfss servo
|
71 | goto pulsIsOff
|
72 | goto pulsIsOn
|
73 | pulsIsOff
|
74 | bsf OPTION_REG,0 ;prescaler auf 1:4 umschalten
|
75 | bcf OPTION_REG,1 ;prescaler auf 1:4 umschalten
|
76 | bcf OPTION_REG,2 ;prescaler auf 1:4 umschalten
|
77 | bsf servo
|
78 | bsf wartePulsDauer
|
79 | movlw D'5' ;=255-250, 250=1ms
|
80 | movwf TMR0
|
81 | goto returnFromInterrupt
|
82 | pulsIsOn
|
83 | btfss wartePulsDauer
|
84 | goto pulsEnde
|
85 | movlw puls
|
86 | movwf TMR0
|
87 | bcf wartePulsDauer
|
88 | goto returnFromInterrupt
|
89 | pulsEnde
|
90 | bcf servo
|
91 | bcf OPTION_REG,0 ;prescaler auf 1:128 umschalten
|
92 | bsf OPTION_REG,1 ;prescaler auf 1:128 umschalten
|
93 | bsf OPTION_REG,2 ;prescaler auf 1:128 umschalten
|
94 | movlw D'111' ;18.5 ms warten (255-x)*128µs
|
95 | movwf TMR0
|
96 | goto returnFromInterrupt
|
97 | returnFromInterrupt
|
98 | bcf INTCON,T0IF ;clear flag
|
99 | MOVF STATUS_TEMP,w ; retrieve copy of STATUS register
|
100 | MOVWF STATUS ; restore pre-isr STATUS register contents
|
101 | SWAPF W_TEMP,f
|
102 | SWAPF W_TEMP,w ; restore pre-isr W register contents
|
103 | RETFIE ; return from interrupt
|
104 |
|
105 |
|
106 |
|
107 |
|
108 | ;------------------------------------------------------------------------------
|
109 | ; MAIN PROGRAM
|
110 | ;------------------------------------------------------------------------------
|
111 | INITIALIZATION CODE
|
112 | INIT
|
113 | ;------------------------------------------------------------------------------
|
114 | ; OSCCAL RESTORE (not required if internal OSC is not used)
|
115 | ;------------------------------------------------------------------------------
|
116 | errorlevel -302
|
117 | BSF STATUS,RP0 ; set file register bank to 1
|
118 | CALL 0x3FF ; retrieve factory calibration value
|
119 | MOVWF OSCCAL ; update register with factory cal value
|
120 | BCF STATUS,RP0 ; set file register bank to 0
|
121 | errorlevel +302
|
122 |
|
123 |
|
124 | ;------------------------------------------------------------------------------
|
125 | ; Pin I/O, pull ups und timer0:
|
126 | ;------------------------------------------------------------------------------
|
127 | bcf STATUS,RP0 ;Bank 0
|
128 | clrf GPIO ;Init GPIO, alle low
|
129 | movlw B'00000111' ;Comparators off
|
130 | movwf CMCON ;Comparators off
|
131 | bsf STATUS,RP0 ;Bank 1
|
132 | clrf ANSEL ;AD Off --> digital IO
|
133 | movlw B'00000011' ;alle output außer GP0 und GP1;
|
134 | movwf TRISIO
|
135 | clrwdt
|
136 | movlw B'01010001'; pull-ups on, Timer 0 internal clock, prescaler für timer0 auf 1:4
|
137 | movwf OPTION_REG
|
138 | bcf STATUS,RP0 ;Bank 0
|
139 | clrf TMR0 ;clear Timer0
|
140 | clrf GPIO ;Init GPIO, alle low
|
141 | movlw D'128' ; Servomittelstellung
|
142 | movwf puls
|
143 | bsf INTCON,T0IE ;Timer0 Interpt enabled
|
144 | bsf INTCON,GIE ;Enable interupts
|
145 |
|
146 |
|
147 | ;------------------------------------------------------------------------------
|
148 | ; Main Program
|
149 | ;------------------------------------------------------------------------------
|
150 | Main
|
151 |
|
152 | movlw D'10'
|
153 | movwf puls
|
154 | movlw D'10'
|
155 | call waitwds
|
156 |
|
157 | movlw D'128'
|
158 | movwf puls
|
159 | movlw D'10'
|
160 | call waitwds
|
161 |
|
162 |
|
163 | movlw D'230'
|
164 | movwf puls
|
165 | movlw D'10'
|
166 | call waitwds
|
167 |
|
168 | movlw D'128'
|
169 | movwf puls
|
170 | movlw D'10'
|
171 | call waitwds
|
172 |
|
173 | goto Main
|