现在键盘电路图设计及编程文件。
本人会用89C51单片机设计4*4矩阵式键盘计算器程序可以发到我的邮箱:938543053@qq...
本人会用89C51单片机设计4*4矩阵式键盘计算器程序
可以发到我的邮箱:938543053@qq 展开
可以发到我的邮箱:938543053@qq 展开
展开全部
/*我写的这个计算器可以算255范围以内的整数计算,本打算再加入小数与做最后的处理工作。可是又太费时间,所以就放那里了。看见了你的提问,也懒得改一改,你看看能不能用。*/
#include<reg51.h>
unsigned char Line,Row,Val;
void delay()
{
unsigned char count;
for(count=0;count<255;count++)
;
}
void delay1()
{
unsigned char count,rt;
for(count=0;count<40;count++)
for(rt=0;rt<100;rt++)
;
}
void InitialCPU(void)
{
P0=0xFF;
P1=0x0F;
P2=0xFF;
P3=0xFF;
}
unsigned char leddata[]=; //"0-9"
unsigned char ledbai(unsigned char dat)
{
unsigned char bai;
bai=dat/100;
if(bai==0)
return 0x00;
P2=0x20;
P0=leddata[bai];
delay();
P2=0x00;
return 0x00;
}
unsigned char ledshi(unsigned char dat)
{
unsigned char shi;
shi=(dat%100)/10;
if(shi==0)
return 0x00;
P2=0x40;
P0=leddata[shi];
delay();
P2=0x00;
return 0x00;
}
void ledge(unsigned char dat)
{
unsigned char ge;
ge=dat%10;
P2=0x80;
P0=leddata[ge];
delay();
}
unsigned char bin=1;
void ledplay(unsigned char dat)
{ //LED显示函数
if(bin==1){
ledbai(dat);
bin++;
}
else if(bin==2){
ledshi(dat);
bin++;
}
else if(bin==3){
ledge(dat);
bin=1;
}
}
unsigned char futemp=0,data1=0,data2=0;
void InitialTimer0(void)
{
TMOD=0x01;
TH0=(65536-1000)/256;
TR0=1; //启动T0
EA=1;
ET0=1; //允许T0中断
}
void Timer0(void) interrupt 1 using 3
{
TR0=0;
if(data1==0&&futemp==0&&data2==0){ //LED显示data1,即初始值
ledplay(data1);
}
else if(data1!=0&&futemp==0&&data2==0) // data1有值了,显示data1,
ledplay(data1);
else if(data1==0&&futemp!=0&&data2==0) //有两种可能,1、数据data1为零;2、直接data1没有给它值。总之显示data1
ledplay(data1);
else if(data1!=0&&futemp!=0&&data2==0) //输入的是符号,接着显示data1
ledplay(data1);
else if(data1!=0&&futemp!=0&&data2!=0) //显示的是data2
ledplay(data2);
TH0=(65536-100)/256;
TR0=1;
}
void denghou()
{
data2=0;
futemp=0;
}
unsigned char KeyTemp,CheckValue,Key1=0x00,Key2=0x00;
void Dispose()
{
unsigned char Val;
if(Line==0x01)
Line=0;
else if(Line==0x02)
Line=1;
else if(Line==0x04)
Line=2;
else if(Line==0x08)
Line=3;
if(Row==0x10)
Row=0;
else if(Row==0x20)
Row=1;
else if(Row==0x40)
Row=2;
else if(Row==0x80)
Row=3;
Val=Line*4+Row;
if(Val<10){ //存数
if(futemp==0){ //存在data1中
if(data1==0)
data1=Val;
else
data1=data1*10+Val;
}
else{ //存在data2中
if(data2==0)
data2=Val;
else
data2=data2*10+Val;
}
}
else if(Val>9&&Val<16){
if(Val!=13&&Val!=12)
futemp=Val; //存符号并进行响应处理
else if(Val==12){
data1=0;
data2=0;
futemp=0;
}
else if(Val==13){
if(futemp==10){
data1=data1*data2;
denghou();
}
else if(futemp==11){
data1=data1/data2;
denghou();
}
else if(futemp==14){
data1=data1-data2;
denghou();
}
else if(futemp==15){
data1=data1+data2;
denghou();
}
else{
while(1){
P2=0xff;
P0=0x00;
}
}
}
}
else
while(1){
P2=0xff;
P0=0x00;
} //显示错误
}
unsigned char GetKey1(void)
{
P1=0x0F;
CheckValue=P1^0x0F;
if(CheckValue==0x00)
return 0x00;
else if(CheckValue==0x01)
Line=CheckValue;
else if(CheckValue==0x02)
Line=CheckValue;
else if(CheckValue==0x04)
Line=CheckValue;
else if(CheckValue==0x08)
Line=CheckValue;
Key1=0x0F;
return Key1;
}
unsigned char GetKey2(void)
{
P1=0xF0;
CheckValue=P1^0xF0;
if(CheckValue==0x00)
return 0x00;
else if(CheckValue==0x10)
Row=CheckValue;
else if(CheckValue==0x20)
Row=CheckValue;
else if(CheckValue==0x40)
Row=CheckValue;
else if(CheckValue==0x80)
Row=CheckValue;
delay1();
KeyTemp = P1^0xF0;
if(KeyTemp==CheckValue)
return 0x00;
Key2=0xF0;
return Key2;
}
void main()
{
unsigned char Key1,Key2;
InitialCPU();
InitialTimer0();
while(1)
{
Key1=GetKey1();
Key2=GetKey2();
if(Key1!=0x00&&Key2!=0x00)
{
Dispose();
P3=0x00;
}
}
}
#include<reg51.h>
unsigned char Line,Row,Val;
void delay()
{
unsigned char count;
for(count=0;count<255;count++)
;
}
void delay1()
{
unsigned char count,rt;
for(count=0;count<40;count++)
for(rt=0;rt<100;rt++)
;
}
void InitialCPU(void)
{
P0=0xFF;
P1=0x0F;
P2=0xFF;
P3=0xFF;
}
unsigned char leddata[]=; //"0-9"
unsigned char ledbai(unsigned char dat)
{
unsigned char bai;
bai=dat/100;
if(bai==0)
return 0x00;
P2=0x20;
P0=leddata[bai];
delay();
P2=0x00;
return 0x00;
}
unsigned char ledshi(unsigned char dat)
{
unsigned char shi;
shi=(dat%100)/10;
if(shi==0)
return 0x00;
P2=0x40;
P0=leddata[shi];
delay();
P2=0x00;
return 0x00;
}
void ledge(unsigned char dat)
{
unsigned char ge;
ge=dat%10;
P2=0x80;
P0=leddata[ge];
delay();
}
unsigned char bin=1;
void ledplay(unsigned char dat)
{ //LED显示函数
if(bin==1){
ledbai(dat);
bin++;
}
else if(bin==2){
ledshi(dat);
bin++;
}
else if(bin==3){
ledge(dat);
bin=1;
}
}
unsigned char futemp=0,data1=0,data2=0;
void InitialTimer0(void)
{
TMOD=0x01;
TH0=(65536-1000)/256;
TR0=1; //启动T0
EA=1;
ET0=1; //允许T0中断
}
void Timer0(void) interrupt 1 using 3
{
TR0=0;
if(data1==0&&futemp==0&&data2==0){ //LED显示data1,即初始值
ledplay(data1);
}
else if(data1!=0&&futemp==0&&data2==0) // data1有值了,显示data1,
ledplay(data1);
else if(data1==0&&futemp!=0&&data2==0) //有两种可能,1、数据data1为零;2、直接data1没有给它值。总之显示data1
ledplay(data1);
else if(data1!=0&&futemp!=0&&data2==0) //输入的是符号,接着显示data1
ledplay(data1);
else if(data1!=0&&futemp!=0&&data2!=0) //显示的是data2
ledplay(data2);
TH0=(65536-100)/256;
TR0=1;
}
void denghou()
{
data2=0;
futemp=0;
}
unsigned char KeyTemp,CheckValue,Key1=0x00,Key2=0x00;
void Dispose()
{
unsigned char Val;
if(Line==0x01)
Line=0;
else if(Line==0x02)
Line=1;
else if(Line==0x04)
Line=2;
else if(Line==0x08)
Line=3;
if(Row==0x10)
Row=0;
else if(Row==0x20)
Row=1;
else if(Row==0x40)
Row=2;
else if(Row==0x80)
Row=3;
Val=Line*4+Row;
if(Val<10){ //存数
if(futemp==0){ //存在data1中
if(data1==0)
data1=Val;
else
data1=data1*10+Val;
}
else{ //存在data2中
if(data2==0)
data2=Val;
else
data2=data2*10+Val;
}
}
else if(Val>9&&Val<16){
if(Val!=13&&Val!=12)
futemp=Val; //存符号并进行响应处理
else if(Val==12){
data1=0;
data2=0;
futemp=0;
}
else if(Val==13){
if(futemp==10){
data1=data1*data2;
denghou();
}
else if(futemp==11){
data1=data1/data2;
denghou();
}
else if(futemp==14){
data1=data1-data2;
denghou();
}
else if(futemp==15){
data1=data1+data2;
denghou();
}
else{
while(1){
P2=0xff;
P0=0x00;
}
}
}
}
else
while(1){
P2=0xff;
P0=0x00;
} //显示错误
}
unsigned char GetKey1(void)
{
P1=0x0F;
CheckValue=P1^0x0F;
if(CheckValue==0x00)
return 0x00;
else if(CheckValue==0x01)
Line=CheckValue;
else if(CheckValue==0x02)
Line=CheckValue;
else if(CheckValue==0x04)
Line=CheckValue;
else if(CheckValue==0x08)
Line=CheckValue;
Key1=0x0F;
return Key1;
}
unsigned char GetKey2(void)
{
P1=0xF0;
CheckValue=P1^0xF0;
if(CheckValue==0x00)
return 0x00;
else if(CheckValue==0x10)
Row=CheckValue;
else if(CheckValue==0x20)
Row=CheckValue;
else if(CheckValue==0x40)
Row=CheckValue;
else if(CheckValue==0x80)
Row=CheckValue;
delay1();
KeyTemp = P1^0xF0;
if(KeyTemp==CheckValue)
return 0x00;
Key2=0xF0;
return Key2;
}
void main()
{
unsigned char Key1,Key2;
InitialCPU();
InitialTimer0();
while(1)
{
Key1=GetKey1();
Key2=GetKey2();
if(Key1!=0x00&&Key2!=0x00)
{
Dispose();
P3=0x00;
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询