跨端口拆分时 PIC18 读/写数据
由于设计限制,我的内存控制器地址线分布在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您正在使用的 I/O 被散列到多个端口中,这并不容易。
您可以做的唯一简化是将内存管理为由三个不同地址块访问的页面:
最好为低地址部分提供更大的块,以便内存页面可以更大。这里你只有 16 字节的页面。
因此,您可以定义一个位字段结构来将内存管理到单个变量中。
这样你就可以更有效地处理端口更新,就像 portB 一样:
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:
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.
This way you can handle more efficiently the port updating like for portB: