本帖最后由 34af9uc 于 2021-12-1 23:52 编辑
/****************联盛德W806呼吸灯******************/
/****************QQ:774145445**********************/
/****************快手:共同学习stm8*****************/
/****************AboutCDK 2.10.1*******************/
/**************************************************/
//a1++ 0|__ __ __ __ __ __ __ __ __ __|ff
// a2↑ ↑
// ledh(开灯) ledl(关灯)
/**************************************************/
#define GPIOB_DATA (*(volatile unsigned int*)(0x40011400+0x0000))
#define GPIOB_DATA_EN (*(volatile unsigned int*)(0x40011400+0X0004))
#define GPIOB_DIR (*(volatile unsigned int*)(0x40011400+0X0008))
#define wei0 0b0000000000000001
#define wei1 0b0000000000000010
#define wei2 0b0000000000000100
#define wei3 0b0000000000001000
#define wei4 0b0000000000010000
#define wei5 0b0000000000100000
#define wei6 0b0000000001000000
#define wei7 0b0000000010000000
#define wei8 0b0000000100000000
#define wei9 0b0000001000000000
#define wei10 0b0000010000000000
#define wei11 0b0000100000000000
#define wei12 0b0001000000000000
#define wei13 0b0010000000000000
#define wei14 0b0100000000000000
#define wei15 0b1000000000000000
#define led_h GPIOB_DATA|=wei0
#define led_l GPIOB_DATA&=~wei0
/**************************************************/
void yanshi(); //延时
/**************************************************/
int main(void)
{
unsigned char a1,a2;
unsigned char b1;
a1 =0; //计数器
a2 =0x30; //比较器
b1 =0; //状态(0渐亮1渐暗)
/**************************************************/ //IO配置
GPIOB_DATA_EN |=wei0;
GPIOB_DIR |=wei0;
GPIOB_DATA |=wei0;
/**************************************************/
led_h; //灭灯
while (1)
{
if(a1 ==a2) {led_l;} //开灯
a1 ++;
if(a1==0xff)
{
led_h; //关灯
if(b1==0) //渐亮
{
a2 --;
if(a2==10){b1=1;}
}
if(b1==1) //渐暗
{
a2 ++;
if(a2==0xe0){b1=0;}
}
}
yanshi();
}
return 0;
}
/**************************************************/
void yanshi() //延时
{
volatile unsigned int x;
for(x=48,x>0;x--;);
}
/**************************************************/
/**************************************************/
/**************************************************/
/**************************************************/
|