#include <ioM16v.h>
#include <macros.h>
#include "delayms.h"
uchar n=0;
uchar down=0;
static uchar R,A,B;
static uchar x1,y1,x2,y2;
static uchar o_k=0;
uchar table[]={0,0,0,0};
//-----------------------------------外中断初始化-----------------------------------
void int_init(void)
{
MCUCR |= 0x08;
MCUCSR|= 0x00;
GICR |= 0x80;
}
void display1()
{
w_com(0X01);
w_com(0x80);
w_data('S');
w_com(0x81);
w_data('T');
w_com(0x82);
w_data('R');
w_com(0x83);
w_data('A');
w_com(0x84);
w_data('T');
w_com(0x85);
w_data('(');
w_com(0x86);
w_data('0');
w_com(0x87);
w_data('0');
w_com(0x88);
w_data(',');
w_com(0x89);
w_data('0');
w_com(0x8A);
w_data('0');
w_com(0x8B);
w_data(')');
}
void display2()
{
w_com(0X01);
w_com(0x80);
w_data('E');
w_com(0x81);
w_data('n');
w_com(0x82);
w_data('d');
w_com(0x85);
w_data('(');
w_com(0x86);
w_data('0');
w_com(0x87);
w_data('0');
w_com(0x88);
w_data(',');
w_com(0x89);
w_data('0');
w_com(0x8A);
w_data('0');
w_com(0x8B);
w_data(')');
}
void display3()
{
w_com(0X01);
w_com(0x80);
w_data('C');
w_com(0x81);
w_data('e');
w_com(0x82);
w_data('n');
w_com(0x85);
w_data('(');
w_com(0x86);
w_data('0');
w_com(0x87);
w_data('0');
w_com(0x88);
w_data(',');
w_com(0x89);
w_data('0');
w_com(0x8A);
w_data('0');
w_com(0x8B);
w_data(')');
}
void display4()
{
w_com(0X01);
w_com(0x80);
w_data('R');
w_com(0x86);
w_data('0');
w_com(0x87);
w_data('0');
w_com(0x88);
w_data('c');
w_com(0x89);
w_data('m');
}
//-----------------------------------外中断1服务程序-----------------------------------
#pragma interrupt_handler int1_isr:3
void int1_isr(void)
{
uchar j;
j=PINA&0X07;
switch(j)
{
case 0x06://第一位
w_com(0x86);
w_data(n+'0');
table[0]=n;
n++;
if(n==10)n=0;
while((PINA&0X07)==0X06);
delayms(20);
break;
case 0x05://第二位
w_com(0x87);
w_data(n+'0');
table[1]=n;
n++;
if(n==10)n=0;
while((PINA&0X07)==0X05);
delayms(20);
break;
case 0x04://第三位
if(!(down&BIT(4)))
{
w_com(0x89);
w_data(n+'0');
table[2]=n;
n++;
if(n==10)n=0;
while((PINA&0X07)==0X04);
delayms(20);
break;
}
case 0x03://第四位
if(!(down&BIT(4)))
{
w_com(0x8A);
w_data(n+'0');
table[3]=n;
n++;
if(n==10)n=0;
while((PINA&0X07)==0X03);
delayms(20);
break;
}
case 0x02://确定键
if(down&BIT(5))//圆心
{
A=table[0]*10+table[1];
B=table[2]*10+table[3];
o_k|=BIT(7);
}
if(down&BIT(4))//半径
{
R=table[0]*10+table[1];
o_k|=BIT(6);
}
if(down&BIT(6))//终点
{
x2=table[0]*10+table[1];
y2=table[2]*10+table[3];
o_k|=BIT(1);
}
if(down&BIT(7))//起点
{
x1=table[0]*10+table[1];
y1=table[2]*10+table[3];
o_k|=BIT(0);
}
while((PINA&0X07)==0X02);
delayms(20);
break;
case 0x01://下翻键
table[0]=n=0;
table[1]=n=0;
table[2]=n=0;
table[3]=n=0;
if(down&BIT(0))
{
if(down&BIT(1))//圆心
{
display3();
down&=~BIT(1);
down|=BIT(5);
down&=~BIT(6);
}
else//半径
{
display4();
down&=~BIT(0);
down|=BIT(4);
down&=~BIT(5);
}
}
else
{
if(down&BIT(1))//终点
{
display2();
down|=BIT(0);
down|=BIT(6);
down&=~BIT(7);
}
else//起点
{
display1();
down|=BIT(1);
down|=BIT(7);
down&=~BIT(4);
}
}
while((PINA&0X07)==0X01);
delayms(20);
break;
default : break;
}
}
/*
void init_devices(void)
{
CLI(); //禁止所有中断
port_init();
int_init();
SEI();//开全局中断
}*/
148编码键盘.C
最新推荐文章于 2022-02-25 19:38:17 发布