用矩阵写了一个计算器,目前计算偶尔出问题,还不完善
计算器实例
7 8 9 +
4 5 6 -
1 2 3 *
0 = /
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();
jisuan();
}
}
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};
char jieguo,qian,hou;
unsigne