Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
;//PREPROCESSOR ===============================================|---|
LIST p=12F683
include "P12F683.INC"
__CONFIG _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOD_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT
errorlevel -302
errorlevel -312
EXTERN adc
EXTERN EEPROMRW
EXTERN Interrupt_on_change
delA equ 20h ;
delB equ 21h ;
temp1 equ 22h ;
temp2 equ 23h ;
pushes equ 24h
flashes equ 25h
Stat_sav equ 26h
W_sav equ 27h
;****************************************************************
;Equates
;****************************************************************
status equ 0x03
rp1 equ 0x06
rp0 equ 0x05
status equ 03h
option_reg equ 81h
;bits
rp0 equ 5 ;bit 5 of the status register
;****************************************************************
;Beginning of program
;****************************************************************
org 0x00
cblock 0x20
d1
d2
d3
d4
count1 ; for 5 minute delay
SW1 ; Switch #1
SW2 ; Switch #2
TMR ; timer value in minutes
endc
GOTO SetUp
nop
ORG 4 ;interrupts always vector to here
GOTO isr
nop
SetUp bsf status, rp0 ;Bank 1
movlw b'10010100' ;Set TRIS GP0,1,5 out GP2,4 input
movwf TRISIO ;
bcf option_reg,7 ;pull-ups enabled
MOVLW b'00000100' ;prescaler (1:32)
movwf option_reg ;TMR0 interrupts = 6 mS apart
BCF STATUS, RP0 ;bank 0
movlw 07h ;turn off Comparator ports
movwf CMCON0 ;must be placed in bank 0
Clrf TMR0 ;clear Timer0 register
clrf flashes
incf flashes
movlw 0xA0 ;set GIE <7> and T0IE <5>
movwf INTCON ;enable Interrupts
goto Main
isr MOVWF W_sav ;first save critical registers
SWAPF STATUS,W
BCF STATUS,RP0 ;change to bank 0
MOVWF Stat_sav
btfss GPIO,2 ;test switchA
call switchPressed
BCF INTCON,T0IF
BCF INTCON,INTF
SWAPF Stat_sav,W
MOVWF STATUS ; restore status
SWAPF W_sav,F
SWAPF W_sav,W ; restore w without changing status
RETFIE
;********************
;* Delays *
;********************
_10mS movlw 0Ah
movwf delB
nop
decfsz delA,f
goto $-2
decfsz delB,f
goto $-4
retlw 00
_250mS nop
decfsz delA,f
goto $-2
decfsz delB,f
goto $-4
retlw 00
; Delay = 300 seconds
; Clock frequency = 4 MHz
; Actual delay = 300 seconds = 300000000 cycles
; Error = 0 %
DelayW movwf count1
Delay5
;299999995 cycles
movlw 0x54
movwf d1
movlw 0xA1
movwf d2
movlw 0xFD
movwf d3
movlw 0x02
movwf d4
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto $+2
decfsz d4, f
goto Delay_0
decfsz count1 ,f
goto Delay5
retlw 0x00
;****************************
;* Sub Routines *
;****************************
switchPressed
movf flashes,W
movwf temp1
movlw 06
xorwf temp1 ;if flashes=6
btfss status,Z ;z=1 if flashes=6
goto $+4
movlw 1
movwf flashes
goto $-8
bsf GPIO,0 ;turn on LED
call _250mS
bcf GPIO,0 ;turn off LED
call _250mS
decfsz temp1,f
goto $-5
incf flashes,f
btfss GPIO,2 ;loop until SwA is released
goto $-1
retlw 00
;************************
;* Main *
;************************
Main
btfss GPIO,2 ;test switchA
call SwA_Pressed
btfss GPIO,3 ;test switchB
call SwB_Pressed
goto $-4
SwA_Pressed
return
goto Main
SwB_Pressed
return
goto Main
;************************
;*EEPROM *
;************************
org 2100h
END
Wow. You did that fast. I reordered the pins in the code a little though. I will change them as you have suggested.Here is the circuit for the Simple Timer:
**broken link removed**
we are using gpio
I meant that PORTA is not in my .inc file. How can I add it or what can I substitute for it?
Here is the program so far.
You can't use the switches to invoke sleep.
All that is left to include is the low-voltage detection.
clrw EEADR ;EEPROM location 0 for flashes of LED
CBLOCK 0x21
NumH
NumL
ENDC
Init_ADC org 0x004
; Set ADCON0
movlw b'10001101'
movwf ADCON0
CALL SampleTime ;Acquisiton delay
; Set ADSEL
BANKSEL ANSEL
MOVLW b'00011000' ;Fosc 8,an3
MOVWF ANSEL ; and GP4 as analog
BANKSEL ADCON0
return
Read_ADC
bsf ADCON0, GO ;initiate conversion
btfsc ADCON0, GO
goto $-1 ;wait for ADC to finish
movf ADRESH,W
andlw 0x03
movwf NumH
BANKSEL ADRESL
movf ADRESL,W
BANKSEL ADRESH
movwf NumL ;return result in NumL and NumH
return
SampleTime nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
return
I don't have a preference or are you saying only one way will work and not the other?You have to work out if you want right or left justified.
Slightly confused about how to do this. I add another led right and use the existing one as well?You have to create an output that reads each bit in "A_Dvalue" and see what value the A/D converter has produced when the supply voltage is 10v. To do this, add a LED and 270R to pin 6 and make one LED "0" and the other "1" Bit test each bit in the file and output with a delay to read the file.