微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > AVR128的程序——EEPROM记录复位次数

AVR128的程序——EEPROM记录复位次数

时间:11-22 来源:互联网 点击:
#include

#include

#define uchar unsigned char

#define uintunsigned int

void EEPROM_write(uint EEPROM_ADDR, uchar EEPROM_DAT);

void Delayms(uint MS);

void display(uchar FirstBit,uchar Num);

void Mcu_IO_Init(void);

uchar EEPROM_read(uint EEPROM_ADDR);

uchar TempData[8];

uchar WeiMa[8] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};

uchar led_discode[11]={0xc0,0xf9,0xa4,0xb0,0x99,

0x92,0x82,0xf8,0x80,0x90,0xff};

void main(void)

{

uchar i;

Mcu_IO_Init();

i=EEPROM_read(1);

i++;

EEPROM_write(1,i);

TempData[2] = led_discode[i/100];

TempData[1] = led_discode[i];

TempData[0] = led_discode[i/10];

while(1)

{

display(6,2);

}

}

void Mcu_IO_Init(void)

{

DDRA=0XFF;

PORTA=0XFF;

DDRC=0XFF;

PORTC=0XFF;

DDRF|=0X0E;

PORTF|=0X0E;

PORTF&=0xF7;

DDRB |=0X10;

PORTB|=0X10;

}

void EEPROM_write(uint EEPROM_ADDR, uchar EEPROM_DAT)

{

CLI();

while(EECR & (1

EEARH = 0X00;

EEARL = EEPROM_ADDR;

EEDR = EEPROM_DAT;

EECR |= (1

EECR |= (1

SEI();

}

uchar EEPROM_read(uint EEPROM_ADDR)

{

CLI();

while(EECR & (1

EEARH = 0X00;

EEARL = EEPROM_ADDR;

EECR |= (1

return EEDR;

SEI();

}

void display(uchar FirstBit,uchar Num)

{

unsigned char i;

for(i=0;i

{

PORTC=led_discode[10];

PORTA=WeiMa[i+FirstBit];

PORTC=TempData[i];

Delayms(5);

}

}

void Delayms(uint MS)

{

uint i,j;

for( i=0;i

for(j=0;j<1141;j++);

}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top