Help in ASM code


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Jan 2009
    Posts
    50

    Default Help in ASM code

    Hi there!
    I have zero knowledge of assembly code. I got this from a website for an IR Remote Control. I used the supplied HEX file to program a 16F684 to success. My application requires I hold down the momentary buttons to perform Volume + and Volume - operations. However, when I use the code, it only transmits for a few seconds. I have to release then re-press the button. Is there anyone who understand assembly how can alter the code to allow continuous pressing of the buttons?

    I am using the 8 channel mode.

    Thanks for your help!
    Here's the code:

    Code:
    	list	p=16f684
    	__CONFIG   _CP_OFF & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _INTRC_OSC_NOCLKOUT & _BOD_OFF & _FCMEN_OFF & _IESO_OFF
    
    ; toggle or momentary mode, 8 channels
    #define MODE_CH8
    
    ; ON/OFF latched mode, 4 channels
    ;define MODE_CH4
    
    #include <p16F684.inc>
    #include <irmtxv4.inc>
    
    variables	UDATA
    ; RAM registers
    tcnt		RES 1
    rcnt		RES 1
    cod		RES 1
    prevcod		RES 1
    cod0		RES 1
    rowstate	RES 1
    
    startup		CODE 0
      		goto main
    		nop
    		nop
    		nop
    		retfie
    
    prog		CODE
    
    main		; program starts here
    		movlw 7
    		movwf CMCON0 ; set outputs digital
    		BANKSEL ANSEL
    		clrf ANSEL
    		movlw 0x17
    		movwf TRISA
    		clrf TRISC
    		movwf WPUA
    		movwf IOCA
    		clrf TMR0
    		bcf OPTION_REG, PSA
    		clrwdt
    		movlw (0<<NOT_RAPU)|(0<<T0CS)|(0<<INTEDG)|(0<<PSA)|(0x07)
    		movwf OPTION_REG ; portA pullups enabled
    		clrwdt
    
    		BANKSEL PORTA
    		clrf PORTA
    		clrf PORTC
    		movlw (1<<RAIE); RA int on change enable
    		movwf INTCON
    
    		call mtx_init
    		clrf mtx_buffer
    		clrf tcnt
    
    loop0		clrf (mtx_buffer+1)
    		movlw 0xff
    		movwf prevcod ; no button was pressed in the previous scan
    		movlw 0x1c ;c0,c1=0,c3=1
    		movwf PORTC
    		movlw 0x00
    		tris PORTC
    		movf PORTA, W
    		bcf INTCON, RAIF
    		sleep
    
    loop		clrf cod
    		movlw 0x1d
    		tris PORTC ; select colA (RC1)
    		clrf PORTC
    #ifdef MODE_CH8
    		clrw
    #endif
    #ifdef MODE_CH4
    		movlw 0x20
    #endif
    		call scan
    		movlw 0x1e
    		tris PORTC ; select colB (RC0)
    #ifdef MODE_CH8
    		movlw 0x04
    #endif
    #ifdef MODE_CH4
    		movlw 0x30
    #endif
    		call scan
    		movf cod, W
    		bz loop2 ; if no buton is pressed, skip
    
    		subwf prevcod, W ; if the same button is pressed, skip
    		bz loop2
    
    		movf cod, W
    		movwf prevcod ; a new button is pressed - rcnt=3
    		movwf (mtx_buffer+1)
    		movlw 3
    		movwf rcnt
    
    		movlw 0x40 ; new button - new transmission
    		addwf tcnt, F
    
    loop2		movlw 0x17
    		tris PORTC ; select ID (RC3)
    		call scanid
    		movf cod0, W
    		movwf (mtx_buffer)
    
    loop3		movf (mtx_buffer+1), W
    		andlw 0x3f
    		iorwf tcnt, W
    		movwf (mtx_buffer+1)
    
    		call mtx_send
    
    		movf rcnt, W
    		bz loop_done
    		decfsz rcnt, F
    		goto loop
    
    loop_done	movf cod, W
    		btfsc STATUS, Z
    		goto loop0 ; no button was pressed, go sleep
    		; if the same button is being hold, repeat the transmission
    		goto loop
    
    scan		movwf cod0
    		;movlw 0xc0
    scandelay	;addlw 1
    		;bnz scandelay
    		movlw 0x17
    		andwf PORTA, W
    		movwf rowstate
    
    		incf cod0, F
    		btfss rowstate, 2
    		goto pressed
    
    		incf cod0, F
    		btfss rowstate, 4
    		goto pressed
    
    		incf cod0, F
    		btfss rowstate, 0
    		goto pressed
    
    		incf cod0, F
    		btfss rowstate, 1
    		goto pressed
    		retlw 0
    
    pressed		movf cod0, W
    		movwf cod
    		return
    
    scanid		clrf cod0
    		clrw
    scandelay2	addlw 1
    		bnz scandelay2
    		movlw 0x17
    		andwf PORTA, W
    		movwf rowstate
    
    		btfss rowstate, 4
    		bsf cod0, 3
    		btfss rowstate, 0
    		bsf cod0, 2
    		btfss rowstate, 2
    		bsf cod0, 1
    		btfss rowstate, 1
    		bsf cod0, 0
    		return
    
    		end

  2. #2
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: Help in ASM code

    Sotasota, There apears to be some code missing?
    Dave Purola,
    N8NTA
    EN82fn

  3. #3
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,598


    Did you find this post helpful? Yes | No

    Default Re: Help in ASM code

    Wonder what's in here.

    #include <irmtxv4.inc>
    Robert

  4. #4
    Join Date
    Jan 2009
    Posts
    50


    Did you find this post helpful? Yes | No

    Default Re: Help in ASM code

    Ooops! Sorry, here is the missing code!! :-)

    Code:
    ;**********************************************************************
    ;                                                                     *
    ;    Filename:	    irmtxv4.inc                                       *
    ;**********************************************************************
    ;    Notes:
    ;
    ; IR transmitter prot.v4 (Manchester)
    ;**********************************************************************
    
    	EXTERN mtx_buffer, mtx_delay
    	EXTERN mtx_init, mtx_send
    And:

    Code:
    ;**********************************************************************
    ;                                                                     *
    ;    Filename:	    irmtxv4.asm                                       *
    ;**********************************************************************
    ;    Notes:
    ;
    ; IR transmitter prot.v4.2 (Manchester)
    ;**********************************************************************
    ;
    ; header : 20xbit1, 1xbit0
    ; bytes : 8xbitX, 1xbit1, 1xbit0
    ;
    ; packet structure: <data0> <data1> <data2> <checksum>
    ;
    ; 020 - library version
    ; untested!
    ;
    ; 021 - add half frame variable
    ;       remove buffer initialization
    ;
    ; 030-20050102 codec-v4.2: 
    ;              checksum with CRC-8
    ;              T=350 usec
    ;              3-byte buffer length
    ;
    ; 031-20050227 same format for IR
    ; the TX output is fixed, it uses the hardware PWM output pin
    ;
    ;**********************************************************************
    
    	list      p=16F684
    	#include <p16F684.inc>
    
    	GLOBAL mtx_buffer, mtx_init, mtx_send, mtx_delay
    
    packet_len	EQU 2
    pwm_freq	EQU d'38000'
    
    ;dc_value	EQU d'500000' / pwm_freq
    ;dc1b_value	EQU (d'2000000' / pwm_freq) - (4 * dc_value)
    
    ; rather use the exact period rate/2 for duty cycle calculation
    dc_value	EQU (d'1000000' / pwm_freq) >> 1
    dc1b_value	EQU ( (d'1000000' / pwm_freq) << 1) - (dc_value << 2)
    
    ccp1con_value	EQU (1<<CCP1M3) | (1<<CCP1M2) | (dc1b_value << 4)
    pr2_value	EQU (d'1000000' / pwm_freq) - 1
    
    ;***** VARIABLE DEFINITIONS
    mtxdata		UDATA
    
    count1		res 1
    count2		res 1
    ncnt		res 1
    bt		res 1
    sum		res 1
    mtx_buffer	res 2
    
    mtx_delay	res 1 ; half_frame delay
    
    ;**********************************************************************
    
    mtx		CODE
    
    mtx_init
    		BANKSEL T2CON
    		movlw (1<<TMR2ON) | (0x00)
    		movwf T2CON ; TMR2 on, 1:1 prescaler
    		movlw dc_value
    		movwf CCPR1L ; PWM duty cycle
    
    		movlw 0 ; ccp1con_value
    		movwf CCP1CON ; turn off CCP module
    
    		BANKSEL PR2
    		movlw pr2_value
    		movwf PR2
    		BANKSEL PORTA
    
    		movlw .117 ; 350 usec
    		movwf mtx_delay
    		return
    		;
    
    mtx_send
    		; send out buffer
    outbuf		movlw 0x14 ; 20xbit1, 1xbit0
    
    header		movwf count2
    head0		call bit1
    		decfsz count2,F
    		goto head0
    		call bit0
    
    		movlw mtx_buffer
    		movwf FSR
    		movlw packet_len
    		movwf count1
    		movlw 0xff
    		movwf sum
    		;
    outbu0		movf INDF,W
    		call update_sum
    		movf INDF,W
    		call outbyte
    		incf FSR,F
    		decfsz count1,F
    		goto outbu0
    		movf sum,W
    		call outbyte
    		; buffer is sent
    
    		return
    
    update_sum	; fast CRC-8 algorithm with poly x^8+x^5+x^4+1
    		; executes in 23 cycles per update
    
    		xorwf	sum,f
    		clrw
    		btfsc	sum,7
    		xorlw	0x7a
    		btfsc	sum,6
    		xorlw	0x3d
    		btfsc	sum,5
    		xorlw	0x86
    		btfsc	sum,4
    		xorlw	0x43
    		btfsc	sum,3
    		xorlw	0xb9
    		btfsc	sum,2
    		xorlw	0xc4
    		btfsc	sum,1
    		xorlw	0x62
    		btfsc	sum,0
    		xorlw	0x31
    		movwf	sum
    		return
    		;
    outbyte		movwf bt
    		movlw 8
    		movwf count2
    outby0		rlf bt,F
    		btfsc STATUS,C
    		goto outby1
    		call bit0
    		goto outby2
    outby1		call bit1
    outby2		decfsz count2,F
    		goto outby0
    		;
    		call bit1
    		; and bit0
    
    bit0		movlw pr2_value-3
    		movwf TMR2
    
    		movlw ccp1con_value ; HIGH
    		movwf CCP1CON
    
    ndelaya0	movf mtx_delay, W
    		movwf ncnt
    ndelaya1	decfsz ncnt, F
    		goto ndelaya1
    
    		movlw 0 ; to LOW transition
    		movwf CCP1CON
    
    ndelayb0	movf mtx_delay, W
    		movwf ncnt
    ndelayb1	decfsz ncnt, F
    		goto ndelayb1
    
    		return
    
    bit1		movlw 0 ; LOW
    		movwf CCP1CON
    
    ndelayc0	movf mtx_delay, W
    		movwf ncnt
    ndelayc1	decfsz ncnt, F
    		goto ndelayc1
    
    		movlw pr2_value-3
    		movwf TMR2
    		movlw ccp1con_value ; to HIGH transition
    		movwf CCP1CON
    
    ndelaye0	movf mtx_delay, W
    		movwf ncnt
    ndelaye1	decfsz ncnt, F
    		goto ndelaye1
    
    		return
    
    		end

  5. #5
    Join Date
    Jan 2009
    Posts
    50


    Did you find this post helpful? Yes | No

    Default Re: Help in ASM code

    The next step once this is figured out will see how I can use Pic Basic 3 to compile and make a HEX file so I can program the pic. I tried to compile already but got lots of errors. But, will cross that bridge later.... :-)

  6. #6
    Join Date
    Jan 2009
    Posts
    50


    Did you find this post helpful? Yes | No

    Default Re: Help in ASM code

    Also SORRY for the multiple posts. I could not figure out how to delete the other post. Can you let me know how I delete posts? Thanks and my apologies. :-)

  7. #7
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,598


    Did you find this post helpful? Yes | No

    Default Re: Help in ASM code

    Don't worry about double thread, it's closed and you didn't get any infraction. I just posted a "canned reply" that we have available.

    Post all your code using code tags in Advanced at bottom right. Also mention which PIC and assembler.

    Robert


    Edit: oh yeah, and the errors!

  8. #8
    Join Date
    Jan 2009
    Posts
    50


    Did you find this post helpful? Yes | No

    Default Re: Help in ASM code

    Thanks Robert! I still do not know how to delete a thread. :-)

    OK, as for the code, at this stage I need to figure out why a key-press only allows for a 1-2 second burst rather than continuous. Then, once that is figured out, I will then try to compile it. I am using PBP3 and EPIC USB programmer. Thanks!

  9. #9
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: Help in ASM code

    Quote Originally Posted by SOTASOTA View Post
    The next step once this is figured out will see how I can use Pic Basic 3 to compile and make a HEX file so I can program the pic. I tried to compile already but got lots of errors. But, will cross that bridge later.... :-)
    That is the job of MPASM. PBP accepts BASIC Mnemonics and creates the Assembly code, mpasm turns the assembly code into the intel hex, which you load into the PIC with your programmer. When you have set up MicroCode Studio correctly it becomes a 1 click operation, unless you have an error in your code or inadvertently choose the wrong PIC.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

Similar Threads

  1. am I being rude to ask this. . .ASM code request
    By camcompco in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 11th March 2013, 11:54
  2. How Convert a Hex Code to a ASM???
    By jenny90 in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 25th January 2011, 01:34
  3. ASM code
    By Bill Legge in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 1st March 2010, 23:55
  4. Adding PBPro code to an ASM file - how to?
    By wjsmarine in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 9th January 2010, 18:49
  5. ASM Interrupts with BASIC code?
    By Desterline in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 31st October 2003, 19:21

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