J
Jason
Guest
Hi,
I have circuit with a MX232 that I pass serial data from my comp. It feeds
into a 16F628 chip and then the chip feeds a LCD screen. I have it set to
2400 baud and it works great. Then what I did was I put a TWS-434 from the
MX232 and a RWS-434 into the 16F628. I am trying not to use a decoder or
encoder. I have it sending data and it seems to be working. The wierd
thing is that when I send it text the first few characters are turned in
wierd characters but after that the rest of the string is ok. It seems to
be having problems initlitzing the transmitter or reciever but once it gets
started it works.
So if I send it:
d d Hello my name is bob
I get:
#&%Hello my name is bob.
Anyone got any ideas?? I included the code for the PIC below. Thanks in
advance!!
processor PIC16F628 ;16F628
__CONFIG 0x3e62
LIST P=16F628, R=DEC ; Use the PIC16F628 and decimal system
#include "P16F628.INC" ; Include header file
CBLOCK 0x20 ; Declare variable addresses starting at
0x20
dataL
ENDC
ORG 0x000 ; Program starts at 0x000
;
; --------------------------------
; SET ANALOG/DIGITAL INPUTS PORT A
; --------------------------------
;
movlw 7
movwf CMCON ; CMCON=7 set comperators off
;
; ----------------
; INITIALIZE PORTS
; ----------------
;
movlw b'00000000' ; set up portA
movwf PORTA
movlw b'00000100' ; RB2(TX)=1 others are 0
movwf PORTB
bsf STATUS,RP0 ; RAM PAGE 1
movlw 0xFF
movwf TRISA ; portA all pins input
movlw b'11110010' ; RB7-RB4 and RB1(RX)=input, others output
movwf TRISB
; ------------------------------------
; SET BAUD RATE TO COMMUNICATE WITH PC
; ------------------------------------
; Boot Baud Rate = 9600, No Parity, 1 Stop Bit
;
bcf TXSTA, SYNC ; set asynchronous
bcf TXSTA, BRGH ; set low baud rate
movlw 0x40 ; 1200bps (51 = 0x33 @ 4MHz) 19 for 2400,
40 for 10mhz at 2400 baud
movwf SPBRG
bcf STATUS, RP0 ; select bank 0
bsf RCSTA, SPEN ; ENable Serial Port
bsf STATUS, RP0 ; select bank 1
bsf TXSTA, TXEN ; ENable TX
bsf PIE1, RCIE ; Enable RX interrupt
bcf STATUS, RP0 ; back to bank 0
bsf RCSTA, CREN ; ENable RX
;
; ------------------------------------
; PROVIDE A SETTLING TIME FOR START UP
; ------------------------------------
;
clrf dataL
settle decfsz dataL,F
goto settle
movf RCREG,W
movf RCREG,W
movf RCREG,W ; flush receive buffer
; ---------
; MAIN LOOP
; ---------
;
call message ;call message ; send "16F628 alive"
loop call receive ; wait for a char
call send ; send the char
goto loop
;
; -------------------------------------------
; RECEIVE CHARACTER FROM RS232 AND STORE IN W
; -------------------------------------------
; This routine does not return until a character is received.
;
receive btfss PIR1,RCIF ; (5) check for received data
goto receive
movf RCREG,W ; save received data in W
return
;
; -------------------------------------------------------------
; SEND CHARACTER IN W VIA RS232 AND WAIT UNTIL FINISHED SENDING
; -------------------------------------------------------------
;
send movwf TXREG ; send data in W
TransWt bsf STATUS,RP0 ; RAM PAGE 1
WtHere btfss TXSTA,TRMT ; (1) transmission is complete if hi
goto WtHere
bcf STATUS,RP0 ; RAM PAGE 0
return
;
; -------
; MESSAGE
; -------
;
message movlw '1'
call send
movlw '6'
call send
movlw 'F'
call send
movlw '6'
call send
movlw '2'
call send
movlw '8'
call send
movlw ' '
call send
movlw 'a'
call send
movlw 'l'
call send
movlw 'i'
call send
movlw 'v'
call send
movlw 'e'
call send
movlw 0x0D ; CR
call send
movlw 0x0A ; LF
call send
return
END
I have circuit with a MX232 that I pass serial data from my comp. It feeds
into a 16F628 chip and then the chip feeds a LCD screen. I have it set to
2400 baud and it works great. Then what I did was I put a TWS-434 from the
MX232 and a RWS-434 into the 16F628. I am trying not to use a decoder or
encoder. I have it sending data and it seems to be working. The wierd
thing is that when I send it text the first few characters are turned in
wierd characters but after that the rest of the string is ok. It seems to
be having problems initlitzing the transmitter or reciever but once it gets
started it works.
So if I send it:
d d Hello my name is bob
I get:
#&%Hello my name is bob.
Anyone got any ideas?? I included the code for the PIC below. Thanks in
advance!!
processor PIC16F628 ;16F628
__CONFIG 0x3e62
LIST P=16F628, R=DEC ; Use the PIC16F628 and decimal system
#include "P16F628.INC" ; Include header file
CBLOCK 0x20 ; Declare variable addresses starting at
0x20
dataL
ENDC
ORG 0x000 ; Program starts at 0x000
;
; --------------------------------
; SET ANALOG/DIGITAL INPUTS PORT A
; --------------------------------
;
movlw 7
movwf CMCON ; CMCON=7 set comperators off
;
; ----------------
; INITIALIZE PORTS
; ----------------
;
movlw b'00000000' ; set up portA
movwf PORTA
movlw b'00000100' ; RB2(TX)=1 others are 0
movwf PORTB
bsf STATUS,RP0 ; RAM PAGE 1
movlw 0xFF
movwf TRISA ; portA all pins input
movlw b'11110010' ; RB7-RB4 and RB1(RX)=input, others output
movwf TRISB
; ------------------------------------
; SET BAUD RATE TO COMMUNICATE WITH PC
; ------------------------------------
; Boot Baud Rate = 9600, No Parity, 1 Stop Bit
;
bcf TXSTA, SYNC ; set asynchronous
bcf TXSTA, BRGH ; set low baud rate
movlw 0x40 ; 1200bps (51 = 0x33 @ 4MHz) 19 for 2400,
40 for 10mhz at 2400 baud
movwf SPBRG
bcf STATUS, RP0 ; select bank 0
bsf RCSTA, SPEN ; ENable Serial Port
bsf STATUS, RP0 ; select bank 1
bsf TXSTA, TXEN ; ENable TX
bsf PIE1, RCIE ; Enable RX interrupt
bcf STATUS, RP0 ; back to bank 0
bsf RCSTA, CREN ; ENable RX
;
; ------------------------------------
; PROVIDE A SETTLING TIME FOR START UP
; ------------------------------------
;
clrf dataL
settle decfsz dataL,F
goto settle
movf RCREG,W
movf RCREG,W
movf RCREG,W ; flush receive buffer
; ---------
; MAIN LOOP
; ---------
;
call message ;call message ; send "16F628 alive"
loop call receive ; wait for a char
call send ; send the char
goto loop
;
; -------------------------------------------
; RECEIVE CHARACTER FROM RS232 AND STORE IN W
; -------------------------------------------
; This routine does not return until a character is received.
;
receive btfss PIR1,RCIF ; (5) check for received data
goto receive
movf RCREG,W ; save received data in W
return
;
; -------------------------------------------------------------
; SEND CHARACTER IN W VIA RS232 AND WAIT UNTIL FINISHED SENDING
; -------------------------------------------------------------
;
send movwf TXREG ; send data in W
TransWt bsf STATUS,RP0 ; RAM PAGE 1
WtHere btfss TXSTA,TRMT ; (1) transmission is complete if hi
goto WtHere
bcf STATUS,RP0 ; RAM PAGE 0
return
;
; -------
; MESSAGE
; -------
;
message movlw '1'
call send
movlw '6'
call send
movlw 'F'
call send
movlw '6'
call send
movlw '2'
call send
movlw '8'
call send
movlw ' '
call send
movlw 'a'
call send
movlw 'l'
call send
movlw 'i'
call send
movlw 'v'
call send
movlw 'e'
call send
movlw 0x0D ; CR
call send
movlw 0x0A ; LF
call send
return
END