PIC16F877A用于串行发送和接收数据的UART代码 [英] PIC16F877A UART code for serially send and receive data
本文介绍了PIC16F877A用于串行发送和接收数据的UART代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我编写了用于在PC-hyper-terminal和PIC16F877A之间串行发送数据传输的代码。当我使用MP LAB IDE Hitech C编译器时,它显示错误,如指针是必需的,你们中的任何人都请检查代码和注册说明是否正确
< b>我尝试了什么:
Hi
I have written the code for serially send data transmission between PC-hyper-terminal and PIC16F877A. When I am using MP LAB IDE Hitech C compiler its showing the error like pointer is required and any of you please check the code and register description is correct or not
What I have tried:
#include<pic.h>
#include<string.h>
void pic_init(void)
{
TRISC7=1;
TRISC6=0;
}
void uart_init(void)
{
TXSTA=0x20;
RCSTA=0x90;
SPBRG=15;
}
void tx(unsigned char byte)
{
int i;
TXREG=byte;
while(!TXIF);
for(i=0;i<400;i++);
}
void string_uart(char *q)
{
while(*q)
{
*(*q++);
}
}
unsigned char rx()
{
while(!RCIF);
return RCREG;
}
void main()
{
//char *q;
pic_init();
uart_init();
tx('N');
rx();
string_uart("test program");
}
推荐答案
Quote:
void string_uart(char * q)
{
while(* q)
{
*(* q ++);
}
void string_uart(char *q)
{
while(*q)
{
*(*q++);
}
你的意思是
Did you actually mean
void string_uart(char *q)
{
while(*q)
{
tx((unsigned char) *q);
++q;
}
}
?
?
void string_uart(char *q)
{
while(*q)
{
tx(*q++);
}
}
这篇关于PIC16F877A用于串行发送和接收数据的UART代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文