AVR-atmega16 BOOTLoader 程序
本程序參照馬潮mega128的編寫(xiě)??芍С?85或232接口。變異軟件ICCAVR,上位機(jī)軟件應(yīng)用超級(jí)終端或avrubd等,Xmodem,9600,8,1,n
#include
#include
#include
#define SPM_PAGESIZE 128 //M16的一個(gè)Flash頁(yè)為128字節(jié)(64字),共128頁(yè)
#define BAUD 9600 //波特率采用9600bps
#define CRYSTAL 14745600 //系統(tǒng)時(shí)鐘 ?? M Hz
//計(jì)算和定義M16的波特率設(shè)置參數(shù)
#define BAUD_SETTING (unsigned char)((unsigned long)CRYSTAL/(16*(unsigned long)BAUD)-1)
#define BAUD_H (unsigned char)(BAUD_SETTING>>8)
#define BAUD_L (unsigned char)BAUD_SETTING
//定義Xmoden控制字符
#define XMODEM_NUL 0x00
#define XMODEM_SOH 0x01
#define XMODEM_STX 0x02
#define XMODEM_EOT 0x04
#define XMODEM_ACK 0x06
#define XMODEM_NAK 0x15
#define XMODEM_CAN 0x18
#define XMODEM_EOF 0x1A
#define XMODEM_RECIEVING_WAIT_CHAR 'C'
//定義接收緩沖區(qū)長(zhǎng)度
#define DATA_BUFFER_SIZE SPM_PAGESIZE
//485使能
#define USART_TX_ENABLE(){asm("sbi 0x12,2"); asm("nop");}//485發(fā)送使能 D口 pin2
#define USART_RX_ENABLE(){asm("cbi 0x12,2"); asm("nop");}//485接收使能
//定義全局變量
const char startupString[]="nrType 'W' download, Others run application program.nr