include <p16F877a.inc>
LIST p=16F877a
errorlevel 1,-302 ;to disable MPLAB bank warnings.
__config _XT_OSC & _PWRTE_ON & _WDT_OFF &_LVP_OFF
;
;Some versions of MPLAB use _LVP_OFF
;This sets all portB pins to output.
;Variables
cblock 0x20 ;start of general purpose registers
count
endc
;/*---------Init Ports
bsf STATUS,RP0
MOVLW B'00000001'
MOVWF TRISA ;All outputs except RA0.
MOVLW B'00000011'
movwf TRISD
CLRF TRISB ;RA0 is wiper of 50k pot/Vin
movlw b'11111111'
movwf TRISC ;PortB is 8 LED output to show
;/*-----Set up A2D parameters
MOVLW B'00001110' ;Hex value of Vin from pot.
MOVWF ADCON1 ;left justified, RA0 = input
MOVLW B'11010111' ;prescaler 1:256 tmr0, internal clock
MOVWF OPTION_REG
BCF STATUS,RP0
;/*---------Set up chip parameters
Start CALL A2D
MOVWF PORTB ;output Hex value to LEDs
PC clrf count
BTFSS PORTD,0
bsf count,0
BTFSS PORTD,1
bsf count,0
BTFSS count,0
goto Start
movf PORTC,w
movwf PORTB
goto PC
A2D
MOVLW B'01000001' ;a2d = on, ch0, fosc/8
MOVWF ADCON0
;/*-----Delay loop to settle A2D, similar to de-bounce???
mnloop btfss INTCON,T0IF ;50us loop delay @ 4Mhz
goto mnloop
;/*-----Stop timer0 interrupt
BCF INTCON,T0IF
BSF ADCON0,GO_DONE ;start a2d conversion
WAITA2D NOP ;wait 4 finish
BTFSC ADCON0,GO_DONE
GOTO WAITA2D
;/*-----Put A2D/PWM value in W and send to ports.
MOVF ADRESH,W ;upper 8 bits-ignor lower 3
RETURN ;DUTY CYCLE IS 25% OF PWM PERIOD
END
#include <p16F877a.inc>
LIST p=16F877a
errorlevel 1,-302 ;to disable MPLAB bank warnings.
__config _XT_OSC & _PWRTE_ON & _WDT_OFF &_LVP_OFF
;
;Some versions of MPLAB use _LVP_OFF
;This sets all portB pins to output.
;Variables
cblock 0x20 ;start of general purpose registers
COUNT
TEMP
CYC
endc
;/*---------Init Ports
bsf STATUS,RP0
MOVLW B'00000001'
MOVWF TRISA ;All outputs except RA0.
MOVLW B'00000011'
movwf TRISE
CLRF TRISB ;PortB is 8 LED output to show
movlw b'11111111'
movwf TRISD
;/*-----Set up A2D parameters
MOVLW B'00001110'
MOVWF ADCON1
MOVLW B'11010111'
MOVWF OPTION_REG
BCF STATUS,RP0
;/*---------Set up chip parameters
Start CALL A2D
MOVWF TEMP
MOVWF PORTB ;output Hex value to LEDs
PC
BTFSC PORTE,0
goto Start
;TEMP <= 80
movf TEMP,w
addlw d'255'-d'80'
skpnc
Call HeatIndex
;TEMP <= 40
movf TEMP,w
addlw d'255'-d'40'
skpc
Call WindChill
GOTO Start
A2D
MOVLW B'01000001' ;a2d = on, ch0, fosc/8
MOVWF ADCON0
;/*-----Delay loop to settle A2D, similar to de-bounce???
mnloop btfss INTCON,T0IF ;50us loop delay @ 4Mhz
goto mnloop
;/*-----Stop timer0 interrupt
BCF INTCON,T0IF
BSF ADCON0,GO_DONE ;start a2d conversion
WAITA2D NOP ;wait 4 finish
BTFSC ADCON0,GO_DONE
GOTO WAITA2D
;/*-----Put A2D W and send to port B.
MOVF ADRESH,W ;upper 8 bits-ignor lower 3
RETURN
HeatIndex
START MOVLW d'10'
MOVWF CYC
CLRF COUNT
L1 BTFSS PORTC,2
GOTO L1
L2 INCF COUNT
BTFSC PORTC,2
GOTO L2
DECFSZ CYC
GOTO L1
MOVF COUNT,w
MOVWF PORTB
BTFSS PORTE,0
GOTO HeatIndex
RETURN
WindChill
movf PORTD,w
movwf PORTB
BTFSS PORTE,0
GOTO WindChill
RETURN
END
engineergirl27 said:Hey Guys,
I have been programming, and I have quite a bit done, I was wondering if any of you could help with the math. The equations are quite extensive and I am not that familiar with it enough to do these extensive of equations.
blueroomelectronics said:R1 & R2 only have one side connected. What sort of humidity sensor are you using?
What language are you going to program it with?
;GetV16 returns (W^0.16)*256 in word variable Acc
;Acc must be in common area (70-7f)
GetV16 addlw low V16Tab ;calculate address in table
bsf STATUS,RP1 ;bank 2
movwf EEADR
movlw high V16Tab
btfsc STATUS,C
addlw 1
movwf EEADRH
call ReadFlash ;will return in bank 0
return
ReadFlash bsf STATUS,RP1 ;#2
bsf STATUS,RP0 ;#3
bsf EECON1,EEPGD ;read flash
bsf EECON1,RD ;do read
nop ;required delay
nop
bcf STATUS,RP0 ;#2
movfw EEDAT ;move into Acc
movwf Acc
movfw EEDATH
movwf Acc+1
bcf STATUS,RP1 ;#0
return
V16Tab dw .0,.256,.286,.305,.319,.331,.340,.349
dw .357,.363,.370,.375,.380,.385,.390,.394
dw .398,.402,.406,.410,.413,.416,.419,.422
dw .425,.428,.431,.433,.436,.438,.441,.443
dw .445,.447,.450,.452,.454,.456,.458,.460
dw .461,.463,.465,.467,.469,.470,.472,.473
dw .475,.477,.478,.480,.481,.483,.484,.486
dw .487,.488,.490,.491,.492,.494,.495,.496
dw .497,.499,.500,.501,.502,.504,.505,.506
dw .507,.508,.509,.510,.511,.512,.514,.515
dw .516,.517,.518,.519,.520,.521,.522,.523
dw .524,.524,.525,.526,.527,.528,.529,.530
dw .531,.532,.533,.534,.534
GetHeat movfw Temperature ;get Temperature
addlw .35 ;table starts at -35
addlw .2 ;course rounding
call Divide5 ;table goes up in steps of 5
movwf Acc ;each table entry is 24 words
clrf Acc+1 ;so we need to multiply by 24
bcf STATUS,C
rlf Acc,F
rlf Acc+1,F
rlf Acc,F ;*4
rlf Acc+1,F
rlf Acc,F ;*8
rlf Acc+1,F
movfw Acc
movwf TempWord
movfw Acc+1
movwf TempWord+1 ;keep a copy of Temperature*8
rlf Acc,F ;*16
rlf Acc+1,F
movfw TempWord
addwf Acc,F ;T*16+T*8=T*24
btfsc STATUS,C
incf Acc+1,F
movfw TempWord+1
addwf Acc+1,F
movfw RH ;get the relative humidity
addlw .2 ;course rounding
call Divide5 ;table is in steps of 5
addwf Acc,F
btfsc STATUS,C
incf Acc+1,F
movfw Acc
addlw low HeatTable ;calculate address in table
bsf STATUS,RP1 ;bank 2
movwf EEADR
bcf STATUS,RP1 ;bank 0
movfw Acc+1
bsf STATUS,RP1 ;bank 2
addlw high HeatTable
btfsc STATUS,C
addlw 1
movwf EEADRH
call ReadFlash ;will return in bank 0
return
ReadFlash bsf STATUS,RP1 ;#2
bsf STATUS,RP0 ;#3
bsf EECON1,EEPGD ;read flash
bsf EECON1,RD ;do read
nop ;required delay
nop
bcf STATUS,RP0 ;#2
movfw EEDATA ;move into Acc
bcf STATUS,RP1 ;#0
movwf Acc
bsf STATUS,RP1 ;#2
movfw EEDATH
btfsc EEDATH,5 ;is it negative
iorlw b'11000000' ;yes, so sign extend
bcf STATUS,RP1 ;#0
movwf Acc+1
return
Divide5 clrf TempWord ;returns W/5
Div5Loop incf TempWord,F
addlw 100h-5 ;add -5
btfsc STATUS,C
goto Div5Loop
decf TempWord,W
return
HeatTable
dw -.122,-.27,.64,.151,.233,.311,.385,.454,.519,.579,.636,.687,.735,.778,.817,.851,.881,.907,.928,.945,.958,.0,.0,.0
dw -.110,-.22,.62,.141,.217,.288,.356,.419,.478,.533,.584,.631,.674,.712,.747,.777,.803,.825,.844,.857,.867,.0,.0,.0
dw -.98,-.17,.60,.133,.202,.267,.328,.386,.440,.489,.535,.577,.615,.650,.680,.707,.729,.748,.763,.774,.781,.0,.0,.0
dw -.86,-.12,.58,.125,.187,.247,.302,.354,.403,.448,.489,.526,.560,.590,.617,.640,.659,.675,.687,.695,.700,.0,.0,.0
dw -.75,-.7,.56,.117,.174,.228,.278,.325,.368,.408,.445,.478,.508,.534,.557,.577,.593,.606,.615,.621,.624,.0,.0,.0
dw -.64,-.3,.55,.110,.161,.210,.255,.297,.335,.371,.403,.432,.459,.481,.501,.518,.531,.541,.548,.552,.552,.0,.0,.0
dw -.53,.2,.54,.103,.150,.193,.233,.270,.305,.336,.364,.390,.412,.432,.448,.462,.473,.480,.485,.487,.486,.0,.0,.0
dw -.42,.7,.54,.97,.139,.177,.213,.245,.276,.303,.328,.350,.369,.385,.399,.410,.418,.424,.427,.427,.424,.0,.0,.0
dw -.32,.12,.53,.92,.128,.162,.194,.222,.249,.272,.294,.312,.329,.342,.353,.362,.368,.371,.372,.371,.367,.0,.0,.0
dw -.23,.16,.53,.87,.119,.149,.176,.201,.224,.244,.262,.278,.291,.302,.311,.317,.321,.323,.323,.320,.314,.0,.0,.0
dw -.13,.21,.53,.83,.111,.136,.160,.181,.201,.218,.233,.246,.257,.266,.272,.277,.279,.279,.277,.273,.267,.0,.0,.0
dw -.4,.26,.53,.79,.103,.125,.145,.164,.180,.194,.206,.217,.225,.232,.237,.239,.240,.239,.236,.231,.224,.0,.0,.0
dw .5,.30,.54,.76,.97,.115,.132,.147,.161,.172,.182,.191,.197,.202,.205,.206,.206,.203,.199,.194,.186,.0,.0,.0
dw .13,.35,.55,.74,.91,.106,.120,.133,.144,.153,.161,.167,.172,.175,.176,.176,.175,.172,.167,.161,.153,.0,.0,.0
dw .21,.39,.56,.72,.86,.98,.110,.120,.128,.136,.142,.146,.149,.151,.151,.150,.148,.144,.139,.133,.125,.0,.0,.0
dw .29,.44,.57,.70,.81,.92,.101,.109,.115,.121,.125,.128,.130,.130,.130,.128,.125,.121,.116,.109,.102,.0,.0,.0
dw .36,.48,.59,.69,.78,.86,.93,.99,.104,.108,.111,.113,.113,.113,.112,.110,.106,.102,.97,.90,.83,.0,.0,.0
dw .43,.52,.61,.69,.76,.82,.87,.91,.95,.97,.99,.100,.100,.99,.97,.95,.91,.87,.82,.76,.69,.0,.0,.0
dw .50,.57,.63,.69,.74,.78,.82,.85,.87,.89,.90,.90,.89,.88,.86,.84,.80,.76,.72,.66,.60,.0,.0,.0
dw .56,.61,.66,.70,.73,.76,.79,.81,.82,.83,.83,.83,.82,.81,.79,.76,.73,.70,.66,.61,.56,.0,.0,.0
dw .62,.65,.68,.71,.73,.75,.77,.78,.78,.79,.79,.78,.77,.76,.75,.73,.70,.67,.64,.61,.57,.0,.0,.0
dw .68,.70,.71,.73,.74,.75,.76,.77,.77,.77,.77,.77,.76,.75,.74,.72,.71,.69,.67,.65,.62,.0,.0,.0
dw .73,.74,.75,.75,.76,.77,.77,.77,.77,.78,.78,.78,.77,.77,.77,.76,.76,.75,.74,.73,.72,.0,.0,.0
dw .78,.78,.78,.78,.79,.79,.79,.80,.80,.80,.81,.81,.82,.82,.83,.84,.84,.85,.86,.86,.87,.0,.0,.0
dw .82,.82,.82,.82,.82,.82,.83,.84,.84,.85,.86,.88,.89,.91,.93,.95,.97,.99,.102,.104,.107,.0,.0,.0
dw .87,.86,.86,.86,.86,.87,.88,.89,.91,.92,.95,.97,.100,.103,.106,.109,.113,.117,.122,.127,.132,.0,.0,.0
dw .91,.90,.90,.91,.91,.93,.94,.96,.99,.102,.105,.109,.113,.118,.123,.128,.134,.140,.147,.154,.161,.0,.0,.0
dw .94,.94,.95,.96,.97,.100,.102,.106,.109,.114,.118,.124,.129,.136,.143,.150,.158,.167,.176,.185,.195,.0,.0,.0
dw .97,.98,.100,.102,.104,.108,.112,.116,.121,.127,.134,.141,.149,.157,.166,.176,.187,.198,.209,.221,.234,.0,.0,.0
dw .100,.102,.105,.108,.112,.117,.122,.129,.136,.143,.152,.161,.171,.182,.194,.206,.219,.233,.247,.262,.278,.0,.0,.0
dw .103,.106,.110,.115,.121,.127,.134,.143,.152,.162,.173,.184,.197,.210,.224,.239,.255,.272,.289,.308,.327,.0,.0,.0
dw .105,.110,.116,.122,.130,.138,.148,.158,.170,.182,.196,.210,.225,.241,.258,.276,.295,.315,.336,.358,.380,.0,.0,.0
dw .107,.114,.121,.130,.140,.151,.163,.176,.190,.205,.221,.238,.256,.275,.296,.317,.339,.362,.387,.412,.439,.0,.0,.0
dw .108,.117,.128,.139,.151,.165,.179,.195,.212,.230,.249,.269,.291,.313,.337,.361,.387,.414,.442,.471,.502,.0,.0,.0
dw .110,.121,.134,.148,.163,.180,.197,.216,.236,.257,.279,.303,.328,.354,.381,.410,.439,.470,.502,.535,.570,.0,.0,.0
dw .110,.125,.141,.158,.176,.195,.216,.238,.262,.286,.312,.340,.368,.398,.429,.461,.495,.530,.566,.604,.642,.0,.0,.0
https://www.onlineconversion.com/engineergirl27 said:I have a simpler equation WC = Temp - Wind Speed/4, but this is for Celcius and km/hour,
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?