program inkubator

  dim LCD_RS as sbit  at RB4_bit
    LCD_EN as sbit  at RB5_bit
    LCD_D4 as sbit  at RB0_bit
    LCD_D5 as sbit  at RB1_bit
    LCD_D6 as sbit  at RB2_bit
    LCD_D7 as sbit  at RB3_bit

    LCD_RS_Direction as sbit at TRISB4_bit
    LCD_EN_Direction as sbit at TRISB5_bit
    LCD_D4_Direction as sbit at TRISB0_bit
    LCD_D5_Direction as sbit at TRISB1_bit
    LCD_D6_Direction as sbit at TRISB2_bit
    LCD_D7_Direction as sbit at TRISB3_bit
' End Lcd module connections


    dim b,i, j, rht    as byte                 ' Loop variable
    dim vysledek, rhat1, c2, c3 as float
    dim c1 as short
    dim rhat as word
    dim  text1 as string[8]
    dim text as string[8]
'--------------------- Reads time and date information from RTC (PCF8583)


'--------------------- startovací sekvence-------------------------------
' RA0 data
'RA1 clock
sub procedure start
 porta = 1
trisa = 0             
   'začátek startvoací sekvence porta jako výstup


nop
nop
setbit(porta,1)
nop
clearbit(porta,0)
nop
clearbit(porta,1)
nop
nop
nop
nop
setbit(porta,1)
nop
setbit(porta,0)
nop
clearbit(porta,1)
nop
clearbit(porta,0)
'--------------------------------------------------------------------
  '         konec startu
for i = 0 to 2
setbit(porta,1)         'první 3 impulsy sck
nop
clearbit(porta,1)
nop
next i

'------------------------------------------------------------------------
'      příkaz 00101 = vlhkost			data vlhkost
if b = 255 then
 setbit(porta,1)         '0
nop
clearbit(porta,1)
nop

setbit(porta,1)         '0
nop
clearbit(porta,1)
nop

 setbit(porta,0)         '1
nop
 setbit(porta,1)
nop
clearbit(porta,1)
nop
clearbit(porta,0)
nop

 setbit(porta,1)         '0
nop
clearbit(porta,1)
nop



setbit(porta,0)         '1
nop
 setbit(porta,1)
nop
clearbit(porta,1)
nop
clearbit(porta,0)
nop
   else
   
 for i = 0 to 2				data teplota
 setbit(porta,1)         '0
nop
clearbit(porta,1)
nop
 next i
 setbit(porta,0)         '1
nop
 setbit(porta,1)
nop
clearbit(porta,1)
nop
clearbit(porta,0)
nop

setbit(porta,0)         '1
nop
 setbit(porta,1)
nop
clearbit(porta,1)
nop
clearbit(porta,0)
nop
   
 end if
'----------------------------------------------------------
'                 konec žádosti o měření RH
ack: trisa = 1

if testbit(porta,0) = 0 then

  setbit(porta,1)         'ack
nop
clearbit(porta,1)
nop
else goto ack
porta = 1
end if
'-------------------------------------------------------------


    trisa = 1
delay_ms(230)          'čekání na konec měření

mer: if testbit(porta,0) = 1 then
     goto mer
     end if
     rhat = 0
     for i = 0 to 1			vyčtení měření.
    for j = 0 to 7
      rhat = rhat << 1
     setbit(porta,1)
     if testbit(porta,0) = 1 then
     setbit(rhat,0)
     else clearbit(rhat,0)
     end if
     clearbit(porta,1)

     next j
     if i = 0 then
     setbit(porta,1)         '0
     nop
     clearbit(porta,1)
     nop
     end if
     next i
 

     porta=1
     trisa = 0
     
end sub





'------------------ Performs project-wide init
sub procedure Init_Main
trisa=0
porta = 0
  CMCON  = CMCON or 0x07   ' turn off comparators
  ADCON1 = 6  ' turn off analog inputs


  Lcd_Init()               ' Initialize Lcd
  Lcd_Cmd(_LCD_CLEAR)      ' Clear Lcd display
  Lcd_Cmd(_LCD_CURSOR_OFF) ' Turn cursor off
 i = 0
 j = 0


  c1 = -4
  c2 = 0.0405
  c3 = -0.0000028
end sub


'----------------- Main sub procedure
main:

  Init_Main()              ' Perform initialization
'  nastaveni()
b = 255
  while TRUE               ' Endless loop


     start()
     if b = 255 then

        vysledek = c1 + (c2 * rhat) + (c3 * (rhat * rhat))
'        Lcd_Out(1,1,"vlhkost")
           else

        vysledek = rhat * 0.01 - 40
'        Lcd_Out(1,1,"teplota")
     end if
        floattostr(vysledek,text)

           Lcd_Out(2,4,text)
    delay_ms  (500)
    b = not b



  wend
end.
