永发信息网

求帮忙看下程序 是什么功能 程序是不是对的

答案:2  悬赏:20  手机版
解决时间 2021-01-30 17:49
  • 提问者网友:浮克旳回音
  • 2021-01-29 20:10
#include < reg52.h >
#define uint unsigned int
#define uchar unsigned char
#include < NRF24L01.h >

void Main(void)
{
InitNRF24L01(); // 初始化IO
while( 1 )
{
KeyScan(); // 按键扫描
}
}



void KeyScan()
{
P2 |= 0x00;
if( s1 == 0 )
{
Delay1ms( 20 );
if( s1 == 0 )
{
SendByte( 0x01 );
while( s1 == 0 );

}
}
if( s2 == 0 )
{
Delay1ms( 20 );
if( s2 == 0 )
{
SendByte( 0x02 );
while( s2 == 0 );
}
}
if( s3 == 0 )
{
Delay1ms( 20 );
if( s3 == 0 )
{
SendByte( 0x03 );
while( s3 == 0 );
}
}
最佳答案
  • 五星知识达人网友:污到你湿
  • 2021-01-29 20:19
这个是nrf24L01无线通信模块的单片机c程序。
KeyScan是按键扫描程序,程序开始时将51单片机P2端口置于低电位,然后分别判断s1,s2,s3是否为高电位(s1,s2,s3应该是P2口的一个管脚) 判断过程中用了延时(Delay1ms)来消除按键机械性接触不良导致的多次重复按键。
如果InitNRF24L01中把所有的初始化都完成了(51的和nrf24L01的),这段代码运行就没问题。
全部回答
  • 1楼网友:老鼠爱大米
  • 2021-01-29 21:14
这个程序的功能是学会静态变量的操作(静态变量的有效范围是全局,所以在非主函数里修改是有效的),并用程序做一个修改前与修改后的对比。哪些地方有错,你对比下面的程序即可,此程序可以直接使用。 #include &lt;stdio.h&gt; void add(int n,int b[]) //int b[],n; { int i=0; printf("\n"); for (i=0; i&lt;n; i++) { printf("%d,",b[i]); b[i]++; } } void main() { int j; static int a[]={0,1,2,3,4,5,6,7,8,9}; add(10,a); printf("\n"); for(j=0;j&lt;10;j++) { printf("%d,",a[j]); } printf("\n"); }
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯