Weiß nicht, ob das ggf helfen kann. ist je eine RS-232 Routine zum Datentausch.
Aber wie ihr schon sehen werden halt leider in ASM
RS232-send.asm
Code: Alles auswählen
list p=16f84
;***********************************************************************
;* Pinbelegung des PIC
;* -------------------
;* PORTA : 0
;* 1
;* 2 seriell Output
;* 3
;* 4
;* PortB 0
;* 1
;* 2
;* 3
;* 4
;* 5
;* 6
;* 7
;***********************************************************************
;* Senden via RS232 am Pin RB2
;* output RA1 (keine RS232-Treiberschaltkreise verwenden)
;* Takt : 4 MHz
#include <p16f84.inc>
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC
;***********************************************************************
;* Variablennamen vergeben
Temp Equ 0x20
cycl_1 equ 0x21 ; Zähler
cycl_2 equ 0x22 ; Zähler
Byte equ 0x23
out equ 2 ; RS-232 Out ist RA2
;**********************************************************************
; los geht's mit dem Programm
; Pin RA2 auf Ausgabe stellen
init bsf STATUS, RP0
movlw B'00111011'
movwf TRISA
bcf STATUS, RP0
clrf PORTA
Loop movlw 'A'
call Send_RS
goto Loop
;***********************************************************************
; senden des Bytes, das im Register 'W' steht
Send_RS movwf Byte
movlw 8
movwf cycl_1
bcf PORTA, out
call Warte_s
bsf PORTA, out
call Warte_s
Send_1 rrf Byte, f
btfsc STATUS, C
bcf PORTA, out
btfss STATUS, C
bsf PORTA, out
call Warte_s
decfsz cycl_1, f
goto Send_1
bcf PORTA, out
call Warte_s
Return
;***********************************************************************
; ein Bit Zeitverzögerung mit einer Warteschleife
; Timing muss genau Stimmen (5%)
; senden 4 MHz 10MHz
; 2400 Bps = 69d 173d
; 9600 Bps = 16D 43d
Warte_s Movlw D'16'
movwf cycl_2
Warte1 nop
nop
nop
decfsz cycl_2, 1
goto Warte1
return
end
RS232-empf.asm
Code: Alles auswählen
list p=16f84
;***********************************************************************
;* Pinbelegung des PIC
;***********************************************************************
;* PORTA : 0
;* 1
;* 2
;* 3 seriell Input
;* 4
;* PortB 0 LED 2^0
;* 1 LED 2^1
;* 2 LED 2^2
;* 3 LED 2^3
;* 4 LED 2^4
;* 5 LED 2^5
;* 6 LED 2^6
;* 7 LED 2^7
;***********************************************************************
;* Rothe, Andreas - Empfänger RS-232
;* input RA3 (keine RS232-Treiberschaltkreise verwenden
;* sondern 22K Reihenwiderstand)
;* Takt : 4 MHz
;* Empfangener Code wird am PORTB ausgeben
#include <p16f84.inc>
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC
;***********************************************************************
;* Variablennamen vergeben
cycl_1 equ 0x20 ; Zähler
cycl_2 equ 0x21 ; Zähler
rs232in equ 0x22
Byte equ 0x23
Temp equ 0x24
in equ 3 ; RS-232 In ist RA3
;**********************************************************************
; los geht's mit dem Programm
; Pin RA2 auf Ausgabe stellen
init bsf STATUS, RP0
movlw B'00000000'
movwf TRISB
bcf STATUS, RP0
clrf PORTA
clrf PORTB ; Alle LEDs ausschalten
Loop call Ser_RX
movlw rs232in
movwf PORTB
goto Loop
;***********************************************************************
; senden des Bytes, das im Register 'W' steht
Ser_RX clrf Byte
movlw 8
movwf cycl_1
btfsc PORTA, in
goto Ser_RX
call Pause
btfsc PORTA, in
goto Ser_RX
RX_2 call Warte
btfsc PORTA, in
bcf STATUS, C
btfss PORTA, in
bsf STATUS, C
rrf Byte, f
decfsz cycl_1, f
goto RX_2
call Warte
btfsc PORTA, in
goto Ser_RX
movf Byte, w
movwf rs232in
Return
;***********************************************************************
; ein Bit Zeitverzögerung mit einer Warteschleife
; Timing muss genau Stimmen (5%) LZ zw sendert und Empfänger
; empfangen 4 MHz 10MHz
; 2400 Bps = 69D 173D
; 4800 Bps = 34D 86D
; 9600 Bps = 16D 43D
Warte Movlw D'16'
movwf cycl_2
Warte1 nop
nop
nop
decfsz cycl_2, 1
goto Warte1
return
;***********************************************************************
; 1/2 bit Zeitverzögerung
; dieses Timing ist nicht ganz so Kritisch (25%)
;
; 4 MHz 10 MHz
; 2400 Bps = 416T = 63D 157D
; 4800 Bps = 31D 78D
; 9600 Bps = 15D 39D
;
Pause Movlw D'15'
Movwf Temp
Pause2 decfsz Temp, f
goto Pause2
return
;***********************************************************************
end
ggf. kann es ja auf dieses Problem angewendet und modiviziert werden. bei bedarf lase ich auch die ASM, HEX hoch.