Output PIC module


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1
    freelancebee's Avatar
    freelancebee Guest


    Did you find this post helpful? Yes | No

    Smile Output PIC module

    Hi Steve:
    Thank you very much for showing the art of programming.
    With your help I was able to reduce number of compiled words
    from 995 to 412.
    Looks like I can write another program up to 500+ compiled
    words and to add to same PIC flash memory.
    I still have one question for you:
    PortB=b6 'pin0-pin7
    Pulsout 6, w9
    Does pins 0,1,2,3,4,5 and 7 not changing their values b6.0,b6.1,b6.2,
    b6.3,b6.4,b6.5, and b6.7 during pulsout on pin 6?
    Or need to use some kind of trick to hold their value during
    pulsout on pin 6.
    Below is corrected program.
    Best Regards,
    Leonid

    'PIC16F84A
    'This program only example that I will test
    'in Three PICs Architecture: Input PIC,Output PIC, and Control PIC.
    'This program serve output PIC.
    'Program used combination pins PortA.0 - PortA.4 for input
    'to change state of pins PortB.0 - PortB.5 and 6,7 for output
    'Input cominations come from second PIC
    'Order
    '1. PortA.4=0 Halt program
    '2. change code PortA.0-PortA.2 and result code from 1 to 7
    'will choose program from 1 to 7
    '3. PortA.3=0 set program
    '4. PortA.4=1 preset
    '5. PortA.3=1 run choosen program
    DEFINE OSC 20
    DEFINE _CP_OFF $3FFF
    DEFINE _PWRTE_OFF $3FFF
    DEFINE _WDT_OFF $3FFB
    'DEFINE _XT_OSC $3FFD
    DEFINE _HS_OSC $3FFE
    OPTION_REG = %10000000
    INTCON = %00000000

    b16 var BYTE
    w9 var WORD
    'set constant
    b0 con %00000000
    b1 con %00000001
    b2 con %00000010
    b3 con %00000100
    b4 con %00001000
    b5 con %00010000
    b6 con %00100000
    b7 con %00001001
    b8 con %00010010
    b9 con %00100100
    b10 con %00011011
    b11 con %00110110
    b12 con %00101101
    b13 con %00010010
    b14 con %00111111
    b15 con %00010101
    'Set Ports
    poke TRISA, 255 '31
    poke TRISB, b0
    'Initialize variable
    w9 = $2710
    Halt:
    PORTB=b0
    b16 = PORTA
    IF PortA.3 = 0 Then Switch
    IF PortA.4 = 0 Then Halt
    goto Halt

    Switch:
    PORTB=b0
    b16 = PORTA & 7
    branch b16,[switch,prog1,prog2,prog3,prog4,prog5,prog6,prog7]
    goto Switch

    PROG1: '------------Program #1
    b16 = PORTA
    IF PortA.4=0 Then Halt
    IF PortA.2=0 Then RL1
    gOTO ROR1
    Goto PROG1
    RL1: '------------Block Rotate Left 1
    PORTB=b6
    gosub SendPulses
    PORTB=b5
    gosub SendPulses
    PORTB=b4
    gosub SendPulses
    PORTB=b3
    gosub SendPulses
    PORTB=b2
    gosub SendPulses
    PORTB=b1
    gosub SendPulses
    gosub M1
    goto PROG1

    ROR1:
    PORTB=b1
    gosub SendPulses
    PORTB=b2
    gosub SendPulses
    PORTB=b3
    gosub SendPulses
    PORTB=b4
    gosub SendPulses
    PORTB=b5
    gosub SendPulses
    PORTB=b6
    gosub SendPulses
    gosub M1
    goto PROG1
    PROG2: '------------Program #2
    peek PORTA, b16
    IF PortA.4= 0 Then Halt
    IF PortA.2= 0 Then RL2
    IF PortA.2= 1 Then ROR2
    Goto PROG2
    RL2: '------------Block Rotate Left 2
    PORTB=b9
    gosub SendPulses
    PORTB=b8
    gosub SendPulses
    PORTB=b7
    gosub SendPulses
    gosub M1
    goto PROG2

    ROR2: '------------Block Rotate Right 2
    PORTB=b7
    gosub SendPulses
    PORTB=b8
    gosub SendPulses
    PORTB=b9
    gosub SendPulses
    gosub M1
    goto PROG2
    PROG3: '------------Program #3
    peek PORTA, b16
    IF PortA.4= 0 Then Halt
    IF PortA.2= 0 Then RL3
    IF PortA.2= 1 Then RR3
    Goto PROG3
    RL3: '------------Block Rotate Left 3
    PORTB=b12
    gosub SendPulses
    PORTB=b9
    gosub SendPulses
    PORTB=b11
    gosub SendPulses
    PORTB=b8
    gosub SendPulses
    PORTB=b10
    gosub SendPulses
    PORTB=b7
    gosub SendPulses
    gosub M1
    goto PROG3

    RR3: '------------Block Rotate Right 3
    PORTB=b7
    gosub SendPulses
    PORTB=b10
    gosub SendPulses
    PORTB=b8
    gosub SendPulses
    PORTB=b11
    gosub SendPulses
    PORTB=b9
    gosub SendPulses
    PORTB=b12
    gosub SendPulses
    gosub M1
    goto PROG3
    PROG4: '------------Program #4
    IF PortA.4= 0 Then Halt
    IF PortA.2= 0 Then RL4
    IF PortA.2= 1 Then RR4
    Goto PROG4
    RL4: '------------Block Rotate Left 4
    PORTB=b14
    gosub SendPulses
    PORTB=b15
    gosub SendPulses
    PORTB=b14
    gosub SendPulses
    PORTB=b13
    gosub SendPulses
    gosub M1
    goto PROG4

    RR4: '------------Block Rotate Right 4
    PORTB=b13
    gosub SendPulses
    PORTB=14
    gosub SendPulses
    PORTB=15
    gosub SendPulses
    PORTB=b14
    gosub SendPulses
    gosub M1
    goto PROG4
    PROG5: '------------Program #5
    IF PortA.4= 0 Then Halt
    GOTO RR5
    Goto PROG5

    RR5: '------------Block Rotate Right 5
    PORTB=b10
    gosub SendPulses
    PORTB=b14
    gosub SendPulses
    PORTB=b11
    gosub SendPulses
    PORTB=b14
    gosub SendPulses
    PORTB=b12
    gosub SendPulses
    PORTB=b14
    gosub SendPulses
    gosub M1
    goto PROG5
    PROG6: '------------Program #6
    IF PortA.4= 0 Then Halt
    IF PortA.2= 0 Then RL6
    IF PortA.2= 1 Then RR6
    Goto PROG6
    RL6: '------------Block Rotate Left 6
    PORTB=b13
    gosub SendPulses
    PORTB=b15
    gosub SendPulses
    gosub M1
    goto PROG6

    RR6: '------------Block Rotate Right 6
    PORTB=b15
    gosub SendPulses
    PORTB=b13
    gosub SendPulses
    gosub M1
    goto PROG6
    PROG7: '------------Program #7
    IF PortA.4= 0 Then Halt
    GOTO RL7
    Goto PROG7
    RL7: '------------Block nO RotateD 7
    PORTB=b0
    gosub SendPulses
    PORTB=b14
    gosub SendPulses
    gosub M1
    goto PROG7

    M1:
    If porta.0=0 then
    w9=w9-1
    endif
    if porta.1=0 then
    w9=w9+1
    EndIf
    select case w9
    case is >$5000
    w9=$5000
    case is <$100
    w9=$100
    end select
    Return

    SendPulses:
    pulsout 6,w9
    Return
    End
    Last edited by freelancebee; - 12th September 2005 at 19:56.

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    still have one question for you:
    PortB=b6 'pin0-pin7
    Pulsout 6, w9
    Does pins 0,1,2,3,4,5 and 7 not changing their values b6.0,b6.1,b6.2,
    b6.3,b6.4,b6.5, and b6.7 during pulsout on pin 6?
    Or need to use some kind of trick to hold their value during
    pulsout on pin 6.
    No Pulsout should affect only one pin. The other, SHOULD stay as is.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. HSERIN & Interupts (aka controlling PIC programs from a remote PC)
    By HankMcSpank in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 17th June 2009, 14:46
  2. Pic getting part power from Analog Port
    By ShaneMichael in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 22nd April 2009, 10:34
  3. pic to pic ir link versus wired link : help please anyone
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 30th May 2008, 21:01
  4. Replies: 8
    Last Post: - 17th September 2006, 17:46
  5. Analog Output from a PIC
    By robertmark68 in forum General
    Replies: 4
    Last Post: - 2nd August 2006, 18:06

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