《按键控制数码管加减程序(3页).doc》由会员分享,可在线阅读,更多相关《按键控制数码管加减程序(3页).doc(3页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、-按键控制数码管加减程序-第 3 页#include #define dataport P1#define uchar unsigned char#define uint unsigned intsbit latch1=P22; /段锁存sbit latch2=P23; /位锁存sbit key1=P32;sbit key2=P33;unsigned int duanma=0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x7,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79;unsigned int weima=0xfe,0xfd,0xfb,0xf7
2、,0xef,0xdf,0xbf,0x7f;unsigned char display8;void suocun(uchar firstbit,uchar num);void delay(uchar z) /延时程序 uchar i,j,k; for(i=0;i50;i+) for(j=0;j50;j+) for(k=0;kz;k+);void main(void) uchar num=0; key1=1; key2=1; while(1) if(!key1) delay(5);if(!key1) num+; if(num=10) num=0; if(!key2) delay(5);if(!key2) num-; if(num=0) num=9; display0=duanmanum%10; suocun(2,1);void suocun(uchar firstbit,uchar num) uchar i ; for(i=0;inum;i+) dataport=0; latch1=1; latch1=0; dataport=weimafirstbit+i; latch2=1; latch2=0; dataport=displayi; latch1=1; latch1=0;最近在学习51单片机,因此偶尔也会写写小程序,因此和大家分享一下,希望大家都能学好单片机。