|
我这有,楼主看看吧:
- #include
- #define uchar unsigned char
- #define uint unsigned int
- #define Left 0x80
- #define Right 0x40
- unsigned char const Tab[]={0x14,0x9F,0x38,0x1A,0x93,0x52,0x50,0x1F,
- 0x10,0x12,0x11,0xD0,0x74,0x98,0x70,0x71};
-
- void display();//负责把显示缓冲区的数据显示到数码管
- void process(uchar left,uchar right);//刷新显示缓冲区
- void delay(uint ticks);//延时
- uchar ShuMa[2];//显示缓冲区
- void WriteEPROM(uint Address,uchar Data);
- uchar ReadEPROM(uchar Address);
- uchar temp=1000;
- void main()
- {
- uint Address=0;
- init_devices();
- //向0-511地址的EEPROM依次写入0--0xFF。共写满512字节EEPROM
- for(Address=0;Address!=512;Address++)WriteEPROM(Address,Address&0x0ff);
- while(1)
- {//把512字节的EEPROM数据依次读出来显示
- for(Address=0;Address!=512;Address++)
- {//读数据到显示缓冲区
- process(ReadEPROM(Address)>>4,ReadEPROM(Address)&0x0f);
- while(temp--) display();//显示
- temp=1000;
- }
- }
- }
- ////////////////////////////////
- void display()
- {
- PORTA=Left|Right;//关显示
- PORTC=ShuMa[0]; //输出数据
- PORTA=~Left; //开左数码管
- delay(10); //延时
- PORTA=Left|Right;//关显示
- PORTC=ShuMa[1]; //输出数据
- PORTA=~Right; //开右数码管
- delay(10); //延时
- }
- ///////////////////////////////////
- void process(uchar left,uchar right)
- {
- ShuMa[0]=Tab[left];//查表
- ShuMa[1]=Tab[right];//查表
- }
- /////////////////////////////////////
- void delay(uint ticks)
- {
- uchar i;
- while(ticks--)for(i=100;i!=0;i--);//约0.1mS
- }
- void WriteEPROM(uint Address,uchar Data)
- {
- while(EECR&0x02);//等待EEWE为0
- EEARH=Address>>8;//写入高地址
- EEARL=Address&0x0ff;//写入低地址
- EEDR=Data; //写数据到EEPROM寄存器
- EECR|=0x04; //置位EEMWE
- EECR|=0x02; //置位EEWE
- while(EECR&0x02); //等待EEWE为0
- }
- uchar ReadEPROM(uchar Address)
- {
- while(EECR&0x01);//等待EERE为0
- EEARH=Address>>8;//写入高地址
- EEARL=Address&0x0ff;//写入低地址
- EECR|=0x01; //置位EERE,读数据
- while(EECR&0x01); //等待EERE为0
- return EEDR; //返回数据
- }
复制代码 |
|