-- An alarm clock for a WOL-startable PC -- Copyright (C) 2006 Niko Kotilainen -- -- This program is free software; you can redistribute it and/or -- modify it under the terms of the GNU General Public License -- as published by the Free Software Foundation; either version 2 -- of the License, or (at your option) any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; if not, write to the Free Software -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. include 16f84_4WD include jlib include interval -- RB1 = data -- RB2 = available -- RB3 = data read -- RB4 = wake on lan -- RB5 = heartbeat -- status led legend: -- flashing slowly (toggles every 2s): -- just started, not receiving data for 5min -- on: waiting for sleep data -- off: received some, but not all sleep data -- flashing quickly (toggles every 1s): -- waiting for sleep time to end pin_b3_direction = output pin_b4_direction = output pin_b5_direction = output function read_bit return byte is -- wait for data to become available while pin_b2 == off loop while pin_b2 == off loop end loop delay_50us end loop delay_50us -- read data var byte data = 0 if pin_b1 == on then data = 1 end if -- announce data read pin_b3 = on -- wait for available-flag to go down while pin_b2 == on loop while pin_b2 == on loop end loop delay_50us end loop delay_50us -- set data-read flag down pin_b3 = off return data end function function read_byte return byte is var byte data for 8 loop data = data << 1 data = data | read_bit clear_watchdog pin_b5 = off end loop return data end function procedure wait is -- if something on parallel port -- reset the device if pin_b1 == on then delay_10ms if pin_b1 == on then option = 0b_1101_1000 while true loop end loop end if end if clear_watchdog delay_1S pin_b5 = ! pin_b5 end procedure var byte a,b,c -- 3 bytes of time data, a being the most significant forever loop pin_b3 = off pin_b4 = off pin_b5 = on -- set long timeout time for watchdog option = 0b_1101_1111 clear_watchdog -- read time to sleep a = read_byte b = read_byte c = read_byte -- wait for pc to shutdown for 90 loop if ! pin_a4 then delay_1S(2) clear_watchdog pin_b5 = ! pin_b5 end if end loop -- sleep for a loop for 256 loop for 256 loop wait end loop end loop end loop for b loop for 256 loop wait end loop end loop for c loop wait end loop -- start the pc pin_b4 = on clear_watchdog delay_500ms pin_b4 = off end loop