;************************************************************************** ; FILE: psi-q.asm * ; CONTENTS: Psi-Q Tester * ; COPYRIGHT: MadLab Ltd. 2000 * ; AUTHOR: James Hutchby * ; UPDATED: 09/04/00 * ;************************************************************************** list p=16C56A ; list p=16F84 ifdef __16C56A include "p16c5x.inc" endif ifdef __16F84 include "p16f84.inc" endif ifdef __16C56A __config _RC_OSC & _WDT_ON & _CP_ON endif ifdef __16F84 __config _RC_OSC & _WDT_ON & _PWRTE_ON & _CP_OFF endif __idlocs h'CA10' errorlevel -305,-306 ;************************************************************************** ; * ; Specification * ; * ;************************************************************************** ; power-up self-test - all LEDs flash twice ; welcome message displayed until pushbutton pressed ; alternate flashing question marks displayed ; pushbutton selects left or right ; correct => tick, incorrect => cross ; first 30 guesses counted down, then psi-q factor displayed ; sleeps after period of inactivity, wakes when pushbutton pressed ; within 1 sigma - 67% ; within 2 sigma - 95% ; within 3 sigma - 99.8% ; within 4 sigma - 99.99% ; within 5 sigma - 100% ; serial link between two units ; master transmits left/right selection and correct/incorrect to slave ; slave displays left/right selection and correct/incorrect ; pushbutton exits slave mode ;************************************************************************** ; * ; Port assignments * ; * ;************************************************************************** PORTA_IO equ b'11111' ; port A I/O status PORTB_IO equ b'00100101' ; port B I/O status ROW1 equ 1 ; LED rows ROW2 equ 3 ROW3 equ 4 ROW4 equ 7 ROW5 equ 6 WEIGHT equ 0 ; spare bits SPARE1 equ 2 SPARE2 equ 5 #define COLUMN1 PORTA,2 ; LED columns #define COLUMN2 PORTA,3 #define COLUMN3 PORTB,0 #define COLUMN4 PORTA,1 #define COLUMN5 PORTB,2 #define COLUMN6 PORTA,0 #define COLUMN7 PORTB,5 PIXELS_MASK equ b'11011010' BUS equ 7 ; 1-wire bus BUTTON1 equ 2 ; pushbutton 1 (port A) BUTTON2 equ 2 ; pushbutton 2 (port B) ;************************************************************************** ; * ; Constants and timings * ; * ;************************************************************************** CLOCK equ d'3500000' ; processor clock frequency in Hz ifdef __16C56A PRESCALE equ b'101111' ; prescale WDT 1:128, external rising edge endif ifdef __16F84 PRESCALE equ b'10101111' ; weak pull-ups disabled endif FLIPS equ d'30' ; initial number of flips ; repeat counts WELCOME_REPEAT equ d'10' QUESTION_REPEAT equ d'250' TX_REPEAT equ d'4' ; delays in 1/100 s POLL_DELAY equ d'4' SCROLL_DELAY equ d'20' QUESTION_DELAY equ d'40' PRESSED_DELAY equ d'50' RESULT_DELAY equ d'75' HITS_DELAY equ d'125' SPIRAL_DELAY equ d'5' ; 1-wire bus timings in 100 us BUS_INTRO equ d'250' BUS_CLOCK equ d'1' BUS_DATA equ d'10' ; 1-wire bus instructions INSTR_LEFT equ b'00' ; display left selection INSTR_RIGHT equ b'01' ; display right selection INSTR_TICK equ b'10' ; display tick INSTR_CROSS equ b'11' ; display cross ;************************************************************************** ; * ; File register usage * ; * ;************************************************************************** ifdef __16C56A RAM set h'07' MAX set h'20' endif ifdef __16F84 RAM set h'0c' MAX set h'50' endif cblock RAM flags ; various flags rand_l, rand_h ; random number seed ; random seed flips:2 ; number of flips hits:2 ; number of hits pixels:7 ; LED pixels count ; scratch counter loop ; loop counter timer ; timer window:0, ndx ; message window / index pnt ; pointer mask ; bit mask instr ; instruction work1, work2, work3 ; work registers RAM_ endc if RAM_ > MAX error "File register usage overflow" endif ; flags RELEASE equ 0 ; set if waiting for pushbutton release PRESSED1 equ 1 ; set if pushbutton 1 pressed PRESSED2 equ 2 ; set if pushbutton 2 pressed LEFTRIGHT equ 3 ; left/right random selection TICKCROSS equ 4 ; correct/incorrect SPIRAL equ 5 ; spiral draw/undraw IGNORE equ 6 ; ignore serial link PRESSED_MASK equ (1< 3 leds set leds|(1<