Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <8051.h>
- #define LIMIT 300
- int i[4] = {1, 1, 1, 1};
- void action(int key) {
- i[key] = i[key] + 1;
- if(i[key]>9)
- i[key]=0;
- }
- void main(void) {
- int btn_before[4] = {1, 1, 1, 1};
- int state[4] = {0, 0, 0, 0};
- int btn_current[4] = {4, 4, 4, 4};
- int debounce_cnt[4] = {0, 0, 0, 0};
- char cyfry[10]={0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F};
- int display[4] = {1, 2, 4, 8};
- int index = 1;
- while(1) {
- P1 = display[index];
- P0 = cyfry[i[index]];
- if(index == 0)
- btn_current[index] = P3_0;
- if(index == 1)
- btn_current[index] = P3_1;
- if(index == 2)
- btn_current[index] = P3_2;
- if(index == 3)
- btn_current[index] = P3_3;
- if(state[index] == 0) {
- if(btn_before[index] != btn_current[index]) {
- state[index] = 1;
- btn_before[index] = btn_current[index];
- }
- }
- if (state[index] == 1) {
- if (btn_before[index] == btn_current[index]) {
- if (debounce_cnt[index] > LIMIT) {
- state[index] = 2;
- action(index);
- } else {
- debounce_cnt[index] = debounce_cnt[index] + 1;
- }
- } else {
- state[index] = 0;
- btn_before[index] = btn_current[index];
- debounce_cnt[index] = 0;
- }
- }
- if (state[index] == 2) {
- if (btn_before[index] != btn_current[index]) {
- state[index] = 0;
- btn_before[index] = btn_current[index];
- debounce_cnt[index] = 0;
- }
- }
- index = index + 1;
- if(index > 3) {
- index = 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement