Urgent!

jpanhalt

Joined Jan 18, 2008
11,087
Code:
    list      p=10F206            ; list directive to define processor
    #include <p10F206.inc>        ; processor specific variable definitions

    __CONFIG   _MCLRE_OFF & _CP_OFF & _WDT_OFF

; '__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
delay1    equ 0x08
delay2    equ    0x09    ;assign memory locations for variables
currnote    equ    0x0A
duration    equ    0x0B
tone        equ    0x0C
notedata    equ    0x0D
durationindex    equ    0x0E
toneindex    equ    0x0F
testend    equ    0x10
testrest    equ    0x11







;**********************************************************************
RESET_VECTOR    CODE   0x1FF      ; processor reset vector

; Internal RC calibration value is placed at location 0x1FF by Microchip
; as a movlw k, where the k is a literal value.
   
MAIN    CODE    0x000
    movwf   OSCCAL          ;update register with factory cal value 
    bcf        OSCCAL,FOSC4    ;oscillator output to GP2 disabled
    movlw    b'00010111'        ;wake on pin change and weak pullups enabled,
    OPTION                    ;timer transition on internal clock, assign prescaler to timer, prescaler value 1:256
    bcf        CMCON0,CMPON    ;comparator off
    movlw    b'00001000'
    tris    GPIO            ;set GP3 input, GP0-GP2 outputs
    movlw    b'00000000'
    movwf    GPIO            ;clear output buffer
   
detectbutton
    btfsc    GPIO,3            ;button pushed? (GP3 low?)
    sleep                    ;no button go to sleep
    movlw     0x00            ;button pushed-reset note pointer to 0
    movwf    currnote                   

nextnote   
    call    getnote            ;get a note to play
    call    decode            ;decode duration and tone data
    goto    nextnote

getnote
    movf     currnote,w        ;current note pointer to W
    call    songtable       
    movwf    notedata
    movwf    testend
    incf     testend
    decfsz    testend            ;is notedata=0 (testend=1)(end of song marker)?
    goto    continue        ;song not over
    goto    detectbutton    ;song is over-check the button
continue   
    incf     currnote        ;increment note counter
    retlw    0x00           

decode
    movf    notedata,w        ;notedata to register w :dddttttt
    movwf    tone            ;notedata to tone
    movwf    duration        ;notedata to duration
    movlw    b'00011111'       
    andwf    tone,f            ;clear bits 7:5 of tone: 000ttttt
    movlw    b'11100000'
    andwf    duration,f        ;clear bits 4:0 of duration: ddd00000
    swapf    duration,f        ;move bits 7:4 to 3:0 and 3:0 to 7:4: 0000ddd0
    rrf        duration,f        ;rotate right from carry: c0000ddd
    bcf        duration,7        ;clear bit from carry (just in case): 00000ddd
    movf    duration,w
    call    durationtable
    movwf    durationindex
    movf    tone,w
    call    tonetable
    movwf    toneindex


play
    clrf    TMR0            ;reset timer
    incf    toneindex,w        ;is toneindex=0? (rest)
    movwf    testrest        ;same as is testrest=1
    decfsz    testrest
    goto    toneloop        ;not a rest
    movlw    d'200'            ;a rest
    movwf    toneindex        ;load a value for inner delay loop
    goto    restloop       
restloop
    bcf        GPIO,2            ;GP2 goes low
    call    delay
    btfss    TMR0,7            ;check timer MSB
    goto    restloop        ;no timer yet
    bcf        TMR0,7            ;timer detected clear TMR0 MSB
    decfsz    durationindex,F    ;decrement durationindex
    goto     restloop        ;not done yet
    retlw    0x00            ;done
toneloop                    ;start tone generation
    bsf        GPIO,2            ;GP2 goes high
    call     delay
    btfss    TMR0,7            ;check timer MSB
    goto    halfcycle        ;no timer yet
    bcf        TMR0,7            ;timer detected, clear TMR0 MSB
    decfsz    durationindex,F    ;decrement durationindex
    goto     halfcycle        ;not done yet
    retlw    0x00            ;done
halfcycle
    bcf        GPIO,2            ;GP2 goes low
    call    delay
    btfss    TMR0,7            ;check timer MSB
    goto    toneloop        ;no timer yet
    bcf        TMR0,7            ;timer detected clear TMR0 MSB
    decfsz    durationindex,F    ;decrement durationindex
    goto     toneloop        ;not done yet
    retlw    0x00            ;done
delay
        movlw    d'5'                ;load delay1 counter
        movwf    delay1
delay_loop1
        movf    toneindex,w            ;load delay2 counter
        movwf    delay2
        decfsz    delay1,F            ;decrement delay1 until zero (outer loop of 1 deep nested loop)
        goto    delay_loop2            ;goto nested inner loop
        retlw    0x00                ;return from the call
delay_loop2
        decfsz    delay2,F            ;decrement delay2 until zero (inner loop of 1 deep nested loop)
        goto    delay_loop2            ;not done decrementing. Stay in inner loop.
        goto    delay_loop1            ;done decrementing. Return to outer loop.


durationtable
    addwf    PCL,f
    retlw    0x1                        ;000=1/64 note
    retlw    0x2                        ;001=1/32 note
    retlw    0x4                        ;010=1/16 note
    retlw    0x8                        ;011=1/8 note
    retlw    0x10                    ;100=1/4 note
    retlw    0x20                    ;101=1/2 note
    retlw    0x40                    ;110=whole note
    retlw    0x80                    ;111=2 whole notes

tonetable
    addwf    PCL,f
    retlw    d'0'             ;00000=rest-no tone
    retlw    d'222'        ;00001=F#3/G3b
    retlw    d'210'        ;00010=G3
    retlw    d'198'        ;00011=G3#/A4b
    retlw    d'186'        ;00100=A4  <---------A220
    retlw    d'176'        ;00101=A4#/B4b
    retlw    d'166'        ;00110=B4
    retlw    d'156'        ;00111=C4
    retlw    d'147'        ;01000=C4#/D4b
    retlw    d'139'        ;01001=D4
    retlw    d'131'        ;01010=D4#/E4b
    retlw    d'123'        ;01011=E4
    retlw    d'116'        ;01100=F4
    retlw    d'110'        ;01101=F4#/G4b
    retlw    d'103'        ;01110=G4
    retlw    d'97'        ;01111=G4#/A5b
    retlw    d'92'        ;10000=A5  <----------A440
    retlw    d'86'        ;10001=A5#/B5b
    retlw    d'81'        ;10010=B5
    retlw    d'77'        ;10011=C5
    retlw    d'72'        ;10100=C5#/D5b
    retlw    d'68'        ;10101=D5
    retlw    d'64'        ;10110=D5#/E5b
    retlw    d'60'        ;10111=E5
    retlw    d'57'        ;11000=F5
    retlw    d'53'        ;11001=F5#/G5b
    retlw    d'50'        ;11010=G5
    retlw    d'47'        ;11011=G5#/A6b
    retlw    d'44'        ;11100=A6  <---------A880
    retlw    d'42'        ;11101=A6#/B6b
    retlw    d'39'        ;11110=B6
    retlw    d'37'        ;11111=C6

songtable
        addwf     PCL,f                ;add offset to program counter
            retlw   b'10001110'    ;G4/4
            retlw   b'10010011'    ;C5/4
            retlw   b'01100000'    ;rest/8
            retlw   b'01100110'    ;B4/8
            retlw   b'10000100'    ;A4/4
            retlw   b'10010011'    ;C5/4
            retlw   b'10000110'    ;B4/4
            retlw   b'10000100'    ;A4/4
            retlw   b'10001110'    ;G4/4
            retlw   b'10010011'    ;C5/4
            retlw   b'10010101'    ;D5/4
            retlw   b'10000110'    ;B4/4
            retlw   b'10000100'    ;A4/4
            retlw   b'10001110'    ;G4/4
            retlw   b'10110011'    ;C5/2
            retlw   b'10000000'    ;rest/4
            retlw   b'10010111'    ;E5/4
            retlw   b'10010111'    ;E5/4
            retlw   b'01100000'    ;rest/8
            retlw   b'01100110'    ;B4/8
            retlw   b'10000110'    ;B4/4
            retlw   b'10010101'    ;D5/4
            retlw   b'10010011'    ;C5/4
            retlw   b'10000110'    ;B4/4
            retlw   b'10000100'    ;A4/4
            retlw   b'01100110'    ;B4/8
            retlw   b'01110011'    ;C5/8
            retlw   b'10010101'    ;D5/4
            retlw   b'10000100'    ;A4/4
            retlw   b'10010111'    ;E5/4
            retlw   b'10010110'    ;D#5/4
            retlw   b'10110101'    ;D5/2
            retlw   b'10000000'    ;rest/4
            retlw   b'10001110'    ;G4/4
            retlw   b'10010011'    ;C5/4
            retlw   b'01100000'    ;rest/8
            retlw   b'01100110'    ;B4/8
            retlw   b'10000100'    ;A4/4
            retlw   b'10010011'    ;C5/4
            retlw   b'10000110'    ;B4/4
            retlw   b'10000100'    ;A4/4
            retlw   b'10001110'    ;G4/4
            retlw   b'10010011'    ;C5/4
            retlw   b'10010101'    ;D5/4
            retlw   b'10010011'    ;C5/4
            retlw   b'10010101'    ;D5/4
            retlw   b'10010110'    ;D#5/4
            retlw   b'10110111'    ;E5/2
            retlw   b'10000000'    ;rest/4
            retlw   b'10010011'    ;C5/4
            retlw   b'10010011'    ;C5/4
            retlw   b'01100000'    ;rest/8
            retlw   b'01110011'    ;C5/8
            retlw   b'10010101'    ;D5/4
            retlw   b'10010011'    ;C5/4
            retlw   b'10010111'    ;E5/4
            retlw   b'01100000'    ;rest/8
            retlw   b'01110011'    ;C5/8
            retlw   b'10011000'    ;F5/4
            retlw   b'10010111'    ;E5/4
            retlw   b'10110111'    ;E5/2
            retlw   b'10110101'    ;D5/2
            retlw   b'10110011'    ;C5/2
            retlw   b'11000000'    ;rest/1

        retlw    b'00000000'            ;END OF SONG (1/64 REST) 
           
   
    END                       ; directive 'end of program'
I want an a capella rendition from you on YouTube.

John

PS: code is not mine
 

djsfantasi

Joined Apr 11, 2010
9,155
HELP!!!

I have to write a program to do something and it doesn't work.

What's wrong?

Please post correct code.

I need it NOW!

Assignment is due in fifteen minutes.
Probably the grand prize winner in the clueless category! The clincher is the line "...due in fifteen minutes."
 

#12

Joined Nov 30, 2010
18,224
We already have 2 or 3 of these today. Probably what stimulated WBahn to have a rant.
(and I'm not pretending I don't have an occasional rant.)
 

Thread Starter

WBahn

Joined Mar 31, 2012
29,932
We already have 2 or 3 of these today. Probably what stimulated WBahn to have a rant.
(and I'm not pretending I don't have an occasional rant.)
Yep. I figured it was rant here or rant there -- because there WAS going to be a rant! :D
 

cmartinez

Joined Jan 17, 2007
8,212
The nine-nine-oners?

Let me guess, they'll be here in sixteen minutes.
Yeah... I didn't know what else to call them... we don't have a 911 system down here where I live...
wait.. I just realized I said 991 instead of 911, :confused: I'm so glad I've never had an emergency while visiting the States! :D
 

killivolt

Joined Jan 10, 2010
835
HELP!!!

I have to write a program to do something and it doesn't work.

What's wrong?

Please post correct code.

I need it NOW!

Assignment is due in fifteen minutes.
They have an app for that:rolleyes:

The Panic Code app.

Every script and construct ever written; user beware. Your file size may be a bit or two large.

Optimization not included.:p

kv
 
Last edited:
Top