;3units-7sement-ADC-PIC16F876A -P - N -TEMP.
Device = 16F876A
Xtal 4
Declare Adin_Res = 10 ' 10-bit result required
Declare Adin_Tad = FRC ' RC OSC chosen
Declare Adin_Stime = 50 ' Allow 50us sample time
;Dim Var1 as Word
TRISA = %00000011 ' Configure AN0 (PortA.0) and AN1(port A .1) as an inputs
ADCON1 = %10000000 ' Set analogue inputs
Output PORTB ; All PORTB pins as output
PORTB = 0 ;Clear PORTB
Output PORTC
PORTC = 0
Dim Temp_P As Word ; Positive temp
Dim Temp_N As Word ;Negative temp
Dim Temp_Result As Word ;Result temp
Dim ONES As Word ;DIGIT 0 for ONES 0 to 9
Dim TENS As Word ;DIGIT 1 for TENS 0 to 9
Dim HUNDREDS As Word ;DIGIT 2 for HUNDREDS 0 to 9
Symbol Enable_ONES = PORTB.6
Symbol Enable_TENS = PORTB.5
START:
;Read the value from channel 0 and channel 1 and store the result.
Temp_P = ADIn 0 ; Place the conversion into variable
Temp_N = ADIn 1 ;Place the conversion into variable
;Convert
Temp_P = Temp_P * 0.488
Temp_N = Temp_N * 0.488
;Case 1
If Temp_P > Temp_N Then
Temp_Result = Temp_P - Temp_N
Diplay_p:
;Temp_Result consists of
ONES=Temp_Result Dig 0
TENS=Temp_Result Dig 1
PORTB=240 | ONES ; Sens ONES data
; Note : 240 = %11110000 , (|) OR to use bit0 to bit3 for 7 segment
;and make bit4 to bit7 high for enable function
;Enable (LE) 4511 ONES digit by low pulse
Low Enable_ONES : DelayMS 1 : High Enable_ONES : DelayMS 1
PORTB=240 | TENS ; Send TENS data
;Enable (LE) 4511 TENS digit by low pulse
Low Enable_TENS : DelayMS 1 : High Enable_TENS : DelayMS 1
PORTC = %01110011 ; Letter "P"
;Case 2
ElseIf Temp_P < Temp_N Then
Temp_Result = Temp_N - Temp_P
Diplay_N:
;Temp_Result consists of
ONES=Temp_Result Dig 0
TENS=Temp_Result Dig 1
PORTB=240 | ONES ; Sens ONES data
; Note : 240 = %11110000 , (|) OR to use bit0 to bit3 for 7 segment
;and make bit4 to bit7 high for enable function
;Enable (LE) 4511 ONES digit by low pulse
Low Enable_ONES : DelayMS 1 : High Enable_ONES : DelayMS 1
PORTB=240 | TENS ; Send TENS data
;Enable (LE) 4511 TENS digit by low pulse
Low Enable_TENS : DelayMS 1 : High Enable_TENS : DelayMS 1
PORTC = %01000000 ; g segment
EndIf
GoTo START
End