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.

PIC16f690_LM35_UART data send problem (using assembler)

Status
Not open for further replies.

linuxj55

Newbie level 1
Joined
Dec 4, 2012
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,316
Hello. I have problem with sending LM35 temperature data to UART in Proteus. When i increment my temperature digits goes from 0 to 9 and repeats. Can somebody look at code and tell me whats wrong?



list p=16f690 ; list directive to define processor
#include <P16F690.inc> ; processor specific variable definitions

__CONFIG _XT_OSC & _CP_OFF & _PWRTE_ON & _WDT_OFF

;********** KINTAMIEJI**********************************************************


RESULTLO EQU 0x20
RESULTHI EQU 0x21
s EQU 0x22
x EQU 0x23
y EQU 0x24
z EQU 0x25
dataL EQU 0x26
dataL1 EQU 0x27
dataL2 EQU 0x28
ADC EQU 0x29
ADC1 EQU 0x2A
ADC2 EQU 0x2B
cflag EQU 0x2C
quotient EQU 0x2D
divisor EQU 0x2E
divisor_low EQU 0x2F
divisor_high EQU 0x30
work EQU 0x31
work_low EQU 0x32
work_high EQU 0x33
wvalue EQU 0x34



;******************PROGRAMA*******************************************************************************
ORG 0x000 ;
clrf PORTA
clrf PORTB
movlw b'10000000' ; RB7(TX)=1 others are 0
movwf PORTB

;*********2 bankas ***************************************************************************************
bcf STATUS, RP0
bsf STATUS, RP1 ; 2 bank
bcf CM1CON0,7 ; disable comparators
bcf CM2CON0,7
bcf CM2CON1,7

clrf ANSEL ; all outputs digital
movlw b'00000100' ; set AN2 as analog
movwf ANSEL



;**************1 bank************************************************************
bsf STATUS, RP0 ; 1 bank
bcf STATUS, RP1
movlw b'01101010'; OSC config 4Mhz external
movwf OSCCON

movlw b'111110'
movwf TRISA ;


movlw b'01010000' ; ADCON1 configureFosc/16 4us
movwf ADCON1

movlw b'01111111' ; RB6-RB0 (RX)=input, others output
movwf TRISB

;---Configure SPBRG for desired baud rate
movlw d'25' ;We will use 9600
movwf SPBRG ;baud at 4MHz
movlw h'00'
movwf SPBRGH

;---Configure TXSTA
movlw B'00100100' ;Configure TXSTA as :
movwf TXSTA ;
;8 bit transmission - 6.bit
;Transmit enabled - 5.bit
;Asynchronous mode - 4.bit
;Enable high speed baud rate - 2.bit

;**************0 bank *****************************
bcf STATUS,RP1 ; 0 bank
bcf STATUS,RP0

movlw b'10001001' ; configure ADCON0, AN2, ADON, Vref pin
movwf ADCON0

movlw b'10000000' ; enable serial port
movwf RCSTA
movlw b'000001'
movwf PORTA


start
;******************* ADC convert LM35*************************
call Ciklas
bsf ADCON0,1 ; start convert
loop btfsc ADCON0,1 ; is convert over?
goto loop ; if not repeat cycle
movf ADRESH,1 ; read upper 2 bits


;**********************UART sending***********************************

bsf STATUS, RP0
movf ADRESL,0 ; read lower 8 bits
bcf STATUS, RP0

call B2Ascii

movwf TXREG
call Ciklas

movlw 0x0D ; CR new line
movwf TXREG
movlw 0x0A ;LF newline
movwf TXREG
goto start

;*************************subroutines********************************************

Ciklas ; delay for UART
decfsz dataL,1
goto Ciklas
decfsz dataL1,1
goto Ciklas

********** binary to ASCII conversion **********
B2Ascii: movwf work ; Move byte to work area
rrf work,1

bcf cflag, 0 ; Reset leading zero supression flag
movlw d'100' ; -- Hundreds
movwf divisor ;
call divide8 ;
call output ; Output hundreds, digit is in W
movlw d'10' ; -- Tens
movwf divisor ;
call divide8 ;
call output ; Output tens, digit in W
movlw d'1' ; -- Ones
movwf divisor ;
bsf cflag, 0 ; Remove leading zero suppression in case of zero
call divide8 ;
call output ; Output ones, digit is in W
return

divide8: clrf quotient ; Divide 8 bit dividend with 8 bit divisor
movfw divisor ; using repetitive subtraction method
div8_1: subwf work, W ; Test to see if division is complete
skpc ;
goto divcommon ;
incf quotient, F ; Bump quotient and subtract divisor
movfw divisor ; from what's left of the original
subwf work, F ; dividend.
bsf cflag, 0 ; Indicate that we have a non-zero digit
goto div8_1 ; and continue
divcommon: movlw '0' ; Add ASCII bias but blank out
addwf quotient, W ; any leading zero digits
btfss cflag, 0 ; If we haven't seen any non-zero digits to
movlw ' ' ; this point, return a space instead of a '0'
return ;

output: nop
return ; Send the digit to the serial port


end


UART.PNG
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top