|
- #include <iom16v.h>
- #include <macros.h>
- #define uchar unsigned char
- #define uint unsigned int
- uchar SEG_CODE[] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F}; //ED数码管从0到9来回显示
- void delay_1ms(int k)
- {
- int i,j;
- for(i=0;i<k;i++)
- {
- for(j=0;j<1000;j++)
- ;
- }
- }
- void EEPROM_write(uint addr,uint adata)
- {
- SREG &= ~BIT(7);
- while(EECR &BIT(EEWE));
- EEAR = addr;
- EEDR = adata;
- EECR |= BIT(EEMWE);
- EECR |= BIT(EEWE);
- SREG |= BIT(7);
- }
- uchar EEPROM_read(uint addr)
- {
- uchar edata;
- SREG &= ~BIT(7);
- while(EECR &BIT(EEWE));
- EEAR = addr;
- EECR |= BIT(EERE);
- edata = EEDR;
- return edata;
- }
- void main(void)
- {
- uchar i;
- DDRB = 0xff; //初始化PB口为输出
- PORTB = 0x00; //PB口一开始输出为0
- i = EEPROM_read(2);
- i ++;
- EEPROM_write(2,i);
- while(1)
- {
- PORTB = SEG_CODE<i>;
- delay_1ms(10000);
- }
- }
- </i>
复制代码
|
|