PICs can do more if use others than delays instructions


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2008
    Location
    New York US
    Posts
    46

    Question PICs can do more if use others than delays instructions

    I wrote program for PIC16F84A, it is working but something tells me that it can be done by easy way.
    I appreciate your any advices that help to improve my program. Boring part is 95uSec delay when
    PIC starts to work before recognizing Start button.
    Due to my program PIC doing total delays equal 744 milliseconds per Sec so it will be great if PIC could do something different than staying in delays short periods of time such as 5 microseconds.
    I check serial set commands but they have duration more than 2 milliseconds so it does not works.
    May be someone has an ideas for that for example if PIC will be able to play music at time when
    PIC has to do delays in different ways.

    '* Notes : Target processor PIC16F84A *
    '* : Driver *
    '************************************************* ***************
    '
    DEFINE OSC 20
    define __CONFIG _CP_OFF&_WDT_OFF&_BODEN_OFF&_PWRTE_ON
    TRISA = 255 ' Set PORTA to all input
    TRISB = %00000000 ' Set all of PORTB to outputs
    CLEAR ' Clear all variables to 0
    youvar var bit
    myvar var bit
    'hisvar var bit
    hervar var bit
    wevar var bit
    pot1 con %00000100
    pot2 con %00010101
    pot3 con %00100110
    pot4 con %00110111
    pot5 con %01001000
    pot6 con %01011001
    pot7 con %01101010
    pot8 con %01111011
    pot9 con %10001100
    pot10 con %10011101
    pot11 con %10101110
    pot12 con %10111111
    pot13 con %11001110
    pot14 con %11011101
    pot15 con %11101100
    pot16 con %11111011
    pot17 con %11101010
    pot18 con %11011001
    pot19 con %11001000
    pot20 con %10110111
    pot21 con %10100110
    pot22 con %10010101
    pot23 con %10000100
    pot24 con %01110011
    pot25 con %01100010
    pot26 con %01010001
    pot27 con %01000000
    pot28 con %00110001
    pot29 con %00100010
    pot30 con %00010011
    rot1 con %11110100
    rot2 con %11100101
    rot3 con %11010110
    rot4 con %11000111
    rot5 con %10111000
    rot6 con %10101001
    rot7 con %10011010
    rot8 con %10001011
    rot9 con %01111100
    rot10 con %01101101
    rot11 con %01011110
    rot12 con %01001111
    rot13 con %00111110
    rot14 con %00101101
    rot15 con %00011100
    rot16 con %00001011
    rot17 con %00011010
    rot18 con %00101001
    rot19 con %00111000
    rot20 con %01000111
    rot21 con %01010110
    rot22 con %01100101
    rot23 con %01110100
    rot24 con %10000011
    rot25 con %10010010
    rot26 con %10100001
    rot27 con %10110000
    rot28 con %11000001
    rot29 con %11010010
    rot30 con %11100011
    sot1 con %10001000
    sot2 con %11001100
    sot3 con %01000100
    sot4 con %01100110
    sot5 con %00100010
    sot6 con %00110011
    sot7 con %00010001
    sot8 con %10011001
    Main:
    PORTB = %00000000
    myvar = PORTA.0 'Run = 1 Stop = 0
    youvar = PORTA.1 'Direct rotation = 0 Reverse = 1
    'hisvar = PORTA.2 '4 Hz two generators 1-2-3-4 5-6-7-8
    hervar = PORTA.3 '2 HZ two generators 1-2-3-4 5-6-7-8
    wevar = PORTA.4 ' ! Hz Two Generators 1-2-3-4 5-6-7-8
    if wevar = 1 then Gen1
    if hervar = 1 then Gen2
    if hisvar = 0 then sRun1
    if hisvar = 1 then sRun2
    goto main
    Gen1:
    PORTB =sot1
    PAUSE 250
    PORTB =sot2
    PAUSE 250
    PORTB =sot3
    PAUSE 250
    PORTB =sot4
    PAUSE 250
    PORTB =sot5
    PAUSE 250
    PORTB =sot6
    PAUSE 250
    PORTB =sot7
    PAUSE 250
    PORTB =sot8
    PAUSE 250
    myvar = PORTA.0
    If myvar = 0 Then main
    goto gen1

    Gen2:
    PORTB =sot1
    PAUSE 125
    PORTB =sot2
    PAUSE 125
    PORTB =sot3
    PAUSE 125
    PORTB =sot4
    PAUSE 125
    PORTB =sot5
    PAUSE 125
    PORTB =sot6
    PAUSE 125
    PORTB =sot7
    PAUSE 125
    PORTB =sot8
    PAUSE 125
    myvar = PORTA.0
    IF myvar = 0 then main
    Goto Gen2


    sRun1:
    myvar = PORTA.0 'Run = 1 Stop = 0
    youvar = PORTA.1
    if myvar = 0 then Main
    if youvar = 0 then RotateL
    goto main
    sRun2:
    myvar = PORTA.0 'Run = 1 Stop = 0
    youvar = PORTA.1
    if myvar = 0 then Main
    if youvar = 1 then RotateR
    goto main
    RotateL:
    PORTB = pot1
    PAUSEUS 5
    PORTB = pot2
    PAUSEUS 5
    PORTB = pot3
    PAUSEUS 5
    PORTB = pot4
    PAUSEUS 5
    PORTB = pot5
    PAUSEUS 5
    PORTB = pot6
    PAUSEUS 5
    PORTB = pot7
    PAUSEUS 5
    PORTB = pot8
    PAUSEUS 5
    PORTB = pot9
    PAUSEUS 5
    PORTB = pot10
    PAUSEUS 5
    PORTB = pot11
    PAUSEUS 5
    PORTB = pot12
    PAUSEUS 5
    PORTB = pot13
    PAUSEUS 5
    PORTB = pot14
    PAUSEUS 5
    PORTB = pot15
    PAUSEUS 5
    PORTB = pot16
    PAUSEUS 5
    PORTB = pot17
    PAUSEUS 5
    PORTB = pot18
    PAUSEUS 5
    PORTB = pot19
    PAUSEUS 5
    PORTB = pot20
    PAUSEUS 5
    PORTB = pot21
    PAUSEUS 5
    PORTB = pot22
    PAUSEUS 5
    PORTB = pot23
    PAUSEUS 5
    PORTB = pot24
    PAUSEUS 5
    PORTB = pot25
    PAUSEUS 5
    PORTB = pot26
    PAUSEUS 5
    PORTB = pot27
    PAUSEUS 5
    PORTB = pot28
    PAUSEUS 5
    PORTB = pot29
    PAUSEUS 5
    PORTB = pot30
    PAUSEUS 5
    myvar = PORTA.0
    if myvar = 0 then Main
    GOTO RotateL
    RotateR:
    PORTB = rot1
    PAUSEUS 5
    PORTB = rot2
    PAUSEUS 5
    PORTB = rot3
    PAUSEUS 5
    PORTB = rot4
    PAUSEUS 5
    PORTB = rot5
    PAUSEUS 5
    PORTB = rot6
    PAUSEUS 5
    PORTB = rot7
    PAUSEUS 5
    PORTB = rot8
    PAUSEUS 5
    PORTB = rot9
    PAUSEUS 5
    PORTB = rot10
    PAUSEUS 5
    PORTB = rot11
    PAUSEUS 5
    PORTB = rot12
    PAUSEUS 5
    PORTB = rot13
    PAUSEUS 5
    PORTB = rot14
    PAUSEUS 5
    PORTB = rot15
    PAUSEUS 5
    PORTB = rot16
    PAUSEUS 5
    PORTB = rot17
    PAUSEUS 5
    PORTB = rot18
    PAUSEUS 5
    PORTB = rot19
    PAUSEUS 5
    PORTB = rot20
    PAUSEUS 5
    PORTB = rot21
    PAUSEUS 5
    PORTB = rot22
    PAUSEUS 5
    PORTB = rot23
    PAUSEUS 5
    PORTB = rot24
    PAUSEUS 5
    PORTB = rot25
    PAUSEUS 5
    PORTB = rot26
    PAUSEUS 5
    PORTB = rot27
    PAUSEUS 5
    PORTB = rot28
    PAUSEUS 5
    PORTB = rot29
    PAUSEUS 5
    PORTB = rot30
    PAUSEUS 5
    myvar = PORTA.0
    if myvar = 0 then Main
    GOTO RotateR
    end

  2. #2
    Join Date
    Dec 2008
    Location
    New York US
    Posts
    46


    Did you find this post helpful? Yes | No

    Wink Using Lookup tables lets increase PIC ability.

    This is the same program that use lookup tables for data.
    Was trying to use arrays - not working very well -some kind limitation for using data.
    '* Notes : Target processor PIC16F84 *
    '* : Driver for four applications *
    '************************************************* ***************
    DEFINE OSC 20
    define __CONFIG _CP_OFF&_WDT_OFF&_BODEN_OFF&_PWRTE_ON
    INCLUDE "modedefs.bas"
    TRISA = 255 ' Set PORTA to all input
    TRISB = %00000000 ' Set all of PORTB to outputs
    youvar var bit
    myvar var bit
    hisvar var bit
    hervar var bit
    wevar var bit
    cot var byte
    cots var byte
    rot var byte
    rots var byte
    sot var byte
    sots var byte
    Main:
    PORTB = %00000000
    myvar = PORTA.0 'Run = 1 Stop = 0
    youvar = PORTA.1 'Direct rotation = 0 Reverse = 1 6200Hz
    'two sin signal shifted by 90 degree
    hisvar = PORTA.2 '10 Hz two generators 1-2-3-4 5-6-7-8
    hervar = PORTA.3 '2 HZ two generators 1-2-3-4 5-6-7-8
    wevar = PORTA.4 ' 1Hz Two Generators 1-2-3-4 5-6-7-8
    if wevar = 1 then Gen1
    if hervar = 1 then Gen2
    IF hisvar = 1 then Gen3
    if youvar = 0 then sRun1
    if youvar = 1 then sRun2
    goto main
    Gen1:
    For sots = 0 to 3
    lookup sots, [$99,$CC,$66,$33],sot
    PORTB = sot
    PAUSE 250
    myvar = PORTA.0
    If myvar = 0 Then main
    next sots
    goto Gen1
    Gen2:
    For sots = 0 to 3
    lookup sots, [$99,$CC,$66,$33],sot
    PORTB = sot
    PAUSE 125
    myvar = PORTA.0
    If myvar = 0 Then main
    next sots
    goto Gen2
    Gen3:
    For sots = 0 to 3
    lookup sots, [$99,$CC,$66,$33],sot
    PORTB = sot
    PAUSE 25
    myvar = PORTA.0
    If myvar = 0 Then main
    next sots
    goto Gen3
    sRun1:
    myvar = PORTA.0 'Run = 1 Stop = 0
    youvar = PORTA.1
    if myvar = 0 then Main
    if youvar = 1 then RotateL
    goto main
    sRun2:
    myvar = PORTA.0 'Run = 1 Stop = 0
    youvar = PORTA.1
    if myvar = 0 then Main
    if youvar = 1 then RotateR
    goto main
    RotateL:
    for cots = 0 to 29
    lookup cots, [$04,$15,$26,$37,$48,$59,$6A,$7B,$8C,$9D,$AE,$BF,$C E,$DD, $EC,_
    $FB,$EA,$D9,$C8,$B7,$A6,$95,$84,$73,$62,$51,$40,$3 1,$22,$13],cot
    PORTB = cot
    PAUSEUS 5
    myvar = PORTA.0
    if myvar = 0 then Main
    next cots
    GOTO RotateL
    RotateR:
    for rots = 0 to 29
    lookup rots, [$F4,$E5,$D6,$C7,$B8,$A9,$9A,$8B,$7C,$6D,$5E,$4F,$3 E,$2D,$1C,_
    $0B,$1A,$29,$38,$47,$56,$65,$74,$83,$92,$A1,$B0,$C 1,$D2,$E3],rot
    PORTB = rot
    PAUSEUS 5
    myvar = PORTA.0
    if myvar = 0 then Main
    next rots
    GOTO RotateR
    end
    So appreciate any ideas what PIC can do in periods like delays PAUSEUS, PAUSE.
    P.S. New York is state of mind

Similar Threads

  1. PBP Using too many instructions
    By The Master in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 22nd December 2009, 00:24
  2. Multiple Pics accessing single EEPROM
    By Atom058 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 3rd February 2008, 18:22
  3. Retrieving infos from multiple PICs on a bus/chain
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 15th October 2007, 05:42
  4. Dead PICs
    By CocaColaKid in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 15th August 2007, 14:12
  5. Self Destructing pics? Copy protection
    By Rob Martin in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 22nd March 2004, 10:39

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts