《基于C51单片机4按键4种花样流水灯设计(共3页).doc》由会员分享,可在线阅读,更多相关《基于C51单片机4按键4种花样流水灯设计(共3页).doc(3页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、精选优质文档-倾情为你奉上 #include #define uchar unsigned char #define uint unsigned int#define LED P3 uchar i,flag1,flag2,flag3,flag4;/*定义按键*/sbit k1=P24; sbit k2=P25; sbit k3=P26;sbit k4=P27; /*流水灯花样设计*/uchar table1=0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfc,0xff;/*从右到左逐一点亮反向灭之
2、*/*0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f*左移*/ uchar table2=0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf; /*左右循环*/ uchar table3=0x7e,0xbd,0xdb,0xe7,0xff;/*两头靠拢*/uchar table4=0xaa,0x55;/*闪烁*/ /*延时程序*/void delay(uint x) uint i; while(x-) for(i=50;i0;i-); /*判断按键*/void keyscan(
3、) if(k1=0) delay(10); if(k1=0) flag2=0; flag3=0;flag4=0; flag1=1; if(k2=0)delay(10);if(k2=0) flag3=0; flag1=0;flag4=0; flag2=1; if(k3=0)delay(10);if(k3=0)flag1=0;flag2=0;flag4=0; flag3=1; if(k4=0)delay(10);if(k4=0)flag1=0;flag2=0;flag3=0;flag4=1; /*主程序*/void main() while(1) keyscan(); if(flag1=1) for(i=0;i16;i+) LED=table1i; delay(200); keyscan(); if(flag2=1) for(i=0;i14;i+) LED=table2i; delay(300); keyscan(); if(flag3=1) for(i=0;i5;i+)LED=table3i; delay(250); keyscan(); if(flag4=1) for(i=0;i2;i+)LED=table4i; delay(600); keyscan(); 专心-专注-专业