【蓝桥杯(51) STC15F2K60S2】之 “数码管实验“

相关代码:
#include “STC15F2K60S2.h”

unsigned char SMG_duanma[18]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x80,0xc6,0xc0,0x80,0x8e,0xbf,0x7f};
unsigned char SMG_weima[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
unsigned char ScanIndex=0;
unsigned char SMG_Segcode[8];

//void Delay(unsigned char t)
//{
// while(t–);
//}

void InitHC138(unsigned char n)
{
switch(n)
{
case 4:
P2=(P2&0x1f)|0x80;
break;
case 5:
P2=(P2&0x1f)|0xa0;
break;
case 6:
P2=(P2&0x1f)|0xc0;
break;
case 7:
P2=(P2&0x1f)|0xe0;
break;
}
}

void display()
{
SMG_Segcode[0]=SMG_duanma[5];
SMG_Segcode[1]=SMG_duanma[2];
SMG_Segcode[2]=SMG_duanma[0];
//SMG_Segcode[3]=SMG_duanma[1];
SMG_Segcode[4]=SMG_duanma[1];
SMG_Segcode[5]=SMG_duanma[3];
SMG_Segcode[6]=SMG_duanma[1];
SMG_Segcode[7]=SMG_duanma[4];
}

void main()
{
TMOD = 0x10;
TH0=-9;
TR0=1;
ET0=1;
EA=1;
while(1)
{
display();
}
}

void IN0() interrupt 1
{
TH0=-9;
InitHC138(7);
P0=0xff;
InitHC138(6);
P0=SMG_weima[ScanIndex];
InitHC138(7);
P0=SMG_Segcode[ScanIndex];
ScanIndex++;
if(ScanIndex == 3)
ScanIndex=4;
ScanIndex %= 8;
}
//等效
void IN0() interrupt 1
{
TH0=-9;
XBYTE[0XE000] = 0XFF;
XBYTE[0XC000] = 0X01 << ScanIndex;
XBYTE[0XE000] = SMG_Segcode[ScanIndex];
ScanIndex++;
if(ScanIndex == 3)
ScanIndex=4;
ScanIndex %= 8;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

world呀

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值