Advertisement
mike2545

FIsh Food Dispenser

Dec 22nd, 2013
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QBasic 11.23 KB | None | 0 0
  1. '****************************************************************
  2. '*  Name    : Fish Food Dispenser.BAS                           *
  3. '*  Author  : Mike Mummert                                      *
  4. '*  Notice  : Copyright (c) 2013                                *
  5. '*          : All Rights Reserved                               *
  6. '*  Date    : 12/22/2013                                        *
  7. '*  Version : 1.0                                               *
  8. '*  Notes   :                                                   *
  9. '*          :                                                   *
  10. '****************************************************************
  11.  INCLUDE "modedefs.bas"
  12.     include "ALLDIGITAL.pbp"
  13.     'ADCON1=1
  14.     OSCCON =$60 'clock speed
  15.     DEFINE OSC 4
  16. '______________Defines
  17.     DEFINE DEBUG_REG PORTB
  18.     DEFINE DEBUG_BIT 4
  19.     define DEBUGIN_REG PORTB
  20.     define DEBUGIN_BIT 1
  21.     DEFINE DEBUG_BAUD 9600
  22.     DEFINE DEBUG_MODE 1
  23.     define debugin_baud 9600
  24.     define debugin_mode 1
  25.      'input PortB.5
  26.    
  27.  debug "start"  
  28.     SDA var PortA.1
  29.     SCL var PortA.0
  30.    I2C_WR CON  $D0              ' I2C write address
  31. I2C_RD CON  $D1              ' I2C read address
  32.  
  33. Readtime VAR byte            ' Set/Read time flag
  34. Second VAR Byte              ' Store second value
  35. Minute VAR Byte              ' Store minute value
  36. Hour VAR Byte                ' Store hour value
  37. Day VAR Byte                 ' Store day value
  38. Date VAR Byte                ' Store date value
  39. Month VAR Byte               ' Store month value
  40. Year VAR Byte                ' Store year value
  41. daycount var byte            ' Store number of turns of the handle
  42. solenoid var PORTB.3
  43. micro_switch var PORTB.5  
  44. allow_turn var bit
  45. group_turn var byte
  46. EightOclockHour var byte
  47. NineOclockHour var byte
  48. TenOclockHour var byte
  49. ElevenOclockHour var byte
  50. TwelveOclockHour var byte
  51. OneOclockHour var byte
  52. TwoOclockHour var byte
  53. ThreeOclockHour var byte
  54. FourOclockHour var byte
  55. turns_per_hour var byte
  56. bank var byte
  57.  
  58. EightOclockHour = turns_per_Hour
  59. NineOclockHour = turns_per_Hour
  60. tenOclockHour = turns_per_Hour
  61. elevenOclockHour = turns_per_Hour
  62. twelveOclockHour = turns_per_Hour
  63. oneOclockHour = turns_per_Hour
  64. twoOclockHour = turns_per_Hour
  65. threeOclockHour = turns_per_Hour
  66. FourOclockHour = turns_per_Hour
  67. daycount =0
  68. allow_Turn = 1
  69. Group_turn = 1
  70. minutebuffer var byte
  71. minutebuffer = 2
  72. x var byte
  73. greed var byte
  74. greed = 0
  75. duration var byte
  76. greedcount var byte
  77. greedcount = 0
  78. greed_time_out var byte
  79. Duration_time_out var byte
  80. number_of_consecutive_turns var byte
  81. setup:
  82.   READ 0,turns_per_Hour
  83.   READ 1,greed_time_out
  84.   READ 2,Duration_time_out
  85.   READ 3,number_of_consecutive_turns
  86.   IF turns_per_Hour > 20 THEN turns_per_Hour = 4
  87.   IF greed_time_out > 5 THEN greed_time_out = 1
  88.   IF Duration_time_out > 5 THEN Duration_time_out = 2
  89.   IF number_of_consecutive_turns > 5 THEN number_of_consecutive_turns = 3
  90.   IF Duration_time_out >5 THEN Duration_time_out = 1
  91.   I2CWRITE SDA,SCL, I2c_WR, [0]       'get time
  92.     I2CREAD SDA,SCL, I2C_RD, [Second,Minute,Hour,Day,Date,Month,Year]
  93.    hour = 10*(hour >>4) + (hour & $0f)
  94.    IF hour = 9 THEN daycount =  turns_per_hour *1  
  95.    IF hour = 10 THEN daycount =  turns_per_hour *2
  96.    IF hour = 11 THEN daycount =  turns_per_hour *3
  97.    IF hour = 12 THEN daycount =  turns_per_hour *4
  98.    IF hour = 1 THEN daycount =  turns_per_hour *5
  99.    IF hour = 2 THEN daycount =  turns_per_hour *6
  100.    IF hour = 3 THEN daycount =  turns_per_hour *7
  101.    IF hour = 4 THEN daycount =  turns_per_hour *8
  102.  
  103. MAIN:
  104.     I2CWRITE SDA,SCL, I2c_WR, [0]       'get time
  105.     I2CREAD SDA,SCL, I2C_RD, [Second,Minute,Hour,Day,Date,Month,Year]
  106.    DEBUG CR, "time is ",HEX2 Month,"/",HEX2 Date, "/20",HEX2 Year, "    ",HEX2 Hour,":",HEX2 Minute,".",HEX2 Second,CR
  107.    hour = 10*(hour >>4) + (hour & $0f)
  108.    
  109.    debug "enter 1 to display menu",cr,cr
  110.   bank = (turns_per_hour * 9) - daycount
  111.   IF greed = number_of_consecutive_turns THEN  
  112.   debug " IN_Greed",cr
  113.   GOTO greedwait
  114.    endif
  115.   IF minute = duration + Duration_time_out THEN greed = 0
  116.    'debug "Greed = ",dec greed, cr
  117.    debug "DayCount" , dec daycount, cr
  118.    'Debug "Bank", dec bank, cr
  119.    
  120.    'pause 200
  121.    
  122.    
  123.    IF hour = 8  THEN
  124.       eightOclockHour = turns_per_hour  - daycount
  125.       allow_turn = 1
  126.     debug "eight = ", dec eightOclockHour  
  127.     IF eightOclockhour = 0 THEN allow_turn = 0
  128.     IF eightOclockHour = 255 THEN eightOclockHour = 0
  129.    ' if daycount = turns_per_hour then allow_turn = 0
  130.     'if daycount < EightOclockHour then  allow_turn = 1
  131.      
  132.      endif
  133.  
  134.   IF hour = 9 THEN
  135.     nineOclockHour = (turns_per_hour *2) - daycount
  136.     allow_turn = 1
  137.    debug "nine  = ",dec  nineOclockHour ,cr
  138.    IF nineOclockhour = 0 THEN allow_turn = 0
  139.    IF nineOclockHour = 255 THEN nineOclockHour = 0
  140.   ' if daycount = nineoclockhour then allow_turn = 0
  141.   ' if daycount < nineoclockhour then allow_turn = 1
  142.  
  143.   endif
  144.  
  145.   IF hour = 10 THEN
  146.     tenOclockHour = (turns_per_hour *3) - daycount
  147.     allow_turn = 1
  148.     debug "ten  = ", dec tenOclockHour
  149.    IF tenOclockhour = 0 THEN allow_turn = 0
  150.    IF tenOclockHour = 255 THEN tenOclockHour = 0
  151.   ' if daycount = tenoclockhour then allow_turn = 0  
  152.   ' if daycount < tenoclockhour then allow_turn = 1
  153.  
  154.   endif
  155.  
  156.   IF hour = 11 THEN
  157.     elevenOclockHour = (turns_per_hour *4) - daycount
  158.     allow_turn = 1
  159.   debug "eleven  = ", dec elevenOclockHour  
  160.   IF elevenOclockhour = 0 THEN allow_turn = 0
  161.   IF elevenOclockHour = 255 THEN elevenOclockHour = 0
  162.  ' if daycount = elevenoclockhour then allow_turn = 0  
  163.   'if daycount < elevenoclockhour then allow_turn = 1
  164.  
  165.   endif
  166.  
  167.   IF hour = 12 THEN
  168.     twelveOclockHour = (turns_per_hour *5)  - daycount
  169.     allow_turn = 1
  170.   debug "twelve = ", dec twelveOclockHour  
  171.   IF twelveOclockhour = 0 THEN allow_turn = 0
  172.   IF TwelveOclockHour = 255 THEN twelveOclockHour = 0
  173.  '' if daycount = twelveoclockhour then allow_turn = 0
  174.   'if daycount < twelveoclockhour then allow_turn = 1
  175.  
  176.   endif
  177.  
  178.   IF hour = 13 THEN
  179.     oneOclockHour = (turns_per_hour *6) - daycount
  180.     allow_turn =1
  181.   debug "one  = ", dec oneOclockHour
  182.    
  183.   IF oneOclockhour = 0 THEN allow_turn = 0
  184.   IF oneOclockHour = 255 THEN oneOclockHour = 0
  185.  ' if daycount = oneoclockhour then allow_turn = 0
  186.   'if daycount < oneoclockhour then allow_turn = 1
  187.  
  188.   endif
  189.  
  190.   IF hour = 14 THEN
  191.     twoOclockHour = (turns_per_hour*7) - daycount
  192.     allow_turn = 1
  193.   debug "two  = ", dec twoOclockHour
  194.   IF twoOclockhour = 0 THEN allow_turn = 0
  195.   IF twoOclockHour = 255 THEN twoOclockHour = 0
  196.  ' if daycount = twooclockhour then allow_turn = 0  
  197.   'if daycount < twooclockhour then allow_turn = 1
  198.  
  199.   endif
  200.  
  201.   IF hour = 15 THEN
  202.    threeOclockHour = (turns_per_hour*8 ) - daycount
  203.      allow_turn = 1
  204.    
  205.       debug "three  = ", dec threeOclockHour
  206.    IF threeOclockHour = 0 THEN   allow_turn = 0
  207.    IF threeOclockHour = 255 THEN threeOclockHour = 0
  208.   ' if daycount = threeoclockhour then allow_turn = 0
  209.   ' if daycount < threeoclockhour then allow_turn = 1
  210.  
  211.   endif
  212.  
  213.   IF hour = 16 THEN
  214.     fourOclockHour = (turns_per_hour*9)  - daycount
  215.      allow_turn =1
  216.        debug "four  = ", dec fourOclockHour  
  217.     IF fourOclockHour = 0 THEN  allow_turn = 0
  218.     IF fourOclockHour = 255 THEN fourOclockHour = 0
  219.    ' if daycount = fouroclockhour then allow_turn = 0
  220.    ' if daycount < fouroclockhour then allow_turn = 1
  221.  
  222.   endif
  223.  
  224.  IF hour => 17  THEN
  225.  allow_turn = 0
  226.  Debug "NO VEND", CR
  227.  endif
  228.  
  229.  IF hour  =< 7  THEN
  230.  allow_turn = 0
  231.  Debug "NO VEND", CR
  232.  endif
  233.  IF hour = 0 THEN daycount = 0
  234. IF allow_turn = 1 THEN high solenoid
  235. IF allow_turn = 0 THEN low solenoid
  236. IF allow_turn = 1 THEN
  237. IF micro_switch =0  THEN GOTO  inturn
  238. endif
  239.  
  240. debugin 500,main,[dec readtime] 'menu prompt
  241.  
  242. IF readtime = 1 THEN GOTO display_menu
  243.  
  244.  
  245. GOTO main  
  246.  
  247.  
  248. inturn:
  249. debug "inturn", cr
  250. 'if hour > 22 then daycount =
  251.  greed =greed + 1
  252.  duration = minute
  253.  
  254.  IF micro_switch =0 THEN daycount = daycount +1
  255.  debug dec daycount, cr, cr
  256.  
  257.  
  258. waitTillDone:
  259. IF micro_switch =0 THEN
  260. allow_turn = 1
  261. low solenoid
  262. pause 6000
  263. GOTO waitTillDone
  264. endif
  265.  
  266.  
  267.   GOTO main
  268.  '**************************************************************
  269. ' Set time subroutine
  270. '**************************************************************
  271.  
  272. Settime:
  273.  
  274.    I2CWRITE SDA,SCL, I2c_WR, [0]       'get time
  275.     I2CREAD SDA,SCL, I2C_RD, [Second,Minute,Hour,Day,Date,Month,Year]
  276.    DEBUG CR, "Enter hours (00-23): "
  277.    DEBUGIN  [HEX2 Hour]
  278.    Hour = Hour & %00111111      ' Disable century
  279.    DEBUG CR, "Enter minutes (00-59): "
  280.    DEBUGIN  [HEX2 Minute]
  281.    DEBUG CR, "Enter seconds (00-59): "
  282.    DEBUGIN  [HEX2 Second]
  283.    Second = Second & %01111111  ' Enable oscillator
  284.    debug cr, "IS The DATE ",HEX2 Month,"/",HEX2 Date, "/20",HEX2 Year, "?" , cr
  285.     debug "1 for yes, 2 for no",cr
  286.    debugin  [dec Readtime]
  287.    IF Readtime = 1 THEN
  288.    GOTO set
  289.      ELSE
  290.    DEBUG CR, "Enter day (01-07): "
  291.    DEBUGIN  [HEX2 Day]
  292.    DEBUG CR, "Enter date (01-31): "
  293.    DEBUGIN  [HEX2 Date]
  294.    DEBUG CR, "Enter month (01-12): "
  295.    DEBUGIN  [HEX2 Month]
  296.    DEBUG CR, "Enter year (00-99): "
  297.    DEBUGIN  [HEX2 Year]
  298.    endif
  299. Set:  
  300.    I2Cwrite SDA,SCL, I2C_WR, [0,Second,Minute,Hour,Day,Date,Month,Year]
  301.  
  302.    
  303.   GOTO main
  304.  
  305.  
  306.  display_menu:
  307.   ' Display menu
  308.   I2cwrite SDA,scl, I2C_WR, [0]
  309.   I2Cread SDA,scl, I2C_RD, [Second,Minute,Hour,Day,Date,Month,Year]
  310.   DEBUG CR, "time is ",HEX2 Month,"/",HEX2 Date, "/20",HEX2 Year, "    ",HEX2 Hour,":",HEX2 Minute,".",HEX2 Second,CR,CR
  311.   DEBUG "(0) set the current time.", CR
  312.   DEBUG "(1) toggle relay.", CR, CR
  313.   debug "(2) turns_per_Hour",cr, Cr
  314.   debug "(3) Time out",cr,cr
  315.   debug "(4) Turn per hour reset" ,cr,cr
  316.   debug "(5) number_of_consecutive_turns",cr ,cr
  317.   DEBUG "(9) To Exit.",CR,CR
  318.   debug "Daycount: ",dec daycount, CR,CR
  319.   ' Get input
  320.   DEBUGIN 64000,main, [dec Readtime]
  321.  
  322.   IF Readtime = 0  THEN   GOTO settime        ' Goto Display time subroutine
  323.   IF Readtime = 1  THEN   toggle solenoid
  324.  
  325.   IF readtime = 2 THEN
  326.   debug "old ", dec turns_per_Hour,cr
  327.   debug "new turns_per_Hour", cr
  328.   debugin [dec turns_per_Hour]
  329.   WRITE 0,turns_per_Hour
  330.   endif
  331.    
  332.   IF readtime = 3 THEN
  333.   debug "old greed_time_out", dec greed_time_out,cr
  334.   Debug "new greed_time_out",cr
  335.   debugin [dec greed_time_out]          
  336.   WRITE 1,greed_time_out
  337.   endif
  338.    
  339.   IF readtime = 4 THEN
  340.   debug "old Duration_time_out" , dec Duration_time_out ,cr
  341.   debug "new Duration_time_out",cr
  342.   debugin [dec Duration_time_out]
  343.   WRITE 2,Duration_time_out
  344.    endif
  345.  
  346.   IF readtime = 5 THEN
  347.   debug "old consecutive_turns" , dec number_of_consecutive_turns ,cr
  348.   debug "new consecutive_turns",cr
  349.   debugin [dec number_of_consecutive_turns]
  350.  
  351.   WRITE 2,Duration_time_out
  352.    endif
  353.  
  354.   IF readtime = 9  THEN  GOTO main              
  355.  
  356.   GOTO display_menu
  357.  
  358. greedWait:
  359.   I2CWRITE SDA,SCL, I2c_WR, [0]       'get time
  360.     I2CREAD SDA,SCL, I2C_RD, [Second,duration,Hour,Day,Date,Month,Year]
  361.    IF duration = minute + greed_time_out THEN
  362.    greed =0
  363.    high solenoid
  364.    allow_turn =1
  365.     GOTO main
  366.     endif
  367.    IF duration = 0 THEN
  368.    greed = 0
  369.    high solenoid
  370.     allow_turn =1
  371.     GOTO main
  372.     endif
  373.    GOTO greedwait
  374.   END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement