Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '****************************************************************
- '* Name : Fish Food Dispenser.BAS *
- '* Author : Mike Mummert *
- '* Notice : Copyright (c) 2013 *
- '* : All Rights Reserved *
- '* Date : 12/22/2013 *
- '* Version : 1.0 *
- '* Notes : *
- '* : *
- '****************************************************************
- INCLUDE "modedefs.bas"
- include "ALLDIGITAL.pbp"
- 'ADCON1=1
- OSCCON =$60 'clock speed
- DEFINE OSC 4
- '______________Defines
- DEFINE DEBUG_REG PORTB
- DEFINE DEBUG_BIT 4
- define DEBUGIN_REG PORTB
- define DEBUGIN_BIT 1
- DEFINE DEBUG_BAUD 9600
- DEFINE DEBUG_MODE 1
- define debugin_baud 9600
- define debugin_mode 1
- 'input PortB.5
- debug "start"
- SDA var PortA.1
- SCL var PortA.0
- I2C_WR CON $D0 ' I2C write address
- I2C_RD CON $D1 ' I2C read address
- Readtime VAR byte ' Set/Read time flag
- Second VAR Byte ' Store second value
- Minute VAR Byte ' Store minute value
- Hour VAR Byte ' Store hour value
- Day VAR Byte ' Store day value
- Date VAR Byte ' Store date value
- Month VAR Byte ' Store month value
- Year VAR Byte ' Store year value
- daycount var byte ' Store number of turns of the handle
- solenoid var PORTB.3
- micro_switch var PORTB.5
- allow_turn var bit
- group_turn var byte
- EightOclockHour var byte
- NineOclockHour var byte
- TenOclockHour var byte
- ElevenOclockHour var byte
- TwelveOclockHour var byte
- OneOclockHour var byte
- TwoOclockHour var byte
- ThreeOclockHour var byte
- FourOclockHour var byte
- turns_per_hour var byte
- bank var byte
- EightOclockHour = turns_per_Hour
- NineOclockHour = turns_per_Hour
- tenOclockHour = turns_per_Hour
- elevenOclockHour = turns_per_Hour
- twelveOclockHour = turns_per_Hour
- oneOclockHour = turns_per_Hour
- twoOclockHour = turns_per_Hour
- threeOclockHour = turns_per_Hour
- FourOclockHour = turns_per_Hour
- daycount =0
- allow_Turn = 1
- Group_turn = 1
- minutebuffer var byte
- minutebuffer = 2
- x var byte
- greed var byte
- greed = 0
- duration var byte
- greedcount var byte
- greedcount = 0
- greed_time_out var byte
- Duration_time_out var byte
- number_of_consecutive_turns var byte
- setup:
- READ 0,turns_per_Hour
- READ 1,greed_time_out
- READ 2,Duration_time_out
- READ 3,number_of_consecutive_turns
- IF turns_per_Hour > 20 THEN turns_per_Hour = 4
- IF greed_time_out > 5 THEN greed_time_out = 1
- IF Duration_time_out > 5 THEN Duration_time_out = 2
- IF number_of_consecutive_turns > 5 THEN number_of_consecutive_turns = 3
- IF Duration_time_out >5 THEN Duration_time_out = 1
- I2CWRITE SDA,SCL, I2c_WR, [0] 'get time
- I2CREAD SDA,SCL, I2C_RD, [Second,Minute,Hour,Day,Date,Month,Year]
- hour = 10*(hour >>4) + (hour & $0f)
- IF hour = 9 THEN daycount = turns_per_hour *1
- IF hour = 10 THEN daycount = turns_per_hour *2
- IF hour = 11 THEN daycount = turns_per_hour *3
- IF hour = 12 THEN daycount = turns_per_hour *4
- IF hour = 1 THEN daycount = turns_per_hour *5
- IF hour = 2 THEN daycount = turns_per_hour *6
- IF hour = 3 THEN daycount = turns_per_hour *7
- IF hour = 4 THEN daycount = turns_per_hour *8
- MAIN:
- I2CWRITE SDA,SCL, I2c_WR, [0] 'get time
- I2CREAD SDA,SCL, I2C_RD, [Second,Minute,Hour,Day,Date,Month,Year]
- DEBUG CR, "time is ",HEX2 Month,"/",HEX2 Date, "/20",HEX2 Year, " ",HEX2 Hour,":",HEX2 Minute,".",HEX2 Second,CR
- hour = 10*(hour >>4) + (hour & $0f)
- debug "enter 1 to display menu",cr,cr
- bank = (turns_per_hour * 9) - daycount
- IF greed = number_of_consecutive_turns THEN
- debug " IN_Greed",cr
- GOTO greedwait
- endif
- IF minute = duration + Duration_time_out THEN greed = 0
- 'debug "Greed = ",dec greed, cr
- debug "DayCount" , dec daycount, cr
- 'Debug "Bank", dec bank, cr
- 'pause 200
- IF hour = 8 THEN
- eightOclockHour = turns_per_hour - daycount
- allow_turn = 1
- debug "eight = ", dec eightOclockHour
- IF eightOclockhour = 0 THEN allow_turn = 0
- IF eightOclockHour = 255 THEN eightOclockHour = 0
- ' if daycount = turns_per_hour then allow_turn = 0
- 'if daycount < EightOclockHour then allow_turn = 1
- endif
- IF hour = 9 THEN
- nineOclockHour = (turns_per_hour *2) - daycount
- allow_turn = 1
- debug "nine = ",dec nineOclockHour ,cr
- IF nineOclockhour = 0 THEN allow_turn = 0
- IF nineOclockHour = 255 THEN nineOclockHour = 0
- ' if daycount = nineoclockhour then allow_turn = 0
- ' if daycount < nineoclockhour then allow_turn = 1
- endif
- IF hour = 10 THEN
- tenOclockHour = (turns_per_hour *3) - daycount
- allow_turn = 1
- debug "ten = ", dec tenOclockHour
- IF tenOclockhour = 0 THEN allow_turn = 0
- IF tenOclockHour = 255 THEN tenOclockHour = 0
- ' if daycount = tenoclockhour then allow_turn = 0
- ' if daycount < tenoclockhour then allow_turn = 1
- endif
- IF hour = 11 THEN
- elevenOclockHour = (turns_per_hour *4) - daycount
- allow_turn = 1
- debug "eleven = ", dec elevenOclockHour
- IF elevenOclockhour = 0 THEN allow_turn = 0
- IF elevenOclockHour = 255 THEN elevenOclockHour = 0
- ' if daycount = elevenoclockhour then allow_turn = 0
- 'if daycount < elevenoclockhour then allow_turn = 1
- endif
- IF hour = 12 THEN
- twelveOclockHour = (turns_per_hour *5) - daycount
- allow_turn = 1
- debug "twelve = ", dec twelveOclockHour
- IF twelveOclockhour = 0 THEN allow_turn = 0
- IF TwelveOclockHour = 255 THEN twelveOclockHour = 0
- '' if daycount = twelveoclockhour then allow_turn = 0
- 'if daycount < twelveoclockhour then allow_turn = 1
- endif
- IF hour = 13 THEN
- oneOclockHour = (turns_per_hour *6) - daycount
- allow_turn =1
- debug "one = ", dec oneOclockHour
- IF oneOclockhour = 0 THEN allow_turn = 0
- IF oneOclockHour = 255 THEN oneOclockHour = 0
- ' if daycount = oneoclockhour then allow_turn = 0
- 'if daycount < oneoclockhour then allow_turn = 1
- endif
- IF hour = 14 THEN
- twoOclockHour = (turns_per_hour*7) - daycount
- allow_turn = 1
- debug "two = ", dec twoOclockHour
- IF twoOclockhour = 0 THEN allow_turn = 0
- IF twoOclockHour = 255 THEN twoOclockHour = 0
- ' if daycount = twooclockhour then allow_turn = 0
- 'if daycount < twooclockhour then allow_turn = 1
- endif
- IF hour = 15 THEN
- threeOclockHour = (turns_per_hour*8 ) - daycount
- allow_turn = 1
- debug "three = ", dec threeOclockHour
- IF threeOclockHour = 0 THEN allow_turn = 0
- IF threeOclockHour = 255 THEN threeOclockHour = 0
- ' if daycount = threeoclockhour then allow_turn = 0
- ' if daycount < threeoclockhour then allow_turn = 1
- endif
- IF hour = 16 THEN
- fourOclockHour = (turns_per_hour*9) - daycount
- allow_turn =1
- debug "four = ", dec fourOclockHour
- IF fourOclockHour = 0 THEN allow_turn = 0
- IF fourOclockHour = 255 THEN fourOclockHour = 0
- ' if daycount = fouroclockhour then allow_turn = 0
- ' if daycount < fouroclockhour then allow_turn = 1
- endif
- IF hour => 17 THEN
- allow_turn = 0
- Debug "NO VEND", CR
- endif
- IF hour =< 7 THEN
- allow_turn = 0
- Debug "NO VEND", CR
- endif
- IF hour = 0 THEN daycount = 0
- IF allow_turn = 1 THEN high solenoid
- IF allow_turn = 0 THEN low solenoid
- IF allow_turn = 1 THEN
- IF micro_switch =0 THEN GOTO inturn
- endif
- debugin 500,main,[dec readtime] 'menu prompt
- IF readtime = 1 THEN GOTO display_menu
- GOTO main
- inturn:
- debug "inturn", cr
- 'if hour > 22 then daycount =
- greed =greed + 1
- duration = minute
- IF micro_switch =0 THEN daycount = daycount +1
- debug dec daycount, cr, cr
- waitTillDone:
- IF micro_switch =0 THEN
- allow_turn = 1
- low solenoid
- pause 6000
- GOTO waitTillDone
- endif
- GOTO main
- '**************************************************************
- ' Set time subroutine
- '**************************************************************
- Settime:
- I2CWRITE SDA,SCL, I2c_WR, [0] 'get time
- I2CREAD SDA,SCL, I2C_RD, [Second,Minute,Hour,Day,Date,Month,Year]
- DEBUG CR, "Enter hours (00-23): "
- DEBUGIN [HEX2 Hour]
- Hour = Hour & %00111111 ' Disable century
- DEBUG CR, "Enter minutes (00-59): "
- DEBUGIN [HEX2 Minute]
- DEBUG CR, "Enter seconds (00-59): "
- DEBUGIN [HEX2 Second]
- Second = Second & %01111111 ' Enable oscillator
- debug cr, "IS The DATE ",HEX2 Month,"/",HEX2 Date, "/20",HEX2 Year, "?" , cr
- debug "1 for yes, 2 for no",cr
- debugin [dec Readtime]
- IF Readtime = 1 THEN
- GOTO set
- ELSE
- DEBUG CR, "Enter day (01-07): "
- DEBUGIN [HEX2 Day]
- DEBUG CR, "Enter date (01-31): "
- DEBUGIN [HEX2 Date]
- DEBUG CR, "Enter month (01-12): "
- DEBUGIN [HEX2 Month]
- DEBUG CR, "Enter year (00-99): "
- DEBUGIN [HEX2 Year]
- endif
- Set:
- I2Cwrite SDA,SCL, I2C_WR, [0,Second,Minute,Hour,Day,Date,Month,Year]
- GOTO main
- display_menu:
- ' Display menu
- I2cwrite SDA,scl, I2C_WR, [0]
- I2Cread SDA,scl, I2C_RD, [Second,Minute,Hour,Day,Date,Month,Year]
- DEBUG CR, "time is ",HEX2 Month,"/",HEX2 Date, "/20",HEX2 Year, " ",HEX2 Hour,":",HEX2 Minute,".",HEX2 Second,CR,CR
- DEBUG "(0) set the current time.", CR
- DEBUG "(1) toggle relay.", CR, CR
- debug "(2) turns_per_Hour",cr, Cr
- debug "(3) Time out",cr,cr
- debug "(4) Turn per hour reset" ,cr,cr
- debug "(5) number_of_consecutive_turns",cr ,cr
- DEBUG "(9) To Exit.",CR,CR
- debug "Daycount: ",dec daycount, CR,CR
- ' Get input
- DEBUGIN 64000,main, [dec Readtime]
- IF Readtime = 0 THEN GOTO settime ' Goto Display time subroutine
- IF Readtime = 1 THEN toggle solenoid
- IF readtime = 2 THEN
- debug "old ", dec turns_per_Hour,cr
- debug "new turns_per_Hour", cr
- debugin [dec turns_per_Hour]
- WRITE 0,turns_per_Hour
- endif
- IF readtime = 3 THEN
- debug "old greed_time_out", dec greed_time_out,cr
- Debug "new greed_time_out",cr
- debugin [dec greed_time_out]
- WRITE 1,greed_time_out
- endif
- IF readtime = 4 THEN
- debug "old Duration_time_out" , dec Duration_time_out ,cr
- debug "new Duration_time_out",cr
- debugin [dec Duration_time_out]
- WRITE 2,Duration_time_out
- endif
- IF readtime = 5 THEN
- debug "old consecutive_turns" , dec number_of_consecutive_turns ,cr
- debug "new consecutive_turns",cr
- debugin [dec number_of_consecutive_turns]
- WRITE 2,Duration_time_out
- endif
- IF readtime = 9 THEN GOTO main
- GOTO display_menu
- greedWait:
- I2CWRITE SDA,SCL, I2c_WR, [0] 'get time
- I2CREAD SDA,SCL, I2C_RD, [Second,duration,Hour,Day,Date,Month,Year]
- IF duration = minute + greed_time_out THEN
- greed =0
- high solenoid
- allow_turn =1
- GOTO main
- endif
- IF duration = 0 THEN
- greed = 0
- high solenoid
- allow_turn =1
- GOTO main
- endif
- GOTO greedwait
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement