打印

nokiatune

[复制链接]
227|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
34af9uc|  楼主 | 2022-6-22 22:06 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

/*****************nokiatune************************/
/*****************qq:774145445*********************/
/*****************快手:共同学习stm8****************/
/*****************2022/6/19************************/
/*****************IDE:0.94*************************/
//            _pms152___    __________
//      led5-|1 pb4     \__/    pb3 16|-led4
//      led6-|2 pb5             pb2 15|-led3
//      led7-|3 pb6             pb1 14|-led2
//      led8-|4 pb7             pb0 13|-led1
//        5v-|5 vdd             gnd 12|-gnd
//        k1-|6 pa7             pa0 11|-zuo
//        k2-|7 pa6             pa4 10|-you
//           |8_pa5_____________pa3__9|-feng

#include        "extern.h"
/**************************************************/
void                chushihua();        //初始化
void                liushui();                //流水灯
word                ya;                                //延时用

void                yue();                        //音乐
void                chang();                //唱歌
word                cx;                                //唱歌音阶长度
word                cy;                                //唱歌低电平时间

void                yanshi();                //延时
/**************************************************/
led1                bit                pb.0;
led2                bit                pb.1;
led3                bit                pb.2;
led4                bit                pb.3;
led5                bit                pb.4;
led6                bit                pb.5;
led7                bit                pb.6;
led8                bit                pb.7;
zuo                        bit                pa.0;
you                        bit                pa.4;
feng                bit                pa.3;
k1                        bit                pa.7;
k2                        bit                pa.6;
/**************************************************/
void        FPPA0 (void)
{
.ADJUST_IC        SYSCLK=IHRC/4                //        SYSCLK=IHRC/4
chushihua();
while (1)
{
//chushihua();
clkmd                =                0xf4;                //ihrc变ilrc
clkmd.4                =                0;                        //ihrc停用
stopexe;                                                //进入掉电模式

if(k1==0)
{
.delay 50;
if(k1==0)
        {
        /**************************************************/
        clkmd.4                =                1;                        //ihrc启用
        .delay 50;
        clkmd                =                0x14;                //ilrc变ihrc/4
        /**************************************************/
        chushihua();
        liushui();
        }
}
if(k2==0)
{
.delay 50;
if(k2==0)
        {
        /**************************************************/
        clkmd.4                =                1;                        //ihrc启用
        .delay 50;
        clkmd                =                0x14;                //ilrc变ihrc/4
        /**************************************************/

        chushihua();
        yue();                //音乐
        }

.delay 10000;

}
}
}
/**************************************************/
void                liushui()                //流水灯
{
byte                l1,l2,l3;
l3                        =5;                //5圈减半圈
while(l3--)
        {
        l1                        =0x01;
        l2                        =0x09;
        if(l3==1){l2=8;}                //升到顶
        zuo                        =0;
        you                        =1;
        while(l2--)
                {
                pb                        =l1;
                //.delay                150000;
                ya=100;
                if(l3==0){ya=1000;}                                        //最后半圈延时加长
                if(l3==0){if(l2==1){ya=8000;}}                //最后半圈的最后二个灯
                if(l3==0){if(l2==0){pb=0; zuo=0; you=0; return;}}                //最后半圈的最后一个灯
                yanshi();
                l1                        <<=1;
                }
        //        if(l3==0){pb=0; return;}        //实现半圈返回
                       
               
        //if(l3==1){ya=2000; yanshi(); pb=0; return;}                //实现半圈返回

        l1                        =0x80;
        l2                        =0x09;
        zuo                        =1;
        you                        =0;
        while(l2--)
                {
                pb                        =l1;
                //.delay                150000;
                ya=100;
                yanshi();

                l1                        >>=1;
                }
        }
}
/**************************************************/
void                chushihua()                //初始化
{
$                led1                out,low;
$                led2                out,low;
$                led3                out,low;
$                led4                out,low;
$                led5                out,low;
$                led6                out,low;
$                led7                out,low;
$                led8                out,low;
$                zuo                        out,high;
$                you                        out,high;
$                feng                out,low;
$                k1                        in,pull;
$                k2                        in,pull;
}
/**************************************************/
void                yue()                        //音乐
{
/**************************************************/ //5
cx=84;//167;                //音阶长度
cy=295;//590;                //低电平时间
chang();
/**************************************************/ //4
cx=72;//145;                //音阶长度
cy=340;//680;                //低电平时间
chang();
/**************************************************/ //6
cx=90;//183;                //音阶长度
cy=600;//1202;                //低电平时间
chang();
/**************************************************/ //7
cx=104;//207;                //音阶长度
cy=510;//1020;                //低电平时间
chang();
/**************************************************/ //3
cx=70;//137;                //音阶长度
cy=365;//726;                //低电平时间
chang();
/**************************************************/ //2
cx=64;//125;                //音阶长度
cy=430;//862;                //低电平时间
chang();
/**************************************************/ //4
cx=73;//146;                //音阶长度
cy=760;//1519;                //低电平时间
chang();
/**************************************************/ //5
cx=82;//164;                //音阶长度
cy=670;//1338;                //低电平时间
chang();
/**************************************************/ //2
cx=62;//122;                //音阶长度
cy=420;//839;                //低电平时间
chang();
/**************************************************/ //1
cx=56;//110;                //音阶长度
cy=476;//952;                //低电平时间
chang();
/**************************************************/ //3
cx=70;//139;                //音阶长度
cy=800;//1610;                //低电平时间
chang();
/**************************************************/ //5
cx=82;//164;                //音阶长度
cy=670;//1338;                //低电平时间
chang();
/**************************************************/ //1
cx=332;//661;                //音阶长度
cy=486;//970;                //低电平时间
chang();
/**************************************************/
}
/**************************************************/
void                chang()                //唱歌
{
word                y;
cx                +=40;
while(cx)                //唱歌音阶长度
//while(1)
        {
        cx--;
        feng                =1;                //高电平时间固定
        .delay 460;
        feng                =0;
        y                =cy;
        while(y)                        //低电平时间
                {
                y--;
                nop; nop; nop; nop; nop;
                }

        }
}
/**************************************************/
/**************************************************/
void                yanshi()                //延时
{
byte                yx=50;
while(ya--)
{
if(yx>10){yx--;if(feng==1){feng=0;}else{feng=1;}}
.delay 1000;
nop;nop;nop;nop;
}
//if(feng==1){feng=0;}
}
/**************************************************/
/**************************************************/
/*
void        Interrupt (void)
{
        pushaf;

        if (Intrq.T16)
        {        //        T16 Trig
                //        User can add code
                Intrq.T16        =        0;
                //...
        }

        popaf;
}
*/


nokia.zip

1.65 KB

使用特权

评论回复
发新帖
您需要登录后才可以回帖 登录 | 注册

本版积分规则

284

主题

441

帖子

55

粉丝