?? ds12997.s
字號:
.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 + -