rs232.asm


1
  list p=16f84
2
;**************************************************************
3
;*
4
;*  ----------------------------------  
5
;*  PORTA:   0 
6
;*    1 
7
;*    2 
8
;*    3 seriell Input
9
;*    4 
10
;*  PORTB:  0 LED     
11
;*    1 LED
12
;*    2 LED
13
;*    3 LED 
14
;*    4 LED
15
;*    5 LED
16
;*    6 LED
17
;*    7 LED
18
;*
19
;**************************************************************
20
;
21
;sprut (zero) Bredendiek 05/2000 (mod. 01/2002)
22
;
23
; Empfangen via RS-232
24
; input : RA3
25
; Takt  : 4 MHz
26
;
27
; Empfangener Code wird am Port B ausgegeben
28
;
29
;**************************************************************
30
; Includedatei für den 16F84 einbinden
31
32
  #include <P16f84.INC>
33
34
; Configuration festlegen
35
; bis 4 MHz: Power on Timer, kein Watchdog, XT-Oscillator
36
37
  __CONFIG  _PWRTE_ON & _WDT_OFF & _XT_OSC
38
39
;**************************************************************
40
;Variablennamen vergeben
41
42
43
44
rs232in  Equ  0x23
45
Byte  Equ  0x24
46
in    Equ  3    ;RS-232  in ist RA3
47
48
Temp  Equ  0x20
49
cycl_1  Equ  0x21    ; Zähler 
50
cycl_2  Equ  0x22    ; Zähler
51
out    EQU  2    ; RS-232 out ist RA2
52
53
w_copy  Equ    0x25               ; Backup für Akkuregister 
54
s_copy  Equ    0x26               ; Backup für Statusregister 
55
56
;************************************************************** 
57
; los gehts mit dem Programm 
58
59
        org    100 
60
        goto   Init               ; Sprung zum Hauptprogramm 
61
62
63
;***************************************************************
64
;senden des Bytes, das im Register W steht 
65
      
66
Send_RS        ; Ausgabe eines Bytes seriell  
67
  movwf  Byte    ; Byte in w
68
  movlw  8    ; es werden 8 Bit gesendet
69
  movwf   cycl_1
70
  
71
  bcf  PORTA, out
72
  call   Warte_s    ; 1 Startbit (0)
73
74
Send_1  rrf  Byte, f    ; aktuelles Bit in das Carry-Flag schieben
75
  btfsc  STATUS, C
76
  bsf  PORTA, out  ; Lo wenn Bit = 1
77
  btfss  STATUS, C
78
  bcf  PORTA, out  ; Hi wenn Bit = 0
79
  call  Warte_s    ; 1 Bit lang warten
80
  decfsz  cycl_1, f  ; waren das schon 8 Bit?
81
  goto  Send_1    ; nein, es geht weiter
82
  bsf  PORTA, out  ; Byte zuende, 1 Stoppbit (1) senden
83
  call   Warte_s    ;
84
  bsf  PORTA, out
85
  call  Warte_s    ; 1 Stopbit (1)
86
  return
87
88
;**********************************************************
89
;ein Bit Zeitverzoegerung mit einer Warteschleife
90
;
91
; senden            4 MHz    10 MHz
92
; 2400 Bps =          69d    173d
93
; 9600 Bps =          15d     43d
94
95
Warte_s  movlw  D'15'    ; 9600 Bps / 4 MHz senden
96
  movwf  cycl_2    ; 
97
  nop
98
  nop
99
  nop
100
  nop
101
  nop
102
Warte1  
103
  nop
104
  nop
105
  nop
106
  decfsz  cycl_2, 1  
107
  goto  Warte1
108
  return
109
110
111
;************************************************************** 
112
; das Hauptprogramm 
113
114
  
115
Init
116
  bsf     STATUS, RP0  ; unschalten auf Bank 1
117
  movlw  B'00111011'  ; RA2 output 
118
  movwf  TRISA    ; 
119
  bcf     STATUS, RP0  ; zurückschalten zur Bank 0
120
  clrf  PORTA    ; 
121
122
; RB0-Interrupt einstellen 
123
    bsf    STATUS, RP0        ; auf Bank 1 umschalten 
124
    bsf    OPTION_REG, INTEDG ; 0-1-Flanke an RB0 
125
    bcf    STATUS, RP0        ; auf Bank 0 zurückschalten 
126
127
    bsf    INTCON, INTE       ; RB0-interupt erlauben 
128
    bsf    INTCON, GIE        ; Interupt generell erlauben 
129
130
131
loop    goto   loop               ; eine Endlosschleife 
132
133
134
135
136
137
;************************************************************** 
138
; die Interuptserviceroutine 
139
140
        org  4  
141
intvec 
142
        movwf  w_copy             ; w retten 
143
        swapf  STATUS, w          ; STATUS retten 
144
        movwf  s_copy  
145
146
    movlw  'a'
147
    call  send_RS
148
149
150
Int_end  
151
        bcf    INTCON, INTF       ; RB0-Interupt-Flag löschen 
152
        swapf  s_copy, w          ; STATUS zurück 
153
        movwf  STATUS  
154
        swapf  w_copy, f          ; w zurück mit flags 
155
        swapf  w_copy, w 
156
        retfie         
157
        
158
159
160
161
;Zeichen empfangen und dann wieder per rs232 schicken
162
163
;Loop
164
;  call  ser_RX    ; Code von RS232 empfangen
165
;  movfw  rs232in    ;
166
;  call  Send_RS    ; Datenwort ausgeben via RS-232
167
  
168
;  goto  Loop
169
170
171
172
173
  end