📄 main._c
字号:
/*****************************************************************************
*
* Copyright (C) 1996-1998 Atmel Corporation
*
* File : main.c
* Compiler : IAR 1.51B
* Output size : 505 bytes (size optimized)
* Created : 16-jun-99
* Modified : 5-jan-2000
* Last modified : 16-may-2001 by jll
*
* Support mail : avr@atmel.com
*
* Description : This Program allows an AVR with bootloader capabilities to
* Read/write its own Flash/EEprom. To enter Programming mode
* PD2 is checked, it this pin is pulled low, programming mode
* is entered. If not, normal execution is done from $0000
* "reset" vector in Application area.
* The PD2 pin should be pulled HIGH by an external Pull-up
* resistor.
*
* Other info : Code must be modified to use this specific code with devices
* other than ATmega161. Following change should be made:
* -Specify device in define list (e.g. _ATMEGA163)
*
* When using this code with (future) parts other than ATmega32,
* ATmega161 and ATmega163, it will be necessary to change more
* than the device name. The changes that should be made is:
* -Device name
* -Device signature and memory settings (defines.h)
* -Device code
* -Linker file
*
* In general the linker file should always be verifyed to match
* the used part's boot address and size. Note that memory size
* is specified in bytes in the linker file.
****************************************************************************/
#include "defines.h"
#include "serial.h"
#include "assembly.h"
void Delay(unsigned int i)
{
while(i--) ;
}
void Display_IAP(void)
{
PORTD = 0xEF;
PORTB = 0x06;
}
void main(void)
{
unsigned int intval,address,data,page_address;
unsigned char val, page_size;
Delay(10000);
SerialInit();
Delay(50000);
timer0_init();
PORTB = 0xFF;
DDRB = 0xFF;
PORTC = 0x7F; //m103 output only
DDRC = 0x79;
PORTD = 0xFF;
DDRD = 0xFC;
sendstr("富友勤 ATMEGA8 DEMO");
sendstr("Start IAP");
for(;;)
{
Display_IAP();
val=recchar();
if(val=='W') //Chip erase
{
sendstr("Start Write ");
page_address=recchar();
page_address|=recchar()<<8;
for(address=0;address < APP_END;address += PAGESIZE) //Application section = 60 pages
{
for(page_size=0;page_size < PAGESIZE;page_size += 2) //Application section = 60 pages
{
if(page_address!=0)
data=recchar();
else
data=0xFF;
if(page_address)
page_address--;
if(page_address!=0)
data|=recchar()<<8;
else
data|=0xFF<<8;
if(page_address)
page_address--;
fill_temp_buffer(data,(page_size)); //call asm routine.
}
write_page((address),0x05);
}
sendstr("End Write ");
}
else if(val=='e') //Chip erase
{
sendstr("Start Erase ");
for(address=0;address < APP_END;address += PAGESIZE) //Application section = 60 pages
{Delay(20000);
write_page(address,0x03); //Perform page erase
}
sendstr("End Erase ");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -