Last active
August 29, 2015 14:23
-
-
Save okok897/7a5723784fa0550465cb to your computer and use it in GitHub Desktop.
8051 七段+按鈕v002
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <reg51.h> //8051????? | |
#define seg7 P1 | |
#define segs P2 | |
#define PB P0 | |
void scanner(int); | |
void delay(int); //????????? | |
int flag; | |
char seg[10]={0xc0,0xf9,0xa4,0xb0,0x99, //???????? | |
0x92,0x82,0xf8,0x80,0x90}; | |
int i; | |
main() | |
{ | |
PB=1; | |
flag=0; | |
i=0; | |
while(1) | |
{ | |
if (PB==0){ | |
delay(10); | |
if(PB==0){ | |
flag=1; | |
} | |
} | |
while(flag && PB){ | |
i++; | |
flag=0; | |
break; | |
} | |
scanner(i); | |
} | |
} | |
void scanner(int num){ | |
segs=0x07; //千位數掃描信號。 | |
seg7=seg[(num/100)/10]; //顯示千位數字。 | |
delay(2); //多工掃描時間約2ms。 | |
segs=0x0b; //百位數掃描信號。 | |
seg7=seg[(num/100)%10]; //顯示百位數字。 | |
delay(2); //多工掃描時間約2ms。 | |
segs=0x0d; //十位數掃描信號。 | |
seg7=seg[(num%100)/10]; //顯示十位數字。 | |
delay(2); //多工掃描時間約2ms。 | |
segs=0x0e; //個位數掃描信號。 | |
seg7=seg[(num%100)%10]; //顯示個位數字。 | |
delay(2); //多工掃描時間約2ms。 | |
} | |
void delay(int t){ | |
int i,j; | |
for(i=0;i<t;i++) | |
for(j=0;j<120;j++); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment