跨端口拆分时 PIC18 读/写数据

发布于 2024-10-28 15:50:45 字数 820 浏览 6 评论 0原文

由于设计限制,我的内存控制器地址线分布在 PIC 18F4550 的 3 个不同端口上。 映射:

#define A0 PORTBbits.RB2
#define A1 PORTBbits.RB3
#define A2 PORTBbits.RB4
#define A3 PORTBbits.RB5
#define A4 PORTAbits.RA0
#define A5 PORTAbits.RÄ1
#define A6 PORTAbits.RÄ2
#define A7 PORTAbits.RÄ3
#define A8 PORTAbits.RÄ4
#define A9 PORTAbits.RÄ5
#define A10 PORTEbits.RE0
#define A11 PORTEbits.RE1
#define A12 PORTEbits.RE2

我想将其作为一个单一变量 ADDRESS 进行访问,并尝试使用联合来实现这一点,但只是得到一个“语法错误”:

union
{
        struct
        {
            A0 :1;
            A1 :1;
            A2 :1;
            A3 :1;
            A4 :1;
            A5 :1;
            A6 :1;
            A7 :1;
            A8 :1;
            A9 :1;
            A10 :1;
            A11 :1;
            A12 :1;
        };
} ADDRESS;

我该如何去做呢?

Due to design limitations, I have an address line for a memory controller split across 3 different ports of a PIC 18F4550.
Mapping:

#define A0 PORTBbits.RB2
#define A1 PORTBbits.RB3
#define A2 PORTBbits.RB4
#define A3 PORTBbits.RB5
#define A4 PORTAbits.RA0
#define A5 PORTAbits.RÄ1
#define A6 PORTAbits.RÄ2
#define A7 PORTAbits.RÄ3
#define A8 PORTAbits.RÄ4
#define A9 PORTAbits.RÄ5
#define A10 PORTEbits.RE0
#define A11 PORTEbits.RE1
#define A12 PORTEbits.RE2

I would like to access this as one single variable ADDRESS, and have tried using a union to do it, but simply get a 'Syntax error' with:

union
{
        struct
        {
            A0 :1;
            A1 :1;
            A2 :1;
            A3 :1;
            A4 :1;
            A5 :1;
            A6 :1;
            A7 :1;
            A8 :1;
            A9 :1;
            A10 :1;
            A11 :1;
            A12 :1;
        };
} ADDRESS;

How do I go about doing this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一笑百媚生 2024-11-04 15:50:45

如果您正在使用的 I/O 被散列到多个端口中,这并不容易。

您可以做的唯一简化是将内存管理为由三个不同地址块访问的页面:

lowAddr will be RB2:RB5
midAddr will be RA0:RA5
highAdd will be RE0:RE2

最好为低地址部分提供更大的块,以便内存页面可以更大。这里你只有 16 字节的页面。

因此,您可以定义一个位字段结构来将内存管理到单个变量中。

struct {
   uint16 lowAddr : 4;
   uint16 midAddr : 6;
   uint16 highAddr : 3;
   uint16 : 3;
} memoryAddr;

这样你就可以更有效地处理端口更新,就像 portB 一样:

LATB &= 0xFF ^ (3 << 2);
LATB |= memoryAddr.lowAddr << 2;

This won't be really easy has the I/O your are using are hashed into several ports.

The only simplification you can do is to manage your memory into pages accessed by three different address chunks:

lowAddr will be RB2:RB5
midAddr will be RA0:RA5
highAdd will be RE0:RE2

It would have been preferable to have the bigger chunk for low address part so the memory pages can be larger. Here you will have only 16 bytes pages.

Hence you can define a bit-field structure to manage your memory into a single variable.

struct {
   uint16 lowAddr : 4;
   uint16 midAddr : 6;
   uint16 highAddr : 3;
   uint16 : 3;
} memoryAddr;

This way you can handle more efficiently the port updating like for portB:

LATB &= 0xFF ^ (3 << 2);
LATB |= memoryAddr.lowAddr << 2;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文