基于AVR ATMEGA128 仿真 EasyAVR M128 DMAVR-128开发板

#include <iom128v.h> 
#include <macros.h> 
#include "KS0108.h"
#include "delay.h" 

#define uchar unsigned char
#define unint unsigned int

uchar Jie=1;//小节数
uchar A_bifen=0,B_bifen=0;//A/B比分

uchar Time_fen=0;//计时分
uchar Time_miao=0;//计时秒

uchar Set_Time=12;  //小节时间设置值 

uchar key_flag=0; //按键标识
uchar Huan_flag=0;//场地交换标识
uchar jieci;
uchar biaozhi;
uchar show;
uchar start;
uchar dao_miao=30;

    

void time1_init(void)
{  
   TCCR1B=0X00;//停止定时器
   TCNT1H=0XC2;
   TCNT1L=0XF7;
   TCCR1A=0X00;
   TCCR1B=4;
   TIMSK=0x04;//设置中断屏蔽寄存器
}

void keyscan()
{
 uchar key;
 if(PIND!=0XFF)
 {
  key=PIND;//调用键盘扫描,
  switch(key)
  {
  case 0xFE:A_bifen+=1;break;//A+1分
  case 0xFD:A_bifen+=2;break;//A+2分
  case 0xFB:A_bifen+=3;break;//A+3分
  case 0xF7:B_bifen+=1;break;//B+1分
  case 0xEF:B_bifen+=2;break;//B+2分
  case 0xDF:B_bifen+=3;break;//B+3分
  case 0xBF:biaozhi=~biaozhi;break;//
  case 0x7F:if(biaozhi)Set_Time++;break; //
  }
  while(PIND!=0XFF);
 }
if(PINE!=0XFF)
{
 key=PINE;//检测E 口
 switch(key)
 {
   case 0xFE:if(biaozhi)Set_Time--;break;
   case 0xFD:Huan_flag=1;break;//A B互换
   case 0xFB:start=1;break;//开始
   case 0xF7:start=2;dao_miao=30;break;//暂停
  }
  while(PINE!=0XFF);
 }
}

//主程序
void main()
{
 uchar j;
  DDRB=0XFF;
    PORTB=0XFF;
  DDRA=0XFF;
    PORTA=0XFF;
  DDRD=0X00;//PORTC 
  PORTD=0XFf;
    DDRE=0X00;//PORTC 
  PORTE=0XFf;
    DDRG=0XFF;
     PORTG&=0X10;//蜂鸣器开启
     delay_nms(100);
    PORTG=0XFF;
  
  time1_init();
  
  init_lcd();
  Clr_LCD();

   SEI();     //全局中断使能
  while(1)
  {
     if(j++>=20)//控制闪烁速度
     {
      j=0;
        show=~show;
     }
   keyscan();  //按键检测
   if(Huan_flag)
   {
   show8(0,16,  0, num[11]); //A对
   show16(0,32, 0, hz[0]); // 
   show8(2,16,  0, num[B_bifen/100]); //A比分
   show8(2,24,  0, num[B_bifen/10%10]); //
   show8(2,32,  0, num[B_bifen%10]); //
   
   show8(0,16,  1, num[10]); //B对
   show16(0,32, 1, hz[0]); //
   show8(2,16,  1, num[A_bifen/100]); //B比分
   show8(2,24,  1, num[A_bifen/10%10]); //
   show8(2,32,  1, num[A_bifen%10]); //

      }
   else
    {     
     show8(0,16,  0, num[10]); //A对
     show16(0,32, 0, hz[0]); //
     show8(2,16,  0, num[A_bifen/100]); //A比分
     show8(2,24,  0, num[A_bifen/10%10]); //
     show8(2,32,  0, num[A_bifen%10]); //
   
   
     show8(0,16,  1, num[11]); //B对
     show16(0,32, 1, hz[0]); //
     
     show8(2,16,  1, num[B_bifen/100]); //B比分
     show8(2,24,  1, num[B_bifen/10%10]); //
     show8(2,32,  1, num[B_bifen%10]); //
     }

    jieci=Time_fen/Set_Time+1;
     if(jieci>=3)
     {
      start=0;
      PORTG&=~0X10;//蜂鸣器开启
    }
    

   show16(4,0, 0, hz[1]); // 节次
   show16(4,16, 0, hz[2]); //
   show8(6,0,  0,num[jieci/10]); //节次数
   show8(6,8,  0,num[jieci%10]); //
   
   show16(4,48, 0, hz[5]); //计时
   show16(4, 0, 1, hz[6]); //
   show8(6,40,  0,num[Time_fen/10]); //走时分钟
   show8(6,48,  0,num[Time_fen%10]); //
   show8(6,56,  0,num[12]); //:
   show8(6,0,  1,num[Time_miao/10]); //走时秒
   show8(6,8,  1,num[Time_miao%10]); //
      show16(4,32, 1, hz[3]); //时间    
   show16(4,48, 1, hz[4]); //
     
   
     //show8(6,48,  1,num[13]); //不显示
     //show8(6,56,  1,num[13]); //
   
   
  show8(0,56, 0,num[dao_miao/10]); //倒计时显示
  show8(0,0, 1, num[dao_miao%10]); //
     
   
   show8(6,48,  1,num[Set_Time/10]); //设置节次时间
   show8(6,56,  1,num[Set_Time%10]); //
     if((biaozhi)&&(show))//闪烁控制
     {
       show8(6,48,  1,num[13]); //不显示
       show8(6,56,  1,num[13]); //
     }
 
  };

篇幅有限 只给出部分代码。。。。。。。。。。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值