共2条
1/1 1 跳转至页
C51 帮忙看一下这段简单的C51程序
问
#include <AT89X51.h> //预处理命令
void main(void) //主函数名
{
unsigned int a; //定义变量a为unsigned int类型
unsigned char b; //定义变量b为unsigned char类型
do
{ //do while组成循环
for (a=0; a<65535; a++)
P1_0 = 0; //65535次设P1.0口为低电平,点亮LED
P1_0 = 1; //设P1.0口为高电平,熄灭LED
for (a=0; a<30000; a++); //空循环
for (b=0; b<255; b++)
P1_1 = 0; //255次设P1.1口为低电平,点亮LED
P1_1 = 1; //设P1.1口为高电平,熄灭LED
for (a=0; a<30000; a++); //空循环
}
while(1);
}
应该是P1.0量的时间长一些,P1.1量的时间短一些,不断闪烁,但是只是P1.0闪动,P1.1不动???? 答 1: 255次设P1.1口为低电平,点亮LED。时间太短了 答 2: 你的晶振频率是多少?255次,会不会时间太短了,
加长点时间试试 答 3: 延时的位置不对,高低变化只有一个指令周期 答 4: 代码质量(与主题无关,探讨一哈)#include <AT89X51.h> //预处理命令
void main(void) //主函数名
{
unsigned int a;
while(1)
{
P1_0 = 0;
a=0;
while(--a!=0);
P1_0 = 1;
a=30000;
while(--a!=0);
P1_1=0;
a=256;
while(--a!=0);
P1_1 = 1;
a=30000;
while(--a!=0);
}
}
答 5: 重新来过#include <AT89X51.h> //预处理命令
void main(void) //主函数名
{
unsigned int a;
while(1)
{
P1_0 = 0;
a=0;
while(--a!=0);
P1_0 = 1;
P1_1=0;
a=30000;
while(--a!=0);
P1_1 = 1;
}
}
这样p1.0亮的长,p1.1亮的短。不停闪烁。。。
答 6: 我也凑热闹,谈代码质量:#include <AT89X51.h>
#define LED1 P1_0
#define LED2 P1_1
void subDelay(unsigned int pTimes);
void main(void) //主函数名
{
while(1)
{
LED1 = 0;
subDelay(65535);
LED1 = 1;
LED2=0;
subDelay(255);
LED2 = 1;
}
}
void subDelay(unsigned int pTimes)
{
while(--pTimes);
} 答 7: xxxx#include <AT89X51.h>
#define LED1 P1_0
#define LED2 P1_1
void subDelay(unsigned int pTimes);
void main(void) //主函数名
{
while(1)
{
LED1 = 0;
LED2 = 1;
subDelay(65535);
LED1 = 1;
LED2 = 0;
subDelay(255);
}
}
void subDelay(unsigned int pTimes)
{
while(--pTimes);
}
答 8: 这样是不是好些撒#include <AT89X51.h>
sbit LED1=P1^0
sbit LED2=P1^1
void subDelay(unsigned int pTimes);
void main(void) //主函数名
{
while(1)
{
LED1 = 0;
LED2 = 1;
subDelay(65535);
LED1 = 1;
LED2 = 0;
subDelay(255);
}
}
void subDelay(unsigned int pTimes)
{
while(--pTimes);
}
答 9: szjgjg 你很幸福,这么多人 答 10: 好!抛砖引玉.向各位学习ing... 答 11: 我太感动了谢谢大家! 答 12: 哈哈,高手如云呀~~除了楼主coding烂点儿,都不错!!
void main(void) //主函数名
{
unsigned int a; //定义变量a为unsigned int类型
unsigned char b; //定义变量b为unsigned char类型
do
{ //do while组成循环
for (a=0; a<65535; a++)
P1_0 = 0; //65535次设P1.0口为低电平,点亮LED
P1_0 = 1; //设P1.0口为高电平,熄灭LED
for (a=0; a<30000; a++); //空循环
for (b=0; b<255; b++)
P1_1 = 0; //255次设P1.1口为低电平,点亮LED
P1_1 = 1; //设P1.1口为高电平,熄灭LED
for (a=0; a<30000; a++); //空循环
}
while(1);
}
应该是P1.0量的时间长一些,P1.1量的时间短一些,不断闪烁,但是只是P1.0闪动,P1.1不动???? 答 1: 255次设P1.1口为低电平,点亮LED。时间太短了 答 2: 你的晶振频率是多少?255次,会不会时间太短了,
加长点时间试试 答 3: 延时的位置不对,高低变化只有一个指令周期 答 4: 代码质量(与主题无关,探讨一哈)#include <AT89X51.h> //预处理命令
void main(void) //主函数名
{
unsigned int a;
while(1)
{
P1_0 = 0;
a=0;
while(--a!=0);
P1_0 = 1;
a=30000;
while(--a!=0);
P1_1=0;
a=256;
while(--a!=0);
P1_1 = 1;
a=30000;
while(--a!=0);
}
}
答 5: 重新来过#include <AT89X51.h> //预处理命令
void main(void) //主函数名
{
unsigned int a;
while(1)
{
P1_0 = 0;
a=0;
while(--a!=0);
P1_0 = 1;
P1_1=0;
a=30000;
while(--a!=0);
P1_1 = 1;
}
}
这样p1.0亮的长,p1.1亮的短。不停闪烁。。。
答 6: 我也凑热闹,谈代码质量:#include <AT89X51.h>
#define LED1 P1_0
#define LED2 P1_1
void subDelay(unsigned int pTimes);
void main(void) //主函数名
{
while(1)
{
LED1 = 0;
subDelay(65535);
LED1 = 1;
LED2=0;
subDelay(255);
LED2 = 1;
}
}
void subDelay(unsigned int pTimes)
{
while(--pTimes);
} 答 7: xxxx#include <AT89X51.h>
#define LED1 P1_0
#define LED2 P1_1
void subDelay(unsigned int pTimes);
void main(void) //主函数名
{
while(1)
{
LED1 = 0;
LED2 = 1;
subDelay(65535);
LED1 = 1;
LED2 = 0;
subDelay(255);
}
}
void subDelay(unsigned int pTimes)
{
while(--pTimes);
}
答 8: 这样是不是好些撒#include <AT89X51.h>
sbit LED1=P1^0
sbit LED2=P1^1
void subDelay(unsigned int pTimes);
void main(void) //主函数名
{
while(1)
{
LED1 = 0;
LED2 = 1;
subDelay(65535);
LED1 = 1;
LED2 = 0;
subDelay(255);
}
}
void subDelay(unsigned int pTimes)
{
while(--pTimes);
}
答 9: szjgjg 你很幸福,这么多人 答 10: 好!抛砖引玉.向各位学习ing... 答 11: 我太感动了谢谢大家! 答 12: 哈哈,高手如云呀~~除了楼主coding烂点儿,都不错!!
共2条
1/1 1 跳转至页
回复
我要赚赏金打赏帖 |
|
|---|---|
| 【S32K3学习整理】使用 LPUART 的loopback 模式实现核间通讯被打赏¥28元 | |
| arduinounoq原生zephyr环境搭建被打赏¥31元 | |
| 树莓派3+Klipper,MPU6050共振补偿被打赏¥41元 | |
| GroveCreatorKit套件+摇杆测评被打赏¥18元 | |
| 设备功耗web监控界面(ESP32C5)被打赏¥28元 | |
| OrangePiZero2W系统被打赏¥33元 | |
| Linux环境下以模拟方式快速实现出入管理功能测试被打赏¥24元 | |
| 树莓派3+Klipper,老3D打印机满血升级被打赏¥33元 | |
| OK1126B-S开发板下串口屏及其应用被打赏¥21元 | |
| 低功耗超声波液位测距仪(ESP32S3)被打赏¥27元 | |
我要赚赏金
