Delay my delay [pic16f690 // pickit2]

Discussion in 'Embedded Systems and Microcontrollers' started by kelvinmead, May 15, 2011.

  1. kelvinmead

    Thread Starter Member

    May 15, 2011
    30
    0
    hi, im having issues using the book pic in practice (which uses the 16f84 chip) and the chip that i got with the pickit2 the 16f690.

    now after bodging the book code (which is a million times easier to understand than the supplied "lesson" code (that leaves out minor items...) that comes with the pickit2.

    i have got the led on, and ive got it flashing, but to get the desired half a second delay in flashes ive had to call the delay routine 8 times for on and 8 times for off... this isnt useful, and is a bodge on how it is meant to be done... so my question is, how do i do this using normal integer numbers without massive duplications.

    Code ( (Unknown Language)):
    1. ;********************************************
    2.  
    3. ; EQUATES SECTION
    4.  
    5. TMR0        EQU     1                   ;means TMR0 is file 1
    6. STATUS      EQU     3                   ;STATUS is file 3
    7. PORTA       EQU     05H                 ;PORTA is file 5
    8. PORTB       EQU     06H                 ;PORTB is file 6
    9. PORTC       EQU     07H                 ;PORTC is file 7
    10. TRISA       EQU     85H                 ;TRISA (the PORTA i/o selection is file 85H
    11. TRISB       EQU     86H                 ;TRISB (the PORTB i/o selection is file 86H
    12. TRISC       EQU     87H                 ;TRISC (the PORTC i/0 selection is file 87H
    13. OPTION_REG  EQU     81H                 ;the OPTION register is file 81H
    14. ZEROBIT     EQU     2                   ;means ZEROBIT is bit 2
    15. COUNT       EQU     0CH                 ;COUNT is file 0C, a register to count events
    16.  
    17. ;********************************************
    18.  
    19. ;           LIST    P=16F690            ;PIC16F690 chip
    20. #include <p16F690.inc>                  ;PIC16F690 CHIP
    21.             ORG     0                   ;the start address is memory 0
    22.             GOTO    START               ;goto START
    23.  
    24. ;********************************************
    25.  
    26. ;CONFIGURATION BITS
    27.  
    28.                                         ;REQUIRES 2X _ _ AND PLACED IN COLOUM 2... THANKS BOOK!
    29.             __CONFIG (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOD_OFF & _IESO_OFF & _FCMEN_OFF);copied from lesson1 low pin count demo
    30.  
    31. ;********************************************
    32.  
    33. ;SUBROUTINE SECTION
    34.  
    35. ;1 Second Delay
    36. DELAY1      CLRF    TMR0                ;START TMR0
    37. LOOPA       MOVF    TMR0,W              ;read TMR0 into W
    38.             SUBLW   .255                    ;TIME-32
    39.             BTFSS   STATUS,ZEROBIT      ;check TIME-W = 0
    40.             GOTO    LOOPA               ;TIME is not = 32
    41.             RETLW   0                   ;TIME is 32, RETURN
    42.            
    43. ;0.5 second delay
    44. DELAYP5     CLRF    TMR0                ;START TMR0
    45. LOOPB       MOVF    TMR0,W              ;read TMR0 into W
    46.             SUBLW   .127                ;TIME-32
    47.             BTFSS   STATUS,ZEROBIT      ;check TIME-W = 0
    48.             GOTO    LOOPB               ;TIME is not = 16
    49.             RETLW   0                   ;TIME is 16, RETURN
    50.  
    51. ;********************************************
    52.  
    53. ;CONFIGURATION SECTION
    54.  
    55. START       ;BSF        STATUS,5            ;turns to BANK1
    56.             BSF     STATUS, RP0        
    57.             MOVLW   B'11111111'         ;sets 8 bits as input (1)
    58.             MOVWF   TRISA               ;move to PORTA
    59.             MOVLW   B'00000000'         ;sets 8 bits as output (0)
    60.             MOVWF   TRISB               ;move to PORTB
    61.             MOVLW   B'00000000'         ;sets 8 bits as output (0)
    62.             MOVWF   TRISC               ;move to PORTC
    63.             MOVLW   B'00000111'         ;prescaler is /256
    64.             MOVWF   OPTION_REG          ;TIMER is 1/32 secs
    65.             BCF     STATUS,RP0          ;return to BANK0
    66.             CLRF    PORTA               ;clears PORTA
    67.             CLRF    PORTB               ;clears PORTB
    68.             CLRF    PORTC               ;clears PORTC
    69.             CLRF    COUNT               ;clears COUNT
    70.  
    71. ;********************************************
    72.  
    73. ;Program starts now
    74.  
    75. BEGIN       BSF     STATUS,1            ;select register page 1
    76.             BCF     TRISC,0             ;make i/0 pin C0 an output             
    77.             BSF     PORTC,0             ;turn ON C0
    78.             CALL    DELAYP5             ;wait 0.5 seconds
    79.             CALL    DELAYP5             ;wait 0.5 seconds
    80.             CALL    DELAYP5             ;wait 0.5 seconds
    81.             CALL    DELAYP5             ;wait 0.5 seconds  
    82.             CALL    DELAYP5             ;wait 0.5 seconds
    83.             CALL    DELAYP5             ;wait 0.5 seconds
    84.             CALL    DELAYP5             ;wait 0.5 seconds
    85.             CALL    DELAYP5             ;wait 0.5 seconds
    86.             BCF     PORTC,0             ;turn OFF C0
    87.             CALL    DELAYP5             ;wait 0.5 seconds
    88.             CALL    DELAYP5             ;wait 0.5 seconds
    89.             CALL    DELAYP5             ;wait 0.5 seconds
    90.             CALL    DELAYP5             ;wait 0.5 seconds
    91.             CALL    DELAYP5             ;wait 0.5 seconds
    92.             CALL    DELAYP5             ;wait 0.5 seconds
    93.             CALL    DELAYP5             ;wait 0.5 seconds
    94.             CALL    DELAYP5             ;wait 0.5 seconds
    95.             BCF     STATUS,0            ;back to register page 0
    96.             BSF     PORTC,0             ;turn on LED C0
    97.             GOTO    BEGIN               ;repeat
    98.             END                         ;This must come at the end of your code
    i should be able to put a number / order the code so that tmr0 is .32 for half a second?
     
Loading...