Urgent!

Discussion in 'Off-Topic' started by WBahn, Jan 11, 2015.

  1. WBahn

    Thread Starter Moderator

    Mar 31, 2012
    17,716
    4,788
    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.
     
    Papabravo, Sinus23, absf and 3 others like this.
  2. WBahn

    Thread Starter Moderator

    Mar 31, 2012
    17,716
    4,788
    Anyone?

    Why won't anyone help me?

    I NEED this NOW!
     
    Papabravo and killivolt like this.
  3. amilton542

    Active Member

    Nov 13, 2010
    494
    64
    No name and shame? ;)
     
  4. jpanhalt

    AAC Fanatic!

    Jan 18, 2008
    5,675
    899
    Code (ASM):
    1.  
    2.  
    3.     list      p=10F206            ; list directive to define processor
    4.     #include <p10F206.inc>        ; processor specific variable definitions
    5.  
    6.     __CONFIG   _MCLRE_OFF & _CP_OFF & _WDT_OFF
    7.  
    8. ; '__CONFIG' directive is used to embed configuration word within .asm file.
    9. ; The lables following the directive are located in the respective .inc file.
    10. ; See respective data sheet for additional information on configuration word.
    11.  
    12.  
    13.  
    14.  
    15. ;***** VARIABLE DEFINITIONS
    16. TEMP_VAR    UDATA
    17. delay1    equ 0x08
    18. delay2    equ    0x09    ;assign memory locations for variables
    19. currnote    equ    0x0A
    20. duration    equ    0x0B
    21. tone        equ    0x0C
    22. notedata    equ    0x0D
    23. durationindex    equ    0x0E
    24. toneindex    equ    0x0F
    25. testend    equ    0x10
    26. testrest    equ    0x11
    27.  
    28.  
    29.  
    30.  
    31.  
    32.  
    33.  
    34. ;**********************************************************************
    35. RESET_VECTOR    CODE   0x1FF      ; processor reset vector
    36.  
    37. ; Internal RC calibration value is placed at location 0x1FF by Microchip
    38. ; as a movlw k, where the k is a literal value.
    39.    
    40. MAIN    CODE    0x000
    41.     movwf   OSCCAL          ;update register with factory cal value
    42.     bcf        OSCCAL,FOSC4    ;oscillator output to GP2 disabled
    43.     movlw    b'00010111'        ;wake on pin change and weak pullups enabled,
    44.     OPTION                    ;timer transition on internal clock, assign prescaler to timer, prescaler value 1:256
    45.     bcf        CMCON0,CMPON    ;comparator off
    46.     movlw    b'00001000'
    47.     tris    GPIO            ;set GP3 input, GP0-GP2 outputs
    48.     movlw    b'00000000'
    49.     movwf    GPIO            ;clear output buffer
    50.    
    51. detectbutton
    52.     btfsc    GPIO,3            ;button pushed? (GP3 low?)
    53.     sleep                    ;no button go to sleep
    54.     movlw     0x00            ;button pushed-reset note pointer to 0
    55.     movwf    currnote                  
    56.  
    57. nextnote  
    58.     call    getnote            ;get a note to play
    59.     call    decode            ;decode duration and tone data
    60.     goto    nextnote
    61.  
    62. getnote
    63.     movf     currnote,w        ;current note pointer to W
    64.     call    songtable      
    65.     movwf    notedata
    66.     movwf    testend
    67.     incf     testend
    68.     decfsz    testend            ;is notedata=0 (testend=1)(end of song marker)?
    69.     goto    continue        ;song not over
    70.     goto    detectbutton    ;song is over-check the button
    71. continue  
    72.     incf     currnote        ;increment note counter
    73.     retlw    0x00          
    74.  
    75. decode
    76.     movf    notedata,w        ;notedata to register w :dddttttt
    77.     movwf    tone            ;notedata to tone
    78.     movwf    duration        ;notedata to duration
    79.     movlw    b'00011111'      
    80.     andwf    tone,f            ;clear bits 7:5 of tone: 000ttttt
    81.     movlw    b'11100000'
    82.     andwf    duration,f        ;clear bits 4:0 of duration: ddd00000
    83.     swapf    duration,f        ;move bits 7:4 to 3:0 and 3:0 to 7:4: 0000ddd0
    84.     rrf        duration,f        ;rotate right from carry: c0000ddd
    85.     bcf        duration,7        ;clear bit from carry (just in case): 00000ddd
    86.     movf    duration,w
    87.     call    durationtable
    88.     movwf    durationindex
    89.     movf    tone,w
    90.     call    tonetable
    91.     movwf    toneindex
    92.  
    93.  
    94. play
    95.     clrf    TMR0            ;reset timer
    96.     incf    toneindex,w        ;is toneindex=0? (rest)
    97.     movwf    testrest        ;same as is testrest=1
    98.     decfsz    testrest
    99.     goto    toneloop        ;not a rest
    100.     movlw    d'200'            ;a rest
    101.     movwf    toneindex        ;load a value for inner delay loop
    102.     goto    restloop      
    103. restloop
    104.     bcf        GPIO,2            ;GP2 goes low
    105.     call    delay
    106.     btfss    TMR0,7            ;check timer MSB
    107.     goto    restloop        ;no timer yet
    108.     bcf        TMR0,7            ;timer detected clear TMR0 MSB
    109.     decfsz    durationindex,F    ;decrement durationindex
    110.     goto     restloop        ;not done yet
    111.     retlw    0x00            ;done
    112. toneloop                    ;start tone generation
    113.     bsf        GPIO,2            ;GP2 goes high
    114.     call     delay
    115.     btfss    TMR0,7            ;check timer MSB
    116.     goto    halfcycle        ;no timer yet
    117.     bcf        TMR0,7            ;timer detected, clear TMR0 MSB
    118.     decfsz    durationindex,F    ;decrement durationindex
    119.     goto     halfcycle        ;not done yet
    120.     retlw    0x00            ;done
    121. halfcycle
    122.     bcf        GPIO,2            ;GP2 goes low
    123.     call    delay
    124.     btfss    TMR0,7            ;check timer MSB
    125.     goto    toneloop        ;no timer yet
    126.     bcf        TMR0,7            ;timer detected clear TMR0 MSB
    127.     decfsz    durationindex,F    ;decrement durationindex
    128.     goto     toneloop        ;not done yet
    129.     retlw    0x00            ;done
    130. delay
    131.         movlw    d'5'                ;load delay1 counter
    132.         movwf    delay1
    133. delay_loop1
    134.         movf    toneindex,w            ;load delay2 counter
    135.         movwf    delay2
    136.         decfsz    delay1,F            ;decrement delay1 until zero (outer loop of 1 deep nested loop)
    137.         goto    delay_loop2            ;goto nested inner loop
    138.         retlw    0x00                ;return from the call
    139. delay_loop2
    140.         decfsz    delay2,F            ;decrement delay2 until zero (inner loop of 1 deep nested loop)
    141.         goto    delay_loop2            ;not done decrementing. Stay in inner loop.
    142.         goto    delay_loop1            ;done decrementing. Return to outer loop.
    143.  
    144.  
    145. durationtable
    146.     addwf    PCL,f
    147.     retlw    0x1                        ;000=1/64 note
    148.     retlw    0x2                        ;001=1/32 note
    149.     retlw    0x4                        ;010=1/16 note
    150.     retlw    0x8                        ;011=1/8 note
    151.     retlw    0x10                    ;100=1/4 note
    152.     retlw    0x20                    ;101=1/2 note
    153.     retlw    0x40                    ;110=whole note
    154.     retlw    0x80                    ;111=2 whole notes
    155.  
    156. tonetable
    157.     addwf    PCL,f
    158.     retlw    d'0'             ;00000=rest-no tone
    159.     retlw    d'222'        ;00001=F#3/G3b
    160.     retlw    d'210'        ;00010=G3
    161.     retlw    d'198'        ;00011=G3#/A4b
    162.     retlw    d'186'        ;00100=A4  <---------A220
    163.     retlw    d'176'        ;00101=A4#/B4b
    164.     retlw    d'166'        ;00110=B4
    165.     retlw    d'156'        ;00111=C4
    166.     retlw    d'147'        ;01000=C4#/D4b
    167.     retlw    d'139'        ;01001=D4
    168.     retlw    d'131'        ;01010=D4#/E4b
    169.     retlw    d'123'        ;01011=E4
    170.     retlw    d'116'        ;01100=F4
    171.     retlw    d'110'        ;01101=F4#/G4b
    172.     retlw    d'103'        ;01110=G4
    173.     retlw    d'97'        ;01111=G4#/A5b
    174.     retlw    d'92'        ;10000=A5  <----------A440
    175.     retlw    d'86'        ;10001=A5#/B5b
    176.     retlw    d'81'        ;10010=B5
    177.     retlw    d'77'        ;10011=C5
    178.     retlw    d'72'        ;10100=C5#/D5b
    179.     retlw    d'68'        ;10101=D5
    180.     retlw    d'64'        ;10110=D5#/E5b
    181.     retlw    d'60'        ;10111=E5
    182.     retlw    d'57'        ;11000=F5
    183.     retlw    d'53'        ;11001=F5#/G5b
    184.     retlw    d'50'        ;11010=G5
    185.     retlw    d'47'        ;11011=G5#/A6b
    186.     retlw    d'44'        ;11100=A6  <---------A880
    187.     retlw    d'42'        ;11101=A6#/B6b
    188.     retlw    d'39'        ;11110=B6
    189.     retlw    d'37'        ;11111=C6
    190.  
    191. songtable
    192.         addwf     PCL,f                ;add offset to program counter
    193.             retlw   b'10001110'    ;G4/4
    194.             retlw   b'10010011'    ;C5/4
    195.             retlw   b'01100000'    ;rest/8
    196.             retlw   b'01100110'    ;B4/8
    197.             retlw   b'10000100'    ;A4/4
    198.             retlw   b'10010011'    ;C5/4
    199.             retlw   b'10000110'    ;B4/4
    200.             retlw   b'10000100'    ;A4/4
    201.             retlw   b'10001110'    ;G4/4
    202.             retlw   b'10010011'    ;C5/4
    203.             retlw   b'10010101'    ;D5/4
    204.             retlw   b'10000110'    ;B4/4
    205.             retlw   b'10000100'    ;A4/4
    206.             retlw   b'10001110'    ;G4/4
    207.             retlw   b'10110011'    ;C5/2
    208.             retlw   b'10000000'    ;rest/4
    209.             retlw   b'10010111'    ;E5/4
    210.             retlw   b'10010111'    ;E5/4
    211.             retlw   b'01100000'    ;rest/8
    212.             retlw   b'01100110'    ;B4/8
    213.             retlw   b'10000110'    ;B4/4
    214.             retlw   b'10010101'    ;D5/4
    215.             retlw   b'10010011'    ;C5/4
    216.             retlw   b'10000110'    ;B4/4
    217.             retlw   b'10000100'    ;A4/4
    218.             retlw   b'01100110'    ;B4/8
    219.             retlw   b'01110011'    ;C5/8
    220.             retlw   b'10010101'    ;D5/4
    221.             retlw   b'10000100'    ;A4/4
    222.             retlw   b'10010111'    ;E5/4
    223.             retlw   b'10010110'    ;D#5/4
    224.             retlw   b'10110101'    ;D5/2
    225.             retlw   b'10000000'    ;rest/4
    226.             retlw   b'10001110'    ;G4/4
    227.             retlw   b'10010011'    ;C5/4
    228.             retlw   b'01100000'    ;rest/8
    229.             retlw   b'01100110'    ;B4/8
    230.             retlw   b'10000100'    ;A4/4
    231.             retlw   b'10010011'    ;C5/4
    232.             retlw   b'10000110'    ;B4/4
    233.             retlw   b'10000100'    ;A4/4
    234.             retlw   b'10001110'    ;G4/4
    235.             retlw   b'10010011'    ;C5/4
    236.             retlw   b'10010101'    ;D5/4
    237.             retlw   b'10010011'    ;C5/4
    238.             retlw   b'10010101'    ;D5/4
    239.             retlw   b'10010110'    ;D#5/4
    240.             retlw   b'10110111'    ;E5/2
    241.             retlw   b'10000000'    ;rest/4
    242.             retlw   b'10010011'    ;C5/4
    243.             retlw   b'10010011'    ;C5/4
    244.             retlw   b'01100000'    ;rest/8
    245.             retlw   b'01110011'    ;C5/8
    246.             retlw   b'10010101'    ;D5/4
    247.             retlw   b'10010011'    ;C5/4
    248.             retlw   b'10010111'    ;E5/4
    249.             retlw   b'01100000'    ;rest/8
    250.             retlw   b'01110011'    ;C5/8
    251.             retlw   b'10011000'    ;F5/4
    252.             retlw   b'10010111'    ;E5/4
    253.             retlw   b'10110111'    ;E5/2
    254.             retlw   b'10110101'    ;D5/2
    255.             retlw   b'10110011'    ;C5/2
    256.             retlw   b'11000000'    ;rest/1
    257.  
    258.         retlw    b'00000000'            ;END OF SONG (1/64 REST)
    259.            
    260.    
    261.     END                       ; directive 'end of program'
    262.  
    263.  
    I want an a capella rendition from you on YouTube.

    John

    PS: code is not mine
     
  5. Brownout

    Well-Known Member

    Jan 10, 2012
    2,375
    998
     
    killivolt, JoeJester and amilton542 like this.
  6. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    2,795
    831
    Probably the grand prize winner in the clueless category! The clincher is the line "...due in fifteen minutes."
     
  7. cmartinez

    AAC Fanatic!

    Jan 17, 2007
    3,555
    2,517
    dude... rest assured, help is on its way... just sit tight and breath in a bag 'till the nine-nine-oners get there....
     
    absf and killivolt like this.
  8. WBahn

    Thread Starter Moderator

    Mar 31, 2012
    17,716
    4,788
    The nine-nine-oners?

    Let me guess, they'll be here in sixteen minutes.
     
  9. #12

    Expert

    Nov 30, 2010
    16,257
    6,757
    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.)
     
  10. WBahn

    Thread Starter Moderator

    Mar 31, 2012
    17,716
    4,788
    Yep. I figured it was rant here or rant there -- because there WAS going to be a rant! :D
     
  11. cmartinez

    AAC Fanatic!

    Jan 17, 2007
    3,555
    2,517
    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 likes this.
  12. killivolt

    Active Member

    Jan 10, 2010
    341
    310
    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: Jan 11, 2015
  13. LDC3

    Active Member

    Apr 27, 2013
    920
    160
    I think I have a remedy.
    There's a book with the words "Don't Panic" in nice soothing letters on the cover...
     
    tshuck, Sinus23 and killivolt like this.
  14. killivolt

    Active Member

    Jan 10, 2010
    341
    310
    ROFL

    kv, Thanks I needed that.
     
    LDC3 likes this.
  15. Lestraveled

    Well-Known Member

    May 19, 2014
    1,957
    1,215
    What number do I dial for 911??
     
  16. WBahn

    Thread Starter Moderator

    Mar 31, 2012
    17,716
    4,788
    Duh! Hello! "Nine-Eleven"! You press '9' followed by '11'! :D
     
    LDC3 likes this.
  17. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,675
    2,722
    11 what?
     
  18. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,866
    988
    Incorrect. Please dial 411 and they will tell you what numbers you need to push to dial 411.
     
  19. WBahn

    Thread Starter Moderator

    Mar 31, 2012
    17,716
    4,788
    Since 911 is prime, maybe you press '1' nine-hundred eleven times.
     
  20. Lestraveled

    Well-Known Member

    May 19, 2014
    1,957
    1,215
    Well, Duh back at you. My phone does not have an "11" button, so there!!
     
Loading...