標(biāo)題:
ATmega8的eeprom讀寫操作程序
[打印本頁]
作者:
筑夢守心
時間:
2019-9-18 11:26
標(biāo)題:
ATmega8的eeprom讀寫操作程序
ATmega8的eeprom讀寫操作,實(shí)測沒問題
單片機(jī)源程序如下:
//ICC-AVR application builder
// Target : M8
// Crystal: 8.0000Mhz
#include <iom8v.h>
#include <macros.h>
#include <74164.h>
#include <eeprom.h>
unsigned char display[4]; // 顯示緩沖區(qū)
unsigned char dis; // 當(dāng)前顯示
unsigned char s,m; // 時間
//TIMER0 initialisation - prescale:256
// WGM: Normal
// desired value: 5mSec
// actual value: 4.992mSec (0.2%)
void timer0_init(void)
{
TCCR0 = 0x00; //stop
TCNT0 = 0x64; //set count
TCCR0 = 0x04; //start timer
}
#pragma interrupt_handler timer0_ovf_isr:10
void timer0_ovf_isr(void)
{
TCNT0 = 0x64; //reload counter value
// display
switch(dis){ // 顯示
case 0: write164(display[dis] | 0x70); break;
case 1: write164(display[dis] | 0xB0); break;
case 2: write164(display[dis] | 0xD0); break;
case 3: write164(display[dis] | 0xE0); break;
}
if(++dis > 3) dis = 0;
//end display
}
//TIMER1 initialisation - prescale:1024
// WGM: 0) Normal, TOP=0xFFFF
// desired value: 1Hz
// actual value: 1.000Hz (0.0%)
void timer1_init(void)
{
TCCR1B = 0x00; //stop
TCNT1H = 0xE1; //setup
TCNT1L = 0x7C;
OCR1AH = 0x1E;
OCR1AL = 0x84;
OCR1BH = 0x1E;
OCR1BL = 0x84;
ICR1H = 0x1E;
ICR1L = 0x84;
TCCR1A = 0x00;
TCCR1B = 0x05; //start Timer
}
#pragma interrupt_handler timer1_ovf_isr:9
void timer1_ovf_isr(void)
{
//TIMER1 has overflowed
TCNT1H = 0xE1; //reload counter high value
TCNT1L = 0x7C; //reload counter low value
if(++s == 60){
s = 0;
if(++m == 60) m = 0;
}
EEPROMwrite(1,s); // 保存時間
EEPROMwrite(2,m);
display[0] = s % 10; // 刷新顯示緩沖
display[1] = s / 10;
display[2] = m % 10;
display[3] = m / 10;
}
//call this routine to initialise all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
DDRB = 0x01; // 初始化操作74LS164的管腳
DDRD = 0xC0; // 初始化操作74LS164的管腳
timer0_init();
timer1_init();
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x05; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialised
}
//
void main(void)
{
init_devices();
s = EEPROMread(1); // 讀取時間
m = EEPROMread(2);
display[0] = s % 10; // 刷新顯示緩沖
display[1] = s / 10;
display[2] = m % 10;
display[3] = m / 10;
while(1);
}
復(fù)制代碼
所有資料51hei提供下載:
ATmega8的eeprom讀寫操作.rar
(18.37 KB, 下載次數(shù): 27)
2019-9-18 11:25 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1