⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 51pro.s

📁 笔者的《用M8L制作的89S51单片机 USB下载线》在无线电2007年第9期已刊登过
💻 S
📖 第 1 页 / 共 2 页
字号:
	.module _51pro.c
	.area text(rom, con, rel)
	.dbfile E:\学习专区\AVR专区\个人创作区\ICC\51pro.c
	.dbfunc e Delay_us _Delay_us fV
;              a -> R20
;              b -> R22
;             us -> R16
	.even
_Delay_us::
	rcall push_gset2
	.dbline -1
	.dbline 16
; //////////////////////////////////////////////////////////////////////////////////////////////////
; //E51Pro.c
; //Easy 51Pro编程器主程序,负责通讯,管理编程操作
; ///////////////////////////////////////////////////////////////////////////////////////////////////
; 
; #include <iom8v.h>
; #include <macros.h>
; #include <e51pro.h>
; #include <signal.h>
; #define uchar unsigned char 
; //BYTE ComBuf[18];//串口通讯数据缓存,发送和接收都使用
; UINT nAddress;//ROM中地址计数
; UINT nTimeOut;//超时计数
; ProWork pw;//编程器一般操作
; void Delay_us(BYTE  us)//微秒级延时<255us
; {
	.dbline 17
; char a=0;
	clr R20
	.dbline 18
; char b=0;
	clr R22
	.dbline 19
; for (a=0;a<7;a++)
	rjmp L5
L2:
	.dbline 20
; for (b=0;b<us;b++)
	clr R22
	rjmp L9
L6:
	.dbline 21
L7:
	.dbline 20
	inc R22
L9:
	.dbline 20
	cp R22,R16
	brlo L6
L3:
	.dbline 19
	inc R20
L5:
	.dbline 19
	cpi R20,7
	brlo L2
	.dbline -2
L1:
	rcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r a 20 c
	.dbsym r b 22 c
	.dbsym r us 16 c
	.dbend
	.dbfunc e Delay_ms _Delay_ms fV
;              a -> R20,R21
;              b -> R22,R23
;             ms -> R16,R17
	.even
_Delay_ms::
	rcall push_gset2
	.dbline -1
	.dbline 24
; ;
; }
; void Delay_ms(UINT ms)//豪秒级的延时<65535ms
; {
	.dbline 25
; int a=0;
	clr R20
	clr R21
	.dbline 26
; int b=0;
	clr R22
	clr R23
	.dbline 27
; for (a=0;a<4000;a++)
L11:
	.dbline 28
; for (b=0;b<ms;b++)
	clr R22
	clr R23
	rjmp L18
L15:
	.dbline 29
L16:
	.dbline 28
	subi R22,255  ; offset = 1
	sbci R23,255
L18:
	.dbline 28
	cp R22,R16
	cpc R23,R17
	brlo L15
L12:
	.dbline 27
	subi R20,255  ; offset = 1
	sbci R21,255
	.dbline 27
	cpi R20,160
	ldi R30,15
	cpc R21,R30
	brlt L11
	.dbline -2
L10:
	rcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r a 20 I
	.dbsym r b 22 I
	.dbsym r ms 16 i
	.dbend
	.dbfunc e uart_init _uart_init fV
	.even
_uart_init::
	.dbline -1
	.dbline 34
; ;
; }
; 
; 
; void uart_init(void)  //串口通信
; {
	.dbline 35
; UCSRB|=(TXEN)|(1<<RXEN);
	in R24,0xa
	ori R24,19
	out 0xa,R24
	.dbline 36
; UBRRL=7;  //设置波特率  57600
	ldi R24,7
	out 0x9,R24
	.dbline 37
; UBRRH=0x00;
	clr R2
	out 0x20,R2
	.dbline 38
; UCSRC|=(1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0);
	in R24,0x20
	ori R24,134
	out 0x20,R24
	.dbline -2
L19:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e uart_putchar _uart_putchar fV
;              x -> R16
	.even
_uart_putchar::
	.dbline -1
	.dbline 41
; }
; void uart_putchar(char x)//发送数据
; {
L21:
	.dbline 43
L22:
	.dbline 42
; while (!(UCSRA&0x20))
	sbis 0xb,5
	rjmp L21
	.dbline 44
; ;
; UDR=x; 
	out 0xc,R16
	.dbline -2
L20:
	.dbline 0 ; func end
	ret
	.dbsym r x 16 c
	.dbend
	.dbfunc e WaitComm _WaitComm fc
;              n -> R16
	.even
_WaitComm::
	.dbline -1
	.dbline 48
; }
; 
; BOOL WaitComm()//等待上位机的命令,18字节
; {
	.dbline 49
; 	BYTE n=0;
	clr R16
L25:
	.dbline 50
	.dbline 50
L26:
	.dbline 50
; 	while(!(UCSRA&0x80)){}//等待第一个字节
	sbis 0xb,7
	rjmp L25
	.dbline 51
; 	ComBuf[n]=UDR;
	ldi R24,<_ComBuf
	ldi R25,>_ComBuf
	mov R30,R16
	clr R31
	add R30,R24
	adc R31,R25
	in R2,0xc
	std z+0,R2
	.dbline 52
; 	n++;
	inc R16
	.dbline 53
; 	for(n;n<=17;n++)
	rjmp L31
L28:
	.dbline 54
; 	{
	.dbline 55
; 		nTimeOut=0;
	clr R2
	clr R3
	sts _nTimeOut+1,R3
	sts _nTimeOut,R2
	rjmp L33
L32:
	.dbline 57
; 		while(!(UCSRA&0x80))
; 		{
	.dbline 58
; 			nTimeOut++;
	lds R24,_nTimeOut
	lds R25,_nTimeOut+1
	adiw R24,1
	sts _nTimeOut+1,R25
	sts _nTimeOut,R24
	.dbline 59
; 			if(nTimeOut>10000)//后17个字节都有超时限制 
	ldi R24,10000
	ldi R25,39
	lds R2,_nTimeOut
	lds R3,_nTimeOut+1
	cp R24,R2
	cpc R25,R3
	brsh L35
	.dbline 60
; 				return 0;
	clr R16
	rjmp L24
L35:
	.dbline 61
L33:
	.dbline 56
	sbis 0xb,7
	rjmp L32
	.dbline 62
	ldi R24,<_ComBuf
	ldi R25,>_ComBuf
	mov R30,R16
	clr R31
	add R30,R24
	adc R31,R25
	in R2,0xc
	std z+0,R2
	.dbline 64
L29:
	.dbline 53
	inc R16
L31:
	.dbline 53
	ldi R24,17
	cp R24,R16
	brsh L28
	.dbline 65
; 		}
; 		ComBuf[n]=UDR;
; 	
; 	}
; 	return 1;
	ldi R16,1
	.dbline -2
L24:
	.dbline 0 ; func end
	ret
	.dbsym r n 16 c
	.dbend
	.dbfunc e WaitResp _WaitResp fc
	.even
_WaitResp::
	.dbline -1
	.dbline 68
; }
; BOOL WaitResp()//等待上位机回应,1字节,有超时限制 
; {
	.dbline 69
; 	nTimeOut=0;
	clr R2
	clr R3
	sts _nTimeOut+1,R3
	sts _nTimeOut,R2
	rjmp L39
L38:
	.dbline 71
; 	while(!(UCSRA&0x80))
; 	{
	.dbline 72
; 		nTimeOut++;
	lds R24,_nTimeOut
	lds R25,_nTimeOut+1
	adiw R24,1
	sts _nTimeOut+1,R25
	sts _nTimeOut,R24
	.dbline 73
; 		if(nTimeOut>50000) 
	ldi R24,50000
	ldi R25,195
	lds R2,_nTimeOut
	lds R3,_nTimeOut+1
	cp R24,R2
	cpc R25,R3
	brsh L41
	.dbline 74
; 		{
	.dbline 75
; 			return 0;
	clr R16
	rjmp L37
L41:
	.dbline 77
L39:
	.dbline 70
	sbis 0xb,7
	rjmp L38
	.dbline 79
; 		}
; 	}
; 	
; 	ComBuf[0]=UDR;
	in R2,0xc
	sts _ComBuf,R2
	.dbline 80
; 	return 1;
	ldi R16,1
	.dbline -2
L37:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e WaitData _WaitData fc
;              n -> R16
	.even
_WaitData::
	.dbline -1
	.dbline 84
; }
; 
; BOOL WaitData()//写器件时等待上位机数据,18字节,有超时限制 
; {
	.dbline 86
; 	BYTE n;
; 	for(n=0;n<=17;n++)
	clr R16
	rjmp L47
L44:
	.dbline 87
; 	{
	.dbline 88
; 		nTimeOut=0;
	clr R2
	clr R3
	sts _nTimeOut+1,R3
	sts _nTimeOut,R2
	rjmp L49
L48:
	.dbline 90
; 		while(!(UCSRA&0x80))
; 		{
	.dbline 91
; 			nTimeOut++;
	lds R24,_nTimeOut
	lds R25,_nTimeOut+1
	adiw R24,1
	sts _nTimeOut+1,R25
	sts _nTimeOut,R24
	.dbline 92
; 			if(nTimeOut>10000)
	ldi R24,10000
	ldi R25,39
	lds R2,_nTimeOut
	lds R3,_nTimeOut+1
	cp R24,R2
	cpc R25,R3
	brsh L51
	.dbline 93
; 			{
	.dbline 94
; 				return 0;
	clr R16
	rjmp L43
L51:
	.dbline 96
L49:
	.dbline 89
	sbis 0xb,7
	rjmp L48
	.dbline 97
	ldi R24,<_ComBuf
	ldi R25,>_ComBuf
	mov R30,R16
	clr R31
	add R30,R24
	adc R31,R25
	in R2,0xc
	std z+0,R2
	.dbline 98
L45:
	.dbline 86
	inc R16
L47:
	.dbline 86
	ldi R24,17
	cp R24,R16
	brsh L44
	.dbline 99
; 			}
; 		}
; 		ComBuf[n]=UDR;
; 	}
; 	return 1;
	ldi R16,1
	.dbline -2
L43:
	.dbline 0 ; func end
	ret
	.dbsym r n 16 c
	.dbend
	.dbfunc e SendData _SendData fV
;              n -> R20
	.even
_SendData::
	rcall push_gset1
	.dbline -1
	.dbline 103
; }
; 
; void SendData()//发送数据或回应操作完成,18字节
; {
	.dbline 104
; 	BYTE n=0;
	clr R20
	.dbline 105
; 	for(n;n<=17;n++)
	rjmp L57
L54:
	.dbline 106
	.dbline 107
	ldi R24,<_ComBuf
	ldi R25,>_ComBuf
	mov R30,R20
	clr R31
	add R30,R24
	adc R31,R25
	ldd R16,z+0
	rcall _uart_putchar
	.dbline 108
L55:
	.dbline 105
	inc R20
L57:
	.dbline 105
	ldi R24,17
	cp R24,R20
	brsh L54
	.dbline -2
L53:
	rcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r n 20 c
	.dbend
	.dbfunc e SendResp _SendResp fV
	.even
_SendResp::
	.dbline -1
	.dbline 112
; 	{
; 	uart_putchar(ComBuf[n]);
; 	}
; }
; 
; void SendResp()//回应上位机1个字节,在写器件函数中使用
; {
	.dbline 113
; 	uart_putchar(ComBuf[0]);
	lds R16,_ComBuf
	rcall _uart_putchar
	.dbline -2
L58:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e RstPro _RstPro fV
	.even
_RstPro::
	.dbline -1
	.dbline 117
; }
; 
; void RstPro()//编程器复位
; {
	.dbline 118
; 	pw.fpProOver();//直接编程结束
	lds R30,_pw+12
	lds R31,_pw+12+1
	rcall xicall
	.dbline 119
; 	SendData();//通知上位机,表示编程器就绪,可以直接用此函数因为协议号(ComBuf[0])还没被修改,下同
	rcall _SendData
	.dbline -2
L59:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e ReadSign _ReadSign fV
	.even
_ReadSign::
	.dbline -1
	.dbline 123
; }
; 
; void ReadSign()//读特征字
; {
	.dbline 124
; 	pw.fpReadSign();
	lds R30,_pw+2
	lds R31,_pw+2+1
	rcall xicall
	.dbline 125
; 	SendData();//通知上位机,送出读出器件特征字
	rcall _SendData
	.dbline -2
L61:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e Erase _Erase fV
	.even
_Erase::
	.dbline -1
	.dbline 129
; }
; 
; void Erase()//擦除器件
; {
	.dbline 130
; 	pw.fpErase();
	lds R30,_pw+4
	lds R31,_pw+4+1
	rcall xicall
	.dbline 131
; 	SendData();//通知上位机,擦除了器件
	rcall _SendData
	.dbline -2
L63:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e Write _Write fV
;              n -> R20
	.even

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -