edofbrighton
Member
hi, i want to use the UART on the PIC16F690. TO START i just want to send some data from its TX pin to the RX PIN, so i can understand how it works. The code below is meant to send it recieve it and display it. The display works fine i just can recieve/transmitt data. can anyone point me in the right direction.
Code:
; DELAY EQUATES
CNT EQU 0X25 ;ADDRESS FOR COUNTER
CNT2 EQU 0X26 ;ADDRESS FOR COUNTER2
CNT3 EQU 0X27 ;ADDRESS FOR COUNTER3
CNT4 EQU 0X28 ;ADDRESS FOR COUNTER4
; LCD EQUATES AND DEFINES
#DEFINE DDRE TRISB,7 ;DATA DIRECTION
#DEFINE DDRRS TRISB,4 ;DATA DIRECTION
#DEFINE E PORTA,2 ;ENABLE LINE ON LCD
#DEFINE RS PORTB,4 ;INSTRUCTION/DATA SELECT
#DEFINE RW PORTB,6
TEMP_LCD EQU 0X3A ;STORAGE FOR LCD
LCD EQU PORTC ;LCD DATA PORT
CLRSCR EQU B'00000001' ;COMMAND FOR CLRSCR
HOME EQU B'00000010' ;SENDS CURSOR TO HOME
ON EQU B'00001100' ;TURNS ON THE DISPLAY
OFF EQU B'00001000' ;TURNS THE DISPLAY OFF
LEFT EQU B'00011000' ;LEFT SHIFT
RIGHT EQU B'00011100' ;RIGHT SHIFT
LIN2 EQU B'11000000' ;SETS TO LINE 2
;----------------------------------------
; VECTOR FOR NORMAL START UP.
ORG 0
GOTO START
; MAIN PROGRAM STARTS HERE:
START CLRW ; CLEAR W.
MOVWF PORTA ; ENSURE PORTA IS ZERO BEFORE WE ENABLE IT.
MOVWF PORTB ; ENSURE PORTB IS ZERO BEFORE WE ENABLE IT.
movwf PORTC
BSF STATUS,RP1
movlw H'00'
movwf ANSEL
movwf ANSELH
BCF STATUS,RP0
BSF STATUS,RP0 ; SELECT BANK 1
MOVLW H'00' ; MASK FOR PORTA FOR ALL OUTPUTS.
MOVWF TRISA ; SET TRISA REGISTER.
MOVLW H'00' ; MASK FOR PORTB FOR ALL OUTPUTS.
MOVWF TRISB ; SET TRISB REGISTER.
MOVLW H'00'
MOVwf TRISC
BCF STATUS,RP0 ; RESELECT BANK 0.
CALL INIT_LCD ; Initialse the LCD
bsf PORTA,2
MOVLW CLRSCR ; Clear the screen
CALL COMMAND ; Initiate the command in the W reg
MOVLW 'H' ; send h
CALL DISPLAY ; Display the w reg on the LCD .;kv
MOVLW CLRSCR ; Clear the screen
CALL COMMAND ; Initiate the command in the W reg
MOVLW 'H'
CALL send
clrw
MOVLW H'FF'
MOVWF CNT3
COUNT3: MOVLW 0xff
CALL DELAY
DECFSZ CNT3,1
GOTO COUNT3
CALL receive
call DISPLAY
goto $ ; Stop here
;**************************lcdv6******************************
;Porta 1 for the enable and porta 2 for rs/ portb for lcd data
;*************************************************************
;************************************************************
; Initialize the LCD
;************************************************************
INIT_LCD:
movlw .120
CALL SEC_DELAY ; '' ''
MOVLW B'00110000' ;tell display its two lines
CALL COMMAND ;output to the screen
movlw .40
CALL SEC_DELAY
MOVLW B'00110000'
CALL COMMAND
MOVLW .100
CALL MDELAY
MOVLW B'00110000'
CALL COMMAND
MOVLW .100
CALL MDELAY
MOVLW B'00111100' ;FUNCTION SET
CALL COMMAND
MOVLW ON ;turn on display
CALL COMMAND ;output to the screen
MOVLW 0X01
CALL COMMAND
MOVLW B'00000110' ;shift along every write
CALL COMMAND ;output to the screen
RETURN
;************************************************************
; This routine is to set the lcd to the second line
;************************************************************
SECOND_LINE:
MOVLW LIN2 ;set to line 2
CALL COMMAND ;output to the screen
RETURN
;************************************************************
; THis executes a command in the W reg
;************************************************************
COMMAND:
BCF RS
BCF RW ;command coming
MOVWF LCD ;PUT OUT ONTO PORT
MOVLW .200 ;delay time in microsecs
CALL MDELAY ;wait a while
MOVLW .250 ;delay time in microsecs
CALL MDELAY ;WAIT
BSF E ;make sure the enable line is up
MOVLW .200 ;delay time
CALL MDELAY ;wait a while
MOVLW .250 ;delay time in microsecs
CALL MDELAY ;WAIT
BCF E ;clock the data in
MOVLW .200 ;delay time
CALL MDELAY ;wait a while
MOVLW .250 ;delay time in microsecs
CALL MDELAY ;WAIT
BSF RS ;return to a data input
RETURN
;************************************************************
; This controls the module. When you call this
; routine, the contents of the 'w' register is
; displayed on the LCD screen. It is written in a
; module like this for portability!!
;************************************************************
DISPLAY:
BSF RS
BCF RW ;make sure it will accept data
MOVWF LCD ;send data to lcd
MOVLW .250 ;delay time in microsecs
CALL MDELAY ;WAIT
MOVLW .250 ;delay time in microsecs
CALL MDELAY ;WAIT
BSF E ;make sure the enable line is up
MOVLW .250 ;delay time
CALL MDELAY ;wait a while
MOVLW .250 ;delay time in microsecs
CALL MDELAY ;WAIT
BCF E ;clock the data in
MOVLW .250 ;delay time
CALL MDELAY ;wait a while
MOVLW .250 ;delay time in microsecs
CALL MDELAY ;WAIT
RETURN
;*************************************************************
; 1 MICROSECOND DELAY
;*************************************************************
MDELAY:
MOVWF CNT ;LOAD DELAY TIME
COUNT:
NOP ;TWO NO OPERATIONS
NOP ;TO OBTAIN THE DELAY
DECFSZ CNT,1 ;DECREMENT THE COUNTER
GOTO COUNT ;GOTO COUNT IF NOT FINISHED
RETURN
;*************************************************************
; quarter us delay
;*************************************************************
DELAY:
MOVWF CNT2
COUNT2: MOVLW 0xff
CALL MDELAY
DECFSZ CNT2,1
GOTO COUNT2
RETURN
; ------------------------------------
; SET BAUD RATE TO COMMUNICATE WITH PC
; ------------------------------------
; Boot Baud Rate = 9600, No Parity, 1 Stop Bit
;
UART_SET_UP:
movlw 0x19 ; 0x19=9600 bps (0x0C=19200 bps)
movwf SPBRG
movlw b'00100100' ; brgh = high (2)
movwf TXSTA ; enable Async Transmission, set brgh
bcf STATUS,RP0 ; RAM PAGE 0
movlw b'10010000' ; enable Async Reception
movwf RCSTA
return
;
; -------------------------------------------
; 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
end