Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

pic16f877A and LM35

Status
Not open for further replies.

kta22

New Member
Hi all , i want to build a LCD thermometer with this two components but it seems i have a problem. When LM35 it's not connected to RA1 (analog imput) the temperature-voltage dependence it's correctly indicated (270mv-27C, 280mv-28C,,etc), but when i connect the output of LM35 to analog imput of PIC16f877a the output voltage of LM35 it's remain the same (145mv) all the time and there are not changes of voltage with temperature anymore. The power supply =5V.I don't know what is the problem.
The ASM code that i've writed (at the end of the convertion, the 8 bit are transfereted to the PORTB in order to see changes), and it is working perfectly with a potentiometer (10K) connected to Vss, Vdd and RA1:


#include <p16F877.inc>
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_OFF & _HS_OSC &_WRT_ENABLE_ON & _LVP_OFF & _DEBUG_OFF & _CPD_OFF

org 0x00
t equ 0x20
q equ 0x21
s equ 0x22
x equ 0x23
y equ 0x24
z equ 0x25

movlw b'10001001' ;
movwf ADCON0

bsf STATUS,RP0
movlw b'00000000'
movwf ADCON1
comf TRISA
clrf TRISB
clrf TRISC
clrf TRISD
clrf TRISE
bcf STATUS,RP0

clrf PORTB
clrf PORTA


loop1
call loopaa
bsf ADCON0,2 ; start conversie
loop
btfsc ADCON0,2
goto loop
movf ADRESH,w
movwf PORTB
goto loop1


loopaa
movlw 0xaf
movwf x
movlw 0xaf
movwf y
movlw 0x0a
movwf z
delay1
bcf STATUS,2
decf x,1
btfss STATUS,2
goto delay1
bcf STATUS,2
movlw 0x10
movwf x
decf y,1
btfss STATUS,2
goto delay1
movlw 0xaf
movwf x
movlw 0xaf
movwf y
decf z,1
btfss STATUS,2
goto delay1
return
nop
end



thanks
 
hi kta,
Most common problem is that you have set the PORTA.1 to a digital output pin.:)
 
hi kta,
Get rid of that comf TRISA and the RA1 is unchanged from analog to digital.




Code:
	list      p=16f877            ; list directive to define processor
	#include <p16f877.inc>        ; processor specific variable definitions
	errorlevel -302, -207

	__config _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_OFF & _HS_OSC &_WRT_ENABLE_ON & _LVP_OFF & _DEBUG_OFF & _CPD_OFF

	org	0x00
t	equ	0x20
q	equ	0x21
s	equ	0x22
x	equ	0x23
y	equ	0x24
z	equ	0x25

	movlw	b'10001001'	;
	movwf	ADCON0

	bsf	STATUS,RP0
	movlw	b'00000000'
	movwf	ADCON1
	;;comf	TRISA,F
	clrf	TRISB
	clrf	TRISC
	clrf	TRISD
	clrf	TRISE
	bcf	STATUS,RP0

	clrf	PORTB
	clrf	PORTA


loop1
	call	loopaa
	bsf	ADCON0,2	; start conversie
loop
	btfsc	ADCON0,2
	goto	loop
	movf	ADRESH,w
	movwf	PORTB
	goto	loop1


loopaa
	movlw	0xaf
	movwf	x
	movlw	0xaf
	movwf	y
	movlw	0x0a
	movwf	z
delay1
	bcf	STATUS,2
	decf	x,1
	btfss	STATUS,2
	goto	delay1
	bcf	STATUS,2
	movlw	0x10
	movwf	x
	decf	y,1
	btfss	STATUS,2
	goto	delay1
	movlw	0xaf
	movwf	x
	movlw	0xaf
	movwf	y
	decf	z,1
	btfss	STATUS,2
	goto	delay1
	return

	nop
	end
 
But

bsf STATUS,RP0 ; set all PORTA pins to be inputs
comf TRISA
bcf STATUS,RP0


movlw b'10001001' ; 1 0=20Mhz; 001=channel RA1;0=go/done;0=0;
1=turn on A/D converter
movwf ADCON0

and

movlw b'00000000' ; 0=8bit sel mode; 000=000; 0000=selection to all
chanels= analog
movwf ADCON1



where it's the problem ?
 
But

bsf STATUS,RP0 ; set all PORTA pins to be inputs
comf TRISA
bcf STATUS,RP0


movlw b'10001001' ; 1 0=20Mhz; 001=channel RA1;0=go/done;0=0;
1=turn on A/D converter
movwf ADCON0

and

movlw b'00000000' ; 0=8bit sel mode; 000=000; 0000=selection to all
chanels= analog
movwf ADCON1



where it's the problem ?

The problem is still with the comf TRISA, its changing the PORTA pins back from analog as set in your ADCON, to digital OUTPUTS!.
 

Attachments

  • AAesp01.gif
    AAesp01.gif
    14.1 KB · Views: 634
  • AAesp02.gif
    AAesp02.gif
    14.4 KB · Views: 572
Last edited:
hello

can you help me regarding my problem in the temperature reading of my pic. The temperature reading from the pic is unstable, for example the normal temperature is 27 degrees Celsius, the temperature reading fluctuates from 27,26,20,30... then back to 27 again.. what do you think is the cause of the problem???
thank you
 
Your code works... BUT!! you only need to call the LCD initiate once before the main loop.. The temp comes in around 23°C and not 20..
Learn to update the screen once per cycle as the display flickers too much and makes for an unreadable interface..

You have a stack underflow as you keep Calling "more" then using a goto to BEGIN...

Code:
PROCESSOR 16F877A
   LIST P=16f877A
   INCLUDE <P16F877A.INC>
   __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _HS_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF
;:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:
;DECLARE VARIABLES
CNT EQU 0X28
;START PROGRAM
   ORG 0 ;START @ ADDRESS 0
MAIN:
;CONFIGURE I/O PINS
   BSF STATUS,RP0  ;SELECT BANK1 TO
   BCF STATUS,RP1; ACCESS SFRs IN BANK1
   CLRF TRISB   ;CONGIGURE PORTB AS OUTPUT O/P
   CLRF TRISD
   ;CLRF TRISC
   BSF TRISA,0
   MOVLW b'00000111'
   MOVWF OPTION_REG
   BCF STATUS,RP0 ; Selection of memory bank 0
   CLRF PORTB ; Setting PORTB to "0000000"
   CLRF PORTD ; Setting PORTD to "0000000"
   CALL InitiateLCD

   BCF STATUS,RP1; ACCESS SFRs IN BANK1
   MOVLW B'00001110'
   MOVWF ADCON1
   BCF STATUS,RP0  ;RETURN BACK TO BANK0
   MOVLW B'11000001'
   MOVWF ADCON0
BEGIN:
   ;CALL InitiateLCD
   MOVLW .28 ; load counter
   MOVWF CNT
LOOP
      DECFSZ CNT,f ; and delay 20us
      GOTO LOOP
    BSF ADCON0,GO ; start ADC..
wait
      BTFSC ADCON0,GO ; ..and wait for finish
      GOTO wait
   
   MOVF ADRESH,W
   SUBLW D'11'        ;15=30c   13=27c
   BTFSS STATUS,C
   goto    More
;LESS
   BCF STATUS,RP0  ;RETURN BACK TO BANK0
   BCF PORTD,2
   ;MOVLW B'00000000'
   ;MOVWF PORTC
   BCF PORTD,RD0 ; Setting RS as 0 (Sends commands to LCD)
   MOVLW b'00000010' ; Set cursor home
   MOVWF PORTB
   CALL Enable
   CALL DELAY_5ms
   BSF PORTD,RD0 ; Setting RS as 1 (Sends information to LCD)
   CALL DELAY_5ms
   MOVLW d'67' ; Print character "C"
   MOVWF PORTB
   CALL Enable
   CALL DELAY_5ms
   MOVLW d'79' ; Print character "O"
   MOVWF PORTB
   CALL Enable
   CALL DELAY_5ms
   MOVLW d'76' ; Print character "L"
   MOVWF PORTB
   CALL Enable
   CALL DELAY_5ms
   MOVLW d'68' ; Print character "D "
   MOVWF PORTB
   CALL Enable
   CALL DELAY_5ms
   MOVLW d'32' ; Print character " "
   MOVWF PORTB
   CALL Enable
   CALL DELAY_5ms
   MOVLW d'60' ; Print character "< "
   MOVWF PORTB
   CALL Enable
   CALL DELAY_5ms
   MOVLW d'50' ; Print character "2"
   MOVWF PORTB
   CALL Enable
   CALL DELAY_5ms
   MOVLW d'48' ; Print character "0"
   MOVWF PORTB
   CALL Enable
   CALL DELAY_5ms
   MOVLW d'67' ; Print character "C"
   MOVWF PORTB
   CALL Enable
   CALL DELAY_5ms
;BCF STATUS,RP0  ;RETURN BACK TO BANK0
   GOTO BEGIN
More
     BCF STATUS,RP0  ;RETURN BACK TO BANK0
     BCF PORTD,2
    ; MOVLW B'01000000'
     ;MOVWF PORTC
     BCF PORTD,RD0 ; Setting RS as 0 (Sends commands to LCD)
     MOVLW b'00000010' ; Set cursor home
     MOVWF PORTB
     CALL Enable
     CALL DELAY_5ms
     BSF PORTD,RD0 ; Setting RS as 1 (Sends information to LCD)
     CALL DELAY_5ms
     MOVLW d'87' ; Print character "W"
     MOVWF PORTB
     CALL Enable
    CALL DELAY_5ms
    MOVLW d'65' ; Print character "A"
    MOVWF PORTB
    CALL Enable
    CALL DELAY_5ms
    MOVLW d'82' ; Print character "R"
    MOVWF PORTB
    CALL Enable
    CALL DELAY_5ms
    MOVLW d'77' ; Print character "M"
    MOVWF PORTB
    CALL Enable
    CALL DELAY_5ms
   
    MOVLW d'32' ; Print character "  "
    MOVWF PORTB
    CALL Enable
    CALL DELAY_5ms
    MOVLW d'62' ; Print character ">"
    MOVWF PORTB
    CALL Enable
    CALL DELAY_5ms
    MOVLW d'50' ; Print character "2"
    MOVWF PORTB
    CALL Enable
    CALL DELAY_5ms
   
    MOVLW d'48' ; Print character "0"
    MOVWF PORTB
    CALL Enable
    CALL DELAY_5ms
   
   
    MOVLW d'67' ; Print character "C"
    MOVWF PORTB
    CALL Enable
    CALL DELAY_5ms
   
    GOTO BEGIN
Enable    BSF PORTD,1 ; E pin is high, (LCD is processing the incoming data)
    NOP
    BCF PORTD,1 ; E pin is low, (LCD does not care what is happening)
    RETURN
DELAY_5ms
    MOVLW .5 ; Delay of 5 ms
    MOVWF TMR0
LOOP3    BTFSS INTCON,2
    GOTO LOOP3
    BCF INTCON,2
    RETURN
InitiateLCD  
    BCF PORTD,RD0 ; Setting RS as 0 (Sends commands to LCD)
    CALL DELAY_5ms
    MOVLW b'00000001' ; Clearing display
    MOVWF PORTB
    CALL Enable
    CALL DELAY_5ms
    MOVLW b'00111000' ; Funtion set
    MOVWF PORTB
    CALL Enable
    CALL DELAY_5ms
    MOVLW b'00001100' ; Display on off
    MOVWF PORTB
    CALL Enable
    CALL DELAY_5ms
    MOVLW b'00000110' ; Entry mod set
    MOVWF PORTB
    CALL Enable
    CALL DELAY_5ms
    RETURN
 
   END
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top