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
|
#ifndef __REG51_H__ #define __REG51_H__ #define uchar unsigned char #define uint unsigned int unsigned char code shuzi[]={0XC0,0XF9,0XA4,0XB0,0X99,0X92,0X82,0XF8,0X80,0X90,0xbf,0xff}; unsigned char code zimu[]={0x88,0x83,0xc6,0xa1,0x86,0x8e,0x89,0xc7,0x8c,0xc1}; unsigned char code num[]={0XC0,0XF9,0XA4,0XB0,0X99,0X92,0X82,0XF8,0X80,0X90}; unsigned char code weizhi[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x00,0x00,0x00}; unsigned char ledweizhi[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0xff};
sfr P0 = 0x80; sfr P1 = 0x90; sfr P2 = 0xA0; sfr P3 = 0xB0; sfr P4 = 0xC0; sfr PSW = 0xD0; sfr ACC = 0xE0; sfr B = 0xF0; sfr SP = 0x81; sfr DPL = 0x82; sfr DPH = 0x83; sfr PCON = 0x87; sfr TCON = 0x88; sfr TMOD = 0x89; sfr TL0 = 0x8A; sfr TL1 = 0x8B; sfr TH0 = 0x8C; sfr TH1 = 0x8D; sfr IE = 0xA8; sfr IP = 0xB8; sfr SCON = 0x98; sfr SBUF = 0x99;
sbit CY = 0xD7; sbit AC = 0xD6; sbit F0 = 0xD5; sbit RS1 = 0xD4; sbit RS0 = 0xD3; sbit OV = 0xD2; sbit P = 0xD0;
sbit TF1 = 0x8F; sbit TR1 = 0x8E; sbit TF0 = 0x8D; sbit TR0 = 0x8C; sbit IE1 = 0x8B; sbit IT1 = 0x8A; sbit IE0 = 0x89; sbit IT0 = 0x88;
sbit EA = 0xAF; sbit ES = 0xAC; sbit ET1 = 0xAB; sbit EX1 = 0xAA; sbit ET0 = 0xA9; sbit EX0 = 0xA8;
sbit PS = 0xBC; sbit PT1 = 0xBB; sbit PX1 = 0xBA; sbit PT0 = 0xB9; sbit PX0 = 0xB8;
sbit RD = 0xB7; sbit WR = 0xB6; sbit T1 = 0xB5; sbit T0 = 0xB4; sbit INT1 = 0xB3; sbit INT0 = 0xB2; sbit TXD = 0xB1; sbit RXD = 0xB0;
sbit SM0 = 0x9F; sbit SM1 = 0x9E; sbit SM2 = 0x9D; sbit REN = 0x9C; sbit TB8 = 0x9B; sbit RB8 = 0x9A; sbit TI = 0x99; sbit RI = 0x98;
#endif
void delay_ms(int ms){ int q,w; for(q = 0;q<ms;q++){ for(w=845;w>0;w--); } } void Delay500us() { unsigned char i, j;
i = 6; j = 211; do { while (--j); } while (--i); } void Delay100us() { unsigned char i, j;
i = 2; j = 39; do { while (--j); } while (--i); }
void allinit() { P2=(P2&0x1f)|0x80; P0=0xff; P2&=0x1f; P2=(P2&0x1f)|0xA0; P0 = P0 & 0XAF; P2&=0x1f; P2=(P2&0x1f)|0xc0; P0=0xff; P2&=0x1f; P2=(P2&0x1f)|0xe0; P0=0xFF; P2&=0x1f; }
void shumaguan_bit(unsigned char a[],unsigned char b) { unsigned char code led_p[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf,0x88,0xc6}; unsigned char i; for(i=0;i<=7;i++) { if((b>>(7-i))&0x01) { P2 = (P2 & 0X1F)|(0X07 << 5); P0 = 0Xff; P2 = (P2 & 0X1F)|(0X06 << 5); P0 = (0x01 << i); delay_ms(1); P2 = (P2 & 0X1F)|(0X07 << 5); P0 = led_p[a[i]]; delay_ms(1); } else { P2 = (P2 & 0X1F)|(0X07 << 5); P0 = 0Xff; P2 = (P2 & 0X1F)|(0X06 << 5); P0 = (0x01 << i); delay_ms(1); P2 = (P2 & 0X1F)|(0X07 << 5); P0 = 0xff; delay_ms(1); } } }
void shumaguan_shuzi(uchar a,uchar b) { delay_ms(1); P2=(P2&0X1f)|0xC0;P0=weizhi[a]; P2=(P2&0X1f)|0xE0;P0=shuzi[b]; delay_ms(1); } void shumaguan_zimu(uchar a,uchar b) { delay_ms(1); P2=(P2&0X1f)|0xC0;P0=weizhi[a]; P2=(P2&0X1f)|0xE0;P0=zimu[b]; delay_ms(1); } void ledlight(uchar x) { P2=(P2&0X1f)|0x80; P0=ledweizhi[x]; }
|