Setup port pins into an array


Closed Thread
Results 1 to 22 of 22

Hybrid View

  1. #1
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: Setup port pins into an array

    the ASM example i have is one where a set pin is used to output , but i required pins to be multi as per my other code , my asm sucks , another area to get better at
    Code:
    
    Pulse:              ' Generate "Cycles" number of 40kHz pulses
    ASM                 ; Keep this routine in code page 1, and jump over to Main
       	BSF	IRTX,PIN		      ; 1 MAKE IR HIGH 35% Duty cycle = 9 uS
    	GOTO	$+1
    	GOTO	$+1
    	GOTO	$+1
    	GOTO	$+1
    	BCF	IRTX,PIN		      ; 1 MAKE IR LOW 17 uS
    	GOTO	$+1
    	GOTO	$+1
    	GOTO	$+1
    	GOTO	$+1
    	GOTO	$+1
    	GOTO	$+1
    	DECFSZ	Cycles,F	
    	GOTO	_Pulse	      ; 2    26 uS
    ENDASM
       return           ' Return to caller

  2. #2
    Join Date
    Feb 2010
    Location
    USA, New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default Re: Setup port pins into an array

    I know effectively nothing about assembly. I don't think HPWM can be used like that on sequential pins. I would try something interrupt based, like this:
    Code:
    '16F1825 
    Define OSC 32
    '32 MHz
    '= 8 MHz instruction time
    '= 0.000000125 s/instruction
    '= 0.000125 ms/instruction
    '= 0.125 us/instruction
    'So, 320 us = 2560 clocks
    
    'Set up Timer1
    T1CON = %00000001
    '        |||||||1 - TMR1ON
    '        ||||||0  - Unimplemented
    '        |||||0   - T1SYNC: 1 = Do not synchronize external clock input
    '        ||||0    - T1OSCEN: 0 = Dedicated Timer1 oscillator circuit disabled
    '        ||00     - T1CKPS: 00 = 1:1 Prescale value
    '        00       - TMR1CS: 00 = Timer1 clock source is instruction clock (FOSC/4)
    
    PortOffset var byte
    Cycles var byte
    Pulse_cnt var byte
    Pulse_cnt = 0
    T var byte
    bGo var bit
    bGo = 0
    T = 0
    
    INCLUDE "DT_INTS-14.bas"     ; Base Interrupt System
    INCLUDE "ReEnterPBP.bas"  ; Include if using PBP interrupts
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler    TMR1_INT,  _TMR1_Handler,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    @   INT_ENABLE   TMR1_INT     ; enable the interrupt
    
    'Load Timer 1 with value to make it interrupt after 320 us
    'for 320 us delay, want 2560 clocks
    ' 65534 - 2560 =  62974
    ' subtract ~7 more to account for the time to load the timer = 62967
    ' in hex, = $F5F7
    TMR1H = $F5 	
    TMR1L = $F7 	
    
    'Main Loop
    Main:
      if bGo = 1 then
        LOOKUP T, [1,2,4,5,16,17,18,19,20,21],PortOffset        ' Offsets from Port A to point to port A and port C I/O ports ( number of offset relates to bits offset in mem map of chip)
        Cycles = 0                                                     ' Set to 0
        for Cycles = 1 to Pulse_cnt                                   ' Each IR led increments the amount of pulses by 2 for IR LED ID use 
          PORTA.0[PortOffset] = 1                                 ' Set IR LED High
          pauseus 2                                                     ' Remain on for 2uS 
          PORTA.0[PortOffset] = 0                                 ' Set IR LED Low
          pauseus 9                                                     ' remain off for 9uS
        next Cycles 
              
        Pulse_cnt = Pulse_cnt + 2               ' increment pulse count by offset of 2 for each IR LED
        T = T + 1
        if T = 10 then
          T = 0
        endif
        bGo = 0
      endif
    goto main
    
    
    
    TMR1_Handler:
      'Re-load Timer1
      TMR1H = $F5 	
      TMR1L = $F7
      bGo = 1 	
    @ INT_RETURN
    Untested but it compiles...

    Best Regards,
    Paul
    The way to avoid mistakes is to gain experience. The way to gain experience is to make mistakes.

Similar Threads

  1. Pointers To Port Pins ?
    By BitHead in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 23rd December 2009, 20:38
  2. Variables and port pins
    By PeterReed in forum mel PIC BASIC
    Replies: 2
    Last Post: - 22nd September 2009, 14:01
  3. Custom array of pins
    By bmagistro in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 28th March 2009, 23:15
  4. Array of pins
    By The Master in forum General
    Replies: 6
    Last Post: - 2nd December 2007, 00:21
  5. Port A pins
    By Eric123 in forum mel PIC BASIC
    Replies: 3
    Last Post: - 22nd August 2006, 03:25

Members who have read this thread : 1

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