Output PIC module


Results 1 to 6 of 6

Threaded View

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


    Did you find this post helpful? Yes | No

    Default

    no big improvement on your revious but compile 772 word now
    Code:
    '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 
    
        c var byte
        d var byte
        e var byte
        b16 var BYTE 
        w9 var WORD 
        pbpin var byte
    
        '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
        TRISA= 255 '31
        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
        pbpin=6
        gosub sendpulses
        
        PORTB=B5
        GOSUB SENDPULSES
    
        PORTB= b4
        GOSUB SENDPULSES
    
        PORTB= b3
        GOSUB SENDPULSES
    
        PORTB= b2
        GOSUB SENDPULSES
    
        PORTB= b1
        PBPIN=7
        GOSUB SENDPULSES
    
        call M1
        goto PROG1
    
    M1:
        If PORTA.0 = 1 Then P1
        w9 = w9 - 1
        If w9 < $100 Then Lm1
        goto PROG1 
    
    P1:
        If PORTA.1 = 1 Then PROG1
        w9 = w9 + 1
        If w9 > $5000 Then Lp1
        w9 = $5000
        Goto PROG1
    
    Lm1:
        w9 = $100
        Goto PROG1 
    
    Lp1:
        w9 = $5000
        Goto PROG1
    
    ROR1:
        PORTB= b1
        PBPIN=6
        GOSUB SENDPULSES
    
        PORTB= b2
        GOSUB SENDPULSES
    
        PORTB= b3
        GOSUB SENDPULSES
    
        PORTB= b4
        GOSUB SENDPULSES
    
        PORTB= b5
        GOSUB SENDPULSES
    
        PORTB= b6
        PBPIN=7
        GOSUB SENDPULSES
    
        call M1
        goto PROG1 
    
    PROG2: 
        '------------Program #2
        b16=PORTA
        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 
        PBPIN=6
        GOSUB SENDPULSES
        
        PORTB= b8 
        GOSUB SENDPULSES
            
        PORTB= b7
        PBPIN=7
        GOSUB SENDPULSES
        
        call M2
        goto PROG2 
    
    M2:
        If PORTA.0 = 1 Then P2
        w9 = w9 - 1
        If w9 < $100 Then Lm2
        goto PROG2 
    
    P2:
        If PORTA.1 = 1 Then PROG2
        w9 = w9 + 1
        If w9 > $5000 Then Lp2
        w9 = $5000
        Goto PROG2 
    
    Lm2:
        w9 = $100
        Goto PROG2 
    
    Lp2:
        w9 = $5000
        Goto PROG2 
    
    ROR2: 
        '------------Block Rotate Right 2
        PORTB= b7
        PBPIN=6
        GOSUB SENDPULSES
            
        PORTB= b8
        GOSUB SENDPULSES
        
        PORTB= b9
        PBPIN=7
        GOSUB SENDPULSES
        
        call M2
        goto PROG2 
    
    PROG3: 
        '------------Program #3 
        b16=PORTA
        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 
        PBPIN=6
        GOSUB SENDPULSES    
    
        PORTB= b9 
        GOSUB SENDPULSES
        
        PORTB= b11
        GOSUB SENDPULSES
    
        PORTB= b8
        GOSUB SENDPULSES
    
        PORTB= b10
        GOSUB SENDPULSES
    
        PORTB= b7
        PBPIN=7
        GOSUB SENDPULSES
    
        call M3
        goto PROG3 
    
    M3:
        If PORTA.0 = 1 Then P3
        w9 = w9 - 1
        If w9 < $100 Then Lm3
        goto PROG3 
    
    P3:
        If PORTA.1 = 1 Then PROG3
        w9 = w9 + 1
        If w9 > $5000 Then Lp3
        w9 = $5000
        Goto PROG3 
    
    Lm3:
        w9 = $100
        Goto PROG3 
    
    Lp3:
        w9 = $5000
        Goto PROG3 
    
    RR3: 
        '------------Block Rotate Right 3
        PORTB= b7
        PBPIN=6
        GOSUB SENDPULSES
        
        PORTB= b10
        GOSUB SENDPULSES
        
        PORTB= b8
        GOSUB SENDPULSES
        
        PORTB= b11
        GOSUB SENDPULSES
        
        PORTB= b9
        GOSUB SENDPULSES
        
        PORTB= b12
        PBPIN=7
        GOSUB SENDPULSES
        
        call M3
        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 
        PBPIN=6
        GOSUB SENDPULSES
        
        PORTB= b15 
        GOSUB SENDPULSES
        
        PORTB= b14
        GOSUB SENDPULSES
        
        PORTB= b13
        PBPIN=7
        GOSUB SENDPULSES
        
        call M4
        goto PROG4 
    
    M4:
        If PORTA.0 = 1 Then P4
        w9 = w9 - 1
        If w9 < $100 Then Lm4
        goto PROG4 
    
    P4:
        If PORTA.1 = 1 Then PROG4
        w9 = w9 + 1
        If w9 > $5000 Then Lp4
        w9 = $5000
        Goto PROG4 
    
    Lm4:
        w9 = $100
        Goto PROG4
    
    Lp4:
        w9 = $5000
        Goto PROG4 
    
    RR4: 
        '------------Block Rotate Right 4
        PORTB= b13
        PBPIN=6
        GOSUB SENDPULSES
        
        PORTB= 14
        GOSUB SENDPULSES
        
        PORTB= 15
        GOSUB SENDPULSES
        
        PORTB= b14
        PBPIN=7
        GOSUB SENDPULSES
        
        call M4
        goto PROG4 
    
    PROG5: 
        '------------Program #5
        IF PortA.4= 0 Then Halt 
        GOTO RR5
        Goto PROG5 
    
    M5:
        If PORTA.0 = 1 Then P5
        w9 = w9 - 1
        If w9 < $100 Then Lm5
        goto PROG5 
    
    P5:
        If PORTA.1 = 1 Then PROG5
        w9 = w9 + 1
        If w9 > $5000 Then Lp5
        w9 = $5000
        Goto PROG5
    
    Lm5:
        w9 = $100
        Goto PROG5
    
    Lp5:
        w9 = $5000
        Goto PROG5
    
    RR5: 
        '------------Block Rotate Right 5
        PORTB= b10
        PBPIN=6
        GOSUB SENDPULSES
        
        PORTB= b14
        GOSUB SENDPULSES
        
        PORTB= b11
        GOSUB SENDPULSES
        
        PORTB= b14
        GOSUB SENDPULSES
        
        PORTB= b12
        GOSUB SENDPULSES
        
        PORTB= b14
        PBPIN=7
        GOSUB SENDPULSES
        
        call M5
        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 
        PBPIN=6
        GOSUB SENDPULSES
        
        PORTB= b15 
        PBPIN=7
        GOSUB SENDPULSES
        
        call M1
        goto PROG6
    
    M6:
        If PORTA.0 = 1 Then P6
        w9 = w9 - 1
        If w9 < $100 Then Lm6
        goto PROG6 
    
    P6:
        If PORTA.1 = 1 Then PROG6
        w9 = w9 + 1
        If w9 > $5000 Then Lp6
        w9 = $5000
        Goto PROG6
    
    Lm6:
        w9 = $100
        Goto PROG6
    
    Lp6:
        w9 = $5000
        Goto PROG6
    
    RR6: 
        '------------Block Rotate Right 6
        PORTB= b15
        PBPIN=6
        GOSUB SENDPULSES
        
        PORTB= b13
        GOSUB SENDPULSES
        
        call M6
        goto PROG6
    
    PROG7: 
        '------------Program #7
        IF PortA.4= 0 Then Halt
        GOTO RL7 
        Goto PROG7 
    
    RL7: 
        '------------Block nO RotateD 7
        PORTB= b0 
        PBPIN=6
        GOSUB SENDPULSES
        
        PORTB= b14 
        PBPIN=7
        GOSUB SENDPULSES
        
        call M7
        goto PROG7
    
    M7:
        If PORTA.0 = 1 Then P7
        w9 = w9 - 1
        If w9 < $100 Then Lm7
        goto PROG7
    
    P7:
        If PORTA.1 = 1 Then PROG7
        w9 = w9 + 1
        If w9 > $5000 Then Lp7
        w9 = $5000
        Goto PROG7 
    
    Lm7:
        w9 = $100
        Goto PROG7
    
    Lp7:
        w9 = $5000
        Goto PROG7 
    
    SendPulses:
        pulsout pbpin, w9
        return
    as there's a lot of jump here, there elsewhere, lalaland, i think you should build a flowchart to help you to structure everything and avoid so many jumps. Well it's my own opinion.

    One thing Jump to my face ... the use Of CALL !!!! usually we use GOSUB with a RETURN.
    Quote Originally Posted by PBP manual
    CALL Label

    Execute the assembly language subroutine named Label. GOSUB is normally used to execute a PicBasic subroutine. The main difference between GOSUB and CALL is that with CALL, the existence of Label is not checked until assembly time. Using CALL, a Label in an assembly language section can be accessed that is otherwise inaccessible to PicBasic.
    don't give up!
    Last edited by mister_e; - 9th September 2005 at 23:24.
    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