📄 ds1302_mega16.s
字号:
; /**********************************************
; 函 数 名:Write_0
; 功 能:写一个Bit到DS18B20
; 入口参数:无
; 出口参数:无
; 修改日期:2007.02.16
; **********************************************/
; void Write_0(void)
; {
.dbline 186
; Set_low();
.dbline 186
sbi 0x11,7
.dbline 186
cbi 0x12,7
.dbline 186
.dbline 187
; Delay_us(80);
ldi R16,80
ldi R17,0
xcall _Delay_us
.dbline 188
; Set_high();
.dbline 188
sbi 0x11,7
.dbline 188
sbi 0x12,7
.dbline 188
.dbline -2
L93:
.dbline 0 ; func end
ret
.dbend
.area lit(rom, con, rel)
_Time::
.byte 16,5
.byte 35,37
.byte 5,5
.byte 7
.dbfile E:\MyDesign\ICCAVR\ATmega16_DEV\DS1302\DS1302_Mega16.c
.dbsym e Time _Time A[7:7]kc
.area data(ram, con, rel)
.dbfile E:\MyDesign\ICCAVR\ATmega16_DEV\DS1302\DS1302_Mega16.c
_Day::
.blkb 4
.area idata
.byte 'M,'o,'n,0
.area data(ram, con, rel)
.dbfile E:\MyDesign\ICCAVR\ATmega16_DEV\DS1302\DS1302_Mega16.c
.blkb 4
.area idata
.byte 'T,'u,'e,0
.area data(ram, con, rel)
.dbfile E:\MyDesign\ICCAVR\ATmega16_DEV\DS1302\DS1302_Mega16.c
.blkb 4
.area idata
.byte 'W,'e,'d,0
.area data(ram, con, rel)
.dbfile E:\MyDesign\ICCAVR\ATmega16_DEV\DS1302\DS1302_Mega16.c
.blkb 4
.area idata
.byte 'T,'h,'u,0
.area data(ram, con, rel)
.dbfile E:\MyDesign\ICCAVR\ATmega16_DEV\DS1302\DS1302_Mega16.c
.blkb 4
.area idata
.byte 'F,'r,'i,0
.area data(ram, con, rel)
.dbfile E:\MyDesign\ICCAVR\ATmega16_DEV\DS1302\DS1302_Mega16.c
.blkb 4
.area idata
.byte 'S,'a,'t,0
.area data(ram, con, rel)
.dbfile E:\MyDesign\ICCAVR\ATmega16_DEV\DS1302\DS1302_Mega16.c
.blkb 4
.area idata
.byte 'S,'u,'n,0
.area data(ram, con, rel)
.dbfile E:\MyDesign\ICCAVR\ATmega16_DEV\DS1302\DS1302_Mega16.c
.dbsym e Day _Day A[28:7:4]c
.area lit(rom, con, rel)
_Number::
.byte 48,49
.byte 50,51
.byte 52,53
.byte 54,55
.byte 56,57
.dbsym e Number _Number A[10:10]kc
.area text(rom, con, rel)
.dbfile E:\MyDesign\ICCAVR\ATmega16_DEV\DS1302\DS1302_Mega16.c
.dbfunc e main _main fV
; i -> R20
.even
_main::
sbiw R28,1
.dbline -1
.dbline 52
; /****************************************
; 工 程:DS1302实时时钟+DS18B20+1602液晶6线显示
; 创建日期:2007年3月30日
; 修改日期:2007年3月31日
; 创 建 人:朱海峰
; 邮 箱:ntzhf100@163.com
; Q Q: 543376422
; *****************************************/
; #include <iom16v.h>
; #include <macros.h>
; #include "def.h"
; #include "LCD_1602_4wires.h"
; #include "DS18B20.h"
; /******************************************
; PIN DEFINE:
; /RST PD6
; SCLK PD4
; IO PD5
; ******************************************/
; /***************************************************************
; COMMAND/ADDRESS FORMAT
; bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0
; 1 RAM/CK A4 A3 A2 A1 A0 R/W
; ***************************************************************/
; // second,mintue,hour,date,month,day,year,control,trickle charge,clock burst
; //adderss: 0 1 2 3 4 5 6 7 8 9
; /**************************************************************/
;
; void Time_Init(const uint8_t *p_time);
; void ChipInit(void);
; void InitDS1302(void);
; void TimeSet(void);
; void ReadTime(void);
; void DisplayTime(void);
; void LCD_display_init(void);
; void Display(uint8_t x, uint8_t y, uint8_t g_data);
; void DS18B20(void);
; //RAM_CLOCK=1,RAM操作;
; //RAM_CLOCK=0,时钟日历操作;
; unsigned char Read_DS1302(uint8_t RAM_CLOCK, uint8_t Address);
; void Write(uint8_t RAM_CLOCK, uint8_t Address, uint8_t Dat);
;
; /*******************************************/
; //second,mintue,hour,date,month,day,year
; const uint8_t Time[]={0x10,0x05,0x23,0x25,0x05,0x05,0x07};
; uint8_t Day[7][4]={{"Mon"},{"Tue"},{"Wed"},{"Thu"},{"Fri"},{"Sat"},{"Sun"}};
; const uint8_t Number[]={'0','1','2','3','4','5','6','7','8','9'};
; unsigned char g_year,g_month,g_date,g_day,g_hour,g_mintue,g_second;
; //uint8_t g_tempeature;
; /******************************************/
; void main(void)
; {
.dbline 54
; uint8_t i;
; ChipInit();
xcall _ChipInit
.dbline 55
; LCD_init();
xcall _LCD_init
.dbline 56
; InitDS1302();
xcall _InitDS1302
.dbline 57
; Write(0,0x07,0x00); //CLOCK操作,控制寄存器,解除写保护
clr R2
std y+0,R2
ldi R18,7
clr R16
xcall _Write
.dbline 58
; Time_Init(&Time[0]); //初始化时间
ldi R16,<_Time
ldi R17,>_Time
xcall _Time_Init
.dbline 59
; LCD_display_init();
xcall _LCD_display_init
xjmp L96
L95:
.dbline 61
; while(1)
; {
.dbline 62
; for(i=0;i<50;i++)
clr R20
xjmp L101
L98:
.dbline 63
; {
.dbline 64
; ReadTime();
xcall _ReadTime
.dbline 65
; DisplayTime();
xcall _DisplayTime
.dbline 66
; if(i == 0)
tst R20
brne L102
X19:
.dbline 67
; {
.dbline 69
; //BEEP_ON();
; DS18B20();
xcall _DS18B20
.dbline 71
; //BEEP_OFF();
; }
L102:
.dbline 72
; Delay_nms(100);
ldi R16,100
ldi R17,0
xcall _Delay_nms
.dbline 73
; }
L99:
.dbline 62
inc R20
L101:
.dbline 62
cpi R20,50
brlo L98
X20:
.dbline 74
; }
L96:
.dbline 60
xjmp L95
X21:
.dbline -2
L94:
.dbline 0 ; func end
adiw R28,1
ret
.dbsym r i 20 c
.dbend
.dbfunc e ChipInit _ChipInit fV
.even
_ChipInit::
.dbline -1
.dbline 78
; }
; /******************************************/
; void ChipInit(void)
; {
.dbline 79
; NOP();
nop
.dbline 81
; /*********************I/O口初始化**************************/
; LCD_DATA_DDR |= LCD_DATA_MASK; //液晶数据口线
in R24,0x17
ori R24,15
out 0x17,R24
.dbline 82
; LCD_CONTROL_DDR |= RS|EN; //
in R24,0x1a
ori R24,12
out 0x1a,R24
.dbline 84
;
; DS1302_DDR |= RST|SCLK|IO;
in R24,0x11
ori R24,56
out 0x11,R24
.dbline 85
; DS1302_PORT = 0X00;
clr R2
out 0x12,R2
.dbline 87
;
; DS18B20_DDR |= DS18B20_IO;
sbi 0x11,7
.dbline -2
L104:
.dbline 0 ; func end
ret
.dbend
.dbfunc e InitDS1302 _InitDS1302 fV
.even
_InitDS1302::
.dbline -1
.dbline 92
; /*********************************************************/
; }
; /******************************************/
; void InitDS1302(void)
; {
.dbline 93
; CLR_RST();
.dbline 93
cbi 0x12,5
.dbline 93
.dbline 93
.dbline 94
; CLR_SCLK();
.dbline 94
cbi 0x12,3
.dbline 94
.dbline 94
.dbline 95
; CLR_IO();
.dbline 95
cbi 0x12,4
.dbline 95
.dbline 95
.dbline -2
L105:
.dbline 0 ; func end
ret
.dbend
.dbfunc e Time_Init _Time_Init fV
; ad -> R10
; i -> R22
; p_time -> R20,R21
.even
_Time_Init::
xcall push_xgsetF00C
movw R20,R16
sbiw R28,1
.dbline -1
.dbline 99
; }
; /****************************************/
; void Time_Init(const uint8_t *p_time)
; {
.dbline 100
; uint8_t i,ad=0;
clr R10
.dbline 101
; for(i=8;i>0;i--)
ldi R22,8
xjmp L110
L107:
.dbline 102
; {
.dbline 103
; Write(0,ad,*p_time);
movw R30,R20
lpm R2,Z
std y+0,R2
mov R18,R10
clr R16
xcall _Write
.dbline 104
; ad++;
inc R10
.dbline 105
; p_time++;
subi R20,255 ; offset = 1
sbci R21,255
.dbline 106
; }
L108:
.dbline 101
dec R22
L110:
.dbline 101
ldi R24,0
cp R24,R22
brlo L107
X22:
.dbline -2
L106:
.dbline 0 ; func end
adiw R28,1
xjmp pop_xgsetF00C
.dbsym r ad 10 c
.dbsym r i 22 c
.dbsym r p_time 20 pkc
.dbend
.dbfunc e LCD_display_init _LCD_display_init fV
.even
_LCD_display_init::
sbiw R28,2
.dbline -1
.dbline 110
; }
; /******************************************/
; void LCD_display_init(void)
; {
.dbline 111
; LCD_write_string(1,1,"20 . .");
ldi R24,<L112
ldi R25,>L112
std y+1,R25
std y+0,R24
ldi R18,1
ldi R16,1
xcall _LCD_write_string
.dbline 112
; LCD_write_string(3,2,": :");
ldi R24,<L113
ldi R25,>L113
std y+1,R25
std y+0,R24
ldi R18,2
ldi R16,3
xcall _LCD_write_string
.dbline 113
; LCD_set_xy(15,2);
ldi R18,2
ldi R16,15
xcall _LCD_set_xy
.dbline 114
; Units();
.dbline 114
ldi R18,223
clr R16
xcall _LCD_write_byte
.dbline 114
ldi R18,67
clr R16
xcall _LCD_write_byte
.dbline 114
.dbline -2
L111:
.dbline 0 ; func end
adiw R28,2
ret
.dbend
.dbfunc e ReadTime _ReadTime fV
; address -> R20
.even
_ReadTime::
xcall push_xgsetF00C
.dbline -1
.dbline 118
; }
; /******************************************/
; void ReadTime(void)
; {
.dbline 120
; uint8_t address;
; address = 0;
clr R20
.dbline 121
; g_second = Read_DS1302(0, address++);
mov R2,R20
subi R20,255 ; addi 1
mov R18,R2
clr R16
xcall _Read_DS1302
sts _g_second,R16
.dbline 122
; g_mintue = Read_DS1302(0, address++);
mov R22,R20
subi R20,255 ; addi 1
mov R18,R22
clr R16
xcall _Read_DS1302
mov R10,R16
sts _g_mintue,R10
.dbline 123
; g_hour = Read_DS1302(0, address++);
mov R22,R20
subi R20,255 ; addi 1
mov R18,R22
clr R16
xcall _Read_DS1302
mov R10,R16
sts _g_hour,R10
.dbline 124
; g_date = Read_DS1302(0, address++);
mov R22,R20
subi R20,255 ; addi 1
mov R18,R22
clr R16
xcall _Read_DS1302
mov R10,R16
sts _g_date,R10
.dbline 125
; g_month = Read_DS1302(0, address++);
mov R22,R20
subi R20,255 ; addi 1
mov R18,R22
clr R16
xcall _Read_DS1302
mov R10,R16
sts _g_month,R10
.dbline 126
; g_day = Read_DS1302(0, address++);
mov R22,R20
subi R20,255 ; addi 1
mov R18,R22
clr R16
xcall _Read_DS1302
mov R10,R16
sts _g_day,R10
.dbline 127
; g_year = Read_DS1302(0, address);
mov R18,R20
clr R16
xcall _Read_DS1302
mov R10,R16
sts _g_year,R10
.dbline -2
L114:
.dbline 0 ; func end
xjmp pop_xgsetF00C
.dbsym r address 20 c
.dbend
.dbfunc e DisplayTime _DisplayTime fV
.even
_DisplayTime::
sbiw R28,2
.dbline -1
.dbline 131
; }
; /******************************************/
; void DisplayTime(void)
; {
.dbline 132
; Display(3,1,g_year);
lds R2,_g_year
std y+0,R2
ldi R18,1
ldi R16,3
xcall _Display
.dbline 133
; Display(6,1,g_month);
lds R2,_g_month
std y+0,R2
ldi R18,1
ldi R16,6
xcall _Display
.dbline 134
; Display(9,1,g_date);
lds R2,_g_date
std y+0,R2
ldi R18,1
ldi R16,9
xcall _Display
.dbline 135
; Display(1,2,g_hour);
lds R2,_g_hour
std y+0,R2
ldi R18,2
ldi R16,1
xcall _Display
.dbline 136
; Display(4,2,g_mintue);
lds R2,_g_mintue
std y+0,R2
ldi R18,2
ldi R16,4
xcall _Display
.dbline 137
; Display(7,2,g_second);
lds R2,_g_second
std y+0,R2
ldi R18,2
ldi R16,7
xcall _Display
.dbline 138
; LCD_write_string(14,1,&Day[(g_day-1)][0]);
ldi R24,<_Day
ldi R25,>_Day
lds R30,_g_day
clr R31
sbiw R30,1
lsl R30
rol R31
lsl R30
rol R31
add R30,R24
adc R31,R25
std y+1,R31
std y+0,R30
ldi R18,1
ldi R16,14
xcall _LCD_write_string
.dbline -2
L115:
.dbline 0 ; func end
adiw R28,2
ret
.dbend
.dbfunc e Display _Display fV
; n -> R12
; m -> R10
; temp_l -> R20
; temp_h -> R22
; g_data -> R14
; y -> R12
; x -> R10
.even
_Display::
xcall push_xgsetF0FC
mov R12,R18
mov R10,R16
ldd R14,y+10
.dbline -1
.dbline 142
; }
; /*******************************************/
; void Display(uint8_t x, uint8_t y, uint8_t g_data)
; {
.dbline 144
; uint8_t temp_h,temp_l,m,n;
; temp_h = temp_l = g_data;
mov R20,R14
mov R22,R14
.dbline 145
; temp_h &= 0xf0;
andi R22,240
.dbline 146
; temp_h >>= 4;
mov R24,R22
swap R24
andi R24,#0x0F
mov R22,R24
.dbline 147
; temp_l &= 0x0f;
andi R20,15
.dbline 148
; m = x;
.dbline 149
; n = y;
.dbline 150
; LCD_set_xy(m,n);
mov R18,R12
mov R16,R10
xcall _LCD_set_xy
.dbline 151
; LCD_write_byte(0,Number[temp_h]);
ldi R24,<_Number
ldi R25,>_Number
mov R30,R22
clr R31
add R30,R24
adc R31,R25
lpm R18,Z
clr R16
xcall _LCD_write_byte
.dbline 152
; LCD_write_byte(0,Number[temp_l]);
ldi R24,<_Number
ldi R25,>_Number
mov R30,R20
clr R31
add R30,R24
adc R31,R25
lpm R18,Z
clr R16
xcall _LCD_write_byte
.dbline -2
L116:
.dbline 0 ; func end
xjmp pop_xgsetF0FC
.dbsym r n 12 c
.dbsym r m 10 c
.dbsym r temp_l 20 c
.dbsym r temp_h 22 c
.dbsym r g_data 14 c
.dbsym r y 12 c
.dbsym r x 10 c
.dbend
.dbfunc e Write _Write fV
; j -> R22
; i -> R10
; temp -> R20
; Dat -> y+6
; Address -> R18
; RAM_CLOCK -> R16
.even
_Write::
xcall push_xgsetF00C
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -