avr单片机应用开发典型实例CD.rar

源代码在线查看: rtc.s

软件大小: 2482 K
上传用户: xinlanwj1226
关键词: avr CD 单片机
下载地址: 免注册下载 普通下载 VIP

相关代码

					.module RTC.c
					.area data(ram, con, rel)
				_Table::
					.blkb 2
					.area idata
					.byte 63,6
					.area data(ram, con, rel)
					.blkb 2
					.area idata
					.byte 91,'O
					.area data(ram, con, rel)
					.blkb 2
					.area idata
					.byte 'f,'m
					.area data(ram, con, rel)
					.blkb 2
					.area idata
					.byte 125,7
					.area data(ram, con, rel)
					.blkb 2
					.area idata
					.byte 127,'o
					.area data(ram, con, rel)
					.blkb 6
					.area idata
					.byte 0,0,0,0,0,0
					.area data(ram, con, rel)
					.dbfile J:\AVRpractice\BOOK\定时器2\RTC.c
					.dbsym e Table _Table A[16:16]c
				_Data::
					.blkb 2
					.area idata
					.byte 0,0
					.area data(ram, con, rel)
					.dbfile J:\AVRpractice\BOOK\定时器2\RTC.c
					.blkb 2
					.area idata
					.byte 0,0
					.area data(ram, con, rel)
					.dbfile J:\AVRpractice\BOOK\定时器2\RTC.c
					.dbsym e Data _Data A[4:4]c
					.area text(rom, con, rel)
					.dbfile J:\AVRpractice\BOOK\定时器2\RTC.c
					.dbfunc e DelayMs _DelayMs fV
				;              j -> R20,R21
				;              i -> R16,R17
					.even
				_DelayMs::
					rcall push_gset1
					.dbline -1
					.dbline 13
				; //***************FileName:Capature.C***************//
				; //***************ICCAVR V6.30编译*****************//
				; 
				; #include                  
				; #define uchar unsigned char
				; #define uint  unsigned int
				; 
				; //数码管字型表,对应0,1,2,3,4,5,6,7,8,9//
				; uchar Table[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
				; uchar Data[4]={0,0,0,0};       //定义初始时间:00:00            
				; uchar CNT;                     //定义中断计数次数      
				; void DelayMs(uint i)           //Ms级延时,参数i为延时时间
				; {uint j;
					.dbline 14
				;  for(;i!=0;i--)
					rjmp L5
				L2:
					.dbline 15
					.dbline 15
					ldi R20,8000
					ldi R21,31
					rjmp L9
				L6:
					.dbline 15
					.dbline 15
					.dbline 15
				L7:
					.dbline 15
					subi R20,1
					sbci R21,0
				L9:
					.dbline 15
					cpi R20,0
					cpc R20,R21
					brne L6
				X0:
					.dbline 15
				L3:
					.dbline 14
					subi R16,1
					sbci R17,0
				L5:
					.dbline 14
					cpi R16,0
					cpc R16,R17
					brne L2
				X1:
					.dbline -2
					.dbline 16
				;   {for(j=8000;j!=0;j--) {;}}
				; }
				L1:
					rcall pop_gset1
					.dbline 0 ; func end
					ret
					.dbsym r j 20 i
					.dbsym r i 16 i
					.dbend
					.dbfunc e Display _Display fV
				;            sel -> R20
				;              i -> R22
				;              p -> R10,R11
					.even
				_Display::
					rcall push_gset3
					mov R10,R16
					mov R11,R17
					.dbline -1
					.dbline 19
				; 
				; void Display(uchar *p)         //动态显示函数,参数p为待显示的数组名
				; {uchar i,sel=0x01;           
					.dbline 19
					ldi R20,1
					.dbline 20
				;  for(i=0;i					clr R22
					rjmp L14
				L11:
					.dbline 21
					.dbline 21
					out 0x1b,R20
					.dbline 22
					mov R30,R22
					clr R31
					add R30,R10
					adc R31,R11
					ldd R30,z+0
					clr R31
					ldi R24,					ldi R25,>_Table
					add R30,R24
					adc R31,R25
					ldd R2,z+0
					clr R3
					ldi R24,255
					ldi R25,0
					sub R24,R2
					sbc R25,R3
					out 0x15,R24
					.dbline 23
					ldi R16,1
					ldi R17,0
					rcall _DelayMs
					.dbline 24
					lsl R20
					.dbline 25
				L12:
					.dbline 20
					inc R22
				L14:
					.dbline 20
					cpi R22,4
					brlo L11
					.dbline -2
					.dbline 26
				;   {PORTA=sel;                  //选通最右边的数码管
				;    PORTC=0xff-Table[p[i]];     //送字型码
				;    DelayMs(1);                 //显示延时    
				;    sel=sel				;   }
				; }
				L10:
					rcall pop_gset3
					.dbline 0 ; func end
					ret
					.dbsym r sel 20 c
					.dbsym r i 22 c
					.dbsym r p 10 pc
					.dbend
					.dbfunc e Init_IO _Init_IO fV
					.even
				_Init_IO::
					.dbline -1
					.dbline 29
				; 
				; void Init_IO(void)             //初始化I/O口
				; {DDRA=0xff;                    //设置A口为推挽1输出
					.dbline 29
					ldi R24,255
					out 0x1a,R24
					.dbline 30
				;  PORTA=0xff;
					out 0x1b,R24
					.dbline 31
				;  DDRC=0xff;                    //设置C口为推挽1输出             
					out 0x14,R24
					.dbline 32
				;  PORTC=0xff;
					out 0x15,R24
					.dbline -2
					.dbline 33
				; }
				L15:
					.dbline 0 ; func end
					ret
					.dbend
					.dbfunc e Add_Second _Add_Second fV
				;              p -> R16,R17
					.even
				_Add_Second::
					.dbline -1
					.dbline 36
				; 
				; void Add_Second(uchar *p)
				; {p[3]++;
					.dbline 36
					mov R24,R16
					mov R25,R17
					adiw R24,3
					mov R30,R24
					mov R31,R25
					ldd R24,z+0
					subi R24,255    ; addi 1
					std z+0,R24
					.dbline 37
				;  if(p[3]==10) {p[3]=0;p[2]++;}
					mov R30,R16
					mov R31,R17
					ldd R24,z+3
					cpi R24,10
					brne L17
					.dbline 37
					.dbline 37
					clr R2
					mov R30,R16
					mov R31,R17
					std z+3,R2
					.dbline 37
					mov R24,R16
					mov R25,R17
					adiw R24,2
					mov R30,R24
					mov R31,R25
					ldd R24,z+0
					subi R24,255    ; addi 1
					std z+0,R24
					.dbline 37
				L17:
					.dbline 38
				;  if(p[2]==6)  {p[2]=0;p[1]++;}
					mov R30,R16
					mov R31,R17
					ldd R24,z+2
					cpi R24,6
					brne L19
					.dbline 38
					.dbline 38
					clr R2
					mov R30,R16
					mov R31,R17
					std z+2,R2
					.dbline 38
					mov R24,R16
					mov R25,R17
					adiw R24,1
					mov R30,R24
					mov R31,R25
					ldd R24,z+0
					subi R24,255    ; addi 1
					std z+0,R24
					.dbline 38
				L19:
					.dbline 39
				;  if(p[1]==10) {p[1]=0;p[0]++;}
					mov R30,R16
					mov R31,R17
					ldd R24,z+1
					cpi R24,10
					brne L21
					.dbline 39
					.dbline 39
					clr R2
					mov R30,R16
					mov R31,R17
					std z+1,R2
					.dbline 39
					mov R30,R16
					mov R31,R17
					ldd R24,z+0
					subi R24,255    ; addi 1
					std z+0,R24
					.dbline 39
				L21:
					.dbline 40
					mov R30,R16
					mov R31,R17
					ldd R24,z+0
					cpi R24,6
					brne L23
					.dbline 40
					.dbline 40
					clr R2
					std z+0,R2
					.dbline 40
				L23:
					.dbline -2
					.dbline 41
				;  if(p[0]==6)  {p[0]=0;}
				; }
				L16:
					.dbline 0 ; func end
					ret
					.dbsym r p 16 pc
					.dbend
					.dbfunc e main _main fV
				;              i -> 
					.even
				_main::
					.dbline -1
					.dbline 44
				; 
				; void main(void)
				; {uchar i;
					.dbline 45
				;  Init_IO();                    //初始化I/O口
					rcall _Init_IO
					.dbline 46
				;  PORTA=0xff;                   //点亮以测试所有的数码管
					ldi R24,255
					out 0x1b,R24
					.dbline 47
				;  PORTC=0x00;   
					clr R2
					out 0x15,R2
					.dbline 48
				;  DelayMs(300);                 //延时
					ldi R16,300
					ldi R17,1
					rcall _DelayMs
					.dbline 49
				;  PORTC=0xff;                   //熄灭所有的数码管
					ldi R24,255
					out 0x15,R24
					.dbline 50
				;  ASSR=0x08;                    //异步时钟使能
					ldi R24,8
					out 0x22,R24
					.dbline 51
				;  TCCR2=0x07;                   //32768的晶振1024分频作为T/C2的时钟源
					ldi R24,7
					out 0x25,R24
					.dbline 52
				;  TIMSK=0x40;                   //T/C2溢出中断使能
					ldi R24,64
					out 0x39,R24
					.dbline 53
				;  SREG=SREG|0x80;               //全局中断使能       
					bset 7
					rjmp L27
				L26:
					.dbline 55
				;  while(1)
				;  {Display(Data);
					.dbline 55
					ldi R16,					ldi R17,>_Data
					rcall _Display
					.dbline 56
				;   if(CNT==32) 
					lds R24,_CNT
					cpi R24,32
					brne L29
					.dbline 57
				;     {CNT=0;
					.dbline 57
					clr R2
					sts _CNT,R2
					.dbline 58
				; 	 Add_Second(Data);}
					ldi R16,					ldi R17,>_Data
					rcall _Add_Second
					.dbline 58
				L29:
					.dbline 59
				L27:
					.dbline 54
					rjmp L26
				X2:
					.dbline -2
					.dbline 60
				;  }
				; }
				L25:
					.dbline 0 ; func end
					ret
					.dbsym l i 1 c
					.dbend
					.area vector(rom, abs)
					.org 8
					rjmp _Timer2
					.area text(rom, con, rel)
					.dbfile J:\AVRpractice\BOOK\定时器2\RTC.c
					.dbfunc e Timer2 _Timer2 fV
					.even
				_Timer2::
					st -y,R24
					st -y,R25
					in R24,0x3f
					st -y,R24
					.dbline -1
					.dbline 64
				; 
				; #pragma interrupt_handler Timer2:5
				; void Timer2(void)
				; {CNT=CNT+1;}
					.dbline 64
					lds R24,_CNT
					subi R24,255    ; addi 1
					sts _CNT,R24
					.dbline -2
					.dbline 64
				L31:
					ld R24,y+
					out 0x3f,R24
					ld R25,y+
					ld R24,y+
					.dbline 0 ; func end
					reti
					.dbend
					.area bss(ram, con, rel)
					.dbfile J:\AVRpractice\BOOK\定时器2\RTC.c
				_CNT::
					.blkb 1
					.dbsym e CNT _CNT c
							

相关资源