Fel*_*unz 3 c microcontroller pointers avr mplab
我使用的是 ATMEGA16M1 微控制器和 MPLAB IDE。
我有以下函数可以写入端口。
void Lcd8_Write_String(char *a)
{
int i;
for(i=0;a[i]!='\0';i++)
Lcd8_Write_Char(a[i]);
}
void Lcd8_Write_Char(char a)
{
pinChange(RS,1); // => RS = 1
Lcd8_Port(a); //Data transfer
pinChange(EN,1); // => E = 1
_delay_ms(1);
pinChange(EN,0); // => E = 04
_delay_ms(1);
}
Run Code Online (Sandbox Code Playgroud)
我用 调用该函数Lcd8_Write_String("Hello World");。
我得到:
错误:将“Lcd8_Write_String”的参数 1 从指针传递到非封闭地址空间。
我该如何解决这个错误?
如果你写:
Lcd8_Write_String("Hello World");
Run Code Online (Sandbox Code Playgroud)
该字符串"Hello World"将位于微控制器的闪存中,而不是 RAM 中。所以你必须将你的功能切换为:
void Lcd8_Write_String(const char *a)
Run Code Online (Sandbox Code Playgroud)