📄 funcs.s
字号:
.module funcs.c
.area text(rom, con, rel)
.dbfile C:\icc\examples.avr\AVR_PQ1A_DEMO\21_uCOSII/AVR_PQ1A.h
.dbfunc e Delayus _Delayus fV
; i -> R20,R21
; US -> R22,R23
.even
_Delayus::
xcall push_gset2
movw R22,R16
.dbline -1
.dbline 29
;
; #ifndef OS_MASTER_FILE
; #include "includes.h"
; #include "AVR_PQ1A.h"
; #endif
;
; #pragma data:code
; const SEGMENT[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d, 0x07,
; 0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
; #pragma data:data
; /*******************************************
; 函数名称: DS1302_init
; 功 能: 初始化DS1302的数据接口
; 参 数: 无
; 返回值 : 无
; /********************************************/
; void DS1302_portinit(void)
; {
; DDRB|=BIT(RTC_CLK)|BIT(RTC_DATA)|BIT(RTC_CS);//将时钟端(RTC_CLK)数据端(RTC_DATA)片选端(RTC_CS)设置为输出
; }
; /*******************************************
; 函数名称: DS1302_writeB
; 功 能: 向DS1302写入一个字节数据(没有RST操作)
; 参 数: byte--要写入的数据
; 返回值 : 无
; /********************************************/
; void DS1302_writeB(uchar byte)
; {
; uchar i;
.dbline 31
; for(i=0;i<8;i++) //8位数据计数
; {
ldi R16,5
ldi R17,0
movw R18,R22
xcall empy16s
movw R22,R16
lsr R23
ror R22
lsr R23
ror R22
.dbline 32
clr R20
clr R21
xjmp L6
L3:
.dbline 32
L4:
.dbline 32
subi R20,255 ; offset = 1
sbci R21,255
L6:
.dbline 32
; PORTB&=~BIT(RTC_CLK); //拉低时钟端
cp R20,R22
cpc R21,R23
brlo L3
.dbline -2
.dbline 33
; if(byte&0x01) //当前位是否是1
L2:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r i 20 i
.dbsym r US 22 i
.dbend
.dbfunc e Delayms _Delayms fV
; i -> R20,R21
; j -> R22,R23
; MS -> R16,R17
.even
_Delayms::
xcall push_gset2
.dbline -1
.dbline 41
; {
; PORTB|=BIT(RTC_DATA); //当前位是1,拉高数据端
; }
; else
; {
; PORTB&=~BIT(RTC_DATA); //当前位是0,拉低数据端
; }
; Delayus(10); //调整时钟和脉冲宽度
.dbline 43
; PORTB|=BIT(RTC_CLK); //时钟上升沿(DS1302采样数据)
; byte>>=1; //数据右移1位,为送出新数据位做准备
clr R20
clr R21
xjmp L11
L8:
.dbline 44
clr R22
clr R23
xjmp L15
L12:
.dbline 44
L13:
.dbline 44
subi R22,255 ; offset = 1
sbci R23,255
L15:
.dbline 44
cpi R22,117
ldi R30,4
cpc R23,R30
brlo L12
L9:
.dbline 43
subi R20,255 ; offset = 1
sbci R21,255
L11:
.dbline 43
cp R20,R16
cpc R21,R17
brlo L8
.dbline -2
.dbline 45
; }
; }
L7:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r i 20 i
.dbsym r j 22 i
.dbsym r MS 16 i
.dbend
.dbfunc e Board_init _Board_init fV
.even
_Board_init::
.dbline -1
.dbline 53
; /*******************************************
; 函数名称: DS1302_readB
; 功 能: 从DS1302读出一个字节数据(没有RST操作)
; 参 数: 无
; 返回值 : byte--读出的数据
; /********************************************/
; uchar DS1302_readB(void)
; {
.dbline 54
; uchar i,byte=0;
clr R2
out 0xd,R2
.dbline 56
; DDRB&=~BIT(RTC_DATA); //将数据端口设置为输入
; PORTB&=~BIT(RTC_DATA); //无上拉电阻
ldi R24,255
out 0x1a,R24
.dbline 57
; for(i=0;i<8;i++) //8位数据计数
out 0x17,R24
.dbline 58
; {
out 0x14,R24
.dbline 59
; byte>>=1; //保存读入的数据位
out 0x11,R24
.dbline 61
; PORTB|=BIT(RTC_CLK); //时钟上升沿
; Delayus(10); //延时,调整时钟脉冲宽度
in R24,0x1b
ori R24,98
out 0x1b,R24
.dbline 62
; PORTB&=~BIT(RTC_CLK); //时钟下降沿,DS1302输出数据位
cbi 0x15,6
.dbline 63
; Delayus(10); //等待数据变化(MEGA16太快,必须等待DS1302的数据位输出,否则不能正确读出)
ldi R24,255
out 0x18,R24
.dbline 64
; if(PINB&BIT(RTC_DATA)) //当前位是否是高电平
ldi R16,5
ldi R17,0
xcall _Delayus
.dbline 65
; {
sbi 0x1b,2
.dbline 66
; byte|=BIT(PB7); //是高电平就将返回数据的当前位置1
ldi R16,15
ldi R17,0
xcall _Delayus
.dbline 67
; }
cbi 0x1b,2
.dbline 69
; else
; {
clr R2
out 0x18,R2
.dbline 70
; byte&=~BIT(PB7); //是低电平就将返回数据的当前位置0
ldi R16,5
ldi R17,0
xcall _Delayus
.dbline 71
; }
sbi 0x1b,3
.dbline 72
; }
ldi R16,15
ldi R17,0
xcall _Delayus
.dbline 73
; DDRB|=BIT(RTC_DATA); //最后将数据端口设置为输出
cbi 0x1b,3
.dbline 75
; return byte; //返回读出的数据
; }
ldi R24,255
out 0x18,R24
.dbline 76
; /*******************************************
ldi R16,5
ldi R17,0
xcall _Delayus
.dbline 77
; 函数名称: DS1302_writeD
sbi 0x1b,4
.dbline 78
; 功 能: 向DS1302的某个地址写入一个字节数据
ldi R16,15
ldi R17,0
xcall _Delayus
.dbline 79
; 参 数: addr--地址值(寄存器或RAM)
cbi 0x1b,4
.dbline 81
; data--要写入的地址
; 返回值 : 无
ldi R24,240
out 0x12,R24
.dbline 82
; /********************************************/
ldi R16,5
ldi R17,0
xcall _Delayus
.dbline 83
; void DS1302_writeD(uchar addr,uchar data)
sbi 0x1b,7
.dbline 84
; {
ldi R16,5
ldi R17,0
xcall _Delayus
.dbline 85
; PORTC&=~BIT(RTC_CS); //拉低片选端
cbi 0x1b,7
.dbline -2
.dbline 86
; PORTB&=~BIT(RTC_CLK); //拉低时钟端
L16:
.dbline 0 ; func end
ret
.dbend
.area code(ram, con, rel)
.dbfile C:\icc\examples.avr\AVR_PQ1A_DEMO\21_uCOSII/AVR_PQ1A.h
.area lit(rom, con, rel)
_SEGMENT::
.word 63
.word 6
.word 91
.word 79
.word 102
.word 109
.word 125
.word 7
.word 127
.word 111
.word 119
.word 124
.word 57
.word 94
.word 121
.word 113
.dbfile C:\icc\examples.avr\AVR_PQ1A_DEMO\21_uCOSII\funcs.c
.dbsym e SEGMENT _SEGMENT A[32:16]I
.area data(ram, con, rel)
.dbfile C:\icc\examples.avr\AVR_PQ1A_DEMO\21_uCOSII\funcs.c
.area text(rom, con, rel)
.dbfile C:\icc\examples.avr\AVR_PQ1A_DEMO\21_uCOSII\funcs.c
.dbfunc e DS1302_portinit _DS1302_portinit fV
.even
_DS1302_portinit::
.dbline -1
.dbline 18
.dbline 19
in R24,0x17
ori R24,160
out 0x17,R24
.dbline -2
.dbline 20
L17:
.dbline 0 ; func end
ret
.dbend
.dbfunc e DS1302_writeB _DS1302_writeB fV
; i -> R20
; byte -> R22
.even
_DS1302_writeB::
xcall push_gset2
mov R22,R16
.dbline -1
.dbline 28
.dbline 30
clr R20
xjmp L22
L19:
.dbline 31
.dbline 32
cbi 0x18,7
.dbline 33
sbrs R22,0
rjmp L23
.dbline 34
.dbline 35
sbi 0x18,5
.dbline 36
xjmp L24
L23:
.dbline 38
.dbline 39
cbi 0x18,5
.dbline 40
L24:
.dbline 41
ldi R16,10
ldi R17,0
xcall _Delayus
.dbline 42
sbi 0x18,7
.dbline 43
lsr R22
.dbline 44
L20:
.dbline 30
inc R20
L22:
.dbline 30
cpi R20,8
brlo L19
.dbline -2
.dbline 45
L18:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r i 20 c
.dbsym r byte 22 c
.dbend
.dbfunc e DS1302_readB _DS1302_readB fc
; i -> R20
; byte -> R22
.even
_DS1302_readB::
xcall push_gset2
.dbline -1
.dbline 53
.dbline 54
clr R22
.dbline 55
cbi 0x17,5
.dbline 56
cbi 0x18,5
.dbline 57
clr R20
xjmp L29
L26:
.dbline 58
.dbline 59
lsr R22
.dbline 60
sbi 0x18,7
.dbline 61
ldi R16,10
ldi R17,0
xcall _Delayus
.dbline 62
cbi 0x18,7
.dbline 63
ldi R16,10
ldi R17,0
xcall _Delayus
.dbline 64
sbis 0x16,5
rjmp L30
.dbline 65
.dbline 66
ori R22,128
.dbline 67
xjmp L31
L30:
.dbline 69
.dbline 70
andi R22,127
.dbline 71
L31:
.dbline 72
L27:
.dbline 57
inc R20
L29:
.dbline 57
cpi R20,8
brlo L26
.dbline 73
sbi 0x17,5
.dbline 74
mov R16,R22
.dbline -2
L25:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r i 20 c
.dbsym r byte 22 c
.dbend
.dbfunc e DS1302_writeD _DS1302_writeD fV
; data -> R20
; addr -> R22
.even
_DS1302_writeD::
xcall push_gset2
mov R20,R18
mov R22,R16
.dbline -1
.dbline 84
.dbline 85
cbi 0x15,7
.dbline 86
cbi 0x18,7
.dbline 87
; Delayus(10);
ldi R16,10
ldi R17,0
xcall _Delayus
.dbline 88
; PORTC|=BIT(RTC_CS); //拉高片选端
sbi 0x15,7
.dbline 89
; Delayus(10); //调整片选脉冲
ldi R16,10
ldi R17,0
xcall _Delayus
.dbline 90
; DS1302_writeB(addr); //写入操作命令(地址)
mov R16,R22
xcall _DS1302_writeB
.dbline 91
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -