Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

A/D through RS-232 problem

Status
Not open for further replies.

Ilia Gildin

Junior Member level 3
Junior Member level 3
Joined
Sep 27, 2014
Messages
26
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
184
hello
I am transmitting A/D conversion result to the computer by RS-232 and the A/D works fine but my problem is that after the first time I am writing to the TXSTA1 register it wont give an indication that it done transmitting when i do step by step or simulate in MPLAB when I do RUN after just one second more or less it goes to the end of my program
here is my code:
Code:
;******************************************************************************
;                                                                             *
;   This file is a basic code template for code generation on the             *
;   PIC18F46K22. This file contains the basic code building blocks to build   *
;   upon.                                                                     *
;                                                                             *
;   Refer to the MPASM User's Guide for additional information on features    *
;   of the assembler.                                                         *
;                                                                             *
;   Refer to the respective data sheet for additional information on the      *
;   instruction set.                                                          *
;                                                                             *
;******************************************************************************
;                                                                             *
;    Filename:         xxx.asm                                                *
;    Date:                                                                    *
;    File Version:                                                            *
;    Author:                                                                  *
;    Company:                                                                 *
;                                                                             *
;******************************************************************************
;                                                                             *
;    Files Required:                                                          *
;                                                                             *
;******************************************************************************
;                                                                             *
;    Notes:                                                                   *
;                                                                             *
;******************************************************************************
;                                                                             *
;    Revision History:                                                        *
;                                                                             *
;******************************************************************************

;------------------------------------------------------------------------------
; PROCESSOR DECLARATION
;------------------------------------------------------------------------------

     LIST      P=PIC18F46K22          ; list directive to define processor
     #INCLUDE <P18F46K22.INC>         ; processor specific variable definitions

;------------------------------------------------------------------------------
;
; CONFIGURATION WORD SETUP
;
; The 'CONFIG' directive is used to embed the configuration word within the 
; .asm file. The lables following the directive are located in the respective 
; .inc file.  See the data sheet for additional information on configuration 
; word settings.
;
;------------------------------------------------------------------------------

     ;Setup CONFIG11H
     CONFIG FOSC = INTIO67, PLLCFG = OFF, PRICLKEN = OFF, FCMEN = OFF, IESO = OFF
     ;Setup CONFIG2L
     CONFIG PWRTEN = OFF, BOREN = OFF, BORV = 190
     ;Setup CONFIG2H
     CONFIG WDTEN = OFF, WDTPS = 1
     ;Setup CONFIG3H
     CONFIG MCLRE = EXTMCLR, CCP2MX = PORTB3, CCP3MX = PORTE0, HFOFST = OFF, T3CMX = PORTB5, P2BMX = PORTD2
     ;Setup CONFIG4L
     CONFIG STVREN = OFF, LVP = OFF, XINST = OFF
     ;Setup CONFIG5L
     CONFIG CP0 = OFF, CP1 = OFF, CP2=OFF, CP3=OFF
     ;Setup CONFIG5H
     CONFIG CPB = OFF, CPD = OFF
     ;Setup CONFIG6L
     CONFIG WRT0 = OFF, WRT1 = OFF, WRT2 = OFF, WRT3 = OFF
     ;Setup CONFIG6H
     CONFIG WRTB = OFF, WRTC = OFF, WRTD = OFF
     ;Setup CONFIG7L
     CONFIG EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF
     ;Setup CONFIG7H
     CONFIG EBTRB = OFF

;------------------------------------------------------------------------------
;
; VARIABLE DEFINITIONS
;
; Refer to datasheet for available data memory (RAM) organization
;
;------------------------------------------------------------------------------

    CBLOCK 0x60 ; Sample GPR variable register allocations
        MYVAR1  ; user variable at address 0x60
        MYVAR2  ; user variable at address 0x61
        MYVAR3  ; user variable at address 0x62
    ENDC

W_TEMP         EQU        0x000  ; w register for context saving (ACCESS)
STATUS_TEMP    EQU        0x001  ; status used for context saving 
BSR_TEMP       EQU        0x002  ; bank select used for ISR context saving

;------------------------------------------------------------------------------
; EEPROM INITIALIZATION
;
; The 18F46K22 has 256 bytes of non-volatile EEPROM starting at 0xF00000
; 
;------------------------------------------------------------------------------

DATAEE    ORG  0xF00000 ; Starting address for EEPROM for 18F46K22

    DE    "MCHP"        ; Place 'M' 'C' 'H' 'P' at address 0,1,2,3

;------------------------------------------------------------------------------
; RESET VECTOR
;------------------------------------------------------------------------------

RES_VECT  ORG     0x0000            ; processor reset vector
          GOTO    START             ; go to beginning of program

;------------------------------------------------------------------------------
; HIGH PRIORITY INTERRUPT VECTOR
;------------------------------------------------------------------------------

ISRH      ORG     0x0008

          ; Run the High Priority Interrupt Service Routine
          GOTO    HIGH_ISR             

;------------------------------------------------------------------------------
; LOW PRIORITY INTERRUPT VECTOR
;------------------------------------------------------------------------------

ISRL      ORG     0x0018
          
          ; Run the High Priority Interrupt Service Routine
          GOTO    LOW_ISR             

;------------------------------------------------------------------------------
; HIGH PRIORITY INTERRUPT SERVICE ROUTINE
;------------------------------------------------------------------------------

HIGH_ISR  

          ; Insert High Priority ISR Here

          RETFIE  FAST

;------------------------------------------------------------------------------
; LOW PRIORITY INTERRUPT SERVICE ROUTINE
;------------------------------------------------------------------------------

LOW_ISR
          ; Context Saving for Low ISR
          MOVWF   W_TEMP              ; save W register
          MOVFF   STATUS, STATUS_TEMP ; save status register
          MOVFF   BSR, BSR_TEMP       ; save bankselect register

          ; Insert Low Priority ISR Here

          ; Context Saving for Low ISR
          MOVFF   BSR_TEMP, BSR       ; restore bankselect register
          MOVF    W_TEMP, W           ; restore W register
          MOVFF   STATUS_TEMP, STATUS ; restore status register
          RETFIE

;------------------------------------------------------------------------------
; MAIN PROGRAM
;------------------------------------------------------------------------------

START	

;A/D conversion over RS 232 communication
;system clock 16MHz boud rate 9600
NumH equ 0X80
NumL equ 0X81
TenK equ 0X82
Thou equ 0X83
Hund equ 0X84
Tens equ 0X85
Ones equ 0X86
Point equ 0X87 ;position of decimal point

	movlw	0x02 ;set decimal point position to two
	movwf	Point
	
	clrf	ANSELC
	movlw 	B'11000000'
	movwf 	TRISC
	bsf 	TRISA,0 ;Set RA0 to input
	bsf 	ANSELA,0 ;Set RA0 to analog
	movlw 	B'01110110'
	movwf	OSCCON
	bcf		BAUDCON1,BRG16
	bcf 	TXSTA1,BRGH
	movlw 	0X19
	movwf 	SPBRG1 ;DESIRED BOUD RATE 9600
	bcf 	TXSTA1,SYNC
	bsf		RCSTA1,SPEN
	bsf  	TXSTA1,TXEN ;WE WRITE DATA ON TXREG1 AND THE TRANSMISION STARTS AUTOMATICLY
;	bsf		RCSTA1,CREN ;RECIEVE DATA FROM COMPUTER TO RCREG1
	movlw 	B'10001111' ;right justify, Frc,
	movwf 	ADCON2 ; & 12 TAD ACQ time
	movlw 	B'00000000' ;ADC ref = Vdd,Vss
	movwf 	ADCON1
	movlw 	B'00000001' ;AN0, ADC on
	movwf 	ADCON0 ;
ff
	BSF 	ADCON0,GO ;Start conversion
ADCPoll
	btfsc 	ADCON0,GO ;Is conversion done?
	bra 	ADCPoll ;No, test again
	movff 	ADRESH,NumH
	movff 	ADRESL,NumL
	call	LCD_Decimal
gg
	bra 	gg
	;bra		ff
	
LCD_CharD	
	addlw	0x30 ;add 0x30 to convert to ASCII
LCD_Char
	call	XMIT_RS232
	retlw	0x00            
	
XMIT_RS232  	
	btfss   TXSTA1,TRMT ;xmit buffer empty?
    GOTO	XMIT_RS232   ;no, wait
    MOVWF   TXREG1		 ;now send
    RETURN

;Rcv_RS232   	
;	BTFSS   PIR1,RCIF ; check for received data
;    GOTO   Rcv_RS232
;    MOVF   RCREG1,W
   ; RETURN
	
LCD_Decimal
		call    Convert
		goto    LCD_TENK
		movf    TenK,W
		btfss   STATUS,Z
		goto    LCD_TENK
		movf    Thou,W
		btfss   STATUS,Z
		goto    LCD_THOU
		movf    Hund,W
		btfss   STATUS,Z
		goto    LCD_HUND
		movf    Tens,W
		btfss   STATUS,Z
		goto    LCD_TENS
		goto    LCD_ONES
LCD_TENK
		movlw	0x05			;test if decimal point 5
		subwf   Point,W
		btfss   STATUS,Z
		goto	NO_DP5
		movlw	'.'
		call	LCD_Char		;display decimal point
NO_DP5		
		movf    TenK,W
		call    LCD_CharD
		movlw	0x04			;test if decimal point 4
		subwf   Point,W
		btfss   STATUS,Z
		goto	LCD_THOU
		movlw	'.'
		call	LCD_Char		;display decimal point
LCD_THOU
		movf    Thou,W
		call    LCD_CharD
		movlw	0x03			;test if decimal point 3
		subwf   Point,W
		btfss   STATUS,Z
		goto	LCD_HUND
		movlw	'.'
		call	LCD_Char		;display decimal point
LCD_HUND
		movf    Hund,W
		call    LCD_CharD
		movlw	0x02			;test if decimal point 2
		subwf   Point,W
		btfss   STATUS,Z
		goto	LCD_TENS
		movlw	'.'
		call	LCD_Char		;display decimal point
LCD_TENS
		movf    Tens,W
		call    LCD_CharD
		movlw	0x01			;test if decimal point 1
		subwf   Point,W
		btfss   STATUS,Z
		goto	LCD_ONES
		movlw	'.'
		call	LCD_Char		;display decimal point
LCD_ONES
		movf     Ones,W
		call     LCD_CharD
		return
;This routine downloaded from http://www.piclist.com
Convert:                        ; Takes number in NumH:NumL
                                ; Returns decimal in
                                ; TenK:Thou:Hund:Tens:Ones
        swapf   NumH,W
		iorlw	B'11110000'
        movwf   Thou
        addwf   Thou,F
        addlw   0XE2
        movwf   Hund
        addlw   0X32
        movwf   Ones

        movf    NumH,W
        andlw   0X0F
        addwf   Hund,F
        addwf   Hund,F
        addwf   Ones,F
        addlw   0XE9
        movwf   Tens
        addwf   Tens,F
        addwf   Tens,F

        swapf   NumL,W
        andlw   0X0F
        addwf   Tens,F
        addwf   Ones,F

        rlncf   Tens,F
        rlncf   Ones,F
        comf    Ones,F
        rlncf   Ones,F

        movf    NumL,W
        andlw   0X0F
        addwf   Ones,F
        rlncf   Thou,F

        movlw   0X07
        movwf   TenK

                    ; At this point, the original number is
                    ; equal to
                    ; TenK*10000+Thou*1000+Hund*100+Tens*10+Ones
                    ; if those entities are regarded as two's
                    ; complement binary.  To be precise, all of
                    ; them are negative except TenK.  Now the number
                    ; needs to be normalized, but this can all be
                    ; done with simple byte arithmetic.

        movlw   0X0A                             ; Ten
Lb1:
        addwf   Ones,F
        decf    Tens,F
        btfss   STATUS,C
        goto    Lb1
Lb2:
        addwf   Tens,F
        decf    Hund,F
        btfss   STATUS,C
        goto    Lb2
Lb3:
        addwf   Hund,F
        decf    Thou,F
        btfss   STATUS,C
        goto    Lb3
Lb4:
        addwf   Thou,F
        decf    TenK,F
        btfss   STATUS,C
        goto    Lb4

        retlw  0x00
	end

and it is based on the tutorial from this site http://www.winpicprog.co.uk/pic_tutorial.htm tutorial 11.4
can you please pinpoint me to the problem in my program?
 

Normally, after you write to the RS232 data register, there will be a flag in the status register or interrrupt, which depends on your setting in the control register.
 

It's in fact unlikely that you ever see transmit shift register full in single stepping. What's your specific problem?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top