Menu

Delays

Help
2008-05-22
2013-05-30
  • Nobody/Anonymous

    Hi super program this is 10/10
    I am trying to make a program for a 16f876 ive got a lcd , switches for time delays for motor & i want a tempeture readout on lcd (ive read about readad) at the moment ive got lcd working and ports are working for switches and show on lcd
    i am very stuck with the delays on the switches

    if i have

    IF SW0 ON THEN 'switch for delay time
    locate 1,5
    print "02 Hrs" ' shows 2hrs on lcd
    'gosub motor  <------------------------STUCK ON THIS
    end if

    'other inputs here
    'blah

    sub motor
    set motor1 on
    wait 1 sec
    set motor1 off
    wait 2 hrs <----------STUCK On THIS
    return

    if i did something like the above then it would  the program would wait 2 hours before continunig and it would not monitor other inputs etc... true
    any ideas please

     
    • Nobody/Anonymous

      Here is my code so far the lcd works in pic sim ide
      but if i call sub with delay 2 hrs stops how can i get around this part
      this is for my garden pond and i hope to learn as i go along (yes i have done leds and etc before and read help file)
      please any ideas

      '---------------------- Fish Feeder and monitor----------------
      'check ldr if night wait for day then start selected (switched) time delay for hours
      'to feed fish 2 hrs, 3 hrs, 5 hrs, 7 hrs or manual  Water temp(thermistor), water level if water to
      'low (min) then turn on relay when water high (max) turn relay Off
      'the above is shown on Lcd

      '******************************************************************************************************************
      '***      THE CHIP MODEL & SETTINGS
      '******************************************************************************************************************
      #chip 16F876, 20

      'LDR to detect if day or night for timer dont want to feed at night
      #define LDR PORTA.0 'LDR ADC
      'thermistor for temp
      #define Ther PORTA.1 ' thermistor for temp ADC
      'Water level
      #define watermin PORTA.2 'ADC Probe in water to messure water min level turn ON relay 
      #define watermin PORTA.2 'ADC Probe in water to messure water max level turn OFF relay

      'Feed Time Switch Settings
      #define SW0 PORTC.0 ' 2 hrs
      #define SW1 PORTC.1 ' 3 hrs
      #define SW2 PORTC.2 ' 5 hrs
      #define SW3 PORTC.3 ' 7 hrs 
      #define SWMAN PORTC.4 ' MANUAL 

      'feed motors
      #define motor0 PORTC.5 'uln2003a to motor 0  / relay
      #define motor1 PORTC.6 'uln2003a motor 1 / relay
      #define motor2 PORTC.7 'uln2003a motor 2 /relay

      'LCD connection settings
      #define LCD_IO 4 
      #define LCD_DB4 PORTB.4 
      #define LCD_DB5 PORTB.5 
      #define LCD_DB6 PORTB.6 
      #define LCD_DB7 PORTB.7 
      #define LCD_RS PORTB.0 
      #define LCD_RW PORTB.1
      #define LCD_Enable PORTB.2

      main:
      locate 0,3
      Print "FISH POND"
      locate 1,0
      PRINT "25c"  ' tempeture reading when finished  Need Table
      locate 1,13
      PRINT "Day" ' day or night dont really need here could be water level instead
      ' -----if statements for time switches might be better as select case-----------
      IF SW0 ON THEN
      locate 1,5
      print "02 Hrs" 'lcd print time delay for feed motors
      'and gosub motor1
      end if

      IF SW1 ON THEN
      locate 1,5
      print "03 Hrs"'lcd print time delay for feed motors
      end if

      IF SW2 ON THEN
      locate 1,5
      print "05 Hrs" 'lcd print time delay for feed motors
      end if

      IF SW3 ON THEN
      locate 1,5
      print "07 Hrs"  'lcd print time delay for feed motors
      end if

      IF SWMAN ON THEN
      locate 1,5
      print "MANUAL" 'lcd print Manual for feed motors
      end if

      Goto Main

      sub motor0
      set mo0 on
      wait 1 sec
      set mo0 off
      wait 1 hrs
      return

       
    • Hugh Considine

      Hugh Considine - 2008-06-02

      Best way to make this work would be to have it delay for a shorter amount of time, say 1 minute, and then increment a counter. Only do something if the counter reads 60, 120, or whatever other value you need.

      To do this, get rid of the delay from the Motor0 sub. Add a shorter delay inside the loop, along with a line to increment a counter. Clear the counter at the start of the loop, and when the motor has run. Use an if to call Motor0 if the counter is the right value.

      If you use a word variable for the counter, you could possibly even use a 1 second delay. It'd be a bit hard to get the whole program to run in exactly 1 second, though. A 10 second delay should be pretty easy, and it'll be able to count up to 655350 seconds (10922 minutes, or 182 hours).

       
    • Nobody/Anonymous

      Thank you for reply
      how silly of me why did'nt i think of that using a counter.
      iam having problems at the minute with even getting the pic see an input work fine in simulator but on the breadboard it just goes thou the program like iam making the switch ive tried sw = 1 then goto blah  else sw = 0, sw= on then goto blah else sw=  off etc and i have debounce's inplace
      dont know if its the pic gone mad but ive tried 2 of them
      thanks again for relpy

       
    • kent_twt4

      kent_twt4 - 2008-06-03

      You should use "Dir PortC.x In" after your PortC.x defines, or possibly Dir PortC b'00011111'.  GCBasic initializes the ports as digital.  The buttons could also be in an undetermined state.  If you can, move your buttons around to PortB so you can use the software PortB pullups.  A simple statement during your set up like "Set NOT_RBPU Off" or "NOT_RBPU = 0" will get the pullups going.  Then just check which switch is off.

       
    • Nobody/Anonymous

      thanks for reply
      quote
      "GCBasic initializes the ports as digital." if the switch is on RA0 or RA1 would that also apply as are these analog ???? i dont know iam just asking
      i dir the inputs but do i need to dir an lcd or does gbasic do it automatic?
      thanks for reply

       
    • kent_twt4

      kent_twt4 - 2008-06-03

      Yes you could put the buttons on RA0, RA1 etc., its better to use other pins in case you have a future need for the a-d.  As a general rule, use the dir(Tris bits) command as appropriate, and not rely on GCBasic default settings.  GCBasic handles the Dir(Tris bits) when using the LCD module, so no need to specify those.

       
    • Nobody/Anonymous

      You have been very helpful thank you
      but i cant understand am i doing something wrong here in the pic simulator ide this works fine no probs but on a breadboard it dont seem to wait for key1 (switch) to be pressed it just goes crazy maybe bad chip! i wired it Ra0(key1)---1k resistors---switch---gnd and the same for key2 and tried even 10k resistors

      #chip 16F628A, 4
      #config INTOSC_OSC_NOCLKOUT, MCLRE_OFF
      #define ADOff

      #define StartUpDelay 150 ms

      #define LCD_IO 4 
      #define LCD_DB4 PORTB.4 
      #define LCD_DB5 PORTB.5 
      #define LCD_DB6 PORTB.6 
      #define LCD_DB7 PORTB.7 
      #define LCD_RS PORTB.2 
      #define LCD_RW PORTB.1
      #define LCD_Enable PORTB.0

      #define key1 porta.0
      #define key2 PORTa.1

      dir key1 in ' SWITICH 1
      dir key2 in ' SWITICH 2

      Startup:
             Wait StartUpDelay

      dim dly as word

      main:

      locate 0,2
      Print "FISH POND "
      locate 1,0
      PRINT "Feed"  ' feed
      locate 1,13
      PRINT "Day" ' day or night dont really need here could be water level instead

      wait 100 ms

      if key1=1 then
      wait 100 ms
      goto time1  ' ######  goto time menu
      wait 150 ms
      end if
      'goto main

      'dly does = 0 i even commented it out and still did not wait for switch press

      if dly=1  then
      GOTO 1HR_DELAY
      end if

      if dly=2 then
      GOTO 2HR_DELAY
      end if

      if dly=3  then
      GOTO 3HR_DELAY
      end if

      if dly=4  then
      GOTO 4HR_DELAY
      end if

      goto main

      any ideas ???? thank you

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.