mplab中的内联汇编... [英] inline assembly in mplab...

查看:71
本文介绍了mplab中的内联汇编...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨.我在通过内联汇编访问一些图片端口时遇到了一些困难,并会提出一些建议.

我只是想使用带有高科技的c18编译器的mplab写入我的pic 18f的端口之一,该编译器主要由switch语句组成.
这个想法是通过一条使能信号在四条数据线上发送一个8位值.我将使用几年前编写的一些代码,但首先我需要弄清楚如何写到引脚.

我已经将所有内容回滚到字面上,只是试图点亮一些指示灯.我知道switch语句会触发ok,因为我可以通过标准c代码访问端口,但是尽管代码可以编译,但是内联asm中没有任何操作...

我已经尝试过两种方式...

Hi. I''m having some difficulty with accessing some pic ports through inline assembly and would appriciate some advice.

I''m just trying to write to one of the ports on my pic 18f using mplab with hitech's c18 compiler, which largly consists of a switch statement.
the Idea is to send an 8-bit value over four data lines with an enable signal. I''m going to use a bit of code I wrote a few years ago, but first I need to figure out how to write to the pins.

I''ve rolled everything back to literally just trying to get some leds to light up. I know the switch statement triggers ok as I can access the port through standard c code, but although the code compiles, there is no action from within the inline asm...

I''ve tried it both ways...

case 0x3F:
        asm ( "GLOBAL _PORTB");     //DECLAIRE AS GLOBAL VARIABLE
        asm ( "movlw 0x00");
        asm ( "movwf _PORTB");       //CLEAR PINS
        asm ( "movlw 0xff" );
        asm ( "movwf _PORTB" );     //SET ALL PINS
IDENT_PORT = 0X01;          //SWITCH STATEMENT IS FINE...
         break; 



还有...



and...

if(j > 0)
      {
         j = j+1;       //dummy loop...recomended on the hitech website
      }                 //when using asm blocks in constructs

#asm volatile
GLOBAL _PORTB;
    movlw 0xff
    movwf _PORTB;
#endasm    



它必须与将PORTB称为变量有关,因为下划线标识了对全局变量的访问,但是PORTB是不是对的变量? ...但是当我尝试以PORTB访问它时,编译器显示错误.手册对asm相当轻巧.



It must be something to do with calling the PORTB as a variable, as the underscore identifies access to a global variable, but PORTB Isn''t a variable right? ...but the compiler shows an error when I try to access it as PORTB. The manual is fairly light on asm...

推荐答案

好吧,我设法解决了这个问题……不确定它是否会有用,但是你永远不知道,有人会在以后的几年中找到它...

well I managed to get round it...not sure if it''ll be of any use, but you never know, somebody my find it in the archives in years to come...

case 0x3F:

    IDENT_PORT = 0X01;
    j = 0x3F;
    lower_nibble = (j && 0xf0);
    PORTB = lower_nibble;
    DelayMs(50);

    asm( " swapf _j " );
    asm( " andlw 0x0f0 " );
    asm( " movwf _upper_nibble ");
    
    PORTB = upper_nibble;

     break;



或完全在c ...



or completly in c...

case 0x3f:                                          //bits 4->7 are data lines. bit 3 is enable.

        j = 0x3f;                                   //load j with recieved movement data
        upper_nibble = j & 0x0f0;                   //and with b11110000 to get upper nibble
        PORTB = upper_nibble;                       //load onto data lines

        RB3 = 1;                                    //set enable pin high
        asm( " nop " );                             //skip instruction
        RB3 = 0;                                    //clear enable pin

        k = (j << 4) | (j >> 4);                    //switch nibbles of 0x3f
        lower_nibble = k & 0x0f0;                   //AND with 0x0f0
        PORTB = lower_nibble;                       //load lower nibble onto portb

        RB3 = 1;                                    //pulse enable line
        asm( " nop " );
        RB3 = 0;
        PORTB = 0x00;                               //clear and break
        break;

,这里是我正在处理的汇编代码(应该)执行相同的操作...

and heres the assembly code I was working on which (should) do the same thing...

#asm
			movlw 0x3f 								
			movwf _tempstore					
			andlw 0x0f0								
			movwf _PORTD							
			call pulse_e					
			call Delay5
			
			swapf _tempstore					
			andlw 0x0f0								
			movwf _PORTD								
			call pulse_e						
			call Delay255
			movlw 0x00
			goto DoNothing

pulse_e: 	        bsf _PORTC, ENABLE				
			call Delay100
			bcf	_PORTC, ENABLE
			retlw 0x00

Delay255:	movlw	0xff							
			goto	d0
Delay100:	movlw	0x64						
			goto	d0
Delay10:	movlw	0x0a							
			goto	d0
Delay5:		movlw	0x05							
d0:			movwf	_count1							
d1:			movlw	0xE7
			movwf	_counta							
			movlw	0x04
			movwf	_countb						
Delay_0:	decfsz	_counta, f						
			goto


+2 decfsz _countb, f goto Delay_0 decfsz _count1 ,f goto d1 retlw 0x00 DoNothing: nop #endasm
+2 decfsz _countb, f goto Delay_0 decfsz _count1 ,f goto d1 retlw 0x00 DoNothing: nop #endasm



不是最吸引人的解决方案,但仍然相当强大...任何问题或批评都只是霍拉...



Not the most attractive of solutions but are still fairly robust...any questions or critisims just holla...


这篇关于mplab中的内联汇编...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆