Easy to program this flowcart in ASM?

Discussion in 'The Projects Forum' started by tigerapna, Mar 22, 2012.

  1. tigerapna

    Thread Starter Member

    Dec 14, 2011
    73
    1
    I purchased a 16F690 PICKIT 2 starter kit and wish to program it in assembler (not familar with C) with the following flow cart.

    Can this easily be done?

    DHW and RADIANT are two input switches and the PUMPs are the output.

    I am rusty with my assembler but can I improve my design anywhere on the flow chart?
     
  2. Meixner

    Member

    Sep 26, 2011
    116
    21
    Yes that looks pretty easy, should be no problem at all.
     
  3. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Should not be that hard. Your flowchart will be a good help. Will the timing be critical? From the look of your problem. I would probably have used the same approach as programming a clock. Putting the time keeping in an interrupt service routine. Maybe using a watch crystal. The 16f690 do have an internal oscillator. But it is not good for accurate timing
     
  4. tigerapna

    Thread Starter Member

    Dec 14, 2011
    73
    1
    Yes the timing accuracy isn't soo important. Anywhere from 50-70 min would be okay. are there examples anywhere for this timing ISR?
     
  5. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Your kit comes with 12 lessons in Assembler. I think a ISR is among the examples
     
  6. tigerapna

    Thread Starter Member

    Dec 14, 2011
    73
    1
    Will I still have to use an external clock to time between 50-70 minutes?
     
  7. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    The internal oscillator should be fine, most of them are specified to be better than 2% accuracy.
     
  8. tigerapna

    Thread Starter Member

    Dec 14, 2011
    73
    1
    So do I just then have a counter to count Timer0 flag and scale it to my approximate time requirements?

    What bit can be used to enable and disable the timer?
     
  9. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    All that information can be found in the datasheet. It is better that you do some research. And then post for comments.
     
  10. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    Here's some code that uses Timer0 interrupts to keep track of time. It does a bit more as well but after you've studied the datasheet you should be able to find the relevant parts.
    http://forum.allaboutcircuits.com/showpost.php?p=452093&postcount=87
    <ed> I've copied the code here, it makes more sense. </ed>
    Code ( (Unknown Language)):
    1.     list      p=16f876            ; list directive to define processor
    2.     #include <p16f876.inc>        ; processor specific variable definitions
    3.     __CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _XT_OSC & _WRT_ENABLE_ON & _LVP_OFF & _DEBUG_OFF & _CPD_OFF
    4. w_temp        EQU     0x7E        ; variable used for context saving
    5. status_temp   EQU     0x7F        ; variable used for context saving
    6.     cblock 0x20
    7.     PORTAtemp
    8.     PORTBtemp
    9.     digit1pins
    10.     digit0pins            ;right digit
    11.     LOOPCOUNT
    12.     multiplexcount
    13.     microsecondsH
    14.     microsecondsM
    15.     microsecondsL
    16.     second_flag
    17.     seconds
    18.     minute_tens
    19.     minute_units
    20.     endc
    21.  
    22.  
    23.     ORG     0x000             ; processor reset vector
    24.     clrf PCLATH
    25.       goto    init              ; go to beginning of program
    26.  
    27.  
    28.     ORG     0x004             ; interrupt vector location
    29.     movwf   w_temp            ; save off current W register contents
    30.     movf    STATUS,w          ; move status register into W register
    31.     movwf    status_temp       ; save off contents of STATUS register
    32.     bcf STATUS, RP0            ;bank 0
    33.  
    34.     movf multiplexcount, W
    35.     addwf PCL, F
    36.     goto digit1
    37.     goto digit0
    38. digit1
    39.     bcf PORTAtemp, 7            ;toggle transistor pins
    40.     bsf PORTAtemp, 6
    41.     movf digit1pins, W            ;display digit
    42.     movwf PORTB
    43.     incf multiplexcount, F
    44.     goto digitdone
    45. digit0
    46.     bcf PORTAtemp, 6            ;toggle transistor pins
    47.     bsf PORTAtemp, 7
    48.     movf digit0pins, W            ;display digit
    49.     movwf PORTB
    50.     clrf multiplexcount
    51. digitdone
    52.     movf PORTAtemp, W
    53.     movwf PORTA
    54.     bcf INTCON, TMR0IF
    55.  
    56.  
    57. ;Interrupt gets here every 1024 cycles, so subtract 1024 from a
    58. ;counter that was preset to 1000000.
    59. ;When the counter overflows add 1000000 so there are no cumulative
    60. ;errors
    61.     movlw 4
    62.     subwf microsecondsM, F        ;microseconds - 1024
    63.     btfsc STATUS, C
    64.     goto ISR_end
    65.     movf microsecondsH, W    ;check if zero
    66.     btfsc STATUS, Z
    67.     goto reset_timer            ;1 second is up
    68.     decf microsecondsH, F
    69.     goto ISR_end
    70. reset_timer        ;just add 1000000 (0x0F4240) to microseconds
    71.     movlw 0x0F  
    72.     addwf microsecondsH            ;no need to check for overflow
    73.     movlw 0x42
    74.     addwf microsecondsM            ;no need to check for overflow
    75.     movlw 0x40
    76.     addwf microsecondsL, F
    77.     btfsc STATUS, C
    78.     incf microsecondsM, F
    79.     bsf second_flag, 0
    80.  
    81.  
    82. ISR_end
    83.     movf    status_temp,w     ; retrieve copy of STATUS register
    84.     movwf    STATUS            ; restore pre-isr STATUS register contents
    85.     swapf   w_temp,f
    86.     swapf   w_temp,w          ; restore pre-isr W register contents
    87.     retfie                    ; return from interrupt
    88.  
    89. ;table is at start to avoid page crossing
    90. bcdto7seg            ;bit 2 not used here (decimal point)
    91.     addwf    PCL, F    ; Jump into the lookup table
    92.     retlw    B'11101011'    ; Return segment code for 0
    93.     retlw    B'00100001'    ; Return segment code for 1
    94.     retlw    B'10111010'    ; Return segment code for 2
    95.     retlw    B'10110011'    ; Return segment code for 3
    96.     retlw    B'01110001'    ; Return segment code for 4
    97.     retlw    B'11010011'    ; Return segment code for 5
    98.     retlw    B'11011011'    ; Return segment code for 6
    99.     retlw    B'10100001'    ; Return segment code for 7
    100.     retlw    B'11111011'    ; Return segment code for 8
    101.     retlw    B'11110011'    ; Return segment code for 9
    102.     return
    103.  
    104. init
    105.  
    106.  
    107.     MOVLW 0x20                    ;clear files
    108.     MOVWF FSR
    109. NEXT
    110.     CLRF INDF
    111.     INCF FSR, F
    112.     BTFSS FSR, 7
    113.     GOTO NEXT
    114.  
    115.     clrwdt
    116.     banksel OPTION_REG
    117.     movlw b'11000001'
    118.     movwf OPTION_REG
    119.     banksel INTCON
    120.     movlw b'10100000'        ;timer0 on interrupts on
    121.     movwf INTCON            ;prescaler 4 so interrupt every 1024 cycles
    122.  
    123.     banksel TRISA
    124.  
    125.     movlw b'00010001'
    126.     movwf TRISA
    127.     clrf TRISB
    128.  
    129.     movlw b'10001110'
    130.     movwf ADCON1
    131.     bcf STATUS,RP0                    ;bank0
    132.     movlw 0x0F
    133.     movwf microsecondsH
    134.     movlw 0x42
    135.     movwf microsecondsM
    136.     movlw 0x40
    137.     movwf microsecondsL
    138.  
    139.  
    140. main
    141.     btfss second_flag, 0
    142.     goto normal
    143.     bcf second_flag, 0
    144.     incf seconds, F            ;just increment seconds and digits to display
    145.     movlw d'60'
    146.     subwf seconds, W
    147.     btfss STATUS, Z
    148.     goto update_display
    149.     clrf seconds
    150.     incf minute_units, F        ;easier to store digits separately
    151.     movlw d'10'
    152.     subwf minute_units, W
    153.     btfss STATUS, Z
    154.     goto update_display
    155.     clrf minute_units
    156.     incf minute_tens, F
    157.  
    158. ;do some more checks to see if total time elapsed
    159.  
    160.  
    161.  
    162. update_display
    163. ;calculate digit0pins and digit1pins
    164.     movf minute_units, W
    165.     call bcdto7seg
    166.     movwf digit0pins
    167.     movf minute_tens, W
    168.     call bcdto7seg
    169.     movwf digit1pins
    170.  
    171. normal
    172. ; remaining code goes here (needs to take less than 1 second)
    173.     goto main
    174.  
    175.  
    176.         END                       ; directive 'end of program'
     
    Last edited: Mar 24, 2012
    tigerapna likes this.
Loading...