Debounce.asm


1
;  PortA  free
2
;portb bit 1-3
3
;R/S = register select line
4
;R/S = 0 ensures that the data to the display will change the registers
5
;R/S = 1 writes the charakters to the display                            ; 
6
;  PortB  Bit0: RS
7
;
8
;         Bit1: RW                        ;
9
;      Bit2: E                          ;
10
;                                  ;
11
;      Bit6: incircuit programming                ;
12
;      Bit7: incircuit programming                ;
13
;                                  ;
14
;  PortC  Bit 0-7: Display                     ;
15
;                                  ;
16
;  PortD  Bit 0-7: Keypad                      ;
17
;  PortE  free  
18
19
#include <p16F887.inc>
20
  __CONFIG    _CONFIG1, _LVP_OFF & _FCMEN_OFF & _IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT
21
  __CONFIG    _CONFIG2, _WRT_OFF & _BOR21V
22
23
     cblock     0x20
24
25
Delay               ; Assign an address to label Delay1
26
Delay2
27
Display             ; define a variable to hold the diplay
28
LastStableState     ; keep track of switch state (open-1; closed-0)
29
COUNT
30
     endc
31
e    equ  3    
32
rw    equ  2    
33
rs    equ  1         
34
zero  equ 0
35
     org 0
36
Start:
37
     bsf       STATUS,RP0          ; select Register Bank 1
38
     movlw     0xFF
39
     movwf     TRISA               ; Make PortA all input
40
   movwf     TRISE         ; Make PortE all input
41
   clrf     TRISB         ; Make PORTB all  output
42
     clrf      TRISC               ; Make Portc all output
43
   clrf     TRISD         ; Make Portd all output (für Tastatur, auf all input umstellen)
44
   MOVLW     B'00000111'       ;load value to configure optionreg
45
   MOVWF     OPTION_REG       ;configure timer 0, internal osci and prescale 256
46
     bcf       STATUS,RP0          ; address Register Bank 0
47
     clrf      PORTD               ; init LEDs to all off
48
   clrf     PORTC
49
   clrf      PORTB
50
   clrf      PORTA
51
     clrf     COUNT
52
     clrf      TMR0
53
 
54
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
55
;Display inititialisation                      ;
56
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
57
    CALL  DELAY1
58
    MOVLW  B'00111100'    ;Function set
59
    MOVWF  PORTC      ;bit 4-3 8bit data,two lines,5x7 dots display 
60
    CALL  CLOCK      
61
    CALL  DELAY1
62
wait1  BTFSC  PORTB,rw
63
    GOTO  wait1
64
    MOVLW  B'00001111'    ;Display on, curcor on, cursor flashing 
65
    MOVWF  PORTC
66
    CALL  CLOCK
67
    CALL  DELAY1
68
wait2  BTFSC  PORTB,rw
69
    GOTO  wait2
70
    MOVLW  B'00000001'    ;clear display, cursor on position top left
71
    MOVWF  PORTC
72
    CALL  CLOCK
73
    CALL  DELAY1
74
wait3  BTFSC  PORTB,rw
75
    GOTO  wait3
76
    MOVLW  B'00000110'    ;cursor auto incrment
77
    MOVWF  PORTC
78
    CALL   CLOCK
79
    GOTO  write
80
81
82
83
84
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
85
;Subroutines;
86
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
87
88
;3 delay
89
DELAY3  CLRF   TMR0      ;start tmr0
90
LOOP1  movf   TMR0,w      ;tmr 0 into w
91
    sublw  .96
92
    BTFSS  STATUS,zero
93
    GOTO   LOOP1
94
    RETLW  0
95
96
;1 delay
97
;DELAY1  CLRF  TMR0      ;start tmr0
98
;LOOP2  MOVF  TMR0,w      ;read tmr0 into w
99
;    SUBLW  .3
100
;    BTFSS  STATUS,zero
101
;    GOTO  LOOP2
102
;    RETLW  0
103
DELAY1  MOVLW   .0     ;value for sampling time
104
    MOVWF   TMR0    ;load value from w to tmr0
105
wait  BTFSS   TMR0,7    ;test if time over
106
    GOTO  wait    ;value is not zero -> delay time not over
107
    Return        ;delay time over -> return
108
109
CLOCK  BSF    PORTB,e
110
    NOP  
111
    BCF    PORTB,e 
112
    NOP
113
    RETLW  0
114
115
NUM0  MOVLW  6        ;enables portb bit 1 and bit 2
116
    MOVWF  PORTB      ;E und RS enable
117
    MOVLW  B'00110000'
118
    MOVWF  PORTC
119
    CALL  CLOCK
120
    RETLW  0
121
122
NUM1  MOVLW  6        ;enables portb bit 1 and bit 2
123
    MOVWF  PORTB      ;E und RS enable
124
    MOVLW  B'00110001'
125
    MOVWF  PORTC
126
    CALL  CLOCK
127
    RETLW  0
128
129
NUM2  MOVLW  6        ;enables portb bit 1 and bit 2
130
    MOVWF  PORTB      ;E und RS enable
131
    MOVLW  B'00110010'
132
    MOVWF  PORTC
133
    CALL  CLOCK
134
    RETLW  0
135
136
NUM3  MOVLW  6        ;enables portb bit 1 and bit 2
137
    MOVWF  PORTB      ;E und RS enable
138
    MOVLW  B'00110011'
139
    MOVWF  PORTC
140
    CALL  CLOCK
141
    RETLW  0
142
143
NUM4  MOVLW  6        ;enables portb bit 1 and bit 2
144
    MOVWF  PORTB      ;E und RS enable
145
    MOVLW  B'00110100'
146
    MOVWF  PORTC
147
    CALL  CLOCK
148
    RETLW  0
149
150
NUM5  MOVLW  6        ;enables portb bit 1 and bit 2
151
    MOVWF  PORTB      ;E und RS enable
152
    MOVLW  B'00110101'
153
    MOVWF  PORTC
154
    CALL  CLOCK
155
    RETLW  0
156
157
NUM6  MOVLW  6        ;enables portb bit 1 and bit 2
158
    MOVWF  PORTB      ;E und RS enable
159
    MOVLW  B'00110110'
160
    MOVWF  PORTC
161
    CALL  CLOCK
162
    RETLW  0
163
164
NUM7  MOVLW  6        ;enables portb bit 1 and bit 2
165
    MOVWF  PORTB      ;E und RS enable
166
    MOVLW  B'00110111'
167
    MOVWF  PORTC
168
    CALL  CLOCK
169
    RETLW  0
170
171
NUM8  MOVLW  6        ;enables portb bit 1 and bit 2
172
    MOVWF  PORTB      ;E und RS enable
173
    MOVLW  B'00111000'
174
    MOVWF  PORTC
175
    CALL  CLOCK
176
    RETLW  0
177
178
NUM9  MOVLW  6        ;enables portb bit 1 and bit 2
179
    MOVWF  PORTB      ;E und RS enable
180
    MOVLW  B'00111001'
181
    MOVWF  PORTC
182
    CALL  CLOCK
183
    RETLW  0
184
185
GAP    MOVLW  6        ;enables portb bit 1 and bit 2
186
    MOVWF  PORTB      ;E und RS enable
187
    MOVLW  B'00111010'
188
    MOVWF  PORTC
189
    CALL  CLOCK
190
    RETLW  0
191
192
DOT    MOVLW  6        ;enables portb bit 1 and bit 2
193
    MOVWF  PORTB      ;E und RS enable
194
    MOVLW  B'00101110'
195
    MOVWF  PORTC
196
    CALL  CLOCK
197
    RETLW  0
198
199
CLRDISP  CLRF  PORTB
200
    MOVLW  B'00000001'        
201
    MOVWF  PORTC
202
    CALL  CLOCK      ;clock charakter onto display
203
    CALL  DELAY1
204
    RETLW  0
205
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
206
207
write  CALL  CLRDISP  
208
    CLRF  PORTB
209
    MOVLW  8H        ;cursor at top left, 80H
210
    MOVWF  PORTB
211
    CALL  CLOCK
212
    MOVLW  0H
213
    MOVWF  PORTC
214
    CALL  CLOCK
215
216
    CALL  NUM0
217
    CALL  DELAY1
218
    CALL  NUM1
219
    CALL  DELAY1
220
    CALL  NUM2
221
    CALL  DELAY1
222
    
223
    CLRF  PORTB
224
    MOVLW  0CH        ;cursor on second line
225
    MOVWF  PORTC
226
    CALL  CLOCK
227
    MOVLW  3H
228
    MOVWF  PORTC
229
    CALL  CLOCK
230
231
    CALL  NUM3
232
    CALL  DELAY1
233
    CALL  NUM4
234
    CALL   DELAY1
235
    CALL  NUM5
236
    CALL  DELAY1
237
    CALL  NUM6
238
    CALL   DELAY1
239
    CALL  NUM7
240
    CALL  DELAY1
241
    CALL  NUM8
242
    CALL   DELAY1
243
    CALL  NUM9
244
    CALL  DELAY1
245
  
246
    CALL  DELAY3      ;wait 3 
247
    GOTO  write
248
    
249
sleep
250
251
end