148编码键盘.C

 #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();//开全局中断
}*/

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值