/*
一、空程序
*/
#include "stm8s208rb.h"
void delay(unsigned int t)
{
while(t--);
}
main()
{
PG_ODR = 0xff;
PG_DDR = 0xff;
PG_CR1 = 0xff;
PG_CR2 = 0x00;
while(1)
{
PG_ODR = 0x00;
delay(50000);
PG_ODR = oxff;
delay(50000);
}
}
/*
二、LED灯闪烁
*/
#include "stm8s208r.h"
void delay(unsigned int time);
void main(void)
{
PB_DDR |= 0X01; //选择输出模式
PB_CR1 |= 0X01; //推挽输出模式
PB_CR2 |= 0X00; //低速输出模式
while(1)
{
PB_ODR &= 0Xfe; //小灯亮
delay(50000); //调用延时函数
PB_ODR |= 0x01; //小灯灭
delay(50000); //调用延时函数
}
}
/*****************延时子程序*******************/
void delay(unsigned int time)
{
while(time--); //在此处循环
}
/*
三、跑马灯
*/
#includde "stm8s208r.h"
void delay(unsigned int time);
void main(void)
{
unsigned char i = 0;
PB_ODR = 0XFF; //设置输出寄存器的输出数值,初始化小灯全灭
PB_DDR = 0XFF; //设置I/O口B为输出
PB_CR1 = 0XFF; //设置I/O口B为推挽方式
PB_CR2 = 0X00; //输出最快速度为 2 MHZ
while(1)
{
switch(i) //让小灯从低位到高位一次亮
{
case 0: PB_ODR = 0xfe;
break;
case 1: PB_ODR = 0xfd;
break;
case 2: PB_ODR = 0xfb;
break;
case 3: PB_ODR = 0xf7;
break;
case 4: PB_ODR = 0xef;
break;
case 5: PB_ODR = 0xef;
break;
case 6: PB_ODR = 0xbf;
break;
case 7: PB_ODR = 0x7f;
break;
default: PB_ODR = 0xfe;
}
Delay(40000); //延时约20ms
i++; //让 i 加 1,下次执行程序时进入到case
if(i == 8)
{
i = 0;
}
}
}
/************延时子程序*************/
void delay(unsigned int time)
{
一、空程序
*/
#include "stm8s208rb.h"
void delay(unsigned int t)
{
while(t--);
}
main()
{
PG_ODR = 0xff;
PG_DDR = 0xff;
PG_CR1 = 0xff;
PG_CR2 = 0x00;
while(1)
{
PG_ODR = 0x00;
delay(50000);
PG_ODR = oxff;
delay(50000);
}
}
/*
二、LED灯闪烁
*/
#include "stm8s208r.h"
void delay(unsigned int time);
void main(void)
{
PB_DDR |= 0X01; //选择输出模式
PB_CR1 |= 0X01; //推挽输出模式
PB_CR2 |= 0X00; //低速输出模式
while(1)
{
PB_ODR &= 0Xfe; //小灯亮
delay(50000); //调用延时函数
PB_ODR |= 0x01; //小灯灭
delay(50000); //调用延时函数
}
}
/*****************延时子程序*******************/
void delay(unsigned int time)
{
while(time--); //在此处循环
}
/*
三、跑马灯
*/
#includde "stm8s208r.h"
void delay(unsigned int time);
void main(void)
{
unsigned char i = 0;
PB_ODR = 0XFF; //设置输出寄存器的输出数值,初始化小灯全灭
PB_DDR = 0XFF; //设置I/O口B为输出
PB_CR1 = 0XFF; //设置I/O口B为推挽方式
PB_CR2 = 0X00; //输出最快速度为 2 MHZ
while(1)
{
switch(i) //让小灯从低位到高位一次亮
{
case 0: PB_ODR = 0xfe;
break;
case 1: PB_ODR = 0xfd;
break;
case 2: PB_ODR = 0xfb;
break;
case 3: PB_ODR = 0xf7;
break;
case 4: PB_ODR = 0xef;
break;
case 5: PB_ODR = 0xef;
break;
case 6: PB_ODR = 0xbf;
break;
case 7: PB_ODR = 0x7f;
break;
default: PB_ODR = 0xfe;
}
Delay(40000); //延时约20ms
i++; //让 i 加 1,下次执行程序时进入到case
if(i == 8)
{
i = 0;
}
}
}
/************延时子程序*************/
void delay(unsigned int time)
{