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

📄 ds12997.s

📁 本程序经调试好使
💻 S
📖 第 1 页 / 共 2 页
字号:
	.module ds12997.c
	.area data(ram, con, rel)
_y::
	.blkb 2
	.area idata
	.byte 0,0
	.area data(ram, con, rel)
	.blkb 2
	.area idata
	.byte 46,0
	.area data(ram, con, rel)
	.blkb 2
	.area idata
	.byte 0,46
	.area data(ram, con, rel)
	.blkb 2
	.area idata
	.byte 0,0
	.area data(ram, con, rel)
	.blkb 2
	.area idata
	.byte 32,0
	.area data(ram, con, rel)
	.blkb 2
	.area idata
	.byte 0,58
	.area data(ram, con, rel)
	.blkb 2
	.area idata
	.byte 0,0
	.area data(ram, con, rel)
	.blkb 2
	.area idata
	.byte 58,0
	.area data(ram, con, rel)
	.blkb 2
	.area idata
	.byte 0,32
	.area data(ram, con, rel)
	.blkb 1
	.area idata
	.byte 32
	.area data(ram, con, rel)
	.dbfile C:\DOCUME~1\wangqinbo\MYDOCU~1\avrc\ds12997.c
	.dbsym e y _y A[19:19]c
	.area text(rom, con, rel)
	.dbfile C:\DOCUME~1\wangqinbo\MYDOCU~1\avrc\ds12997.c
	.dbfunc e usart_init _usart_init fV
	.even
_usart_init::
	.dbline -1
	.dbline 114
; /******************************************************/
; //Title:ATMAGE16 & DS12887加上串口通信显示时钟程序-查询方式
; //ICC-AVR : 2009-3-4 17:04:40
; // Target : M16
; // Crystal: 1.0000Mhz ~8.0000Mhz都好使
; //Author  :borlittle
; //Function:usart+DS12887 RTC test
; //备注	  :本程序经调试好使,如果程序不好使,请注意检查硬件连线,内部时钟
; //记得要校验准,串口才能发送正确,
; // AVR 执行时间:8MHZ ->0.125us  4MHZ->0.25us  //有串口,模拟总线最简版
; //               2MHZ->0.5us      *1MHZ->1us ,每句后延时2句
; // at89s52  执行时间:11.0592MHZ->2.17us 
; //
; //
; /****************************************************/
; 
; #include <iom16v.h>        
; #include <macros.h>
; 
; #define uchar unsigned char		//定义无符号字符为 uchar
; #define uint  unsigned int       //定义无符号整型
; #define Crystal 8000000   //晶振8MHZ 
; #define Baud 9600         //波特率
; 
; uchar y1,y2,y3,y4,y5,y6; //用于调试用,在JTAG仿真器与AVR Studio 中查看是否读取正确
; uchar y[19]={0,0,'.',0,0,'.',0,0,' ',0,0,':',0,0,':',0,0,' ',' '}; //09.3.4 17:06:50
; //上位机接收到得时间数据格式
; /**********************接口定义*********************************/
; //GND <--   MOT		   VCC  -->VCC
; //			.		   SQW
; //			.		   .
; //PA_0<-- 	AD0	       .     
; //PA_1<-- 	AD1		   .
; //PA_2<-- 	AD2        IRQ   -->PB_0
; //PA_3<-- 	AD3        REET	 -->VCC
; //PA_4<-- 	AD4		   DS	 -->PB_1
; //PA_5<-- 	AD5		   .
; //PA_6<-- 	AD6		   R/W	 -->PB_2
; //PA_7<-- 	AD7		   AS	 -->PB_3
; //		    GND		   CS    -->GND--可以用端口控制以省电降功耗 
; /*********************引脚说明***********************************/
; //DS12887       16    器件
; //数据线       PA口    数据地址公用总线
; //DS_IRQ        PB0    时间中断     
; //DS_DS         PB1    数据选通
; //DS_RW    		PB2	   读写控制
; //DS_AS			PB3	   地址选通
; //DS_CS         PB4	   芯片片选
; //DS_MOT        GND    模式选择
; 
; /*******************数据地址定义*************************************/
; #define	DS12887_Second		0x00	//秒
; #define	DS12887_Minute		0x02	//分
; #define	DS12887_Hour		0x04	//时
; #define	DS12887_Week		0x06	//星期
; #define	DS12887_Day		    0x07	//日
; #define	DS12887_Month		0x08	//月
; #define	DS12887_Year		0x09	//年
; 
; //引脚电平定义
; #define P_DS_1 PORTB|=BIT(PB1)	  	//DS_DS为1
; #define P_DS_0 PORTB&=~BIT(PB1)		//DS_DS为0
; #define D_DS_1 DDRB |=BIT(PB1)      //设为输出
; 
; #define P_RW_1  PORTB|=BIT(PB2)	    //DS_RW为1
; #define P_RW_0  PORTB&=~BIT(PB2)	//DS_RW为0
; #define D_RW_1   DDRB |=BIT(PB2)    //设为输出
; 
; #define P_AS_1 PORTB|=BIT(PB3)		//DS_AS为1
; #define P_AS_0 PORTB&=~BIT(PB3)    	//DS_AS为0
; #define D_AS_1  DDRB |=BIT(PB3)     //设为输出
; 
; #define P_CS_1 PORTB|=BIT(PB4)     //DS_CS为1
; #define P_CS_0 PORTB&=~BIT(PB4)	   //DS_CS为0				
; #define D_CS_1  DDRB |=BIT(PB4)     //设为输出
; 
;  			
; //数据端口定义
; #define AD_DDR DDRA 			//AD(地址/数据服用线)的输入/输出控制
; #define AD_PORT PORTA			//AD(地址/数据服用线)的输出电平控制
; #define AD_PIN PINA			//AD(地址/数据服用线)的输入电平控制
; 
; //定义时间类型,结构体数据类型
; typedef struct _SYSTEMTIME_
; {
; 	unsigned  char Second;
; 	unsigned  char Minute;
; 	unsigned  char Hour;
; 	unsigned  char Week;
; 	unsigned  char Day;
; 	unsigned  char Month;
; 	unsigned  char Year;
; 	unsigned  char DateString[9];
; 	unsigned  char TimeString[9];
; }SYSTEMTIME;			
; 
; /***********************函数声明*****************************/
; void DS12887_Init(void);											//DS12887初始化
; void DS12887_Write( uchar Address,  uchar Value);		//DS12887指定地址写入数据
; uchar DS12887_Read(uchar Address);					//DS12887指定地址中读出数据	
; void DS12887_SetTime( uchar Address,  uchar Value);	//设置时间函数
; void DS12887_GetTime(SYSTEMTIME *Time);								//读出时间
; void delay_8nus(uchar n);
; void port_init(void);
; void usart0_init(void);
; void init_devices(void);
; 
; void usart_char_send(uchar i);
; void usart_str_send(char *s);
; uchar usart_char_receive(void);
; 
; /*****************串口初始化*********************************/
; void usart_init(void) 
; {
	.dbline 115
;  UCSRB = 0x00;                     //禁止发送和接收
	clr R2
	out 0xa,R2
	.dbline 116
;  UCSRA = 0x02;                     //倍速异步模式USX=1
	ldi R24,2
	out 0xb,R24
	.dbline 117
;  UCSRC = 0x06;                     //0000 0110,UCSZ1=1,UCSZ0=1;8位字符,1位停止位 
	ldi R24,6
	out 0x20,R24
	.dbline 118
;  UBRRL=(Crystal/8/(Baud+1))%256;   //若为正常异步模式USX0=0则位(Crystal/16/(Baud+1))%256
	ldi R24,104
	out 0x9,R24
	.dbline 119
;  UBRRH=(Crystal/8/(Baud+1))/256;   //参见ATMAGE16使用手册
	out 0x20,R2
	.dbline 120
;  UCSRB = 0x18;                     //允许发送和接收
	ldi R24,24
	out 0xa,R24
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e port_init _port_init fV
	.even
_port_init::
	.dbline -1
	.dbline 124
; }
; /******************端口初始化*******************************/
; void port_init(void) 
; {
	.dbline 125
;   DDRB  = 0xFF; 
	ldi R24,255
	out 0x17,R24
	.dbline 126
;  PORTB = 0xFF; //设为输出高电平
	out 0x18,R24
	.dbline 128
;  
;  DDRA  = 0x00; 
	clr R2
	out 0x1a,R2
	.dbline 129
;  PORTA = 0x00; //设为高阻态
	out 0x1b,R2
	.dbline 131
;   
;  PORTD = 0xFF;   //设置RXD0和TXD0
	out 0x12,R24
	.dbline 132
;  DDRD  = 0x02;
	ldi R24,2
	out 0x11,R24
	.dbline -2
L2:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e usart_char_send _usart_char_send fV
;              i -> R16
	.even
_usart_char_send::
	.dbline -1
	.dbline 138
; 
; }
; 
; //****************发送一个字符******************************
; void usart_char_send(uchar i)
; {
L4:
	.dbline 139
L5:
	.dbline 139
; while(!(UCSRA&(1<<UDRE)));
	sbis 0xb,5
	rjmp L4
	.dbline 140
; UDR=i;
	out 0xc,R16
	.dbline -2
L3:
	.dbline 0 ; func end
	ret
	.dbsym r i 16 c
	.dbend
	.dbfunc e usart_str_send _usart_str_send fV
;              s -> R20,R21
	.even
_usart_str_send::
	xcall push_gset1
	movw R20,R16
	.dbline -1
	.dbline 144
; }
; /******************发送一个字符串*************************/
; void usart_str_send(char *s) 
; {
	xjmp L9
L8:
	.dbline 146
	.dbline 147
	movw R30,R20
	ldd R16,z+0
	xcall _usart_char_send
	.dbline 148
	subi R20,255  ; offset = 1
	sbci R21,255
	.dbline 149
L9:
	.dbline 145
;  while(*s)
	movw R30,R20
	ldd R2,z+0
	tst R2
	brne L8
	.dbline -2
L7:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r s 20 pc
	.dbend
	.dbfunc e usart_send_arry _usart_send_arry fV
;              i -> R20
	.even
_usart_send_arry::
	xcall push_gset1
	.dbline -1
	.dbline 153
;  {
;  usart_char_send(*s); 
;  s++;
;  }
; }
; /*****************发送数组数据**************************************/
; void usart_send_arry(void)
; {
	.dbline 155
; uchar i;
; for(i=0;i<19;i++)
	clr R20
	xjmp L15
L12:
	.dbline 156
	ldi R24,<_y
	ldi R25,>_y
	mov R30,R20
	clr R31
	add R30,R24
	adc R31,R25
	ldd R16,z+0
	xcall _usart_char_send
L13:
	.dbline 155
	inc R20
L15:
	.dbline 155
	cpi R20,19
	brlo L12
	.dbline -2
L11:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r i 20 c
	.dbend
	.dbfunc e usart_char_receive _usart_char_receive fc
	.even
_usart_char_receive::
	.dbline -1
	.dbline 160
; usart_char_send(y[i]);
; }
; /*****************接收一个字符****************************/
; uchar usart_char_receive(void) 
; {
L17:
	.dbline 161
L18:
	.dbline 161
; while(!(UCSRA&(1<<RXC)));
	sbis 0xb,7
	rjmp L17
	.dbline 162
; return UDR;
	in R16,0xc
	.dbline -2
L16:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e delay5ms _delay5ms fV
;              i -> R16
;              j -> R18
	.even
_delay5ms::
	.dbline -1
	.dbline 168
; }
; 
; 
; /*********************延时5000+0us 函数定义**********/
; void delay5ms(void)
; {
	.dbline 170
;     uchar i,j;
;     for(i=185;i>0;i--)
	ldi R16,185
	xjmp L24
L21:
	.dbline 171
	ldi R18,12
	xjmp L28
L25:
	.dbline 171
L26:
	.dbline 171
	dec R18
L28:
	.dbline 171
	clr R2
	cp R2,R18
	brlo L25
L22:
	.dbline 170
	dec R16
L24:
	.dbline 170
	clr R2
	cp R2,R16
	brlo L21
	.dbline -2
L20:
	.dbline 0 ; func end
	ret
	.dbsym r i 16 c
	.dbsym r j 18 c
	.dbend
	.dbfunc e delay_1ms _delay_1ms fV
;              i -> R16,R17
	.even
_delay_1ms::
	.dbline -1
	.dbline 175
;     for(j=12;j>0;j--);
; }
; /*****************延时1秒子函数*******************/
; void delay_1ms(void)
; {
	.dbline 177
;  uint i;
; for(i=1;i<(8*143-2);i++) //8为晶振频率
	ldi R16,1
	ldi R17,0
	xjmp L33
L30:
	.dbline 178
L31:
	.dbline 177
	subi R16,255  ; offset = 1
	sbci R17,255
L33:
	.dbline 177
	cpi R16,118
	ldi R30,4
	cpc R17,R30
	brlo L30
	.dbline -2
L29:
	.dbline 0 ; func end
	ret
	.dbsym r i 16 i
	.dbend
	.dbfunc e delay_nms _delay_nms fV
;              i -> R20,R21
;              n -> R22,R23
	.even
_delay_nms::
	xcall push_gset2
	movw R22,R16
	.dbline -1
	.dbline 182
; ;
; }
; /****************延时N毫秒子函数****************/
; void delay_nms(uint n)
; {
	.dbline 184
; uint i;
; for(i=0;i<n;i++)
	clr R20
	clr R21
	xjmp L38
L35:
	.dbline 185
	xcall _delay_1ms
L36:
	.dbline 184
	subi R20,255  ; offset = 1
	sbci R21,255
L38:
	.dbline 184
	cp R20,R22
	cpc R21,R23
	brlo L35
	.dbline -2
L34:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r i 20 i
	.dbsym r n 22 i
	.dbend
	.dbfunc e delay_8nus _delay_8nus fV
;              i -> R22,R23
;              k -> R20,R21
;              n -> R16
	.even
_delay_8nus::
	xcall push_gset2
	.dbline -1
	.dbline 189
; delay_1ms();
; }
; /****************精确延时微妙级,8MHZ,0.25us/step***********/
; void delay_8nus(uchar n)
; {
	.dbline 191
;   uint i,k;
;   i=n;
	mov R22,R16
	clr R23
	.dbline 192
;   for(k=i;k>0;k--)
	movw R20,R22
	xjmp L43
L40:
	.dbline 193
	.dbline 194
	nop
	.dbline 195
L41:
	.dbline 192
	subi R20,1
	sbci R21,0
L43:
	.dbline 192
	cpi R20,0
	cpc R20,R21
	brne L40
X0:
	.dbline -2
L39:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r i 22 i
	.dbsym r k 20 i
	.dbsym r n 16 c
	.dbend
	.dbfunc e DS12887_Write _DS12887_Write fV
;          Value -> R18
;        Address -> R16
	.even
_DS12887_Write::
	.dbline -1
	.dbline 199
;   {
;    _NOP();
;     }
; }
; /*******DS12887指定地址写入数据 ,严格按照INTERL的时序,程序**********/
; void DS12887_Write( uchar Address, uchar Value)
; {
	.dbline 201
; 	
; 	P_AS_0; 
	cbi 0x18,3
	.dbline 202
;     _NOP(); 
	nop
	.dbline 203
;     _NOP();     
	nop
	.dbline 204
;     P_DS_1; 
	sbi 0x18,1
	.dbline 205
; 	_NOP(); 
	nop
	.dbline 206
;     _NOP();
	nop
	.dbline 207
;     P_RW_1;            //给出读信号 
	sbi 0x18,2
	.dbline 208
;     _NOP(); 
	nop
	.dbline 209
;     _NOP();    
	nop
	.dbline 210
;     P_AS_1;            //锁存信号高电平 
	sbi 0x18,3
	.dbline 211
;     _NOP(); 
	nop
	.dbline 212
;     _NOP(); 
	nop
	.dbline 213
;     AD_DDR = 0xFF;          //数据口设置为输出 
	ldi R24,255
	out 0x1a,R24
	.dbline 214
;     _NOP(); 
	nop
	.dbline 215
;     _NOP();
	nop
	.dbline 216
; 	_NOP();
	nop
	.dbline 217
; 	_NOP(); 
	nop
	.dbline 218
;     AD_PORT = Address;       //给出地址 
	out 0x1b,R16
	.dbline 219
;     _NOP(); 
	nop
	.dbline 220
;     _NOP();  
	nop
	.dbline 221
; 	_NOP(); 
	nop
	.dbline 222
;     _NOP();
	nop
	.dbline 223
; 	_NOP();
	nop
	.dbline 224
; 	_NOP();                     // 
	nop
	.dbline 225
;     P_AS_0;            //锁存信号低电平 
	cbi 0x18,3
	.dbline 226
;     _NOP(); 
	nop
	.dbline 227
;     _NOP();  
	nop
	.dbline 228
;     P_RW_0;            //给出写信号 
	cbi 0x18,2
	.dbline 229
;     _NOP(); 
	nop
	.dbline 230
;     _NOP(); 
	nop
	.dbline 231
;     _NOP(); 
	nop
	.dbline 232
;     AD_PORT = Value;  //写出数据 
	out 0x1b,R18
	.dbline 233
;     _NOP(); 
	nop
	.dbline 234
;     _NOP(); 
	nop
	.dbline 235
;     _NOP(); 
	nop
	.dbline 236
;     _NOP();
	nop
	.dbline 237
; 	_NOP();
	nop
	.dbline 238
; 	_NOP();
	nop
	.dbline 239
; 	_NOP();
	nop
	.dbline 240
; 	_NOP(); 
	nop
	.dbline 241
;     P_RW_1;            //给出读信号 
	sbi 0x18,2
	.dbline 242
;     _NOP(); 
	nop
	.dbline 243
;     _NOP(); 
	nop
	.dbline 244
;     _NOP(); 
	nop
	.dbline 245
;     P_AS_1;            //片选信号高电平 
	sbi 0x18,3
	.dbline 246
;     _NOP(); 
	nop
	.dbline 247
;     _NOP();  
	nop
	.dbline -2
L44:
	.dbline 0 ; func end
	ret
	.dbsym r Value 18 c
	.dbsym r Address 16 c
	.dbend
	.dbfunc e DS12887_Read _DS12887_Read fc
;           temp -> R20
;        Address -> R16
	.even
_DS12887_Read::
	xcall push_gset1
	.dbline -1
	.dbline 251
; }
; /*********DS12887指定地址中读出数据,严格按照INTERL的时序!!!!!********/
; uchar DS12887_Read( uchar Address)
; {   
	.dbline 252
; 	 unsigned char temp = 0;     
	clr R20
	.dbline 253
;     P_AS_0;            //锁存信号高电平 
	cbi 0x18,3
	.dbline 254
;     _NOP(); 
	nop
	.dbline 255
;     _NOP(); 
	nop
	.dbline 256
; 	P_DS_1; 
	sbi 0x18,1
	.dbline 257
; 	_NOP(); 
	nop
	.dbline 258
;     _NOP();
	nop
	.dbline 259
;     P_RW_1;            //给出读信号    
	sbi 0x18,2
	.dbline 260
;     _NOP(); 
	nop
	.dbline 261
;     _NOP(); 
	nop
	.dbline 262
;     P_AS_1;            //锁存信号高电平 
	sbi 0x18,3
	.dbline 263
;     _NOP(); 

⌨️ 快捷键说明

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