Skip to content

Instantly share code, notes, and snippets.

@nutchy
Created October 26, 2018 05:00
Show Gist options
  • Save nutchy/29e5058b124e35fd443a1583add63391 to your computer and use it in GitHub Desktop.
Save nutchy/29e5058b124e35fd443a1583add63391 to your computer and use it in GitHub Desktop.
#pragma SMALL
#include <reg52.h>
sbit p10 = P1^0;
sbit p11 = P1^1;
sbit kr1 = P2^0;
sbit kr2 = P2^1;
sbit kr3 = P2^2;
sbit kr4 = P2^3;
sbit kc1 = P2^4;
sbit kc2 = P2^5;
sbit kc3 = P2^6;
sbit kc4 = P2^7;
void delay(int count){
int i, j;
for (i = 0; i < count; i++)
for (j = 0; j < 500; j++);
}
void main(){
int count = 0;
int display[] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F, 0x77, 0x7C, 0x39, 0x5E, 0x79, 0x71};
int check = 0;
bit push = 0;
P0 = 0;
while(1){
//count = (count + 1 ) % 16;
//P0 = display[2];
//delay(100);
kc1 = 0;
if (kr1 == 0 && kr2 == 1 && kr3 == 1 && kr4 == 1) {
P0 = display[1];
}
if (kr1 == 1 && kr2 == 0 && kr3 == 1 && kr4 == 1) {
P0 = display[2];
}
if (kr1 == 1 && kr2 == 1 && kr3 == 0 && kr4 == 1) {
P0 = display[3];
}
if (kr1 == 1 && kr2 == 1 && kr3 == 1 && kr4 == 0) {
P0 = display[10];
}
kc1 = 1;
kc2 = 0;
if (kr1 == 0 && kr2 == 1 && kr3 == 1 && kr4 == 1) {
P0 = display[4];
}
if (kr1 == 1 && kr2 == 0 && kr3 == 1 && kr4 == 1) {
P0 = display[5];
}
if (kr1 == 1 && kr2 == 1 && kr3 == 0 && kr4 == 1) {
P0 = display[6];
}
if (kr1 == 1 && kr2 == 1 && kr3 == 1 && kr4 == 0) {
P0 = display[11];
}
kc2 = 1;
kc3 = 0;
if (kr1 == 0 && kr2 == 1 && kr3 == 1 && kr4 == 1) {
P0 = display[7];
}
if (kr1 == 1 && kr2 == 0 && kr3 == 1 && kr4 == 1) {
P0 = display[8];
}
if (kr1 == 1 && kr2 == 1 && kr3 == 0 && kr4 == 1) {
P0 = display[9];
}
if (kr1 == 1 && kr2 == 1 && kr3 == 1 && kr4 == 0) {
P0 = display[12];
}
kc3 = 1;
kc4 = 0;
if (kr1 == 0 && kr2 == 1 && kr3 == 1 && kr4 == 1) {
P0 = display[13];
}
if (kr1 == 1 && kr2 == 0 && kr3 == 1 && kr4 == 1) {
P0 = display[0];
}
if (kr1 == 1 && kr2 == 1 && kr3 == 0 && kr4 == 1) {
P0 = display[14];
}
if (kr1 == 1 && kr2 == 1 && kr3 == 1 && kr4 == 0) {
P0 = display[15];
}
kc4 = 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment