marC:)
Code: Select all
; This file is a basic code template for assembly code generation *
; on the PIC10F222. This file contains the basic code *
; building blocks to build upon. *
; *
; Refer to the MPASM User's Guide for additional information on *
; features of the assembler (Document DS33014). *
; *
; Refer to the respective PIC data sheet for additional *
; information on the instruction set. *
; *
;**********************************************************************
; *
; Filename: xxx.asm *
; Date: JULY 17/11 *
; File Version: Rev.A *
; *
; Author: Patrick Mitchell *
; Company: www.engineeringshock.com *
; *
; *
;**********************************************************************
; *
; Files Required: P10F222.INC *
; *
;**********************************************************************
; *
; Notes: *
; *
;**********************************************************************
list p=10F222 ; list directive to define processor
#include <p10F222.inc> ; processor specific variable definitions
__CONFIG _MCLRE_OFF & _CP_OFF & _WDT_OFF & _MCPU_OFF & _IOFSCS_4MHZ
; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.
;***** VARIABLE DEFINITIONS
TEMP_VAR UDATA
TEMP1 RES 1 ;DELAY REGISTER1
TEMP2 RES 1 ;DELAY REGISTER2
TEMP3 RES 1 ;DELAY REGISTER3
TEMP4 RES 1 ;DELAY REGISTER4
TEMP5 RES 1 ;TIMING REGISTER
TEMP6 RES 1 ;TINING REGISTER
errorlevel -302 ; suppress message 302 from list file
;**********************************************************************
ORG 0xFF ; processor reset vector
; Internal RC calibration value is placed at location 0xFF by Microchip
; as a movlw k, where the k is a literal value.
ORG 0x000 ; coding begins here
movwf OSCCAL ; update register with factory cal value
INITIALIZE
MOVLW B'1000' ; GPIO1=COMPARATOR IN - GPIO0-RELAY ACTIVATE
TRIS GPIO ; INITIALIZE
CLRF ADCON0 ; ADC DISABLE
CLRF GPIO
MOVLW B'00001000'
OPTION
CALL LOOP3
CLRF TEMP5
START:
CLRF GPIO
MOVLW B'01000001' ;analog i/p configuration
MOVWF ADCON0 ;setup GPIO,0 as ADC input
BSF ADCON0,GO ;take an ADC reading
WAITADC:
BTFSC ADCON0,GO ; poll for reading to complete
GOTO WAITADC ; if not done, keep polling
MOVLW B'00000001' ; place 01H in compare register
SUBWF ADRES,C ; compare instruction
BTFSC STATUS,C ; if ADC reading is more than 01H, a clap has been detected
GOTO NEXT ; if clap has been detected, to go NEXT routine
GOTO START ; if not, start from beginning of program
NEXT:
CALL LOOP3 ; delay
GOTO HI
;
;BCF STATUS,C ; clear STATUS flag so that we can use ADC again
;MOVLW 0XFF ; Place FFH in WREG
;MOVWF TEMP3 ; Place FFH into timing register - Will take the following steps up to 255 times (FF Hex)
NEXT2:
CALL LOOP1 ; short delay
BCF STATUS,C
MOVLW B'01000001' ; analog i/p configuration
MOVWF ADCON0 ; setup ADC
BSF ADCON0,GO ; Take an ADC reading
WAITADC2:
BTFSC ADCON0,GO ; poll for ADC reading to complete
GOTO WAITADC2 ; if not complete, poll again
MOVLW B'00000001' ; repeat same steps in earlier programming to look for second clap
SUBWF ADRES,C
BTFSC STATUS,C
GOTO HI ; if second clap is detected, to go step that turns on relay
DECFSZ TEMP3 ; if not, decrement countdown register and compare with 0
GOTO NEXT2 ; if timing register is not 0, repeat ADC reading
GOTO START ; if timing register = 0, restart program from scratch
OFF:
; the following set of routines follow the same programming as the first half of the program, only
; this time, we're looking for two claps that will turn the relay off
MOVLW B'01000001' ;analog i/p configuration
MOVWF ADCON0
BSF ADCON0,GO
WAITADC3:
BTFSC ADCON0,GO
GOTO WAITADC3
MOVLW B'00000001'
SUBWF ADRES,C
BTFSC STATUS,C
GOTO NEXT3
GOTO OFF
NEXT3:
CALL LOOP3
BCF STATUS,C
MOVLW 0XFF
MOVWF TEMP3
NEXT4:
CALL LOOP1
BCF STATUS,C
MOVLW B'01000001' ;analog i/p configuration
MOVWF ADCON0
BSF ADCON0,GO
WAITADC4:
BTFSC ADCON0,GO
GOTO WAITADC4
MOVLW B'00000001'
SUBWF ADRES,C
BTFSC STATUS,C
GOTO LO
DECFSZ TEMP3
GOTO NEXT4
GOTO OFF
HI:
; this routine turns the relay on
BSF GPIO,1
CALL LOOP3
GOTO OFF
LO:
; this routine turns the relay off
BCF GPIO,1
CALL LOOP1
GOTO INITIALIZE ; resets system to start from scratch
; *** LOOP1/2 Routines work together as a short delay routine
LOOP1:
MOVLW 0X00
MOVWF TEMP1
MOVLW 0X02
MOVWF TEMP2
LOOP2:
DECFSZ TEMP1
GOTO LOOP2
DECFSZ TEMP2
GOTO LOOP2
RETURN
; LOOP3/4 work together as a long delay routine
LOOP3:
MOVLW 0X00
MOVWF TEMP1
MOVLW 0X30
MOVWF TEMP2
LOOP4:
DECFSZ TEMP1
GOTO LOOP4
DECFSZ TEMP2
GOTO LOOP4
RETURN
END
Code: Select all