| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 469 人关注过本帖
标题:高手帮忙下,想将常亮的LED变成闪烁的,请问程序要怎么编.
只看楼主 加入收藏
ytechcn
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2012-6-16
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:3 
高手帮忙下,想将常亮的LED变成闪烁的,请问程序要怎么编.
问题补充:我是初学者,这个程序是7个按钮分别控制7个LED,一个总按钮做RESET用,但我只会用按钮把LED点亮,但我想要闪烁的效果,望高手们指教,不胜感激,程序如下!

#include<reg52.h>

#define uint unsigned int

#define uchar unsigned char

sbit led1=P0^0;
sbit led2=P0^1;
sbit led3=P0^2;
sbit led4=P0^3;
sbit led5=P0^4;
sbit led6=P0^5;
sbit led7=P0^6;

sbit key1=P2^0;
sbit key2=P2^1;
sbit key3=P2^2;
sbit key4=P2^3;
sbit key5=P2^4;
sbit key6=P2^5;
sbit key7=P2^6;
sbit reset_k=P2^7;

uchar numt0,num;


void delayms(uint xms)

       {

        uint i,j;

        for(i=xms;i>0;i--)

                for(j=110;j>0;j--);

        }        

void init()

        {

         TMOD=0x01;

         TH0=(65536-50000)/256;

         TL0=(65536-5000)%256;

         EA=1;

         ET0=1;

         TR0=1;


        }


void T0_timer()interrupt 1

     {

              TH0=(65536-50000)/256;

              TL0=(65536-50000)%256;

              numt0++;

              

       }


void keyscan()

       {

          if(key1==0)

                {
                       delayms(10);

                       if(key1==0)
                       
                       {
                                                
                        led1=0;   
                                                                                                            
                        while(!key1);
                        

                        }
                        
                 }


            if(key2==0)

                {
                       delayms(10);

                       if(key2==0)

                       {

                        led2=0;
                              
                        while(!key2);
        

                        }

                 }


              if(key3==0)

                {
                       delayms(10);

                       if(key3==0)

                       {

                        led3=0;
                              
                        while(!key3);
        

                        }

                 }


               if(key4==0)

                {
                       delayms(10);

                       if(key4==0)

                       {

                        led4=0;
                              
                        while(!key4);
        

                        }

                 }


               if(key5==0)

                {
                       delayms(10);

                       if(key5==0)

                       {

                        led5=0;
                              
                        while(!key5);
        

                        }

                 }


                if(key6==0)

                {
                       delayms(10);

                       if(key6==0)

                       {

                        led6=0;
                              
                        while(!key6);
        

                        }

                 }


                 if(key7==0)

                {
                       delayms(10);

                       if(key7==0)

                       {

                        led7=0;
                              
                        while(!key7);
        

                        }

                 }


                  if(reset_k==0)

                {
                       delayms(10);

                       if(reset_k==0)

                       {

                        led1=1;
                        led2=1;
                        led3=1;
                        led4=1;
                        led5=1;
                        led6=1;
                        led7=1;      
                        while(!reset_k);
        

                        }

                 }

          }
           

void main()
{
   
    init();
     
    while(1)

    {
              keyscan();

     }

}


搜索更多相关主题的帖子: 不胜感激 include 
2012-06-16 01:44
pauljames
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:千里冰封
威 望:9
帖 子:1555
专家分:10000
注 册:2011-5-8
收藏
得分:10 
闪烁的效果很简单,可以用点亮一次,然后延迟1s,再熄灭,然后延迟1s,再点亮,如此循环;延迟1s可以用双重循环做,也可以用定时器做。

经常不在线不能及时回复短消息,如有c/单片机/运动控制/数据采集等方面的项目难题可加qq1921826084。
2012-06-16 06:20
qq383264679
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:155
专家分:130
注 册:2012-1-19
收藏
得分:10 
小飞侠 你是选的单片机的方向?
2012-06-16 09:40
ytechcn
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2012-6-16
收藏
得分:0 
2楼的,请问用定时器应该怎样编,具体在哪里插入,可以列出来看看吗?
2012-06-16 09:48
快速回复:高手帮忙下,想将常亮的LED变成闪烁的,请问程序要怎么编.
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021101 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved