这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 嵌入式开发 » MCU » keilc做出来的惩法

共5条 1/1 1 跳转至

keilc做出来的惩法

助工
2011-10-18 10:00:01     打赏
#include<reg52.h>
typedef unsigned char uint8;
typedef unsigned int uint16;

uint8 code smgdu[]={0x3f,0x06,0x5b,0x4f,0x66,
                    0x6d,0x7d,0x07,0x7f,0x6f};
sbit smgen=P2^3;
sbit rs=P3^6;

void delay(uint16 k)
{
     uint16 i,j;
    for(i=0;i<k;i++)
    {
        for(j=0;j<121;j++)
    {;}
    }
}

void main()
{
    uint8 x=30;
    uint16 y=55;
    uint16 z;
    rs=0;

    z=x*y;
        while(1)
        {
            smgen=1;
            P1=smgdu[z/1000];
            P2=0x30;
            delay(1);

//            smgen=1;
            P1=smgdu[z%1000/100];
            P2=0x20;
            delay(1);
        
//            smgen=1;
            P1=smgdu[z%100/10];
            P2=0x10;
            delay(1);

//            smgen=1;
            P1=smgdu[z%10];
            P2=0x00;
            delay(1);

        }
}
结果1110;

            smgen=1;
            P1=smgdu[z/1000];
            P2=0x30;
            delay(1);

            smgen=1;
            P1=smgdu[z%1000/100];
            P2=0x20;
            delay(1);
        
//            smgen=1;
            P1=smgdu[z%100/10];
            P2=0x10;
            delay(1);

//            smgen=1;
            P1=smgdu[z%10];
            P2=0x00;
            delay(1);
结果1668

        while(1)
        {
            smgen=1;
            P1=smgdu[z/1000];
            P2=0x30;
            delay(1);

            smgen=1;
            P1=smgdu[z%1000/100];
            P2=0x20;
            delay(1);
        
            smgen=1;
            P1=smgdu[z%100/10];
            P2=0x10;
            delay(1);

//            smgen=1;
            P1=smgdu[z%10];
            P2=0x00;
            delay(1);
结果1658

void main()
{
    uint8 x=30;
    uint16 y=55;
    uint16 z;
    rs=0;

    z=x*y;
        while(1)
        {
            smgen=1;
            P1=smgdu[z/1000];
            P2=0x30;
            delay(1);

            smgen=1;
            P1=smgdu[z%1000/100];
            P2=0x20;
            delay(1);
        
            smgen=1;
            P1=smgdu[z%100/10];
            P2=0x10;
            delay(1);

            smgen=1;
            P1=smgdu[z%10];
            P2=0x00;
            delay(1);

        }
}
结果正解1650

这个数码管的全能太重要了



关键词: keilc     出来     惩法     smgdu     smgen     d    

助工
2011-10-18 10:02:06     打赏
2楼
Keil C做这个简单的计算是不成问题的,但是如果省略了后面几个“smgen=1;”smgen将等于0而不是1。

助工
2011-10-18 10:03:12     打赏
3楼
这个和keil有关系吗?应该是你逻辑就有问题,换其他处理器一样有相同的效果的

院士
2011-10-18 10:11:13     打赏
4楼
你没按KEIL的规则出牌,当然会这样了。。。。

菜鸟
2011-10-18 16:13:05     打赏
5楼
野路子啊!

共5条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]