I am working on a project based around a PIC16F88, and am currently trying to get the PIC to talk to the computer's serial port. I will put my code at the bottom of this post. As far as I can tell, I have all the hardware connected properly, yet I have been unable to get the PIC to send even a single character to the computer. I am using an ICL3232 (with all the required caps) to invert the signal and bring it to RS-232 levels. As you will see in the code, I have 3 LED's that I am lighting up to see if the program is hanging up somewhere. All 3 light up properly, so it seems to be making it through the program.
Do I have the UART initialized incorrectly? Any suggestions or tips?
Do I have the UART initialized incorrectly? Any suggestions or tips?
Code:
radix dec
#include <p16f88.inc>
__CONFIG _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_ON & _PWRTE_ON & _WDT_OFF & _XT_OSC
__CONFIG _CONFIG2, _IESO_OFF & _FCMEN_OFF
#DEFINE TRASET b'10000000' ;these are values that will be moved to TRISA and TRISB
#DEFINE TRBSET b'00100100' ;bits 5 and 2 must be set according to datasheet
;registers
TMP EQU h'20' ;scratch
org 0
RVECTOR goto INIT
;SEND subroutine
;======================================================
SEND movwf TXREG
bsf STATUS,5 ;bank 1
WAIT btfss TXSTA,1 ;loop until this bit gets set
goto WAIT ;when the shift register has been emptied
bcf STATUS,5 ;bank 0
return
;======================================================
;Initializations
;======================================================
INIT clrf PORTA ;clear port a
clrf PORTB ;clear port b
bsf STATUS,5 ;select bank 1
clrf ANSEL
movlw TRASET
movwf TRISA
movlw TRBSET
movwf TRISB
bcf STATUS,5 ;bank 0
;======================================================
bsf PORTA,1 ;pull RA1 high, big LED should turn on
;Set up serial port
;======================================================
SERIAL BSF STATUS,RP0 ; Go to Bank1
MOVLW 25 ; Set Baud rate
MOVWF SPBRG
MOVLW b'00100100' ;8-bit transmit, transmitter enabled,
MOVWF TXSTA ;asynchronous mode, high speed mode
bcf PIE1,TXIE ;disable transmit interrupts
bcf PIE1,RCIE ;disable receive interrupts
BCF STATUS,RP0 ;Go to Bank 0
MOVLW b'10010000' ;8-bit receive, receiver enabled,
MOVWF RCSTA ;serial port enabled
;======================================================
bsf PORTA,4 ;turn on small red LED, RA4
;Delay to let things settle
;======================================================
SETTLE clrf TMP
SLOOP decfsz TMP,1 ;decrement TMP, store in TMP
goto SLOOP
;======================================================
bsf PORTB,0 ;turn on yellow LED, RB0
;Test serial port
;======================================================
MESSAGE movlw '1' ;send: 16F88 alive
call SEND
movlw '6'
call SEND
movlw 'F'
call SEND
movlw '8'
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 h'0D' ; CR
call SEND
;======================================================
bsf PORTB,0 ;turn on yellow LED, RB0
end
Last edited: