这个bootload非常简陋,源码是在silicon 官网例程和在网上找的一个汇编例程的基础上修改的,经过几天的努力实现了基本功能。
程序主体是用汇编写的,因为感觉用C重定位中断向量比较麻烦。发送HEX文件的上位机使用 win32 API 写的,也相当的简单。
用户程序模板测试了串口中断ADC中断,测试过程中未发现问题。
bootload 在芯片上电后会检测P1.3脚,低电平直接跳转至用户程序,若为高电平则调用flash擦除代码,擦除地址400H之后的10页flash空间,然后等待接收HEX文件,程序下载成功后跳转至用户程序。
C8051F330 bootload 源代码:
开发环境:keil
;iap for c8051f330 ;data:2013-11-29 ;zxx
$INCLUDE(C8051F330.INC) ; Register definition file.
cra1 equ 0dh ; carriage return cra2 equ 0ah ; carriage return error_led equ p1.2 ; active low - clr to turn on load_en equ p1.3 ; active low - clr to turn on
ram set 400h ; programs into
;******************************************************************** ; Interrupt vector table ;******************************************************************** org 0 ; System reset RST ljmp main org 3 ; External 0 IE0 ljmp (ram+3) org 0bh ; Timer 0 TF0 ljmp (ram+0bh) org 13h ; External 1 IE1 ljmp (ram+13h) org 1bh ; Timer 1 TF1 ljmp (ram+1bh) org 23h ; Serial port TI or RI ljmp (ram+23h) org 2bh ; Timer 2 TF2 or EXF2 ljmp (ram+2bh) org 33h ljmp (ram+33h) ;spi org 3bh ljmp (ram+3bh) ;smb0 org 4bh ljmp (ram+4bh) ;adc0 windows org 53h ljmp (ram+53h) ;adc0 convert over org 5bh ljmp (ram+5bh) ;pca org 63h ljmp (ram+63h) ;comparator org 73h ljmp (ram+73h) ;timer3 overflow ;******************************************************************** ; Main program starts here ; ;******************************************************************** org 80h main: clr EA lcall init ; init serial port
clr c mov c,load_en jc done lcall erase_flash call intro ; print welcome message call load1 done: mov dptr,#prompt8 ; end lcall outstr ljmp ram ; start running program
error: mov dptr,#prompt6 ; end lcall outstr stop: sjmp $
;******************************************************************** ; Receive hex file and write it to flash ;******************************************************************** load1: lcall inchar skip1: cjne a,#':',load1 ; each record begins with ':' mov r1,#0 ; init checksum to zero
length: lcall gethex ; get byte from serial port mov b,a ; use b as byte counter jz done ; if b = 0 address: lcall gethex ; get address high byte mov dph,a lcall gethex ; get address low byte mov dpl,a
record_type: lcall gethex ; get record type (ignore this) cjne a,#01h,check1 sjmp done ; if record type is 01h hex file reach the end check1: jz load4 ; if record type is zer
写给C8051F330的bootload、WIN32 API iap下载上位机
最新推荐文章于 2025-05-02 14:11:31 发布