main.c
#include <stc15f2k60s2.h>
#include <juzhen.h>
extern unsigned char display[];
extern unsigned char key;
void Timer0Init();
void main()
{
Timer0Init();EA=1;ET0=1;
P2=0XA0;P0=0X00;P2=0X1f;
while(1)
{
anjian();
xianshi();
}
}
void Timer0Init(void) //2毫秒@11.0592MHz
{
AUXR |= 0x80; //定时器时钟1T模式
TMOD &= 0xF0; //设置定时器模式
TL0 = 0x9A; //设置定时初值
TH0 = 0xA9; //设置定时初值
TF0 = 0; //清除TF0标志
TR0 = 1; //定时器0开始计时
}
void shuma() interrupt 1
{
unsigned char i;
P2=0XE0;
P0=0XFF;
P2=0X1f;
P2=0XC0;
P0=1<<i;
P2=0X1f;
P2=0XE0;
P0=display[i];
P2=0X1f;
i++;
if(i>=8)i=0;
}
juzhen.c
#include <stc15f2k60s2.h>
#include <juzhen.h>
unsigned char display[]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
unsigned char smg[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
sbit h1=P3^0;
sbit h2=P3^1;
sbit h3=P3^2;
sbit h4=P3^3;
unsigned char key;
sbit l1=P4^4;
sbit l2=P4^2;
sbit l3=P3^5;
sbit l4=P3^4;
void xianshi()
{
display[0]=smg[key/10];
display[1]=smg[key%10];
display[2]=smg[2];
display[3]=smg[3];
display[4]=smg[4];
display[5]=smg[5];
display[6]=smg[6];
display[7]=smg[7];
}
void anjian()
{
l1=0;
l4=l2=l3=1;
h1=h2=h3=h4=1;
if(h1==0)
{
Delay10ms();
if(h1==0)
{key=1;}
while(!h1);
}
if(h2==0)
{
Delay10ms();
if(h2==0)
{key=2;}
while(!h2);
}
if(h3==0)
{
Delay10ms();
if(h3==0)
{key=3;}
while(!h3);
}
if(h4==0)
{
Delay10ms();
if(h4==0)
{key=4;}
while(!h4);
}
l2=0;
l3=l1=l4=1;
h1=h2=h3=h4=1;
if(h1==0)
{
Delay10ms();
if(h1==0)
{key=5;}
while(!h1);
}
if(h2==0)
{
Delay10ms();
if(h2==0)
{key=6;}
while(!h2);
}
if(h3==0)
{
Delay10ms();
if(h3==0)
{key=7;}
while(!h3);
}
if(h4==0)
{
Delay10ms();
if(h4==0)
{key=8;}
while(!h4);
}
l3=0;
l1=l2=l4=1;
h1=h2=h3=h4=1;
if(h1==0)
{
Delay10ms();
if(h1==0)
{key=9;}
while(!h1);
}
if(h2==0)
{
Delay10ms();
if(h2==0)
{key=10;}
while(!h2);
}
if(h3==0)
{
Delay10ms();
if(h3==0)
{key=11;}
while(!h3);
}
if(h4==0)
{
Delay10ms();
if(h4==0)
{key=12;}
while(!h4);
}
l4=0;
l1=l2=l3=1;
h1=h2=h3=h4=1;
if(h1==0)
{
Delay10ms();
if(h1==0)
{key=13;}
while(!h1);
}
if(h2==0)
{
Delay10ms();
if(h2==0)
{key=14;}
while(!h2);
}
if(h3==0)
{
Delay10ms();
if(h3==0)
{key=15;}
while(!h3);
}
if(h4==0)
{
Delay10ms();
if(h4==0)
{key=16;}
while(!h4);
}
}
void Delay10ms() //@11.0592MHz
{
unsigned char i, j;
i = 108;
j = 145;
do
{
while (--j);
} while (--i);
}
juzhen.h
#ifndef __JUZHEN_H_
#define __JUZHEN_H_
void Delay10ms();
void anjian();
void xianshi();
#endif
这篇博客主要探讨了蓝桥杯比赛中的模块练习3,重点在于矩阵的处理。通过分析`main.c`,`juzhen.c`和`juzhen.h`这三个文件,博主详细讲解了矩阵计算的实现细节,包括矩阵的初始化、加减乘运算以及相关的算法优化。
776

被折叠的 条评论
为什么被折叠?



