基于atmega16l单片机的抢答器设计内容摘要:

LCD_DATA_PORT|=tempamp。 0b00111100。 //写高四位 LCD_en_write()。 mand=mand2。 //低四位移到高四位 LCD_DATA_PORTamp。 =0b11000011。 //清高四位 LCD_DATA_PORT|=mandamp。 0b00111100。 //写低四位 LCD_en_write()。 } void LCD_write_data(unsigned char data) //写数据 { unsigned char temp。 data=((dataamp。 0b10000000)7)|((dataamp。 0b01000000)5)|((dataamp。 0b00100000)3)|((dataamp。 0b00010000)1)|((dataamp。 0b00001000)1)|((dataamp。 0b00000100)3)|((dataamp。 0b00000010)5)|((dataamp。 0b00000001)7)。 delay_nus(16)。 temp=data2。 LCD_RS_PORT|=LCD_RS。 //RS=1 LCD_DATA_PORTamp。 =0b11000011。 //清高四位 LCD_DATA_PORT|=tempamp。 0b00111100。 //写高四位 LCD_en_write()。 data=data2。 //低四位移到高四位 LCD_DATA_PORTamp。 =0b11000011。 //清高四位 LCD_DATA_PORT|=dataamp。 0b00111100。 //写低四位 LCD_en_write()。 } void LCD_set_xy( unsigned char x, unsigned char y ) //写地址函数 8 { unsigned char address。 if (y == 0) address = 0x80 + x。 else address = 0xc0 + x。 LCD_write_mand( address)。 } void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s) //列 x=0~15,行 y=0,1 { LCD_set_xy( X, Y )。 //写地址 while (*s) // 写显示字符 { LCD_write_data( *s )。 s ++。 } } void LCD_write_char(unsigned char X,unsigned char Y,unsigned char data) //列 x=0~15,行 y=0,1 { LCD_set_xy( X, Y )。 //写地址 LCD_write_data( data)。 } void delay_1us(void) //1us 延时函数 { asm(nop)。 } void delay_nus(unsigned int n) //N us 延时函数 { unsigned int i=0。 for (i=0。 in。 i++) delay_1us()。 } void delay_1ms(void) //1ms 延时函数 { unsigned int i。 for (i=0。 i1140。 i++)。 } void delay_nms(unsigned int n) //N ms 延时函数 { unsigned int i=0。 9 for (i=0。 in。 i++) delay_1ms()。 } unsigned char *Format(unsigned char data,unsigned char *str) { str[0]=tab[(data/10)%10]。 str[1]=tab[data%10]。 return str。 } 部分程序的流程图如图 3 所示 10 开始 系统初始化 LCD显示状态 测试选手按键 显示测试选手号数 主持键按下 调用键盘扫描处理函数 抢答开始 显示选手序号 求出选手序号 答题 答题时间到 声音提醒 结束 倒计时启动 显示违规者序号 声音报警 有违规者 Y N Y N Y Y N N 等待抢答开始 调整倒计时值写EEPOM 启动 15S 抢题时间 选手抢答 N 声音提醒 此题作废 15s 到了 Y Y 11 5 源程序 //包含所需头文件 include include include define LED PORTC //定义 LED显示端口 define readkey (~(PINA|0x80)) //定义按键端口 define on_beep PORTDamp。 =~(15) //定义蜂鸣器开 define off_beep PORTD|=15 //定义蜂鸣器关 define MAINKEY ((PINDamp。 0x01)==0x00) // define UPKEY ((PINDamp。 0x02)==0x00) /*宏定义 */ define uchar unsigned char define uint unsigned int //全局变量定义 unsigned char key。 uchar Nmiao=15。 uchar Dmiao,Emiao=30。 uint Tcount=4。 uchar stop_flag=0。 //定义时间到标志 uchar start_flag。 //定义启动计时标志 uchar MAIN_KEY。 //开始抢答标志 uchar LM=0。 //定义 LED移动位 uchar flag=0。 //定义 LED移动方向标志 uchar i=0。 //定义 30 秒计时数值 /***************************************** * 延时函数 1:入口 i,单位 mS,最大 65536mS * *****************************************/ void delay_ms(uint i) { uchar a。 for(。 i。 i) {for(a=141。 a。 a) //针对时钟频率为 1M {。 } } 12 } /***************************************** * 延时函数 2:入口 i,单位 uS,最大 65536uS * *****************************************/ void delay_us(uint i) { i=i/2。 for(。 i。 i) {。 }。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。