仿真设计 | 八路抢答器

目录

前言

设计目标

仿真设计

程序代码

总结


前言

       今天清理电脑发现了上学期做的八路抢答器仿真设计文件,删了可惜,分享出来大家一起学习。

设计目标

1、主持人按下抢答开始按键,抢答者才可以开始抢答,数码管抢答倒计时30s。

2、抢答成功后显示抢答选手编号。

3、可以通过按键修改倒计时时间。

4、抢答成功后绿色指示灯闪烁。

仿真设计

Proteus版本为8.9。整体仿真图如下所示:

蜂鸣器记得设置一下,要不然不会响

分析:

点击仿真开始后,倒计时和抢答显示区不会显示数字(本来就是不显示的,别担心是你哪里弄错了)。如下图所示:

点击主持人区的开始键后,倒计时从30s开始倒计时,抢答显示区显示00.如下图所示:

当1-8号中有选手抢答时,倒计时会停止,抢答显示区会显示抢答选手编号,绿色指示灯会不停闪烁,蜂鸣器也会响一下。如下如所示:

然后复位键的作用是在抢答结束后,将倒计时复位到30s,具体操作步骤是:在抢答完成后,就是有选手抢答后,点击一下,倒计时会回到30,同时显示区显示00.如下图所示:

然后时间加和时间减的作用是改变倒计时。记住,刚开始第一次不能立马就改变倒计时,第一次必须是30s倒计时,因为刚开始啥也不显示,点加减也没用。当第一次30s倒计时内有人抢答后,你可以直接就点击时间加或减;又或者点一下复位键,让倒计时变为30后,再加减,其实都一样。改变时间后,点一下开始就开始倒计时了。如下图所示:

如果没有人抢答,倒计时结束,蜂鸣器会响一下。

程序代码

程序编写使用keil平台,编译0错误,0警告

#include<reg51.h>
#define uint	unsigned	int
#define uchar	unsigned	char
	
sbit DIN=P3^0;	//与max7219接口定义
sbit LOAD=P3^1;
sbit CLK=P3^2;

sbit key0=P1^0;	//8路抢答器按键
sbit key1=P1^1;
sbit key2=P1^2;
sbit key3=P1^3;
sbit key4=P1^4;
sbit key5=P1^5;
sbit key6=P1^6;
sbit key7=P1^7;

sbit buzzer=P3^6;//蜂鸣器
sbit LED1=P3^7;

sbit begin=P2^0;	//主持人开始按键
sbit key_clear=P2^1;	//主持人复位
sbit key_add=P2^2;	//时间加
sbit key_sub=P2^3;	//时间减

uchar second=30;	//秒表计数值
uchar counter=0;	//counter每100,minite加1
uchar people=0;	//抢答结果

uchar num_add[]={0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08};	//max7219读写地址、内容
uchar num_dat[]={0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89};

void delay(uint xms)
{
	uchar i, j;
	while(xms--)
	{
		i = 2;
		j = 239;
		do
		{
			while (--j);
		} while (--i);
	}
}

uchar keyscan()//键盘扫描函数
{
  uchar key_value,temp;
  key_value=0;
  P1=0xFF;
  temp=P1;
  if(~(P1&temp))
		{
			switch(temp)
			{
				case 0xfe:
					key_value=1;
					break;
				case 0xfd:
					key_value=2;
					break;
				case 0xfb:
					key_value=3;
					break;
				case 0xf7:
					key_value=4;
					break;
				case 0xef:
					key_value=5;
					break;
				case 0xdf:
					key_value=6;
					break;
				case 0xbf:
					key_value=7;
					break;
					case 0x7f:
					key_value=8;
					break;
				default:
					key_value=0;
					break;
			}
		}
  return key_value;
}

void max7219_send(uchar	add,uchar	dat)//向max7219写指令函数
{
  uchar	ADS,i,j;
  LOAD=0;
  i=0;
  while(i<16)
		{
			if(i<8)
				{
					ADS=add;
				}
			else
				{
					ADS=dat;
				}
			for(j=8;j>=1;j--)
				{
					DIN=ADS&0x80;
					ADS=ADS<<1;
					CLK=1;
					CLK=0;
				}
			i=i+8;
		}
	LOAD=1;
}

void max7219_init()//max7219初始化函数
{
  max7219_send(0x0c,0x01);
  max7219_send(0x0b,0x07);
  max7219_send(0x0a,0xf5);
  max7219_send(0x09,0xff);
}

void time_display(uchar x)//时间显示
{
  uchar i,j;
  i=x/10;
  j=x%10;
  max7219_send(num_add[1],num_dat[j]);
  max7219_send(num_add[0],num_dat[i]);
}

void scare_display(uchar x)//抢答结果显示
{
  uchar i,j;
  i=x/10;
  j=x%10;
  max7219_send(num_add[3],num_dat[j]);
  max7219_send(num_add[2],num_dat[i]);
	
	if(x >= 1 && x <= 8) 
		{
			LED1=~LED1;
			delay(100);
		}
}

void holderscan()//抢答时间设置,0-60s
{
  time_display(second);
  scare_display(people);
  if(~key_clear)//如果有键按下,改变抢答时间
		{
			while(~key_clear);
			if(people)//如果抢答结果没有清空,抢答器重置
				{
					second=30;
					people=0;
				}
			else
				{}	
		}	
	if(~key_add)
		{
			while(~key_add);
			if(second<60)
				{
					second++;
				}
			else
				{
					second=0;
				}
		}
	if(~key_sub)
		{
			while(~key_sub);
			if(second>0)
				{
					second--;
				}
			else
				{
					second=60;
				}
		}		
}

void timer_init()
{
  EA=1;
  ET0=1;
  TMOD=0x01;
  TH0=0xd8;//设定10ms中断一次
  TL0=0xef;
}

void main()
{
  while(1)
	{
		do
		{
			holderscan();
		}while(begin);//开始前进行设置,未按下开始键
		
		while(~begin);//防抖
		max7219_init(); //芯片初始化
		timer_init();	  //中断初始化
		TR0=1;		  //开始中断
	
		do
		{	
			time_display(second);
			scare_display(people);
			people=keyscan();
		}while((!people)&&(second));//运行直到抢答结束或者时间结束
		TR0=0;
		buzzer = 0;
		delay(100);
		buzzer = 1;
	}
}

void timer0() interrupt 1
{
	TH0=0xd8;//重新装载
  TL0=0xef;
  TR0=1;	
  if(counter<100)
		{
			counter++;
		}
  else
		{
			counter=0;
			second=second-1;
		}
}

总结

以上就是今天要讲的内容。

基于数字电设计八路抢答器原理图+说明文档+Multisim仿真源文件,可以做为你的学习设计,实验参考。 一、设计要求 本设计要求的时钟具有如下功能: 1、总共有八位选手参与抢答; 2、当主持人没有按下开始时,任何抢答都无效; 3、当主持人按下开始按键后,开始30倒计时,此时任何选手都可以参与抢答; 4、当第一个选手抢答成功后,会显示选手的编号,同时倒计时停止,并且后面的其他选手抢答均无效; 5、当倒计时到最后五时,指示灯会闪烁,并且如果倒计时到0了还没有选手抢答,那么此次无效。 二、总体思设计主要分成两大块电抢答倒计时抢答要解决如下几个问题: 1、计算出选手的编号,这个可以采用8-3编码器。 2、要保证只有第一个选手抢答是有效的,后面其他的无效,这个就需要采取锁存电,当还没有任何人抢答的时候,锁存器是不生效的,处于直通的工作状态,当有第一个抢答了,锁存器就开始起作用,将该号码固定下来,后面的即使有人抢答,其编号也无法通过锁存电,实现该电可以采用4个D触发器。前三个触发器用来输出选手编号,后面一个触发器用来控制锁存器的工作状态(是直通还是锁存),只需要让D触发器的CLK端控制得当,就可以实现锁存。
### AUTOSAR CAN PDU Specification and Implementation Details #### Definition of CAN PDU A **CAN PDU (Protocol Data Unit)** represents a segment of information that is processed at the protocol layer within the CAN communication stack. According to the definition provided, a CAN hardware object serves as an L-PDU buffer located inside the CAN RAM of the CAN hardware unit/controller[^2]. This implies that PDUs act as buffers holding data intended for transmission over the CAN bus or received from it. #### Structure and Handling of CAN PDUs Within the context of AUTOSAR, different types of PDUs exist such as I-PDUs (Inter-PDU), which carry application-layer messages between ECUs; N-PDUs (Network Layer Protocol Data Units) used in transport protocols like CanTp where segmentation/reassembly occurs; and others depending on specific requirements. For instance, when dealing with J1939 requests through COM and PduR configurations, certain actions need to be taken regarding IPDU group management and routing path setup[^4]. #### Configuration Parameters Related to CAN PDUs Configuration settings play a crucial role in defining how PDUs operate within systems adhering to AUTOSAR standards. In particular, modules like CanTp involve configuring various parameters including those related to SDUs (Service Data Units). Although older versions might have included deprecated fields like `CanTpRxDl` and `CanTpTxDl`, these do not affect current implementations since newer revisions disregard them entirely[^1]. #### Vendor-Specific Customizations Through Attributes To accommodate diverse hardware platforms while maintaining compatibility across vendors' products implementing CAN drivers under AUTOSAR guidelines, unique identifiers named `"VendorId"` along with `"VendorApiInfix"` attribute values serve as means to address distinct driver instances correctly during system integration processes[^3]. ```cpp // Example C++ code snippet showing usage of vendor-specific attributes if ((canDriver->getVendorId() == VENDOR_ID_BOSCH) && (!strcmp(canDriver->getVendorApiInfix(), "BoschAPI"))) { // Specific initialization routine for Bosch CAN driver } ```
评论 14
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值