#include "stm8s105c_s.h"
#define LED PG_ODR
#define shuzhi PB_ODR
long int a;
char t,f='1';
int shumaguan[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
int o,i,u,y,k=-1;
void xianshi(void)
{
while(1)
{
PD_ODR=0B00001110;
shuzhi=shumaguan[y];
for(a=0;a<1000;a++);
PD_ODR=0B00001101;
shuzhi=shumaguan[u];
for(a=0;a<1000;a++);
PD_ODR=0B00001011;
shuzhi=shumaguan[i];
for(a=0;a<1000;a++);
PD_ODR=0B00000111;
shuzhi=shumaguan[o];
for(a=0;a<1000;a++);
}
}
void jingzhen(void)//开16兆晶振
{
CLK_ECKR |=0x1; //开启外部时钟
while(!(CLK_ECKR&0x2)); //等待外部时钟
CLK_CKDIVR &= 0xF8; //CPU无分频 16M
CLK_SWR = 0xB4; //选择外部时钟
while(!(CLK_SWCR&0x8));
CLK_SWCR |=0x2; //使能外部时钟
}
void Init_UART2(void)
{
UART2_CR1=0x01;//8字节、校验中断使能
UART2_CR3=0X00;//1个停止位
UART2_BRR2=0X01;//设置波特率
UART2_BRR1=0X67; //设置波特率
UART2_CR2=0x2c; //使能发送、接收模式\开接收中断
}
@far @interrupt void UART2_Recv(void)//接收中断
{
PG_ODR=~PG_ODR;
t=UART2_DR;
k++;
if(k==0)
o=t-48;
if(k==1)
i=t-48;
if(k==2)
u=t-48;
if(k==3)
y=t-48;
if(k==4)
{k=k-4;
o=t-48;
}
return;
}
main()
{
PG_DDR=0B10;
PG_CR1=0B10;
PD_DDR=0B00001111;
PD_CR1=0B00001111;
PB_DDR=0XFF;
PB_CR1=0XFF;
jingzhen();
Init_UART2();
_asm("rim");
while(1)
{
xianshi();
}
}