我试图对 PIC 16f877A 微控制器进行编程,以将伺服电机旋转 0 到 180 度,但每次我尝试构建该程序时,都会收到错误“成员引用基类型‘易失性无符号字符’不是结构或联合” “.我正在使用带有 xc8 编译器的 MPLAB。我找不到问题。
#include<xc.h>
void Rotation0()
{
int i;
for(i=0;i<50;i++)
{
PORTB.F0 = 1;
__delay_us(800);
PORTB.F0 = 0;
__delay_us(19200);
}
}
void Rotation90()
{
int i;
for(i=0;i<50;i++)
{
PORTB.F0 = 1;
__delay_us(1500);
PORTB.F0 = 0;
__delay_us(18500);
}
}
void Rotation180()
{
int i;
for(i=0;i<50;i++)
{
PORTB.F0 = 1;
__delay_us(2200);
PORTB.F0 = 0x00;
__delay_us(17800);
}
}
void main()
{
TRISB = 0;
PORTB = 0x00;
do
{
Rotation0();
__delay_ms(2000);
Rotation90();
__delay_ms(2000);
Rotation180();
}while(1);
}
Run Code Online (Sandbox Code Playgroud)
正如@user3386109 在评论中指出的那样,PORTB它不是一个结构。
您可以使用PORTBbits.RB0 = 1;or 正如RB0 = 1;它所定义的那样。我更喜欢第一个,因为它更冗长。
所有具有特殊命名位的寄存器都使用相同的命名约定。寄存器和位名称与数据表中的名称匹配。有时,多个寄存器中可能会使用相同的位名称。在这种情况下,您需要详细方法。
PORTB指 8 位寄存器本身,可用于直接 8 位赋值,例如PORTB = 0x00;
| 归档时间: |
|
| 查看次数: |
707 次 |
| 最近记录: |