hrefspace

 找回密码
 立即注册
搜索
热搜: PHP PS 程序设计
查看: 428|回复: 0

单片机课设,有几个地方卡住 了,麻烦大神指点一下!

[复制链接]

930

主题

1141

帖子

3598

积分

超级版主

Rank: 8Rank: 8

积分
3598

论坛头条论坛元老谋士数据帝优秀版主超级版主见习版主论坛版主

发表于 2024-2-9 12:16:05 | 显示全部楼层 |阅读模式
实现按下k1,执行操作,按一下k2,暂停程序,在按一下k1恢复程序;长按k2,中止程序。
谢谢亲们,感激不尽

#include "reg52.h"   
#include "intrins.h"
typedef unsigned int u16;  
typedef unsigned char u8;
u16 scale;
u16 count = 0;
sbit k1=P3^2;  
sbit k2=P3^3;  
sbit led1=P2^0;  
sbit led2=P2^1;
sbit led3=P2^2;
sbit led4=P2^3;
sbit led5=P2^4;
sbit pwm = P1^0;

/*timer0() interrupt 1   
{ static  u16   tt ;   
tt++;   
if(tt==10)   
{ tt=0;  
led5=0;  
}
if(scale==tt)  
led5=1;  

}
*/

//¶¶¶ˉÑóê±
void delay1(u16 i)
{
while(i--);
}
//¼ÆêyÑóê±
void delay2(u16 i)
{
        u8 a;
        for(a=0;a<i;a++)
        {
                TMOD = 0x00;
                TH0 = (65536-50000)/256;
                TL0 = (65536-50000)%256;
                TR0=1;
                while(!TF0);
                TF0=0;
        }
               
}


//עˮ
void light1()
{
        if(count == 0)led1=0;
        if(count == 0)delay2(20);
        if(count == 0)led1 = ~led1;
}
//Ï′μó£¨μç»úÔË×a£©
void light2()
{
        if(count == 0)led5 = ~led5;
        if(count == 0)led3 = ~led3;
        if(count == 0)delay2(20);
        if(count == 0)led3 = ~led3;
        if(count == 0)delay2(20);
        if(count == 0)led4 = ~led4;
        if(count == 0)delay2(20);
        if(count == 0)led4 = ~led4;
        if(count == 0)delay2(20);
        if(count == 0)led3 = ~led3;
        if(count == 0)delay2(20);
        if(count == 0)led3 = ~led3;
        if(count == 0)delay2(20);
        if(count == 0)led4 = ~led4;
        if(count == 0)delay2(20);
        if(count == 0)led4 = ~led4;
        if(count == 0)led5 = ~led5;
        if(count == 0)delay2(20);
        
}
//ÅÅË®£¨μç»úí£Ö1£©
void light3()
{
        if(count == 0)led2 = ~led2;
        if(count == 0)delay2(20);
        if(count == 0)led2 = ~led2;

}
//ÆˉÏ′
void light4()
{
        if(count == 0)led5 = ~led5;
        if(count == 0)led1 = ~led1;
        if(count == 0)led3 = ~led3;
        if(count == 0)delay2(20);
        if(count == 0)led3 = ~led3;
        if(count == 0)delay2(20);
        if(count == 0)led4 = ~led4;
        if(count == 0)delay2(20);
        if(count == 0)led4 = ~led4;
        if(count == 0)delay2(20);
        if(count == 0)led1 = ~led1;

}
/*
//Ë|¸é
void light5()
{   
      
u16 n;     
TMOD=0x02;  
TH0=0x06;   
TL0=0x06;   
TR0=1;   
ET0=1;   
EA=1;     
while(1)
{for(n=0;n<5000;n++);  
scale++;   
}
        
}
*/
//éá˸
void light6()
{
        while(1)
        {
                if(count == 0)led1 = ~led1;
                if(count == 0)led2 = ~led2;
                if(count == 0)delay2(20);
                if(count == 0)led1 = ~led1;
                if(count == 0)led2 = ~led2;
                if(count == 0)delay2(20);
        }
        
}
//¶àᢰ′¼ü
void key1()
{
        if(k1==0)   
        {
                delay1(1000);   
                if(k1==0)  
                {
               
                        light1();
                        light2();
                        light3();
                        light4();
                        /*light5();*/
                        light6();
               
                }
                while(!k1);  
        }  
}
void key2()
{
        if(k2==0)   
        {
                TH0=(65536-60000)/256;
                TL0=(65536-60000)%256;  
                if(k2==0)  
                {   
                                count = 1;
                                while(1)
                                {
                                        key1();
                                }
                        
                                
                }
         
        }  
}
//°′¼üÖD¶Ï
stop()interrupt 1
{
        key2();
}


void main()
{
        led1 = 1;
        led2 = 1;
        led3 = 1;
        led4 = 1;
        led5 = 1;

        TMOD=0x01;
        TH0=(65536-60000)/256;
        TL0=(65536-60000)%256;
        TR0=1;
        EA=1;
        ET0=1;
        while(1)
        {
                key1();        
        }
}
世界上最遥远的距离,不是生与死的距离,而是我站在你面前,你却不知道我爱你
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|hrefspace

GMT+8, 2024-5-5 08:48 , Processed in 0.060128 second(s), 22 queries .

Powered by hrefspace X3.4 Licensed

Copyright © 2022, hrefspace.

快速回复 返回顶部 返回列表