求写一段简单的51单片机C语言代码
展开全部
#include < reg52.h >
#include <intrins.h>
sbit P00 = P0^0;
void delay(unsigned int ms)
{
unsigned char i;
while(ms--) for(i = 110; i-- ; i > 0);
}
void main()
{
unsigned char LED = 0xfe, COUN = 0;
while(1) {
P1 = LED;
P2 = COUN;
if (P00 == 1) {
delay(2);
if (P00 == 1) {
while (P00 == 1);
LED = _cror_(LED, 1);
COUN++;
} } } }
#include <intrins.h>
sbit P00 = P0^0;
void delay(unsigned int ms)
{
unsigned char i;
while(ms--) for(i = 110; i-- ; i > 0);
}
void main()
{
unsigned char LED = 0xfe, COUN = 0;
while(1) {
P1 = LED;
P2 = COUN;
if (P00 == 1) {
delay(2);
if (P00 == 1) {
while (P00 == 1);
LED = _cror_(LED, 1);
COUN++;
} } } }
展开全部
单片机检测高电平。1、可以用外部中断,外接激光传感器最好用普通光耦隔离一下,顺便改成低电平触发单片机中断。然后用位移指令移动跑马灯,然后计数值加1. 2、可以用循环检测,也建议用光耦隔离先,在MAIN里面不断检测P00,发现变化后,再次检测以便确认,确认后同样位移一下跑马灯,然后计数加1。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
假如LED是8位,输出口为PB
void ledshift(void)
{
static uchar i=0x01;
static counter = 0;
if(P00==1)
{
if(counter++%8==0)
{
i = 0x01;
}
i=i<<1;
PB = i;
}
}
void ledshift(void)
{
static uchar i=0x01;
static counter = 0;
if(P00==1)
{
if(counter++%8==0)
{
i = 0x01;
}
i=i<<1;
PB = i;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询