您好,欢迎访问三七文档
单片机端口扩展—74LS138显示及按键数字秒表项目5数字秒表1、单片机端口扩展—74LS138A074LS138Y0A1A2E2AE1E2BY1Y2Y3Y4Y5Y6Y7151413121110971234561234567816151413121110974LS138A0GNDVCCY0Y1Y2Y3Y4Y5Y6A1A2E2AE2BE1Y7(a)(b)控制输入输出E1/E2A+/E2BA2A1A0/Y7/Y6/Y5/Y4/Y3/Y2/Y1/Y0×1×××111111110××××1111111110000111111101000111111101100101111101110011111101111010011101111101011101111110110101111111011101111111LED大屏幕显示器和接口LED大屏幕显示器结构及原理LED点阵显示器是把很多LED发光二极管按矩阵方式排列在一起,通过对每个LED进行发光控制,完成各种字符或图形的显示。最常见的LED点阵显示模块有5×7(5列7行),7×9(7列9行),8×8(8列8行)结构。LED点阵由一个一个的点(LED发光二极管)组成,总点数为行数与列数之积,引脚数为行数与列数之和。2、其它显示及按键LED大屏幕显示器和接口LED大屏幕显示器结构及原理LED大屏幕显示器和接口LED大屏幕显示器结构及原理“大”字显示字型码示意图LED大屏幕显示器和接口LED大屏幕显示器结构及原理显示字符“大”的过程如下:先给第一行送高电平(行高电平有效),同时给8列送11110111(列低电平有效);然后给第二行送高电平,同时给8列送11110111,……最后给第八行送高电平,同时给8列送11111111。每行点亮延时时间为1ms,第八行结束后再从第一行开始循环显示。利用视觉驻留现象,人们看到的就是一个稳定的图形。LED大屏幕显示器和接口LED大屏幕显示器接口LED大屏幕显示器和接口LED大屏幕显示器扩展接口XTAL218XTAL119ALE30EA31PSEN29RST9P0.0/AD039P0.1/AD138P0.2/AD237P0.3/AD336P0.4/AD435P0.5/AD534P0.6/AD633P0.7/AD732P1.01P1.12P1.23P1.34P1.45P1.56P1.67P1.78P3.0/RXD10P3.1/TXD11P3.2/INT012P3.3/INT113P3.4/T014P3.7/RD17P3.6/WR16P3.5/T115P2.7/A1528P2.0/A821P2.1/A922P2.2/A1023P2.3/A1124P2.4/A1225P2.5/A1326P2.6/A1427U1AT89C51R11kR21kR31kR41kR51kR61kR71kR81kXTAL218XTAL119ALE30EA31PSEN29RST9P0.0/AD039P0.1/AD138P0.2/AD237P0.3/AD336P0.4/AD435P0.5/AD534P0.6/AD633P0.7/AD732P1.01P1.12P1.23P1.34P1.45P1.56P1.67P1.78P3.0/RXD10P3.1/TXD11P3.2/INT012P3.3/INT113P3.4/T014P3.7/RD17P3.6/WR16P3.5/T115P2.7/A1528P2.0/A821P2.1/A922P2.2/A1023P2.3/A1124P2.4/A1225P2.5/A1326P2.6/A1427U1AT89C51R1330R2330R31kR4330R51kR61kR7330R8330A02B018A13B117A24B216A35B315A46B414A57B513A68B612A79B711CE19AB/BA1U274LS245//阵列显示0-9数字#includereg51.hunsignedcharcodetab[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//列选unsignedcharcodedigittab[10][8]={{0x00,0x00,0x3e,0x41,0x41,0x41,0x3e,0x00},//0{0x00,0x00,0x00,0x00,0x21,0x7f,0x01,0x00},//1{0x00,0x00,0x27,0x45,0x45,0x45,0x39,0x00},//2{0x00,0x00,0x22,0x49,0x49,0x49,0x36,0x00},//3{0x00,0x00,0x0c,0x14,0x24,0x7f,0x04,0x00},//4{0x00,0x00,0x72,0x51,0x51,0x51,0x4e,0x00},//5{0x00,0x00,0x3e,0x49,0x49,0x49,0x26,0x00},//6{0x00,0x00,0x40,0x40,0x40,0x4f,0x70,0x00},//7{0x00,0x00,0x36,0x49,0x49,0x49,0x36,0x00},//8{0x00,0x00,0x32,0x49,0x49,0x49,0x3e,0x00}//9};unsignedinttimecount;unsignedcharcnta;unsignedcharcntb;例一voidmain(void){TMOD=0x01;//定时器T0工作方式1TH0=(65536-3000)/256;//初值TL0=(65536-3000)%256;TR0=1;ET0=1;//开中断EA=1;while(1){;}}voidt0(void)interrupt1using0{TH0=(65536-3000)/256;TL0=(65536-3000)%256;P3=tab[cnta];P1=digittab[cntb][cnta];cnta++;if(cnta==8){cnta=0;}timecount++;if(timecount==333)//显示1s{timecount=0;cntb++;if(cntb==10){cntb=0;}}}//显示图像#includereg51.Hunsignedcharcodetab[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//列选unsignedcharcodegraph[3][8]={{0x12,0x14,0x3c,0x48,0x3c,0x14,0x12,0x00},//星形{0x00,0x00,0x38,0x44,0x44,0x44,0x38,0x00},//圆形{0x30,0x48,0x44,0x22,0x44,0x48,0x30,0x00}//心型};unsignedcharcount;unsignedcharcnta;sbitP2_0=P2^0;例二voidmain(void){unsignedchari,j;TMOD=0x01;TH0=(65536-4000)/256;TL0=(65536-4000)%256;TR0=1;ET0=1;EA=1;while(1){if(P2_0==0){for(i=5;i0;i--)for(j=248;j0;j--);if(P2_0==0){count++;if(count==3){count=0;}while(P2_0==0);}}}}voidt0(void)interrupt1using0{TH0=(65536-4000)/256;TL0=(65536-4000)%256;P3=tab[cnta];P1=graph[count][cnta];cnta++;if(cnta==8){cnta=0;}}单片机与键盘接口按键的去抖机械式按键在按下或释放时,由于机械弹性作用的影响,通常伴随有一定时间的触点机械抖动,然后其触点才稳定下来,抖动时间一般为510ms,在触点抖动期间检测按键的通与断状态,可能导致判断出错。闭合稳定键按下前沿抖动后沿抖动其实,作为一个按键从没有按下到按下以及释放是一个完整的过程,也就是说,当我们按下一个按键时,总希望某个命令只执行一次,而在按键按下的过程中,不要有干扰进来,因为,在按下的过程中,一旦有干扰过来,可能造成误触发过程,这并不是我们所想要的。因此在按键按下的时候,要把我们手上的干扰信号以及按键的机械接触等干扰信号给滤除掉。一般情况下,我们可以采用电容来滤除掉这些干扰信号,但实际上,会增加硬件成本及硬件电路的体积,这是我们不希望,总得有个办法解决这个问题,因此我们可以采用软件滤波的方法去除这些干扰信号。单片机与键盘接口按键的去抖(a)检测按键(b)释放按键按键去抖流程图#includereg51.Hunsignedcharcount;sbitP3_7=P3^7;voiddelay10ms(void){unsignedchari,j;for(i=20;i0;i--)for(j=248;j0;j--);}voidmain(void){while(1){if(P3_7==0){delay10ms();if(P3_7==0){count++;if(count==16){count=0;}P1=~count;while(P3_7==0);}}}}XTAL218XTAL119ALE30EA31PSEN29RST9P0.0/AD039P0.1/AD138P0.2/AD237P0.3/AD336P0.4/AD435P0.5/AD534P0.6/AD633P0.7/AD732P1.01P1.12P1.23P1.34P1.45P1.56P1.67P1.78P3.0/RXD10P3.1/TXD11P3.2/INT012P3.3/INT113P3.4/T014P3.7/RD17P3.6/WR16P3.5/T115P2.7/A1528P2.0/A821P2.1/A922P2.2/A1023P2.3/A1124P2.4/A1225P2.5/A1326P2.6/A1427U1AT89C51D1LED-BIRGD2LED-BIRGD3LED-BIRGD4LED-BIRGD5LED-BIRGD6LED-BIRGD7LED-BIRGD8LED-BIRG//功能:独立式按键程序#includeREG51.H//函数名:delay10ms//函数功能:采用定时器1实现延时10ms//形式参数:无//返回值:无voiddelay()//定时10ms,采用定时器1,工作方式1实现{TH1=0xd8;//设置10ms定时初值TL1=0xf0;TR1=1;//启动定时器1while(!TF1);//判断10ms定时时间到TF1=0;}voidmain()//主函数{unsignedchari;TMOD=0x10;//设置定时器1工作方式1P1=0xff;//P1口作为输入口,置全1i=0;while(1){while(i==0)//循环判断是否有键按下{i=P1;//读按键状态i=~i;//按键状态取反}delay();//有键按下,延时10ms去抖do{i=P3;//再次读按键状态i=~i;//按键状态取反}while(i==0);switch(i)//根据键值调用不同的处理函数{case0x01:key1();break;//调用按键1子函数,该函数此处省略case0x02:key2();break;//调用按键2子函数,该函数此处省略case0x04:key3();break;//调用按键3子函数,该函数此处省略case0x08:key4();break;//调用按键4子函数,该函数此处省略case0x10:key5();break;//调用按键5子函数,该函数此处省略case0x20:key6();break;//调用按键6子函数,该函数此处省略case0x40:key7();break;//调用按键7子函数,该函数此处
本文标题:5-数字秒表
链接地址:https://www.777doc.com/doc-3825083 .html