;; ;; pic pummer 05'2010 ;; ;; drive the led of a pummer with a pic. ;; ;; pic 10f200 contacts: ;; ;; pin 2 Vdd (+) of two or three AAA NiMH cells ;; pin 4 GP1 input of the solar cell (+) contact ;; with diode against Vdd ;; pin 5 GP0 LED output (+) contact ;; with 100 ohm or so against Vss ;; pin 7 Vss (-) of the accu cells and solar cell ;; ;; picture at http://bertnase.de/beam/pp.php ;; ;; have fun! ;; list #include __CONFIG _CP_OFF & _WDT_OFF & _MCLRE_OFF ;; ;; variables: ;; cblock 0x10 i j perc wp_p wp_d wms_i1 wms_i2 wms_i3 endc ;; ;; i/o defines: ;; #define LED GPIO, GP0 ;; LED output #define SOLAR GPIO, GP1 ;; SOLAR input ;; ;; program entry: ;; org 0x0000 movwf OSCCAL ;; 10f200 special ;; init movlw b'00001110' ;; GP0 for LED tris GPIO ;; pins other are input movlw b'01000000' ;; wake up on pin enabled, option ;; so solar change wakes up ;; ;; main startup: ;; main ;; switch led off, to be sure: bcf LED ;; check solar cell status: btfsc SOLAR ;; low == dark, high == light sleep ;; sleep if we charge blink_start ;; ;; start with some bright light: ;; bsf LED movlw .20 call wait_some_ms ;; ;; then dim the led: count down from 99 percent: ;; movlw .99 movwf perc l_perc movlw .25 ;; inner delay loop movwf i l_i movfw perc call wait_p decfsz i, F goto l_i ;; inner delay loop decfsz perc, F goto l_perc ;; percent loop ;; ;; now loop sometime with low 1 percent ;; movlw .50 movwf j l_j movlw .250 ;; low percent inner loop movwf i l_i2 movlw .1 call wait_p decfsz i, F goto l_i2 ;; low percent inner loop decfsz j, F goto l_j ;; low percent loop ;; ;; then some off time: ;; m_off bcf LED movlw .180 ;; wait some time... call wait_some_ms ;; goto main ;; we are done, start blinking again ;; ;; subroutine: ;; ;; light led to w = 1..99 percent for some time ;; wait_p movwf wp_p ;; wait high percent movlw .100 movwf wp_d movfw wp_p subwf wp_d, F ;; wait low percent (difference) ;; d = 100 - p: bsf LED wp_on nop decfsz wp_p, F goto wp_on ;; loop on percent bcf LED wp_off nop decfsz wp_d, F goto wp_off ;; loop off percent retlw .0 ;; ;; subroutine: ;; ;; wait w * some ms ;; not very accurate, just a delay loop. ;; wait_some_ms movwf wms_i3 wms_l3 movlw .20 movwf wms_i2 wms_l2 movlw .250 movwf wms_i1 wms_l1 nop decfsz wms_i1, F goto wms_l1 decfsz wms_i2, F goto wms_l2 decfsz wms_i3, F goto wms_l3 retlw .0 end ;; ;; blink blink ;;