blueroomelectronics
Well-Known Member
No decoupling caps, and the temperature sensing accuracy depends on your power supply accuracy.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
list p=pic16f877, f=inhx8m
include <P16F877.INC>
__config _CP_OFF & _PWRTE_ON & _XT_OSC & _WDT_OFF & _BODEN_OFF & _LVP_OFF
ERRORLEVEL -302 ;Suppress bank warning
CBLOCK h'20'
digit1
digit2
digit3
resultlbyte
resulthbyte
L_byte
H_byte
R0
R1
R2
count
temp
delaytime
s_digit
R2_TEMP
INDICATOR
disp_u ;1st digit address
disp_t ;10th digit address
disp_h ;100th digit address
g_time1
g_time2
ledindex
delaylarge
delaysmall
ENDC
RC0 equ .0
RC1 equ .1
RC2 equ .2
;----------------------------------------------------------------------------
; RESET VECTOR
;----------------------------------------------------------------------------
ORG 0x00
goto start
;
;----------------------------------------------------------------------------
org 0x04
BCF STATUS,RP1 ; select bank 0
BCF STATUS,RP0
BTFSC PIR1,TMR2IF
goto display
BTFSC INTCON,T0IF
goto getvalue
goto $
;----------------------------------------------------------------------------
getvalue
BCF STATUS,RP1 ; select bank 0
BCF STATUS,RP0
BCF INTCON,T0IF
BSF ADCON0,GO ; conversion starts now!
again2
BTFSC ADCON0,GO
goto again2
call getresult
retfie
getresult
BCF STATUS,RP1 ; select bank 1
BSF STATUS,RP0
movf ADRESL,w ; low byte of result.
bcf STATUS,RP0
movwf resultlbyte ; a/d low byte saved
movf ADRESH,w ; high byte of result
movwf resulthbyte ; a/d high byte saved
call atodforbcd
call xxx
call B2_BCD
call bcdsplit
call match
return
atodforbcd rrf resultlbyte,f ; routine for dividing the value
bcf STATUS,C
rrf resulthbyte,f
btfsc STATUS,C
bsf resultlbyte,7 ;
xxx movf resultlbyte,w ;
movwf L_byte ; bcd conversion subroutine.
movf resulthbyte,w ;
movwf H_byte ;
return
B2_BCD bcf STATUS,0 ; clear the carry bit
movlw .16
movwf count
clrf R0
clrf R1
clrf R2
loop16 rlf L_byte, f
rlf H_byte, f
rlf R2, f
rlf R1, f
rlf R0, f
;
decfsz count, f ; routine for bcd conversion
goto adjDEC
retlw 0
;
adjDEC movlw R2
movwf FSR
call adjBCD ; no bank switching, always
; ; indirect access for RAM
movlw R1
movwf FSR
call adjBCD
;
movlw R0
movwf FSR
call adjBCD
;
goto loop16
;
adjBCD movlw 3
addwf 0,W
movwf temp
btfsc temp,3 ; test if result > 7
movwf INDF
movlw 30
addwf 0,W
movwf temp
btfsc temp,7 ; test if result > 7
movwf INDF ; save as MSD
retlw 0
;----------------------------------------------------------------------------
; Arrange the result as digits 1,2,3.
bcdsplit movf R1,w ; bring first nibble
andlw 0Fh ; mask the upper nibble
movwf digit1 ; send to display routine variable.
movf R2,w ; bring the second digit!
MOVWF R2_TEMP
andlw 0F0h ; mask the lower nibble.
movwf digit2 ; send to display routine variable.
swapf digit2,f ; after swaping!
movf R2,w ; Again bring the lowbyte
andlw 0Fh ; mask the upper nibble
movwf digit3 ; send it to display routine variable
return
;----------------------------------------------------------------------------
match
MOVF R2_TEMP,W
SUBLW H'80'
BTFSS STATUS,Z
BTFSS STATUS,C
GOTO ON
GOTO STOP
ON
MOVLW B'10000000'
MOVWF PORTD
RETURN
STOP
MOVLW B'00000000'
MOVWF PORTD
RETURN
;**************** LED display control *****************
display_table
addwf PCL,f ; W + PCL -> PCL
retlw b'00111111' ; '0'
retlw b'00000110' ; '1'
retlw b'01011011' ; '2'
retlw b'01001111' ; '3'
retlw b'01100110' ; '4' table for segment patterns
retlw b'01101101' ; '5'
retlw b'01111101' ; '6'
retlw b'00000111' ; '7'
retlw b'01111111' ; '8'
retlw b'01100111' ; '9'
retlw b'10000000' ; '.'
;----------------------------------------------------------------------------
; SUBROIUTINES
;----------------------------------------------------------------------------
display
BCF STATUS,RP1 ;
bcf STATUS,RP0 ; bank 0
BCF PIR1,TMR2IF
movf digit1,w
movwf disp_h
movf digit2,w
movwf disp_t
movf digit3,w
movwf disp_u
BSF STATUS,C ; set carry bit so that when rotate = 0 to on
movlw b'11111110' ; select the left most digit
movwf ledindex ;
movwf PORTC ; digit selecting transistor on!
movf disp_h,w ; get the bcd value to display
call digitout ; illuminate for a period
BSF STATUS,C ; set carry bit so that when rotate = 0 to on
rlf ledindex,f ; rotate to left to select next digit
movf ledindex,w ; enable next digit
movwf PORTC ; digit selecting transistor on!
movf disp_t,w ; get the bcd value.
call digitout ; illuminate for a period
BSF STATUS,C ; set carry bit so that when rotate = 0 to on
rlf ledindex,f
movf ledindex,w ; last digit selected.
movwf PORTC
movf disp_u,w ; get bcd value
call digitout ; illuminate for a period
retfie
;----------------------------------------------------------------------------
digitdelay movlw 5h ; outer loop for delay
movwf delaylarge
loopl decf delaylarge,f
btfsc STATUS,Z
return
movlw 0FFh
movwf delaysmall
loops decfsz delaysmall,f ; inner loop for delay
goto loops
goto loopl
;----------------------------------------------------------------------------
digitout nop
call display_table ; illuminate digit and wait
movwf PORTB ; for some time
call digitdelay
clrf PORTB ; off the digit and return.
clrf PORTC
return
;----------------------------------------------------------------------------
; Main program starts
;----------------------------------------------------------------------------
start
CLRF resultlbyte
CLRF resulthbyte
CLRF s_digit
call iniports ; initialise all relevent ports.
call iniatod ; initialise a/d converter module.
call initimer0
call initimer2 ;
movlw h'07'
movwf delaytime
aquiloop
decfsz delaytime,f ; wait for aqusition time.
goto aquiloop
BCF STATUS,RP1 ; select bank 0
BCF STATUS,RP0
BCF PIR1,ADIF
BSF ADCON0,GO ; conversion starts now!
again1
BTFSC ADCON0,GO
goto again1
call getresult
goto $ ; wait for interrupt
;_______________________________________________________________________________________________________________
;______________________________________________________________________________________________________________
iniports bsf STATUS,RP0 ; set bank 1
movlw b'00000001' ; input for analogue temp sensor
movwf TRISA ; RA0 as the input
movlw b'01111000'
movwf TRISC
movlw b'00000000'
movwf TRISB ; all portd output for segments.
movwf TRISD ; porte for digit selection
bcf STATUS,RP0 ; return to bank 0 and return
clrf PORTA
clrf PORTB
clrf PORTC
return
;_________________________________________________________________________________________________________________
iniatod bsf STATUS,RP0
movlw b'10001110' ; result right justified ,ra0 as
movwf ADCON1 ; analogue input with Vdd as Vref
bcf STATUS,RP0
movlw b'01000001' ; a/d clock Tosc*8 and Ra0 channel
movwf ADCON0 ; selected. a/d module still off.
return
;_____________________________________________________________________________________________________________________
initimer0
BCF STATUS,RP1 ; set bank 0
BSF STATUS,RP0
movlw b'11010011'
movwf OPTION_REG
movlw h'43'
movwf TMR0
BCF TMR0,T0IF
return
;______________________________________________________________________________________________________________________
initimer2 ;*** Display initialization (Timer2)
BCF STATUS,RP1 ; set bank 0
BCF STATUS,RP0
movlw b'00011110' ;OPS=1:4,T2=ON,EPS=1:16
movwf T2CON ;Set T2CON register
bsf STATUS,RP0 ;Change to Bank1
movlw d'157' ;157x64=10048usec 157
movwf PR2 ;Set PR2 register
bsf PIE1,TMR2IE ;TMR2IE=ON
bcf STATUS,RP0 ;Change to Bank0
;*** Interruption control
movlw b'11100000' ;GIE=ON,PEIE=ON,T0IE=ON
movwf INTCON ;Set INTCON register
return
;______________________________________________________________________________________________
;_________________________________________________________________________________________________________________________
end
eng1 said:Hi Eric, is your observation directed at me? I totally agree with your point of view.
BSF STATUS,C ; set carry bit so that when rotate = 0 to on
movlw b'11111110' ; select the left most digit
movwf ledindex ;
movwf PORTC ; digit selecting transistor on!
movf disp_h,w ; get the bcd value to display
call digitout ; illuminate for a period
BSF STATUS,C ; set carry bit so that when rotate = 0 to on
rlf ledindex,f ; rotate to left to select next digit
movf ledindex,w ; enable next digit
movwf PORTC ; digit selecting transistor on!
movf disp_t,w ; get the bcd value.
call digitout ; illuminate for a period
BSF STATUS,C ; set carry bit so that when rotate = 0 to on
rlf ledindex,f
movf ledindex,w ; last digit selected.
movwf PORTC
movf disp_u,w ; get bcd value
call digitout ; illuminate for a period
retfie
;----------------------------------------------------------------------------
derrick826 said:Hi guys, it works perfectly well and i have some questions to ask,
why must we put a 1kohm resistor at the RC0,Rc1 and RC2 pin of the PIC microcontroller?
how come the resistor value which I put, 470ohm at the RB0- RB7 differs from the 1kohm resistor at RC0-RC2.... ?
what is the purpose of having this resistors for?
They limit the current into the base of the transistors when they're switched on.derrick826 said:why must we put a 1kohm resistor at the RC0,Rc1 and RC2 pin of the PIC microcontroller?
The 470 ohm resistors limit the current into the LEDs.derrick826 said:how come the resistor value which I put, 470ohm at the RB0- RB7 differs from the 1kohm resistor at RC0-RC2.... ?
blueroomelectronics said:X4ce your math is off, the A/D has 1024 steps not 1000. The ideal solution is a vref of 4.096 V
Hi, I wanted to add a negative temperature reading into this project. what will I add in the circuit? tnx