Many of your elseif comparators could simply be else. The code also sets Hpwm then enters "if then" potentially changing the value again the first Hpwm is not needed. Just to give you some ideas here is an example of what could be done. I have included a space either side of the comparators, Vp < 300 not Vp<300. Just personal preference on my part? Probably but I have learned to be very strict with code syntax.
I am now thinking why sending "B" does not work and an answer eludes me. I need time for more thought.Code:main: Serin portc.7,2,char 'Receive data sent from the transmitting pic if (char = "A" ) then 'if data is character A pause 50 Adcin 0, Temp ' Read channel 0 to Temp (0-1023) Temp = (Temp */ 500)>>2 ' Equates to: (Temp * 500)/1024 LCDOut ,$fe,$80,"Temp= ",DEC2 Temp 'Display Temp On The First Line Adcin 1, Vp 'Read channel 1 to Vp (0-1023) Vp = (Vp */ 500)>>2 'Equates to: (Vp * 500)/1024 LCDOut $fe,$c0 ,"Pressure = ",DEC (Vp/100),".", DEC2 Vp," volt" 'Display Voltage out of pressure sensor on second line Adcin 2, Vl 'Read channel 2 to Vl (0-1023) Vl = (Vl */ 500)>>2 'Equates to: (Vl * 500)/1024 LCDOut $fe,$94 ,"Level= ",DEC (Vl/100),".", DEC2 Vl," volt" 'Display Voltage out of Level sensor on third line if portd.0 = 0 then 'Soil Moisture is lower than preset value if Vp < 300 then 'Voltage From Pressure Sensor is Less than preset value (3 volt) if Vl < 300 then 'If voltage of Level sensor is Less than preset value (3 volt) hpwm 1,179,5000 'Pump is on with 70% duty cycle at 5 khz else 'If voltage of Level sensor is more than or equal preset value hpwm 1,77,5000 'Pump is on with 30% duty cycle at 5 kHz endif 'vl < endif 'vp< if Vp >= 300 then 'Voltage From Pressure Sensor is more than or equal preset value (3 volt) if Vl < 300 then 'If voltage of Level sensor is less than preset value (3 volt) hpwm 1,179,5000 'Pump is on with 70% duty cycle at 5 khz else 'If voltage of Level sensor is more than or equal preset value hpwm 1,77,5000 'Pump is on with 30% duty cycle at 5 khz endif 'vl< endif 'vp> endif '= if portd.0 != 0 then 'Soil Moisture is high or equal to preset value hpwm 1,0,5000 'Turn off Pump hpwm 2,0,5000 'Turn off Solenoid endif '!= endif 'A if (char = "B") then lcdout $fe,1 'Clear LCD hpwm 1,0,5000 'Turn off Pump hpwm 2,0,5000 'Turn off Solenoid endif Goto main 'Do it forever




Bookmarks