;************************************************************************** ; FILE: reactometer.asm * ; CONTENTS: Reactometer reaction timer * ; COPYRIGHT: MadLab Ltd. 2005 * ; AUTHOR: James Hutchby * ; UPDATED: 02/03/05 * ;************************************************************************** list p=10F200 include "p10f200.inc" __config _IntRC_OSC & _WDT_OFF & _MCLRE_OFF & _CP_ON __idlocs h'ED10' errorlevel -305 ;************************************************************************** ; * ; Specification * ; * ;************************************************************************** ; power-up self-test - all LEDs lit in turn (in demonstration of ; scoring system) ; button starts running lights, freezes after random period ; times player response to this and displays as score (1 to 10) ; player loses if button pressed too early or too late (all LEDs flash) ;************************************************************************** ; * ; Port assignments * ; * ;************************************************************************** GPIO_IO equ b'1111' ; port I/O status BUTTON equ 3 ; pushbutton IO_1 equ b'1100' ; LED I/O status and masks MASK_1 equ b'1110' IO_2_3 equ b'1101' MASK_2_3 equ b'1101' IO_4_5 equ b'1110' MASK_4_5 equ b'1111' IO_6_7 equ b'1011' MASK_6_7 equ b'1111' ;************************************************************************** ; * ; Constants and timings * ; * ;************************************************************************** CLOCK equ d'4000000' ; processor clock frequency in Hz SCORE equ d'10' ; maximum score RELEASE equ d'25' ; button release time MIN_REACT equ d'12' ; minimum reaction time MAX_REACT equ d'32' ; maximum reaction time ; delay periods in ms POLL_DELAY equ d'25' DEMO_DELAY equ d'225' RUNNING_DELAY equ d'75' FREEZE_DELAY equ d'250' REACT_DELAY equ d'20' SCORE_DELAY equ d'40' FLASH_DELAY equ d'200' ;************************************************************************** ; * ; File register usage * ; * ;************************************************************************** RAM set h'10' cblock RAM release ; button timer leds ; LED flags score ; score, 0 to 10 react ; reaction timer random ; random number timer ; timer work1, work2 ; work registers RAM_ endc if RAM_ > h'20' error "File register usage overflow" endif ; LED flags LED_1 equ 0 ; set if LED1 on LED_2_3 equ 1 ; set if LED2 and LED3 on LED_4_5 equ 2 ; set if LED4 and LED5 on LED_6_7 equ 3 ; set if LED6 and LED7 on ;************************************************************************** ; * ; Macros * ; * ;************************************************************************** routine macro label ; routine label endm table macro label ; define lookup table label addwf PCL endm entry macro value ; define table entry retlw value endm index macro label ; index lookup table call label endm jump macro label ; jump through table goto label endm tstw macro ; test w register iorlw 0 endm movff macro f1,f2 ; move file to file movfw f1 movwf f2 endm movlf macro n,f ; move literal to file movlw n movwf f endm ;-------------------------------------------------------------------------- ; reset vector ;-------------------------------------------------------------------------- org 0 andlw ~1 movwf OSCCAL goto main_entry ;************************************************************************** ; * ; Lookup tables * ; * ;************************************************************************** table scores entry (0<