| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 446 人关注过本帖
标题:C语言外部中断初始化程序后面能否跟一个循环语句
只看楼主 加入收藏
mycbaobei
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2011-8-15
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:2 
C语言外部中断初始化程序后面能否跟一个循环语句

#include<reg52.h>
#include<intrins.h>

#define    uchar unsigned char
#define uint  unsigned int

#define    Cntrol_Port1    P1
#define Cntrol_Port2    P2

uchar    code Num[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//显示数字0--9
uint    code dbl[241]={49,49,49,49,48,48,48,48,48,47,47,47,47,47,46,46,46,45,45,45,
45,44,44,44,44,44,44,43,43,42,42,42,42,42,41,41,41,41,41,40,40,40,40,39,39,39,38,38,
38,37,37,37,37,37,37,36,36,36,35,35,35,35,34,34,34,33,33,33,33,32,32,31,31,31,31,31,
30,30,30,30,30,30,30,29,29,28,28,28,27,26,25,25,25,24,24,24,23,23,23,23,23,23,22,22,
22,22,21,21,21,21,21,21,20,20,19,19,19,18,18,18,18,17,17,17,17,17,16,16,16,15,15,15,
14,14,14,14,14,14,14,13,13,13,12,12,12,12,12,12,12,12,11,11,11,11,11,10,10,10,10,10,
10,10,10,10,10,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,10,10,10,11,11,11,11,12,12,12,13,13,
13,13,14,14,14,16,16,6,16,17,17,19,19,19,21,22,22,23,23,24,25,27,28,29,30,31,33,34,
35,37,38,40,42,43,45,47,48,51,53,55,57,60,62,64,68,71,74};
int        flay0,flay1,flay2;

sbit    p14=P1^4;
sbit    p15=P1^5;                                 
sbit    p16=P1^6;
sbit    p17=P1^7;
sbit    F3=P3^0;
sbit    F4=P3^1;
sbit    F1=P3^2;
sbit    F2=P3^3;
sbit    F5=P3^4;
sbit    F6=P3^5;

void    Delay(uint i)                             
{
    while(--i);
}

void zdcsh()
{
    IT0=0;
    IT1=0;
    EX0=1;
    EX1=1;
    EA=1;
//    IE0=1;
//    IE1=1;
}

void    getkey()                                 
{
    if(F1==0) F2=1;
    if(F2==0) F1=1;
    if(F3==0) F4=1;
    if(F4==0) F3=1;
}

void led(uint n)
{
    P0=0xff;
    Cntrol_Port2=0x01;
    P0=Num[n%10];
    Delay(100);
    P0=0xff;
    Cntrol_Port2=0x02;
    P0=Num[n/10%10];
    Delay(100);
    P0=0xff;
    Cntrol_Port2=0x04;
    P0=Num[n/100%10];
    Delay(100);
    P0=0xff;
    Cntrol_Port2=0x08;
    P0=Num[n/1000%10];
    Delay(100);
    Cntrol_Port1=0xff;
}

void led1(uint n)
{
    P0=0xff;
    Cntrol_Port2=0x10;
    P0=Num[n%10];
    Delay(100);
    P0=0xff;
    Cntrol_Port2=0x20;
    P0=Num[n/10%10];
    Delay(100);
    P0=0xff;
    Cntrol_Port2=0x40;
    P0=Num[n/100%10];
    Delay(100);
    P0=0xff;
    Cntrol_Port2=0x80;
    P0=Num[n/1000%10];
    Delay(100);
    Cntrol_Port1=0xff;
}
 
void djfw1()
{
    while(1)
    {
        if(F5==1) break;
        p15=1;
        Delay(3200);
        p14=0;
        Delay(3200);
        p15=0;
        Delay(3200);
        p14=1;
        Delay(3200);
    }
    flay0=121;
}

void djfw2()
{
    while(1)
    {
        if(F5==0) break;
        p14=1;
        Delay(3200);
        p15=0;
        Delay(3200);
        p14=0;
        Delay(3200);
        p15=1;
        Delay(3200);
    }
    flay0=120;
}

void djfw3()
{
    while(1)
    {        
        if(F6==1) break;
        p16=1;
        Delay(3200);
        p17=0;
        Delay(3200);
        p16=0;
        Delay(3200);
        p17=1;
        Delay(3200);
    }
    flay1=61;
}

void djfw4()
{
    while(1)
    {
         if(F6==0) break;
         p17=1;
        Delay(3200);
        p16=0;
        Delay(3200);
        p17=0;
        Delay(3200);
        p16=1;
        Delay(3200);
    }
    flay1=62;
}

void _zdj()
{
    uint i,j;
    flay2=flay1;
    flay1=dbl[flay0];
    if(flay2>flay1)
    {
        for(i=0;i<(flay2-flay1);i++)
        {
        p17=1;
        Delay(3200);
        p16=0;
        Delay(3200);
        p17=0;
        Delay(3200);
        p16=1;
        Delay(3200);
        }
    }
    if(flay2<flay1)
    {
        for(j=0;j<(flay1-flay2);j++)
        {
        p16=1;
        Delay(3200);
        p17=0;
        Delay(3200);
        p16=0;
        Delay(3200);
        p17=1;
        Delay(3200);
        }
    }
}

void ledxs()
{
    uint m;
    do                                           //数值用数码管显示
    {
    m=0;
    if(F1==0)    break;
    if(F2==0)    break;
    led(flay0);
    led1(flay1);
    m++;   
    }while(m<=100000);
}

void djwt()
{
    uint q;
    q=5;
    while(1)
    {
        if(F3==0)
        {
        p17=1;
        Delay(3200);
        p16=0;
        Delay(3200);
        p17=0;
        Delay(3200);
        p16=1;
        Delay(3200);
        q--;
        if(q<0)      q=0;   
        }
        if(F4==0)
        {
        p16=1;
        Delay(3200);
        p17=0;
        Delay(3200);
        p16=0;
        Delay(3200);
        p17=1;
        Delay(3200);
        q++;
        if(q>10) q=10;   
        }
        if(F1==0) break;
        if(F2==0) break;
    }   
}

void djzz() interrupt 0
{
    EA=0;
    while(1)
    {
        getkey();
        p14=1;
        Delay(3200);
        p15=0;
        Delay(3200);
        p14=0;
        Delay(3200);
        p15=1;
        Delay(3200);
        flay0--;
        if(flay0<0) flay0=0;
        if(F1==1) break;
    }
/*    flay2=flay1;
    if(flay0==0)
        flay1=49;
    if(flay0>0&&flay0<=190)
    {   
        flay1=dbl[flay0];
    }
    if(flay0>190&&flay0<=240)
    {
        flay1=dbl[flay0]-2;
    }  */
    _zdj();
    ledxs();
    djwt();
    EA=1;   
}

void djfz() interrupt 2
{
    EA=0;
    while(1)
    {
        getkey();
        p15=1;
        Delay(3200);
        p14=0;
        Delay(3200);
        p15=0;
        Delay(3200);
        p14=1;
        Delay(3200);
        flay0++;
        if(flay0>240) flay0=240;
        if(F2==1) break;
    }
/*    flay2=flay1;
    if(flay0==0)
        flay1=49;
    if(flay0>0&&flay0<=190)
    {
        flay1=dbl[flay0];
    }
    if(flay0>190&&flay0<=240)
    {
        flay1=dbl[flay0]+2;
    }     */
    _zdj();
    ledxs();
    djwt();
    EA=1;   
}
 void main()                                        //主程序
{
    uint a,b;
    Cntrol_Port1=0xff;                 //端口初始化
        flay0=0;
        flay1=0;
        a=F5;                                //电机初始化
        b=F6;               
    switch(a)
    {
        case 0:    djfw1(); break;
        case 1: djfw2(); break;
    }
    switch(b)
    {
        case 0:    djfw3(); break;
        case 1: djfw4(); break;
    }
    _zdj();                                //自动调焦
    ledxs();                                //LED灯显示
    zdcsh();                            //中断初始化
    djwt();                            //电机微调
}


[ 本帖最后由 mycbaobei 于 2011-8-16 15:59 编辑 ]
搜索更多相关主题的帖子: C语言 
2011-08-16 15:37
laoyang103
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:内蒙古包头
等 级:贵宾
威 望:19
帖 子:3082
专家分:11056
注 册:2010-5-22
收藏
得分:14 
完整程序

                                         
===========深入<----------------->浅出============
2011-08-16 15:42
mycbaobei
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2011-8-15
收藏
得分:0 
回复 2楼 laoyang103
就是后面加了个电机微调  用不了   不加的话 我就用了 可以用的  完整程序发出来了  帮我看看

[ 本帖最后由 mycbaobei 于 2011-8-16 15:59 编辑 ]
2011-08-16 15:48
快速回复:C语言外部中断初始化程序后面能否跟一个循环语句
数据加载中...
 
   



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

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