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.
i know it's work but iwant to let the value of tepretuer appear on LCD. i cant understand what you say abve, can you put your modify on the code here
I only just works.. Lots wrong..

I did this

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
TEMP EQU 0x29
DIGIT EQU 0x2A
TENS EQU 0x2B
;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

   BSF STATUS,RP0; ACCESS SFRs IN BANK1
   MOVLW B'10001110'
   MOVWF ADCON1
   BCF STATUS,RP0  ;RETURN BACK TO BANK0
   MOVLW B'11000001'
   MOVWF ADCON0
   CALL DELAY_5ms
BEGIN:
   BCF PORTD,RD0 ; Setting RS as 0 (Sends commands to LCD)
   MOVLW b'11000000' ; Set cursor home
   MOVWF PORTB
   CALL Enable
   CALL DELAY_5ms
   BSF PORTD,RD0 ; Setting RS as 1 (Sends data to LCD)
   MOVF TEMP,W
   CALL  div
   MOVF TENS,W
   ADDLW 0x30
   MOVWF PORTB
   CALL Enable
   CALL DELAY_5ms
   MOVF DIGIT,W
   ADDLW 0x30
   MOVWF PORTB
   CALL Enable
   CALL DELAY_5ms
   MOVLW 0xDF
   MOVWF PORTB
   CALL Enable
   CALL DELAY_5ms
   MOVLW  'C'
   MOVWF PORTB
   CALL Enable
   CALL DELAY_5ms
 
   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
   
   BSF STATUS,RP0  ;RETURN BACK TO BANK1
   MOVF ADRESL,W
 
   BCF STATUS,RP0  ;RETURN BACK TO BANK0
   MOVWF TEMP
   BCF STATUS,C
   RRF TEMP,W
   MOVWF  TEMP
   SUBLW 0x14
   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
 
div
   movwf  DIGIT        ; w contains the dividend
   clrf        TENS
   movlw   0xA
   subwf    DIGIT,f
   btfss      STATUS,0   ; check for positive (Carry bit).
   goto      $+3               ; result is negative
   incf       TENS,f
   goto      $-4
   addwf   DIGIT,w
   movwf DIGIT
   RETURN
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

Notice I used ANSEL to get the precision.. When you use the ANSEH two vital bit were missing..
 
Capture.jpg
 
The output from the sensor will need mapping... I get slightly over double the bits.. ie.. 20 degrees is 41 bits... 30 degrees was 62 bits... Linear but not quite half..

The ADC on your chip will differ, hence a map...
 
You will need a divide routine.... The input from LM35 is linear (straight line ) but doubles each bit...

You'll see in the code.. The RLF TEMP divides by two... Close but no cigar...

The process to change the input to an acceptable output is call mapping..
 
how i can do this
is this possible
Of course you can.... Go to piclist and grab 8x8 multiply and 16x8 divide routines.. ( The small div by 10 is from elsewhere )

Then you can make the map..
 
I can't do it all.... You'll need to step up sometime.. Piclist Is the goto place for code... .

Here you can borrow ( indefinitely ) all the math routines you need..
Incidentally! I hope you know how the ancient Chinese divide and multiply... Because if you do not... Hop over to Wiki and take a look see... This is how micro's do it effectively.. https://en.wikipedia.org/wiki/Chinese_mathematics..
Multiply:
Quotient <<
dividend >>
sum quotient only when LSB of dividend = 1...

Division is reverse..
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top