前置

模板代码展示
#include <STC15F2K60S2.h>
#define uchar unsigned char
#define uint unsigned int
uchar code SMG_duanma[18] =
{0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,
0x88,0x80,0xc6,0xc0,0x86,0x8e,
0xbf,0x7f};
uchar code SMG_Dot_AC[10] =
{0X40,0X79,0X24,0X30,0X19,0X12,0X02,0X78,0X00,0X10};
void Initsys();
void SelectHC138(uchar channel);
void DisplaySMG_Bit(uchar pos, uchar value);
void SMG_Display();
void Delay_one_ms_SMG();
void Alone_Key();
void Delay_five_ms_Key();
void Matrix_Key();
void main()
{
Initsys();
while(1)
{
Matrix_Key();
}
}
void Matrix_Key()
{
uchar temp;
P3 = 0X7F;P44 = 0; P42 = 1;
temp = P3;
temp = temp & 0X0F;
if(temp != 0X0F)
{
Delay_five_ms_Key();
temp = P3;
temp = temp & 0X0F;
if(temp != 0X0F)
{
temp = P3;
switch(temp)
{
case 0X7E:
DisplaySMG_Bit(0, SMG_duanma[1]);
break;
case 0X7D:
DisplaySMG_Bit(1, SMG_duanma[1]);
break;
case 0X7B:
DisplaySMG_Bit(2, SMG_duanma[1]);
break;
case 0X77:
DisplaySMG_Bit(3, SMG_duanma[1]);
break;
}
while(temp != 0X0F)
{
temp = P3;
temp = temp & 0X0F;
}
}
}
P3 = 0XBF;P44 = 1; P42 = 0;
temp = P3;
temp = temp & 0X0F;
if(temp != 0X0F)
{
Delay_five_ms_Key();
temp = P3;
temp = temp & 0X0F;
if(temp != 0X0F)
{
temp = P3;
switch(temp)
{
case 0XBE:
DisplaySMG_Bit(0, SMG_duanma[2]);
break;
case 0XBD:
DisplaySMG_Bit(1, SMG_duanma[2]);
break;
case 0XBB:
DisplaySMG_Bit(2, SMG_duanma[2]);
break;
case 0XB7:
DisplaySMG_Bit(3, SMG_duanma[2]);
break;
}
while(temp != 0X0F)
{
temp = P3;
temp = temp & 0X0F;
}
}
}
P3 = 0XDF;P44 = 1; P42 = 1;
temp = P3;
temp = temp & 0X0F;
if(temp != 0X0F)
{
Delay_five_ms_Key();
temp = P3;
temp = temp & 0X0F;
if(temp != 0X0F)
{
temp = P3;
switch(temp)
{
case 0XDE:
DisplaySMG_Bit(0, SMG_duanma[3]);
break;
case 0XDD:
DisplaySMG_Bit(1, SMG_duanma[3]);
break;
case 0XDB:
DisplaySMG_Bit(2, SMG_duanma[3]);
break;
case 0XD7:
DisplaySMG_Bit(3, SMG_duanma[3]);
break;
}
while(temp != 0X0F)
{
temp = P3;
temp = temp & 0X0F;
}
}
}
P3 = 0XEF;P44 = 1; P42 = 1;
temp = P3;
temp = temp & 0X0F;
if(temp != 0X0F)
{
Delay_five_ms_Key();
temp = P3;
temp = temp & 0X0F;
if(temp != 0X0F)
{
temp = P3;
switch(temp)
{
case 0XEE:
DisplaySMG_Bit(0, SMG_duanma[4]);
break;
case 0XED:
DisplaySMG_Bit(1, SMG_duanma[4]);
break;
case 0XEB:
DisplaySMG_Bit(2, SMG_duanma[4]);
break;
case 0XE7:
DisplaySMG_Bit(3, SMG_duanma[4]);
break;
}
while(temp != 0X0F)
{
temp = P3;
temp = temp & 0X0F;
}
}
}
}
void Delay_five_ms_Key()
{
uint i,j;
for(i = 0; i < 5; i++)
for(j = 845; j > 0; j--);
}
void Alone_Key()
{
if(P30 == 0)
{
Delay_five_ms_Key();
if(P30 == 0)
{
DisplaySMG_Bit(0, SMG_duanma[0]);
}
while(!P30);
}
else if(P31 == 0)
{
Delay_five_ms_Key();
if(P31 == 0)
{
DisplaySMG_Bit(1, SMG_duanma[1]);
}
while(!P31);
}
else if(P32 == 0)
{
Delay_five_ms_Key();
if(P32 == 0)
{
DisplaySMG_Bit(2, SMG_duanma[2]);
}
while(!P32);
}
else if(P33 == 0)
{
Delay_five_ms_Key();
if(P33 == 0)
{
DisplaySMG_Bit(3, SMG_duanma[3]);
}
while(!P33);
}
}
void SelectHC138(uchar channel)
{
switch(channel)
{
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;
case 0:
P2 = (P2 & 0X1F) | 0X00;
break;
}
}
void Initsys()
{
SelectHC138(5);
P0 = 0X00;
SelectHC138(4);
P0 = 0XFF;
SelectHC138(6);
P0 = 0XFF;
SelectHC138(7);
P0 = 0XFF;
}
void DisplaySMG_Bit(uchar pos, uchar value)
{
SelectHC138(6);
P0 = 0X01 << pos;
SelectHC138(7);
P0 = value;
}
void SMG_Display()
{
DisplaySMG_Bit(0, SMG_duanma[0]);
Delay_one_ms_SMG();
DisplaySMG_Bit(1, SMG_duanma[1]);
Delay_one_ms_SMG();
DisplaySMG_Bit(2, SMG_duanma[2]);
Delay_one_ms_SMG();
DisplaySMG_Bit(3, SMG_duanma[3]);
Delay_one_ms_SMG();
DisplaySMG_Bit(4, SMG_duanma[4]);
Delay_one_ms_SMG();
DisplaySMG_Bit(5, SMG_duanma[5]);
Delay_one_ms_SMG();
DisplaySMG_Bit(6, SMG_duanma[6]);
Delay_one_ms_SMG();
DisplaySMG_Bit(7, SMG_duanma[7]);
Delay_one_ms_SMG();
}
void Delay_one_ms_SMG()
{
uint j;
for(j = 845; j > 0; j--);
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理