1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
|
#ifndef _INTRINS_H_ #define _INTRINS_H_
#define __push(x) __asm push _##x __endasm #define __pop(x) __asm pop _##x __endasm
#define _push_ __push #define _pop_ __pop
#define pushSfr(x) do{\ __push(x)
#define popSfr(x) __pop(x);\ }while(0)
#endif
#ifndef _MY_H_ #define _MY_H_ #include<8052.h>
#define BEEP P2_5
#define DEGITAL_LED P0 #define DEGITAL_LED_SELECT P2
#define KEY1 P3_1 #define KEY2 P3_0 #define KEY3 P3_2 #define KEY4 P3_3
typedef unsigned char u8; typedef unsigned int u16;
u8 smg_code[16] = {0x3F,0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F, 0x77, 0x7C, 0x39, 0x5E, 0x79, 0x71};
u8 smg_pos[8] = {0x1C,0x18,0x14,0x10,0x0C,0x08,0x04,0x00};
u8 smg_show_code[2][8] = { {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, };
void delay_10us(u16 us){ while(us--); }
void show_digital_led(u8 pos, u8 degital, u8 ledCode){ u8 realPos = 0; realPos = pos % 8; DEGITAL_LED_SELECT = smg_pos[realPos]; if(degital >= 0 && degital <= 15) { DEGITAL_LED = smg_code[degital]; } else { DEGITAL_LED = ledCode; } }
void display_digital_led(){ for(int i = 0; i < 8; i++){ show_digital_led(i, smg_show_code[0][i], smg_show_code[1][i]); delay_10us(100); show_digital_led(i, 16, 0x00); } }
void beep(u8 voiceHigh, u8 voiceLow, u16 time){ while(time--){ delay_10us(voiceHigh); BEEP = 1; delay_10us(voiceLow); BEEP = 0; } }
#endif
#include"header/my.h"
#define KEY1_VALUE 1 #define KEY2_VALUE 2 #define KEY3_VALUE 3 #define KEY4_VALUE 4 #define NO_KEY_VALUE 5
u8 keyScan(){ delay_10us(1000); if(KEY1 == 0){ return KEY1_VALUE; } if(KEY2 == 0){ return KEY2_VALUE; } if(KEY3 == 0){ return KEY3_VALUE; } if(KEY4 == 0){ return KEY4_VALUE; } return NO_KEY_VALUE; }
void initDegitalLED(u8 key){ if(key >=0 && key <= 3){ smg_show_code[0][key] = 16; smg_show_code[1][key] = 0x40; }else { smg_show_code[0][0] = 16; smg_show_code[1][0] = 0x40; smg_show_code[0][1] = 16; smg_show_code[1][1] = 0x40;
smg_show_code[0][2] = 16; smg_show_code[1][2] = 0x40;
smg_show_code[0][3] = 16; smg_show_code[1][3] = 0x40;
} }
void main(){ u8 key = 0; u8 cur = 0; initDegitalLED(5); while(1){ if(smg_show_code[0][0] == 1 && smg_show_code[0][1] == 2 && smg_show_code[0][2] == 3 && smg_show_code[0][3] == 4){ beep(100, 10, 1000); }else{ key = keyScan(); if(key != NO_KEY_VALUE) { smg_show_code[0][key -1] = key; smg_show_code[1][key -1] = 0x00; if(cur != (key -1)){ smg_show_code[0][key-1] = 16; smg_show_code[1][key-1] = 0x40; } cur++; } if(cur > 4){ cur = 0; } display_digital_led(); } } }
|