;********************************************************************************** ;Software License Agreement ; ;The software supplied herewith by Erlich Industrial Development, Corp. EID, Corp. ;(the "Company") is intended and supplied to you, the Company’s customer, for use ;solely and exclusively on EID micro-base Kits and interface board products line. ;The software is owned by the Company and/or its supplier, and is protected under ;applicable copyright laws. All rights are reserved. Any use in violation of the ;foregoing restrictions may subject the user to criminal sanctions under applicable ;laws, as well as to civil liability for the breach of the terms and conditions of ;this license. ; ;THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES, WHETHER EXPRESS, ;IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF ;MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. ;THE COMPANY SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR ;CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. ;********************************************************************************** ;Filename: BEACONER.asm ;Author: Dr. R. Erlich ;Date: 2/24/08 ;Version: 3.00 ;Description: ; This firmware implements a simple state machine. In each state coresponding ; LED is iluminate ceating a beacon like efect. ; The 8 states are: ; STATE_0 = LED #1 is on all other LED's off ; STATE_1 = LED #2 is on all other LED's off ; STATE_2 = LED #3 is on all other LED's off ; STATE_3 = LED #4 is on all other LED's off ; STATE_4 = LED #5 is on all other LED's off ; STATE_5 = LED #6 is on all other LED's off ; STATE_6 = LED #7 is on all other LED's off ; STATE_7 = LED #8 is on all other LED's off ;********************************************************************************** ;Instructions On How To Use This Program ;********************************************************************************** ; Press Switch (SW) on the BEACONER-B8(tm) kit board to cycle through the eight ; LEDs (states.) ;********************************************************************************** list p=12f675 ; list directive to define processor 12F675 #include ; processor specific variable definitions errorlevel -302 ; suppress message 302 from list file ; ; Set config register for: ; Code / Memory protection off ; Brown-out detect off ; MCLR disabled (use pin for input) ; Watch Dog timer enabled (It use the same reg as Timer 0) ; Power on reset delay enabled ; Internal Clock Osc, enabled __CONFIG _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_OFF & _WDT_ON & _PWRTE_ON & _INTRC_OSC_NOCLKOUT ;************************** VARIABLE DEFINITIONS ********************************** cblock 0x20 STATE_LED ; LED state machine counter STATE_DEBOUNCE ; Button swithch debounce state counter endc ;*************************** DEFINE STATEMENTS ************************************ ; input and output definitions #define SW GPIO,3 ; toggle switch button ; define input/output designation for LEDs (what TRISIO will equal) #define TRIS_LEDS B'00001000' ; TRISIO setting for LEDS and Swithch ; All LED as outputs ("0"s), Switch Input ("1") ; define LED state (what GPIO will equal) ; '76543210' #define L1_ON B'00100000' ; L1 LED #define L2_ON B'00010111' ; L2 LED #define L3_ON B'00000010' ; L3 LED #define L4_ON B'00110101' ; L4 LED #define L5_ON B'00000100' ; L5 LED #define L6_ON B'00110011' ; L6 LED #define L7_ON B'00000001' ; L7 LED #define L8_ON B'00110110' ; L8 LED ;****************************** Start of Program ********************************** org 0x000 ; processor reset vector nop nop goto Initialize ;********************************************************************************** ; Initialize ; Initialize Special Function Registers ;********************************************************************************** Initialize call 0x3FF ; Retrieve factory calibration value bsf STATUS,RP0 ; Bank 1 movwf OSCCAL ; Update register with factory cal. value ; '76543210' movlw B'00001000' ; Set all I/O pins as outputs accept GP3 as inputs movwf TRISIO movlw B'10000100' ; Weak pullups: disabled movwf OPTION_REG ; TMR0 prescaler: 1:32 (TMR0 will ; overflow in 8.2ms) ; 1EXP-6 * 32 = 32EXP-6 , 256 * 32EXP-6 = ; 8.192EXP-3 =~8.2mS clrf ANSEL ; Disable Analog on GPIO pins clrf INTCON ; Disable all interrupts, clear all flags bcf STATUS,RP0 ; Bank 0 movlw .7 ; Turn off comparator movwf CMCON ;7 clrf GPIO ; Clear all outputs clrf TMR0 ; Clear Timer 0 clrf STATE_LED ; Clear LED state machine counter clrf STATE_DEBOUNCE ; Clear debounce state machine counter ;****************************************************************************** ; State_Machine ; Implements a state machine function that lights up the LEDs (clockwise) on ; the BEACONER-R8(tm) kit board sequentially when SW is pressed. after each ; the switch press and release STATE_LED register is incriment by one ; therefore the Progam counter go to the next state loop ;****************************************************************************** State_Machine clrwdt ; Clear Watch Dog Timer ; It use the same reg as Timer 0 call Button_Press ; Increments STATE_LED if button is pressed ; goto R_CCW_L ;Remove the Semi colnm for Rotation ;Counter ColockWise of the LEDs (CCW_L) R_CW_L movf STATE_LED, w ; Mask out the high order bits of andlw B'00000111' ; STATE_LED (therefore f = 0 to 8) addwf PCL, f ; The program clock (PCL) is incremented goto State0 ; by STATE_LED in order to go to the goto State1 ; appropiate state routine goto State2 goto State3 goto State4 goto State5 goto State6 goto State7 R_CCW_L movf STATE_LED, w ; Mask out the high order bits of andlw B'00000111' ; STATE_LED (therefore f = 0 to 8) addwf PCL, f ; The program clock (PCL) is incremented goto State7 ; by STATE_LED in order to go to the goto State6 ; appropiate state routine goto State5 goto State4 goto State3 goto State2 goto State1 goto State0 State0 ; Turns on LED 1 bsf STATUS, RP0 ; Bank 1 movlw TRIS_LEDS ; Move predefined value to TRISIO movwf TRISIO bcf STATUS, RP0 ; Bank 0 movlw L1_ON ; Move predefined value to GPIO movwf GPIO goto State_Machine ; Go back to state machine jump table State1 ; Turns on LED 2 bsf STATUS, RP0 ; Bank 1 movlw TRIS_LEDS ; Move predefined value to TRISIO movwf TRISIO bcf STATUS, RP0 ; Bank 0 movlw L2_ON ; Move predefined value to GPIO movwf GPIO goto State_Machine ; Go back to state machine jump table State2 ; Turns on LED 3 bsf STATUS, RP0 ; Bank 1 movlw TRIS_LEDS ; Move predefined value to TRISIO movwf TRISIO bcf STATUS, RP0 ; Bank 0 movlw L3_ON ; Move predefined value to GPIO movwf GPIO goto State_Machine ; Go back to state machine jump table State3 ; Turns on LED 4 bsf STATUS, RP0 ; Bank 1 movlw TRIS_LEDS ; Move predefined value to TRISIO movwf TRISIO bcf STATUS, RP0 ; Bank 0 movlw L4_ON ; Move predefined value to GPIO movwf GPIO goto State_Machine ; Go back to state machine jump table State4 ; Turns on LED 5 bsf STATUS, RP0 ; Bank 1 movlw TRIS_LEDS ; Move predefined value to TRISIO movwf TRISIO bcf STATUS, RP0 ; Bank 0 movlw L5_ON ; Move predefined value to GPIO movwf GPIO goto State_Machine ; Go back to state machine jump table State5 ; Turns on LED 6 bsf STATUS, RP0 ; Bank 1 movlw TRIS_LEDS ; Move predefined value to TRISIO movwf TRISIO bcf STATUS, RP0 ; Bank 0 movlw L6_ON ; Move predefined value to GPIO movwf GPIO goto State_Machine ; Go back to state machine jump table State6 ; Turns on LED 7 bsf STATUS, RP0 ; Bank 1 movlw TRIS_LEDS ; Move predefined value to TRISIO movwf TRISIO bcf STATUS, RP0 ; Bank 0 movlw L7_ON ; Move predefined value to GPIO movwf GPIO goto State_Machine ; Go back to state machine jump table State7 ; Turns on LED 8 bsf STATUS, RP0 ; Bank 1 movlw TRIS_LEDS ; Move predefined value to TRISIO movwf TRISIO bcf STATUS, RP0 ; Bank 0 movlw L8_ON ; Move predefined value to GPIO movwf GPIO goto State_Machine ; Go back to state machine jump table ;****************************************************************************** ; Button_Press ; Looks for button press and implements a button debounce routine. ;****************************************************************************** Button_Press movf STATE_DEBOUNCE, w ; Mask out the high order bits of andlw B'00000011' ; STATE_DEBOUNCE. addwf PCL, f goto Debounce_1 goto Debounce_2 goto Debounce_3 goto Debounce_2 ; Send to second state if noise ; corrupts debounce state counter. Debounce_1 btfsc SW ; Is Switch pushed? retlw 0 ; No, then return incf STATE_DEBOUNCE, f ; Yes, then increment both state incf STATE_LED, f ; machines. retlw 0 Debounce_2 btfss SW ; Is Switch released? retlw 0 ; No, then return clrf TMR0 ; Yes, clear Timer0 and Timer0 flag bcf INTCON, T0IF incf STATE_DEBOUNCE, f ; Increment debounce state machine retlw 0 Debounce_3 ; Switch must be high for approximately 8.2 ms before debounce state machine is ; re-initialized. btfss INTCON, T0IF ; Has 8.2 ms passed? goto Debounce_3_A ; No, then check for switch jitter clrf STATE_DEBOUNCE ; Yes, then re-initialize state machine retlw 0 Debounce_3_A btfss SW ; Is Switch low again (due to switch jitter? decf STATE_DEBOUNCE, f ; Yes, then go back to debounce state2 retlw 0 ; No, then return. org 0x330 ; Write data to memory address 330 HEX dt "ELECTRONIC BEACON PIC 12F675 BY DR R. ERLICH EID CORP. FEB. 2008" dt "THIS SOFTWARE IS PROVIDED IN AN AS IS CONDITION. " ; "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" ; ==================================================================================== ; ==================================================================================== ; End of program ; ==================================================================================== ; ==================================================================================== end ; Directive 'the end of program'