Problem using ASM instruction


Results 1 to 6 of 6

Threaded View

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


    Did you find this post helpful? Yes | No

    Default

    Well there's a few mistake in your code anyways...

    First, you check for a High level for your push-button... fine, but you enable the internal pull-up... thus this 'should' always consider that there's one push button pressed.

    Next, you never loop in your code.. there's on missing GOTO LOOP.. this results in stack underflow.

    Assuming your push button are connected between, gnd and the I/O and GND, using the internal weak-pull-ups, i would bet the following will work

    Code:
            @ DEVICE PIC12F675, XT_OSC
            @ DEVICE pic12F675, WDT_ON 
            @ DEVICE pic12F675, PWRT_ON
            @ DEVICE pic12F675, MCLR_OFF 
            @ DEVICE pic12F675, BOD_ON
            
            DEFINE OSC 3
            
            TRISIO.0 = 0 ' set GPIO.0 as output
            TRISIO.1 = 1 ' set GPIO.0 as input
            TRISIO.2 = 1 ' set GPIO.0 as input
            
            CMCON = 7 ' turn off analog comparator
            ADCON0.0 = 0
            ADCON0.1 = 0
            ADCON0.2 = 0
            OPTION_REG.7 = 0
            VRCON = 0
            ANSEL = 0
            
            '// Setup IR bit widths / carrier cycle times     
            Header  CON 96    '// Header = (96 * 25uS) = 2.4mS burst
            Zero    CON 24    '// Zero = (24 * 25uS) = 0.6mS burst
            One     CON 48    '// One = (48 * 25uS) = 1.2mS burst
            
            '// Define variables
            Cycles   VAR BYTE BANK0    '// Holds number of 40KHz carrier cycles
            i        var byte
    
    Loop:
            if gpio.1 = 0 then
               cycles = header
               gosub pulse
               cycles = zero
               gosub dark
            
               cycles = zero
               gosub pulse
               cycles = zero
               gosub dark
            endif
            
            if gpio.2 = 0 then
               cycles = header
               gosub pulse
               cycles = zero
               gosub dark
            
               cycles = one
               gosub pulse
            
            endif
            
            GOTO LOOP
    
    Pulse:                '// Emits # of 38.461 kHz bursts held in variable Cycles
        for i = 1 to cycles
            ASM                   ;// with auto delay between bursts
               ;bsf GPIO, 0         ;// 1uS, LED=on [need 25uS total
               MOVE?CT 1, GPIO,0
               goto $+1           ;// 3uS (2uS per goto $+1)
               goto $+1           ;// 5uS
               goto $+1           ;// 7uS
               goto $+1           ;// 9uS
               goto $+1           ;// 11uS
               goto $+1           ;// 13uS 
               bcf GPIO, 0        ;// 14uS, LED=off
               decfsz _Cycles,F   ;// 24uS
               goto $+1           ;// 16uS
               goto $+1           ;// 18uS
               goto $+1           ;// 20uS
               goto $+1           ;// 22uS
            ENDASM   
        next i
    
    return
       
    Dark:
        for i = 1 to cycles
            ASM                   ;// with auto delay between bursts
               ;bcf GPIO, 0         ;// 1uS, LED=on [need 25uS total
               MOVE?CT 0,GPIO,0
               goto $+1           ;// 3uS (2uS per goto $+1)
               goto $+1           ;// 5uS
               goto $+1           ;// 7uS
               goto $+1           ;// 9uS
               goto $+1           ;// 11uS
               goto $+1           ;// 13uS 
               goto $+1           ;// 13uS 
               goto $+1           ;// 13uS 
               goto $+1           ;// 16uS
               goto $+1           ;// 18uS
               goto $+1           ;// 20uS
               goto $+1           ;// 20uS
            ENDASM   
        next i
    
    return
    I may feel some incoming timing problem(s)
    Last edited by mister_e; - 28th March 2008 at 18:01.
    Steve

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

Similar Threads

  1. Instant Interrupts - Revisited
    By Darrel Taylor in forum Code Examples
    Replies: 772
    Last Post: - 17th February 2016, 22:14
  2. PBP, ASM and LST files
    By HenrikOlsson in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th January 2010, 13:43
  3. Problem to compile my program
    By wagner in forum Off Topic
    Replies: 5
    Last Post: - 7th July 2008, 20:17
  4. Problem with ASM IRQ using FSR0 on PIC18F252
    By mytekcontrols in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 11th March 2008, 20:48
  5. problem with asm interrupt
    By servo260 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 20th December 2004, 17:02

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