//晟矽微单片机编程第四天//流水灯
//为了方便移植和后期更改io方便不得不用#define宏定义,这样太麻烦了也没有别的办法了.
//qq:74145445
//快手:共同学习stm8
// MC32P7311
// _____@_____
// led0--p16|1 16|p17--led13
// vdd|2 15|vss
// led1--p15|3 14|p00--led12
// led2--p14|4 13|p01--led11
// led3--p13|5 12|p02--led10
// led4--p12|6 11|p03--led9
// led5--p11|7 10|p04--led8
// led6--p10|8_________9|p05--led7
#define bit0 0b00000001
#define bit1 0b00000010
#define bit2 0b00000100
#define bit3 0b00001000
#define bit4 0b00010000
#define bit5 0b00100000
#define bit6 0b01000000
#define bit7 0b10000000
#define bit8 0b0000000100000000
#define bit9 0b0000001000000000
#define bit10 0b0000010000000000
#define bit11 0b0000100000000000
#define bit12 0b0001000000000000
#define bit13 0b0010000000000000
#define bit14 0b0100000000000000
#define bit15 0b1000000000000000
//led0--p16
#define led_0chu OEP1 |=bit6 //输出使能0输入1为输出
#define led_0h IOP1 |=bit6 //点亮led
#define led_0l IOP1 &=~bit6 //熄灭led
//led1--p15
#define led_1chu OEP1 |=bit5
#define led_1h IOP1 |=bit5
#define led_1l IOP1 &=~bit5
//led2--p14
#define led_2chu OEP1 |=bit4
#define led_2h IOP1 |=bit4
#define led_2l IOP1 &=~bit4
//led3--p13
#define led_3chu OEP1 |=bit3
#define led_3h IOP1 |=bit3
#define led_3l IOP1 &=~bit3
//led4--p12
#define led_4chu OEP1 |=bit2
#define led_4h IOP1 |=bit2
#define led_4l IOP1 &=~bit2
//led5--p11
#define led_5chu OEP1 |=bit1
#define led_5h IOP1 |=bit1
#define led_5l IOP1 &=~bit1
//led6--p10
#define led_6chu OEP1 |=bit0
#define led_6h IOP1 |=bit0
#define led_6l IOP1 &=~bit0
//led7--p05
#define led_7chu OEP0 |=bit5
#define led_7h IOP0 |=bit5
#define led_7l IOP0 &=~bit5
//led8--p04
#define led_8chu OEP0 |=bit4
#define led_8h IOP0 |=bit4
#define led_8l IOP0 &=~bit4
//led9--p03
#define led_9chu OEP0 |=bit3
#define led_9h IOP0 |=bit3
#define led_9l IOP0 &=~bit3
//led10--p02
#define led_10chu OEP0 |=bit2
#define led_10h IOP0 |=bit2
#define led_10l IOP0 &=~bit2
//led11--p01
#define led_11chu OEP0 |=bit1
#define led_11h IOP0 |=bit1
#define led_11l IOP0 &=~bit1
//led12--p00
#define led_12chu OEP0 |=bit0
#define led_12h IOP0 |=bit0
#define led_12l IOP0 &=~bit0
//led13--p17
#define led_13chu OEP1 |=bit7
#define led_13h IOP1 |=bit7
#define led_13l IOP1 &=~bit7
#include"MC32P7311.h"
void yanshi(); //延时
void main()
{
unsigned int a1,a2;
led_1chu;
led_1chu;
led_2chu;
led_3chu;
led_4chu;
led_5chu;
led_6chu;
led_7chu;
led_8chu;
led_9chu;
led_10chu;
led_11chu;
led_12chu;
led_0l;
led_1l;
led_2l;
led_3l;
led_4l;
led_5l;
led_6l;
led_7l;
led_8l;
led_9l;
led_10l;
led_11l;
led_12l;
led_13l;
for(;;)
{
a2=0x01;
for(a1=14;a1>0;a1--)
{
if(a2&&bit0){led_0h;} else{led_0l;}
if(a2&&bit1){led_1h;} else{led_1l;}
if(a2&&bit2){led_2h;} else{led_2l;}
if(a2&&bit3){led_3h;} else{led_1l;}
if(a2&&bit4){led_4h;} else{led_1l;}
if(a2&&bit5){led_5h;} else{led_1l;}
if(a2&&bit6){led_6h;} else{led_1l;}
if(a2&&bit7){led_7h;} else{led_1l;}
if(a2&&bit8){led_8h;} else{led_1l;}
if(a2&&bit9){led_9h;} else{led_1l;}
if(a2&&bit10){led_10h;} else{led_1l;}
if(a2&&bit11){led_11h;} else{led_1l;}
if(a2&&bit12){led_12h;} else{led_12l;}
if(a2&&bit13){led_13h;} else{led_13l;}
yanshi();
a2 >>=1; //右移一位
}
}
}
void yanshi() //延时
{
unsigned char x,y;
for(x=100;x>0;x--)
{
for(y=100;y>0;y--);
}
} |