This is a multi-part message in MIME format.
------=_NextPart_000_001C_01C0CE9A.782EEAC0
Content-Type: multipart/alternative;
        boundary="----=_NextPart_001_001D_01C0CE9A.782EEAC0"
------=_NextPart_001_001D_01C0CE9A.782EEAC0
Content-Type: text/plain;
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
----- Original Message -----=20
From: Mike Laurin=20
To: pic microcontroller discussion list=20
Sent: Thursday, April 26, 2001 9:41 PM
Subject: Help! Gotta a bug!
Sorry!! forgot the [PIC]:
Hi everyone!
I'm new to PICs and I'm working on my first "real"  project using a =
PIC16F84A.
I'm building a circuit and writing the code to create a "Simon-Says" toy =
for my daughter. (You remember: the round toy with 4 lights/buttons.  It =
makes a pattern and your supposed to repeat it).  Anyways, I'm in the =
middle of writing the code and I'm testing it as I go along.  I've run =
into a really wierd bug.  In part of the code I output 1 of 4 different =
tones/lights based on 1 of 4 different random numbers.  All of the tones =
work correctly except "tone #2" which locks up the program.  Thing is, =
the code for all 4 tones is the same!   I've tried my best to de-bug it =
but it's got me stumped!
Well, if anyone wants to take a look at it the code is attached.
Thanks.
Mike
------=_NextPart_001_001D_01C0CE9A.782EEAC0
Content-Type: text/html;
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
 
----- Original Message -----=20
Sent: Thursday, April 26, 2001 9:41 PM
Subject: Help! Gotta a bug!
 
Sorry!! forgot the [PIC]:
Hi everyone!
I'm new to PICs and I'm working on my =
first=20
"real"  project using a PIC16F84A.
I'm building a circuit and writing the =
code to=20
create a "Simon-Says" toy for my daughter. (You remember: the round toy =
with 4=20
lights/buttons.  It makes a pattern and your supposed to repeat =
it). =20
Anyways, I'm in the middle of writing the code and I'm testing it as I =
go=20
along.  I've run into a really wierd bug.  In part of the code =
I=20
output 1 of 4 different tones/lights based on 1 of 4 different =
random=20
numbers.  All of the tones work correctly except "tone #2" which =
locks up=20
the program.  Thing is, the code for all 4 tones is the =
same!  =20
I've tried my best to de-bug it but it's got me stumped!
Well, if anyone wants to take a look at =
it the code=20
is attached.
 
Thanks.
Mike
------=_NextPart_001_001D_01C0CE9A.782EEAC0--
------=_NextPart_000_001C_01C0CE9A.782EEAC0
Content-Type: application/octet-stream;
        name="simon2.asm"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
        filename="simon2.asm"
; simon2.asm
; 04.25.2001
; M. Laurin
; This program is for the "Simon-Says" Toy.
;-----------------------
        list    p=16f84A
        radix   hex
;-------------------------EQUATES
w       equ     0x00            ;
f       equ     0x01            ;
z       equ     0x02            ;
c       equ     0x00            ;
status  equ     0x03            ;
porta   equ     0x05            ;
portb   equ     0x06            ;
switch  equ     0x27            ;
nuval   equ     0x26            ;
dlay1   equ     0x25            ;
dlay2   equ     0x24            ;
seed1   equ     0x23            ;
seed2   equ     0x22            ;
rand1   equ     0x21            ;
rand2   equ     0x20            ;
ctr1    equ     0x1f            ;
ctr2    equ     0x1e            ;
ctr3    equ     0x1d            ;
ctr4    equ     0x1c            ;
count   equ     0x1b            ;
debo    equ     0x11            ;
debo2   equ     0x10            ;
        org     0x00
;---------------------------START
START   movlw   0xff            ;
        tris    porta           ; make porta inputs
        movlw   0x00            ;
        tris    portb           ; make portb outputs
        clrf    portb           ; clear outputs
        clrf    dlay1           ;
        clrf    dlay2           ;
        clrf    ctr1            ;
        clrf    ctr2            ;
        clrf    ctr3            ;
        clrf    ctr4            ;
        clrf    count           ;
        clrf    debo            ;
        clrf    debo2           ;
        clrf    seed1           ;
        clrf    seed2           ;
        clrf    rand1           ;
        clrf    rand2           ;
        clrf    nuval           ;
        clrf    switch          ;
;-----------------generate seed #
SEED    incf    seed1, f        ; press key2 to get
        call    INPT2           ; seed# low byte
        iorlw   0x00            ;
        btfss   status, 2       ;
        goto    SEED            ;
        movf    seed1, w        ; create
        xorlw   0xaa            ; seed# high byte
        movwf   seed2           ; from
        swapf   seed2, f        ; seed# low byte
        comf    seed2, f        ;
;--------------random # generater
CYCLE   clrf    switch          ;
        incf    count, f        ; cycle count
        movf    count, w        ;
        movwf   ctr1            ;
        sublw   0x10            ; if count > 16
        btfss   status, c       ; quit cycle
        goto    START           ; and start over
        movf    seed1, w        ; copy seed #s
        movwf   rand1           ; into rand registers
        movf    seed2, w        ;
        movwf   rand2           ;
MASK    btfsc   switch, 0       ; choose rand1 or rand2
        goto    MASK2           ; for next output
MASK1   movf    rand1, w        ;
        andlw   b'00000011'     ;
        movwf   portb           ; mask rand1 to output
        movwf   nuval           ; store value for tone select
        rrf     rand1, f        ; rotate byte for next output value
        goto    SOUND           ;
MASK2   movf    rand2, w        ;
        andlw   b'00000011'     ;
        movwf   portb           ; mask rand2 to output
        movwf   nuval           ; store value for tone select
        rlf     rand2, f        ; rotate byte for next output value
SOUND   call    SONIC           ;
        call    DLAY            ;
        incf    switch, f       ;
        decfsz  ctr1, f         ;
        goto    MASK            ;
NEXT    call    INPT2           ;
        iorlw   0x00            ;
        btfss   status, 2       ;
        goto    NEXT            ;
        goto    CYCLE           ; start next cycle
;---------------------CALL: SONIC
SONIC   xorlw   0x00            ; test for tone 1
        btfsc   status, 2       ;
        goto    TONE1           ;
        movf    nuval, w        ;
        xorlw   0x01            ; test for tone 2
        btfsc   status, 2       ;
        goto    TONE2           ;
        movf    nuval, w        ;
        xorlw   0x02            ; test for tone 3
        btfsc   status, 2       ;
        goto    TONE3           ;
        movf    nuval, w        ;
        xorlw   0x03            ; test for tone 4
        btfsc   status, 2       ;
        goto    TONE4           ;
NEXT1   return
;-------------------------TONE #1
TONE1   movlw   0x84            ;
        movwf   ctr3            ;
TONE1A  bsf     portb, 3        ;
        movlw   0x70            ;
        movwf   dlay1           ;
        movlw   0x05            ;
        movwf   dlay2           ;
        call    DLAY            ;
        bcf     portb, 3        ;
        movlw   0x70            ;
        movwf   dlay1           ;
        movlw   0x05            ;
        movwf   dlay2           ;
        call    DLAY            ;
        decfsz  ctr3, f         ;
        goto    TONE1A          ;
        goto    NEXT1           ;
;-------------------------TONE #2
TONE2   movlw   0xc5            ;
        movwf   ctr3            ;
TONE2A  bsf     portb, 3        ;
        movlw   0xf6            ;
        movwf   dlay1           ;
        movlw   0x03            ;
        movwf   dlay2           ;
        call    DLAY            ;
        bcf     portb, 3        ;
        movlw   0xf6            ;
        movwf   dlay1           ;
        movlw   0x03            ;
        movwf   dlay2           ;
        call    DLAY            ;
        decfsz  ctr3, f         ;
        goto    TONE2A          ;
        goto    NEXT1           ;
;-------------------------TONE #3
TONE3   movlw   0xeb            ;
        movwf   ctr3            ;
TONE3A  bsf     portb, 3        ;
        movlw   0x7d            ;
        movwf   dlay1           ;
        movlw   0x03            ;
        movwf   dlay2           ;
        call    DLAY            ;
        bcf     portb, 3        ;
        movlw   0x7d            ;
        movwf   dlay1           ;
        movlw   0x03            ;
        movwf   dlay2           ;
        call    DLAY            ;
        decfsz  ctr3, f         ;
        goto    TONE3A          ;
        decfsz  ctr4, f         ;
        goto    TONE3A          ;
        goto    NEXT1           ;
;-------------------------TONE #4
TONE4   movlw   0x28            ;
        movwf   ctr3            ;
        movlw   0x02            ;
        movwf   ctr4            ;
TONE4A  bsf     portb, 3        ;
        movlw   0xfa            ;
        movwf   dlay1           ;
        movlw   0x02            ;
        movwf   dlay2           ;
        call    DLAY            ;
        bcf     portb, 3        ;
        movlw   0xfa            ;
        movwf   dlay1           ;
        movlw   0x02            ;
        movwf   dlay2           ;
        call    DLAY            ;
        decfsz  ctr3, f         ;
        goto    TONE4A          ;
        decfsz  ctr4, f         ;
        goto    TONE4A          ;
        goto    NEXT1           ;
;---------------------CALL: DLAY
DLAY    decfsz  dlay1, f        ;
        goto DLAY               ;
        decfsz  dlay2, f        ;
        goto DLAY               ;
        return                  ;
;---------------------CALL: INPT2
INPT2   movlw   0xff            ; preset debounce
        movwf   debo            ;
        movlw   0x04            ;
        movwf   debo2           ;
CHECK   btfsc   porta,2         ; check for input
        retlw   0xff            ;
        decfsz  debo, f         ; debounce input
        goto    CHECK           ;
        decfsz  debo2, f        ;
        goto    CHECK           ;
RLSE    btfss   porta,2         ; look for release
        goto    RLSE            ;
        retlw   0x00            ;
;------------------END OF PROGRAM
        end
------=_NextPart_000_001C_01C0CE9A.782EEAC0--
--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads