صفحه اصلی فروش و نصب سرویس و نگهداری پروژه های الکترونیک ارتباط با ما

'****************************************************************

'*  Name    : incubation system                                 *

'*  Author  : [select VIEW...EDITOR OPTIONS]                    *

'*  Notice  : Copyright (c) 2003 [select VIEW...EDITOR OPTIONS] *

'*          : All Rights Reserved                               *

'*  Date    : 12/25/2007                                        *

'*  Version : 1.0                                               *

'*  Notes   :                                                   *

'*          : www.omidravanro.com   09125354921 mehdi rajabinia *

'****************************************************************

    

DEFINE LCD_EREG PORTC        'LCD enable port

DEFINE LCD_EBIT 7            'LCD enable bit

DEFINE LCD_RSREG PORTA

DEFINE LCD_RSBIT 4

' Set LCD bus size (4 or 8 bits)

DEFINE LCD_BITS 4

' Set number of lines on LCD

DEFINE LCD_LINES 2

' Set command delay time in us

DEFINE LCD_COMMANDUS 2000

' Set data delay time in us

DEFINE LCD_DATAUS 50

DEFINE OSC 4   


'** Constants

cmdtr CON %00000011 ' Command "read temperature"

cmdhr CON %00000101 ' Command "read humitity"

'** Variables

result VAR WORD ' RAW Data from Sensor

chksum VAR BYTE ' Checksum

cmd VAR WORD ' Sensor Command

RHlin VAR WORD ' Rel. Humidity (RH) Linear (% *10)

RHtc VAR WORD ' Rel. Humidity (RH) temp. compensated (% *10)

Temp VAR WORD ' Temperature (°C *100)

DP VAR WORD ' Dewpiont (°C *10)


'** Temp variables used in div. calculations

TempDP VAR WORD

Rchk VAR BYTE

logEW VAR WORD

sign2 VAR BIT

wy VAR WORD

wz VAR WORD

wj VAR WORD

wx VAR WORD

i VAR BYTE

ix VAR BYTE

bt VAR BIT

b0 var byte

b1 var byte

b2 var byte

b3 var byte

bx var word

bxx var word

'** Pin-Assingments

dta VAR PORTB.1 ' Sensor Data

clk VAR PORTB.0 ' Sensor Clock

enter   var portc.0

up      var portc.1

down    var portc.2

symbol oxijen=portb.2     ; humidity uper fan control

symbol hiter=portb.3      ; temp control

symbol motor1=portb.4      ; motor1 control

symbol buzer=portb.5

symbol hum=portb.6        ; humidity control

symbol normalled=portb.7  ; cpu ok  view

symbol motor2=portc.3     ; motor2 control

read 1,b0    ;motaqayer up temp

read 5,b1    ;motaqayer down temp

read 10,bxx  ;motaqayer motor

read 20,b2    ;motaqayer up hum

read 15,b3    ;motaqayer down hum


;Low PORTA.5 ;enable rw pin

Pause 100

LCDOut $FE,1," **  SHT 11 **"

pause 500

lcdout $fe,1," TEMP HUMIDITY"

lcdout $fe,$c0 ," MEHDI RAJABINIA"

high hiter

high buzer

high hum

high oxijen

pause 1000

low hiter

low buzer

low hum

low oxijen

lcdout $fe,1, "                "  ; pak kardan lcd


main:

low motor1

low motor2

for bx=1 to bxx        ;baraye farman be motor

if enter=1 then meno   ;raftan be meno

high normalled         ;namayesh normal led

if (temp/100)>=b0 then

   pause 1000

   low hiter

   pause 2

   endif

if (temp/100)<=b1 then high hiter

if (temp/100)>=38 then high buzer

pause 100

low buzer

if (temp/100)<=35 then high buzer

pause 100

low buzer

if (rhlin/10)>=b2 then

low hum

high oxijen

pause 2000

else

low oxijen

endif

if (rhlin/10)<= b3 then high hum

GoSub init  ;marbut be barname asli

cmd = cmdtr ;marbut be barname asli

GoSub readsensor  ;marbut be barname asli

Temp=result-3995  ;marbut be barname asli

GoSub init        ;marbut be barname asli

cmd = cmdhr       ;marbut be barname asli

GoSub readsensor  ;marbut be barname asli

RHlin=(26542-(54722**result+result))**result-40 ' RH linear

RHtc=655+(result*5)+(result**15917)

RHtc=(RHtc**(Temp/10+2480))-(RHtc**2730)+RHlin ' RH temp. compensated

GoSub dewpoint  ;marbut be barname asli

LCDOut $FE,$80," ",$DF,"C |"," ",$25,"RH  |"," DWP "

LCDOut $FE,$C0,DEC2 (TEMP/100),".",DEC1 (temp/10),"  ",DEC2 RHlin/10,".",DEC1 RHlin,"  ",DEC2 ABS DP/10,".",DEC1 ABS dp

;LCDOut $FE,$C0,DEC2 (TEMP/100),".",DEC1 (temp/10)," ",DEC2 RHtc/10,".",DEC1 RHtc," ",DEC2 ABS DP/10,".",DEC1 ABS dp

;sleep 10   ;marbut be barname asli

low normalled

pause 200

next bx     ; marbut be on motor bad az bx

low hiter   ; dar max motor  hiter off

low hum     ; dar max motor  hum off

high motor1

pause 4000  ; modate chakhesh motor

low motor1

high motor2

pause 4000

low motor2

GoTo main

'** Init Sensor

init:

High dta

Low clk

For i=1 to 10

High clk

Pause 1

Low clk

Pause 1

Next i

Call tstart

Return

'** start transfer

tstart:

High clk

Pause 1

Low dta

Pause 1

Low clk

Pause 1

High clk

Pause 1

High dta

Pause 1

Low clk

Return

'** get Data from Sensor

readsensor:

if enter=1 then meno

GoSub tstart

GoSub WaitSensor

ShiftOut dta,clk,1,[cmd\8] ' send command

Input dta ' wait acknowledge

Low clk

While dta=1

Wend

PulsOut clk,10 ' send ack

While dta=0

Wend

While dta=1 ' wait for conversion to complete

Wend

Low clk

ShiftIn dta,clk,0,[result.highbyte\8] ' get first byte

Low dta

PulsOut clk,10 ' send ack

ShiftIn dta,clk,0,[result.lowbyte\8] ' get second byte

Low dta

PulsOut clk,10 ' send ack

ShiftIn dta,clk,0,[chksum\8] ' get third byte (checksum)

High dta

PulsOut clk,10 ' send ack

Input dta ' End of Transmission

Input clk

Return

'** Dewpoint Calculation

' See: SENSIRION Application Note "Dewpoint Calculation"

' logEW = (0.66077+7.5*T/(237.3+T)+(log(RH)-2)

' DP = ((0.66077-logEW)*237.3)/(logEW-8.16077)

DewPoint:

if enter=1 then meno

TempDP=Temp/10

logEW=6608

sign2=TempDP.bit15

wz=ABS TempDP

wx=(7*wz)+(wz/2)

wy=2373+wz

wj=wx/wy

For ix=15 to 0 step -1

wx=(wx//wy)<<1

wz.bit0(ix)=wx/wy

Next

wx=(-sign2^((wj*10000)+(wz**10000)))+sign2

logEW=wx+logEW

wx=RHtc

wj=(NCD wx) - 1

wx=wx<<(15-wj)

wz=0

For ix=14 to 0 step -1

wy=wx**wx

wz.bit0(ix)=wy.bit15

bt=~wy.bit15

wx=(wy<Next

wx=((wj*4000)**49321)+(wz**6021)

logEW=wx+logEW-30000

sign2=logEW.bit15

logEW=(-sign2^(((ABS logEW)+2)/4))+sign2

wx=1652-logEW

sign2=~wx.bit15

wx=ABS wx

wy=20402-logEW

wj=wx/wy

For ix=15 to 0 step -1

wx=(wx//wy)<<1

wz.bit0(ix)=wx/wy

Next

DP=((23730**wz)+5)/10

DP=(-sign2^DP)+sign2

Return

WaitSensor:

result=4096

Loop:

result=result-1

IF dta && result.bit11 Then Loop

Return

;End

meno:

lcdout  $fe,1,  " Mehdi Rajabinia"

lcdout  $fe,$c0," TEL:09125354921"

pause 2000

low hiter

low hum

    meno2:

    pause 10

    lcdout  $fe,1,  " meno ** enter"

    lcdout  $fe,$c0," exit ** up/down "

    pause 1000

if up=1 and down=1 then main

if enter=1 then

    gosub timer

    gosub hi_off

    gosub lo_on

    gosub humhi

    gosub humlo

    

else

    goto meno2

endif

    

    

    timer :

    

    lcdout $fe,1," motor timer:"

    lcdout $fe,$c0," *",#bxx,"*  time"

    pause 300

if up=1 then   bxx=bxx+10

    pause 2

if down=1 then bxx=bxx-10

    pause 2

if bxx>=600 then bxx=600

if bxx<=10 then bxx=10

    pause 2

    write 10,bxx

    pause 5

if enter=1 then  return

    goto timer

    

    hi_off :

     

    lcdout  $fe,1,  " off hiter :",#b0,$DF

     pause 300

if up=1 then   b0=b0+1

    pause 2

if down=1 then b0=b0-1

    pause 2

if b0>=45 then b0=45

if b0<=0 then b0=0

    pause 2

    write 1,b0

    pause 5

if enter=1 then  return

    goto hi_off

    

    lo_on :

     

     lcdout  $fe,1, "  on hiter :",#b1,$DF

     pause 300

if up=1   then   b1=b1+1

     pause 2

if down=1 then   b1=b1-1

     pause 2

if b1>=40 then b1=40

if b1<=0 then b1=0

     pause 2

     write 5,b1

     pause 5

if enter=1 then return

     goto lo_on

    

   humhi:

    

     lcdout $fe,1," humidity hi off"

     lcdout $fe,$c0,"   ",#b2,$25

     pause 300

if up=1 then   b2=b2+1

    pause 2

if down=1 then b2=b2-1

    pause 2

    if b2>=99 then b2=99

if b2<=0 then b2=0

    pause 2

    write 20,b2

    pause 5

if enter=1 then  return

    goto humhi

    

    humlo:

    

     lcdout $fe,1," humidity lo on"

     lcdout $fe,$c0,"   ",#b3,$25

     pause 300

if up=1 then   b3=b3+1

    pause 2

if down=1 then b3=b3-1

    pause 2

    if b3>=99 then b3=99

if b3<=0 then b3=0

    pause 2

    write 15,b3

    pause 5

if enter=1 then  meno2

    goto humlo

     

   END