#chip 16LF18326,4 #config RSTOSC=hfint1, MCLRE=Off, WDTE=off, boren=off, FEXTOSC_OFF, CLKOUTEN_OFF, CP_OFF, WRT_OFF wait 10 ms 'peripheral pin select unlockpps 'UNLOCK PPS RC1PPS = 0x19 ' RC1<-MSSP1:SDA1(25) SSP1CLKPPS = 0x10 ' RC0->MSSP1:SCL1(16) SSP1DATPPS = 0x11 ' RC1->MSSP1:SDA1(17) RC0PPS = 0x18 ' RC0->MSSP1:SCL1(24) lockpps 'LOCK PPS #include #define hi2c_BAUD_RATE 400 #define hi2c_DATA PORTC.1 #define hi2c_CLOCK PORTC.0 Dir hi2c_DATA in Dir hi2c_CLOCK in hi2cMode Master wait 10 ms dir portc.5 out dir portc.4 out dir portc.3 out dir portc.2 out dir porta.2 OUT dir porta.1 OUT dir porta.0 OUT set portc.5 off set portc.4 off set portc.3 off set portc.2 off set porta.2 off set porta.1 off set porta.0 off dir porta.4 in 'timer1 dir porta.5 in 'timer1 ht=37 'mausica (was 42) 'ht=22 'st augustine kint=0:jint=1 'option_reg.7=0 'wpu on wpuc=b'00000011' 'hi2c pins 'wpuc=b'00110000' 'hi2c pins 'wpua=b'00110111' 'front buttons wait 10 ms dir porta.4 in 'timer1 dir porta.5 in 'timer1 TMR1H=b'0000000' 'two seconds TMR1L=b'0000000' 'to overflow pir1.0=0 t1con=b'10001101' 'timer1 1:1 intcon.6=1 pie1.0=1 t1gcon.7=0 dim xx1 as word xx1=0 dim xx2 as word xx2=0 dim d11 as word dim d12 as word dim k as word dim q1 as word dim q2 as word dim abk as word dim x1 as word dim tt as word dim hh as word dim cal1 as word dim cal2 as word dim xx3 as word dim zz3 as word dim xx7 as word dim prav as long dim adr1 as word dim temp as word dim kstep as word dim hh1 as word dim hh2 as word dim prh3hr(15) dim prl3hr(15) dim kcomp as word adr1=2048 '*********start address for writing data '*******************MUST be beyond program memory prav=0 xx3=0 for i=1 to 15 prh3hr(i)=44 prl3hr(i)=61 next i zz3=11325 'initial reading xx7=11325 'less 900mb ktimes=0 ktimem=54 'start time ktimeh=16 '16:54:00 ktimed=0 'day zero i3hr=0 kstep=0 mstep=0 kcomp=0 wait 10 ms 'midas display MCCOG SL=0x7C 'DISPLAY ID COMSEND=0x00 'display COMMAND send DS=0X40 'display DATA send 'reset pressure 'LPS22HB pressure sensor hi2cstart hi2csend 0xba hi2csend 0x11 hi2csend b'00000010' 'reset hi2cstop wait 10 ms hi2cstart hi2csend 0xba hi2csend 0x10 hi2csend b'00001100' 'filter on x20 'hI2CSEND b'00000100' 'x9 'hI2CSEND b'00000000' 'FILTER OFF hi2cstop wait 10 ms iicread(0x33,t1) 'reset filter wait 10 ms twoline 'initialize display wait 10 ms ht=37 'height above sea level cal1=220 'device calibration cal2=ht*12 'offset for ht + DO 'start of main loop hi2cstart hi2csend 0xba hi2csend 0x11 hi2csend b'00000001' 'one shot hi2cstop wait 40 ms iicread (0x28,p1) 'low iicread (0x29,p2) 'mid iicread (0x2a,p3) 'high xx1=p2 xx1_h=p3 xx2=xx1%16 xx1=xx1/16 xx3=(xx1-900)*100 ' take off 900mb xx2=(xx2*256+p1)*10 'so it fits in 14bits z1=xx2/4096 xx2=(xx2%4096)*10 z2=xx2/4096 xx2=(xx2%4096)*10 z3=xx2/4096 xx3=xx3+z1*10+z2-cal1+cal2 'add on last two dp q1=xx3/10000+9 'add 900mb for display xx2=xx3%10000 q2=xx2/1000 xx2=xx2%1000 q3=xx2/100 xx2=xx2%100 q4=xx2/10 q5=xx2%10 q11=q1/10 q10=q1%10 'q10=q10+1 'if q10=10 then q10=0 if q10=0 then q10=31 'use letter O if q2=0 then q2=31 'instead of number 0 if q3=0 then q3=31 if q4=0 then q4=31 if q5=0 then q5=31 if z3=0 then z3=31 hi2cStart hi2cSEND(Sl) hi2cSEND(Comsend) hi2csend(0x80) 'first line hi2cstop kstep=kstep+1 prav=prav+xx3 '12m average if kstep=360 then '12 minutes kstep=0 prav=(prav+180)/360 xx7=prav prav=0 kstep=0 mstep=mstep+1 if mstep=16 then mstep=1 zz3=prl3hr(mstep) zz3_h=prh3hr(mstep) prl3hr(mstep)=xx7 prh3hr(mstep)=xx7_h flashdata1 adr1=adr1+1 end if 'recalc 3hour variation if zz3>xx7 then m=1:d11=zz3-xx7 if zz30 then hi2csend(pz1+48):pz9=pz9-1 if (pz1+pz2)>0 then if pz2=0 then pz2=31 hi2csend(pz2+48) pz9=pz9-1 end if if pz3=0 then pz3=31 hi2csend(pz3+48) if pz4=0 then pz4=31 hi2csend(pz4+48) repeat pz9 hi2csend(32) end repeat hi2cstop hi2cStart hi2cSEND(Sl) hi2cSEND(Comsend) hi2csend(0xC0) 'second line hi2cstop hi2cstart hi2csend(Sl) hi2csend(DS) hi2csend ((ktimed/10)+48) hi2csend ((ktimed%10)+48) hi2csend (58) hi2csend ((ktimeh/10)+48) hi2csend ((ktimeh%10)+48) hi2csend (58) hi2csend ((ktimem/10)+48) hi2csend ((ktimem%10)+48) hi2csend (58) hi2csend ((ktimes/10)+48) hi2csend ((ktimes%10)+48) temp=temp+5 'round up hi2cstop sleep 'sleep until timer1 overflow nop pir1.0=0 ktimes=ktimes+2 if ktimes>59 then ktimes=ktimes-60:ktimem=ktimem+1:kcomp=kcomp+1 if ktimem>59 then ktimem=0:ktimeh=ktimeh+1 if ktimeh>23 then ktimeh=0:ktimed=ktimed+1 if kcomp=1184 then kcomp=0:tmr1h=b'10000000' '-1 sec every 1184 mins (slow) Loop 'end of main loop sub iicread(adr,vlr) hi2cstart hi2csend(0xba) 'send to hi2csend(adr) 'read id hi2crestart hi2csend(0xbb) 'read from hi2creceive vlr ,nack hi2cstop end sub sub iicwrite(adw,vlw) hi2cstart hi2csend(0xba) hi2csend(adw) hi2csend(vlw) hi2cstop end sub sub screen hi2cStart hi2cSEND(Sl) hi2cSEND(Comsend) hi2csend(0x80) 'first line hi2cstop 'pressure print hi2cStart hi2csend(Sl) hi2csend(DS) if q11=0 then hi2csend(32) if q11>0 then hi2csend(q11+48) hi2csend(q10+48) hi2csend(q2+48) hi2csend(q3+48) hi2csend(q4+48) hi2csend(q5+48) hi2cSend (46) hi2cSend (z3+48) hi2csend(80) hi2csend(97) 'pressure change pz9=2 if pz1>0 then hi2csend(pz1+48):pz9=pz9-1 if (pz1+pz2)>0 then if pz2=0 then pz2=31 hi2csend(pz2+48) pz9=pz9-1 end if if pz3=0 then pz3=31 hi2csend(pz3+48) if pz4=0 then pz4=31 hi2csend(pz4+48) repeat pz9 hi2csend(32) end repeat hi2cstop end sub sub twoline hi2cStart hi2cSEND(Sl) hi2cSEND(Comsend) 'hi2cSEND(0x34) 'initialize 16x1 hi2csend(0x38) '16x2 hi2cSEND(COMSEND) 'hi2cSEND(0x35) '16x1 hi2csend(0x39) '16x2 hi2cSEND(0x10) 'osc set to slowest hi2cSEND(0x7A) 'contrast low byte=75 to 7A hi2cSEND(0x54) 'pwr booster on hi2cSEND(0x6F) 'follower hi2cSEND(0x0C) 'on/off hi2cSEND(0x01) 'clear hi2cstop end sub sub flashdata1 'write to flash memory 'adr1=address xx7=data nvmadrl=adr1 nvmadrh=adr1_h set nvmCON1.NVMREGS off set NVMCON1.wren on ' Enable writes set NVMCON1.lwlo on ' Write Latches NVMdatl=xx7 NVMdath=xx7_h set NVMcon1.lwlo off 'write SET INTCON.GIE OFF NVMcon2=0x55 NVMcon2=0xAA set NVMcon1.wr on 'SET INTCON.GIE ON set PMcon1.wren off end sub