I just remembered this: (I'm not sure how I forgot it because I use it every day).
The PIC (12F675) is similar but has analog capabilities and a few other tricks like an extra timer and the ability to use an external crystal for timing but still use the internal oscillator for code execution. The 508/509 always runs code at the external crystal frequency if a crystal is used.
None of these are really necessary - I just like making things complicated.
It turns a fairly bright LED on for 10 minutes when I turn my light off so I can find my way across my room. It then waits in low power mode for 8 hours and then flashes the LED in a doomed attempt to wake me up.
It is probably a good example of some of the things you are trying to do; it uses a high accuracy crystal to keep time and senses light. It also does software PWM dimming of the LEDs in the flashing mode. All in 225 program words (147 without the table for the sine wave flashing).
Rich (BB code):list p=12F675 radix hex title "Timelapse" #include <p12f675.inc> __config _CP_OFF & _BODEN_OFF & _MCLRE_OFF & _PWRTE_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT cblock 0x20 count count2 delay16bitH ;8 hours is 0x7080 seconds = 0x3840 2 second interrupts delay16bitL sinecount sinecurrent sinecopy ADRESHcopy W_TEMP STATUS_TEMP eetemp GPIOtemp mode ;0 off 8 hours, 1 on until GP3 button, ;2 off until light off, 3 on 10 minutes ;mode 3 at power on endc org 0x2100 ;initial values for timer H and L bytes (10 seconds) de 0x00,0x0a ; ;---------------------------------------------------------------------- org 0x000 goto init org 0x004 ;interrupt goes here MOVWF W_TEMP ; Copy W to TEMP register, SWAPF STATUS, W ; Swap status to be saved into W MOVWF STATUS_TEMP ; Save status to STATUS_TEMP register ;ISR : : ; Interrupt Service Routine ;test interrupt source btfss INTCON, GPIF ;pin change, any activity change to mode 2 goto TMRinterrupt movlw 0x02 movwf mode bcf GPIO, 2 ;led off, wait for lights out goto endint TMRinterrupt btfsc mode, 0 goto mode1or3 btfsc mode, 1 goto mode2 goto mode0 mode1or3 btfss mode, 1 goto mode1 ;mode3 by elimination ;light on for 10 minutes bsf GPIOtemp, 2 ;LED on movf GPIOtemp, W movwf GPIO movlw 0x01 ;count down for 10 minutes subwf delay16bitL, F btfss STATUS, C subwf delay16bitH, F subwf delay16bitH, W btfsc STATUS, C goto endint movlw 0x01 subwf delay16bitL, W ;w=1 btfsc STATUS, C goto endint bcf GPIO, 2 ;10 minutes up turn off LED clrf mode ;mode 0, 8 hours off movlw 0x38 ;set delay = 8 hours = 0x3840 movwf delay16bitH movlw 0x40 movwf delay16bitL goto endint mode1 goto endint ;GPIO interrupt changes to mode 2 mode2 ;wait with LED off until room light turned off bcf GPIOtemp, 2 ;LED off movf GPIOtemp, W movwf GPIO bsf ADCON0, 1 ;start conversion call delay1ms ;way too long movlw 0x96 ;test brightness subwf ADRESH, W btfss STATUS, C goto endint incf mode, F movlw 01 ;10 minutes = 0x0258 sec = 0x012C x 2 sec ints movwf delay16bitH movlw 2C movwf delay16bitL goto endint mode0 ; incf mode, F bcf GPIOtemp, 2 ;LED off movf GPIOtemp, W movwf GPIO movlw 0x01 ;count down for 8 hours subwf delay16bitL, F btfss STATUS, C subwf delay16bitH, F subwf delay16bitH, W btfsc STATUS, C goto endint movlw 0x01 subwf delay16bitL, W ;w=1 btfsc STATUS, C goto endint incf mode, F ; count finished, mode 1 endint ; should configure Bank as required ; SWAPF STATUS_TEMP,W ; Swap nibbles in STATUS_TEMP register ; and place result into W MOVWF STATUS ; Move W into STATUS register ; (sets bank to original state) SWAPF W_TEMP, F ; Swap nibbles in W_TEMP and place result in W_TEMP SWAPF W_TEMP, W ; Swap nibbles in W_TEMP and place result into W ; CLRF TMR1L ; Clear Low byte, Ensures no rollover into TMR1H ; movlw 0xC0 ;set up timer1 ; movwf TMR1H ; clrf TMR1L clrf INTCON ;clr interupts bsf INTCON,PEIE ;timer1 interrupt on bsf INTCON, GPIE ;gpio change interrupt on bcf PIR1, 0 ;clr tmr1 interrupt flag retfie init ;initialise stuff here movlw B'00000111' movwf CMCON ;comparitors off movlw B'00001111' movwf T1CON ;enable timer1 external LP crystal BSF STATUS, RP0 ; Bank 1 movlw B'00010001' movwf ANSEL ;AN0 analog and Fosc/8 for 4MHz bsf PIE1, 0 ;timer1 int enabled ; BSF STATUS, RP0 ; Bank 1 clrf OPTION_REG ; movlw B'00001000' movwf IOC ; interrupt on change pin GP3 bcf STATUS, RP0 ; bank 0 movlw B'01001000' ; enable timer 1 interrupt and gpio change (not GIE yet) movwf INTCON ; CLRF TMR1L ; Clear Low byte, Ensures no rollover into TMR1H clrf TMR1H movlw 0x02 movwf mode CLRF GPIO ; Initialize GPIO by ; clearing output ; data latches BSF STATUS, RP0 ; Select Bank 1 MOVLW B'00100001' ; Value used to ; initialize data ; direction MOVWF TRISIO ; Set GP<4-1> as output, GP0 input BCF STATUS, RP0 ;bank 0 movlw B'00000001' movwf ADCON0 ;left justified, A/D on, AN0, ref VDD movlw D'75' movwf sinecount bsf INTCON, GIE ;enable interrupts, then sleep sleeploop sleep nop movlw 1 subwf mode, W btfss STATUS, Z goto sleeploop ;if mode 1 goto main main ; bsf ADCON0, 1 ;start conversion ; call delay1ms ;way too long movf sinecurrent, W movwf sinecopy bsf GPIOtemp, 2 ;LED on movf GPIOtemp, W movwf GPIO LEDon decfsz sinecopy, F goto LEDon movf sinecurrent, W movwf sinecopy bcf GPIOtemp, 2 ;LED off movf GPIOtemp, W movwf GPIO LEDoff incfsz sinecopy, F goto LEDoff decf sinecount, W btfsc STATUS, Z movlw D'75' ;reset if one (wastes 1 space in lookup) movwf sinecount movf sinecount, W call sinetable movwf sinecurrent movlw 1 subwf mode, W btfss STATUS, Z goto sleeploop ;if not mode 1 goto sleeploop goto main sinetable addwf PCL, F nop ;never going to happen retlw D'128' retlw D'139' retlw D'149' retlw D'160' retlw D'170' retlw D'180' retlw D'189' retlw D'198' retlw D'207' retlw D'215' retlw D'222' retlw D'229' retlw D'235' retlw D'241' retlw D'245' retlw D'249' retlw D'252' retlw D'254' retlw D'255' retlw D'255' retlw D'254' retlw D'253' retlw D'250' retlw D'247' retlw D'243' retlw D'238' retlw D'232' retlw D'226' retlw D'219' retlw D'211' retlw D'203' retlw D'194' retlw D'184' retlw D'175' retlw D'165' retlw D'154' retlw D'144' retlw D'133' retlw D'123' retlw D'112' retlw D'102' retlw D'91' retlw D'81' retlw D'72' retlw D'62' retlw D'53' retlw D'45' retlw D'37' retlw D'30' retlw D'24' retlw D'18' retlw D'13' retlw D'9' retlw D'6' retlw D'3' retlw D'2' retlw D'1' retlw D'1' retlw D'2' retlw D'4' retlw D'7' retlw D'11' retlw D'15' retlw D'21' retlw D'27' retlw D'34' retlw D'41' retlw D'49' retlw D'58' retlw D'67' retlw D'76' retlw D'86' retlw D'96' retlw D'107' retlw D'117' retlw D'128' delay1ms: ; movlw 0xFF movwf count loop1ms nop decfsz count,F goto loop1ms return ;delay20ms end
Wow! Thank you big time! It is the first circuit that I've seen on this thread! w00t!
What does L324 do?
I've read through this, but I can not understand it: http://www.national.com/mpf/LM/LMV324.html#Overview
oh and what language is that code written in?