- #include<reg52.h>
- #include<intrins.h>
- #define uchar unsigned char
- #define MAIN_Fosc 11059200UL
- typedef unsigned int INT16U;
- sbit DU = P2^6;
- sbit WE = P2^7;
- uchar code table[]={
- // 0 1 2 3 4 5
- 0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92,
- // 6 7 8 9 . 关显示
- 0x82, 0xf8, 0x80, 0x90, 0x7f, 0xff
- };
- uchar code T_COM[] = {
- //1 2 3 4 5 6
- 0x01, 0x02, 0x04, 0x08, 0x10, 0x20
- };
- void Delay_Ms(INT16U ms)
- {
- INT16U i;
- do{
- i = MAIN_Fosc / 96000;
- while(--i); //96T per loop
- }while(--ms);
- }
- void Display(uchar z)
- {
- //------------------------------
- DU = 0;
- P0 = table[z];
- DU = 1;
- DU = 0;
- WE = 0;
- P0 = T_COM[0];
- WE = 1;
- WE = 0;
- Delay_Ms(3);
- //-------------------------------
- DU = 0;
- P0 = table[z] & 0x7f;
- DU = 1;
- DU = 0;
- WE = 0;
- P0 = T_COM[1];
- WE = 1;
- WE = 0;
- Delay_Ms(3);
- //------------------------------
- DU = 0;
- P0 = table[z];
- DU = 1;
- DU = 0;
- WE = 0;
- P0 = T_COM[2];
- WE = 1;
- WE = 0;
- Delay_Ms(3);
- //-------------------------------
- DU = 0;
- P0 = table[z] & 0x7f;
- DU = 1;
- DU = 0;
- WE = 0;
- P0 = T_COM[3];
- WE = 1;
- WE = 0;
- Delay_Ms(3);
- //------------------------------
- DU = 0;
- P0 = table[z];
- DU = 1;
- DU = 0;
- WE = 0;
- P0 = T_COM[4];
- WE = 1;
- WE = 0;
- Delay_Ms(3);
- //-------------------------------
- DU = 0;
- P0 = table[z] & 0x7f;
- DU = 1;
- DU = 0;
- WE = 0;
- P0 = T_COM[5];
- WE = 1;
- WE = 0;
- Delay_Ms(3);
- }
- void main()
- {
- Display(0);
- }
复制代码
想不太明白 DP最高位为0的时候会亮 如果输出0 十六进制是 c0 二进制就是 1100 0000 与上 0x7F 0111 1111 变成 0100 0000 没想到有啥毛病 数码一直不显示
|