Microchip
直播中

王萍

7年用户 1337经验值
私信 关注
[问答]

PIC16F628A可以在PORT B注册表中旋转吗?

Hican你在端口B寄存器中右转?IE RRF PORTBI试图在端口B上使用4位到7位的中断,并希望在RB0到RB3i上输出RB4-RB7上的任何数据,也需要保持RB0到RB3作为输入,直到数据在那里,以避免与另一个PICIF旋转不允许的总线争用,指令真的是真的。像是MOVFF,但不能在16FCAN上这样做:-MOVLW 0xF0;设置RB0到RB3作为输出MOVWF TrISB;端口B设置RRF PORTB,0;向右旋转4次,留下结果WRRF PORTB,0 RRF PORTB,0 RRF PORTB,0;W应该包含RB4-7作为比特0到3 BCF PORTA,0;这是用来在PIC18F2550软中断上拉低R3,以改变从O/P到I/P的四个端口,当您在可用端口上运行时,在16F628 A MOVWF端口上杂乱地读取RB0 RB3上的地址:(我是新手,所以没有火焰。

以上来自于百度翻译


      以下为原文

    Hi
can you rotate right in the PORT B register ?
ie   RRF    PORTB

I'm attempting to use the interrupt on bits 4 to 7 on Port B and would like to output what ever is on RB4-RB7 on RB0 to RB3
I also need to keep RB0 to RB3 as inputs until the data is there, to avoid bus contention with another PIC
If rotate right not allowed , the instruction I'd really like is  MOVFF, but that not available on a 16F
can I do something like this:-
movlw 0xF0        ; set RB0 to RB3 as outputs
movwf TRISB     ; port B set up
rrf  PORTB,0       ; rotate right 4 times, leave result in W
rrf  PORTB,0
rrf  PORTB,0
rrf  PORTB,0       ; W should contain RB4-7 as bits 0 to 3
bcf PORTA,0      ; this is used to pull RE3 low on a PIC18F2550 soft interrupt to change four ports from o/p to i/p to read whats on RB0-RB3 on the 16F628A
movwf  PORTB

very messy when you run out of usable ports :(
I'm a novice , so no flames please
thanks
Richard

回帖(19)

张丽

2019-3-12 13:18:15
好的,没有火焰,但是你的方法是天真的,没有考虑GPIO端口一般如何操作的特殊性质,以及PIC16F628 A的目标特定要求。PIC16F628 A是一个过时的设备,不应该用于任何新的设计。我知道有很多关于这个特定设备的信息在互联网上,但在某些时候你需要继续前进。你的特定任务是读取POTB上的4、5、6、7位的输入状态,然后将这些状态输出到POTB的0、1、2、3位。这是可能的代码:这个代码是UNTES。特德。你独自一人完成这项任务,希望你的课程成绩好。

以上来自于百度翻译


      以下为原文

    OK, no flames but your approach is naive and fails to consider the "special" nature of how GPIO ports must operate in general and the target specific requirements of the PIC16F628A.
 
The PIC16F628A is an archaic device that should not be used for any new design. I know there is a lot of information about this specific device on the internet but at some point you need to move on.
 
Your particular task is to read the input states of bits 4,5,6,7 on PORTB then output those states on bits 0,1,2,3 of PORTB.
This is code that is likely to to that:    movlw   0xF0        ; Bit mask to make bits 4-7 inputs, 0-3 outputs
    banksel TRISB       ; Select bank where TRIS register is
    movwf   TRISB       ; Make PORTB bits 4-7 inputs, 0-3 outputs
    banksel PORTB       ; Select bank where PORT register is
    swapf   PORTB,W     ; Use nibble swap to read PORTB bits 4-7 and store them in WREG bits 0-3
    movwf   PORTB       ; Write to output bits 0-3
This code is UNTESTED. You are on your own with that task.
Hope you do well in your course.
举报

邓天文

2019-3-12 13:32:47
谢谢,我使用16F628 A的唯一原因是一小部分新设备,我更喜欢使用一个更扩展的指令集的18F系列。您的代码要简单得多,我没有发现SWAPF指令,因为设备是“过时的”,它可能是值得使用18F1220或类似的,并使用它F。或者其他一些功能,比如音调生成。

以上来自于百度翻译


      以下为原文

    Thanks Dan
The only reason I used a 16F628A was  a handful of new devices, I much prefer the using the 18F series with a more extended instruction set.
your code is a lot simpler, I hadn't spotted the swapf instruction, As the device is "archaic" it may be worth using a 18F1220 or similar and use it for a few other functions, like tone generation as well.
 
many thanks
Richard
举报

tijing忽忽

2019-3-12 13:45:21
一句话:是的。

以上来自于百度翻译


      以下为原文

   
In a word: Yes.
举报

王焕树

2019-3-12 13:58:36
一句话:是的…但是,如果引脚不是全部设置为输出,或者如果一些电容负载,结果可能不是你所期望的。

以上来自于百度翻译


      以下为原文

   
In a word: Yes.

... but if the pins are not all set to output, or if some have capacitive loading, the result may not be what you expect.
 
举报

更多回帖

发帖
×
20
完善资料,
赚取积分