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

📄 timer1leddisplay.s

📁 51单片机时钟程序
💻 S
字号:
	.module timer1leddisplay.c
	.area text(rom, con, rel)
	.dbfile F:\avr单片机学习\我自编程序\定时器数码管显示\timer1leddisplay.c
	.area lit(rom, con, rel)
_led_tab::
	.word 63
	.word 6
	.word 91
	.word 79
	.word 102
	.word 109
	.word 125
	.word 7
	.word 127
	.word 111
	.dbsym e led_tab _led_tab A[20:10]kI
	.area text(rom, con, rel)
	.dbfile F:\avr单片机学习\我自编程序\定时器数码管显示\timer1leddisplay.c
	.dbfunc e port_init _port_init fV
	.even
_port_init::
	.dbline -1
	.dbline 33
; //ICC-AVR application builder : 2007-8-1 21:29:13
; // Target : M16
; // Crystal: 4.0000Mhz
; 
; #include <iom16v.h>
; #include <macros.h>
; 
; #define key_hour    PD0     
; #define key_min     PD1     
; #define key_sec     PD2   
; #define key_clr     PD3
; /*共阴数码管七段码*/
; const led_tab[10]={    
;         0x3F,/*0*/
;         0x06,/*1*/
;         0x5B,/*2*/
;         0x4F,/*3*/
;         0x66,/*4*/
;         0x6D,/*5*/
;         0x7D,/*6*/
;         0x07,/*7*/
;         0x7F,/*8*/
;         0x6F,/*9*/
; 		};
; unsigned char second,minute,hour;	
; unsigned char time_group[6];
; 
; void delay_ms(unsigned char);
; void display(void);
; void set_detect(void);
; 
; void port_init(void)
; {
	.dbline 34
;  PORTA = 0x00;
	clr R2
	out 0x1b,R2
	.dbline 35
;  DDRA  = 0xFF;
	ldi R24,255
	out 0x1a,R24
	.dbline 36
;  PORTB = 0x00;
	out 0x18,R2
	.dbline 37
;  DDRB  = 0xFF;
	out 0x17,R24
	.dbline 38
;  PORTC = 0x00; //m103 output only
	out 0x15,R2
	.dbline 39
;  DDRC  = 0x00;
	out 0x14,R2
	.dbline 40
;  PORTD = 0xff;
	out 0x12,R24
	.dbline 41
;  DDRD  = 0x00;
	out 0x11,R2
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e timer1_init _timer1_init fV
	.even
_timer1_init::
	.dbline -1
	.dbline 49
; }
; 
; //TIMER1 initialize - prescale:64
; // WGM: 0) Normal, TOP=0xFFFF
; // desired value: 1Hz
; // actual value:  1.000Hz (0.0%)
; void timer1_init(void)
; {
	.dbline 50
;  TCCR1B = 0x00; //stop
	clr R2
	out 0x2e,R2
	.dbline 51
;  TCNT1H = 0x0B; //setup
	ldi R24,11
	out 0x2d,R24
	.dbline 52
;  TCNT1L = 0xDC;
	ldi R24,220
	out 0x2c,R24
	.dbline 54
; 
;  TCCR1A = 0x00;
	out 0x2f,R2
	.dbline 55
;  TCCR1B = 0x03; //start Timer
	ldi R24,3
	out 0x2e,R24
	.dbline -2
L2:
	.dbline 0 ; func end
	ret
	.dbend
	.area vector(rom, abs)
	.org 32
	jmp _timer1_ovf_isr
	.area text(rom, con, rel)
	.dbfile F:\avr单片机学习\我自编程序\定时器数码管显示\timer1leddisplay.c
	.dbfunc e timer1_ovf_isr _timer1_ovf_isr fV
	.even
_timer1_ovf_isr::
	st -y,R2
	st -y,R24
	st -y,R25
	in R2,0x3f
	st -y,R2
	.dbline -1
	.dbline 60
; }
; 
; #pragma interrupt_handler timer1_ovf_isr:iv_TIM1_OVF
; void timer1_ovf_isr(void)
; {
	.dbline 62
;  //TIMER1 has overflowed
;  TCNT1H = 0x0B; //reload counter high value
	ldi R24,11
	out 0x2d,R24
	.dbline 63
;  TCNT1L = 0xDC; //reload counter low value
	ldi R24,220
	out 0x2c,R24
	.dbline 64
;  second++;
	lds R24,_second
	subi R24,255    ; addi 1
	sts _second,R24
	.dbline 65
;  if(second==60)
	cpi R24,60
	brne L4
X0:
	.dbline 66
;  {
	.dbline 67
;   second=0x00;
	clr R2
	sts _second,R2
	.dbline 68
;   minute++;
	lds R24,_minute
	subi R24,255    ; addi 1
	sts _minute,R24
	.dbline 69
;   if(minute==60)
	cpi R24,60
	brne L6
X1:
	.dbline 70
;   {
	.dbline 71
;    minute=0x00;
	sts _minute,R2
	.dbline 72
;    hour++;
	lds R24,_hour
	subi R24,255    ; addi 1
	sts _hour,R24
	.dbline 73
;    if(hour=24)
	ldi R24,24
	sts _hour,R24
	tst R24
	breq L8
X2:
	.dbline 74
;    {
	.dbline 75
;    hour=0x00;
	sts _hour,R2
	.dbline 76
;    }
L8:
	.dbline 77
;   }
L6:
	.dbline 78
;  }
L4:
	.dbline -2
L3:
	.dbline 0 ; func end
	ld R2,y+
	out 0x3f,R2
	ld R25,y+
	ld R24,y+
	ld R2,y+
	reti
	.dbend
	.dbfunc e data_split _data_split fV
	.even
_data_split::
	.dbline -1
	.dbline 83
; }
; 
; /*数据拆分程序*/
; void data_split(void)  
; {
	.dbline 84
;  time_group[0]=second%10;
	ldi R17,10
	lds R16,_second
	xcall mod8u
	sts _time_group,R16
	.dbline 85
;  time_group[1]=second/10;
	ldi R17,10
	lds R16,_second
	xcall div8u
	sts _time_group+1,R16
	.dbline 86
;  time_group[2]=minute%10;
	ldi R17,10
	lds R16,_minute
	xcall mod8u
	sts _time_group+2,R16
	.dbline 87
;  time_group[3]=minute/10;
	ldi R17,10
	lds R16,_minute
	xcall div8u
	sts _time_group+3,R16
	.dbline 88
;  time_group[4]=hour%10;
	ldi R17,10
	lds R16,_hour
	xcall mod8u
	sts _time_group+4,R16
	.dbline 89
;  time_group[5]=hour/10;
	ldi R17,10
	lds R16,_hour
	xcall div8u
	sts _time_group+5,R16
	.dbline -2
L10:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e set_detect _set_detect fV
	.even
_set_detect::
	.dbline -1
	.dbline 94
; }
; 
; /*时间设置检测*/
; void set_detect(void)   
; {
	.dbline 95
;   if(!(PIND&(1<<key_clr))) //清零键检测
	sbic 0x10,3
	rjmp L17
X3:
	.dbline 96
;   {
	.dbline 97
;    delay_ms(10);
	ldi R16,10
	xcall _delay_ms
	.dbline 98
;    if(!(PIND&(1<<key_clr)))
	sbic 0x10,3
	rjmp L19
X4:
	.dbline 99
;    {
	.dbline 100
;     hour=0x00;
	clr R2
	sts _hour,R2
	.dbline 101
; 	minute=0x00;
	sts _minute,R2
	.dbline 102
; 	second=0x00;
	sts _second,R2
	.dbline 103
;    }
L19:
	.dbline 104
;   }
L17:
	.dbline 107
;   
; 
;   if(!(PIND&(1<<key_hour)))  //小时调整键检测
	sbic 0x10,0
	rjmp L21
X5:
	.dbline 108
;   {
	.dbline 109
;    delay_ms(10);
	ldi R16,10
	xcall _delay_ms
	.dbline 110
;    if(!(PIND&(1<<key_hour)))
	sbic 0x10,0
	rjmp L23
X6:
	.dbline 111
;    {
	xjmp L26
L25:
	.dbline 113
;     while(!(PIND&(1<<key_hour)))
; 	{
	.dbline 114
; 	 display();
	xcall _display
	.dbline 115
; 	}
L26:
	.dbline 112
	sbis 0x10,0
	rjmp L25
X7:
	.dbline 116
; 	hour++;
	lds R24,_hour
	subi R24,255    ; addi 1
	sts _hour,R24
	.dbline 117
; 	if(hour==24)
	cpi R24,24
	brne L28
X8:
	.dbline 118
; 	{
	.dbline 119
; 	 hour=0;
	clr R2
	sts _hour,R2
	.dbline 120
; 	}
L28:
	.dbline 121
;    }
L23:
	.dbline 122
;   }
L21:
	.dbline 124
;   
;   if(!(PIND&(1<<key_min)))//分钟调整键检测
	sbic 0x10,1
	rjmp L30
X9:
	.dbline 125
;   {
	.dbline 126
;    delay_ms(10);
	ldi R16,10
	xcall _delay_ms
	.dbline 127
;    if(!(PIND&(1<<key_min)))
	sbic 0x10,1
	rjmp L32
X10:
	.dbline 128
;    {
	xjmp L35
L34:
	.dbline 130
;     while(!(PIND&(1<<key_min)))
; 	{
	.dbline 131
; 	 display();
	xcall _display
	.dbline 132
; 	}
L35:
	.dbline 129
	sbis 0x10,1
	rjmp L34
X11:
	.dbline 133
; 	minute++;
	lds R24,_minute
	subi R24,255    ; addi 1
	sts _minute,R24
	.dbline 134
; 	if(minute==60)
	cpi R24,60
	brne L37
X12:
	.dbline 135
; 	{
	.dbline 136
; 	 minute=0;
	clr R2
	sts _minute,R2
	.dbline 137
; 	}
L37:
	.dbline 138
;    }
L32:
	.dbline 139
;   }
L30:
	.dbline 140
;    if(!(PIND&(1<<key_sec)))//秒调整键检测
	sbic 0x10,2
	rjmp L39
X13:
	.dbline 141
;   {
	.dbline 142
;    delay_ms(10);
	ldi R16,10
	xcall _delay_ms
	.dbline 143
;    if(!(PIND&(1<<key_sec)))
	sbic 0x10,2
	rjmp L41
X14:
	.dbline 144
;    {
	xjmp L44
L43:
	.dbline 146
;     while(!(PIND&(1<<key_sec)))
; 	{
	.dbline 147
; 	 display();
	xcall _display
	.dbline 148
; 	}
L44:
	.dbline 145
	sbis 0x10,2
	rjmp L43
X15:
	.dbline 149
; 	second++;
	lds R24,_second
	subi R24,255    ; addi 1
	sts _second,R24
	.dbline 150
; 	if(second==60)
	cpi R24,60
	brne L46
X16:
	.dbline 151
; 	{
	.dbline 152
; 	 second=0;
	clr R2
	sts _second,R2
	.dbline 153
; 	}
L46:
	.dbline 154
;    }
L41:
	.dbline 155
;   }
L39:
	.dbline -2
L16:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e init_devices _init_devices fV
	.even
_init_devices::
	.dbline -1
	.dbline 160
; }
; 
; //call this routine to initialize all peripherals
; void init_devices(void)
; {
	.dbline 162
;  //stop errant interrupts until set up
;  CLI(); //disable all interrupts
	cli
	.dbline 163
;  port_init();
	xcall _port_init
	.dbline 164
;  timer1_init();
	xcall _timer1_init
	.dbline 165
;  hour=0x00;
	clr R2
	sts _hour,R2
	.dbline 166
;  minute=0x00;
	sts _minute,R2
	.dbline 167
;  second=0x00;
	sts _second,R2
	.dbline 168
;  MCUCR = 0x00;
	out 0x35,R2
	.dbline 169
;  GICR  = 0x00;
	out 0x3b,R2
	.dbline 170
;  TIMSK = 0x04; //timer interrupt sources
	ldi R24,4
	out 0x39,R24
	.dbline 171
;  SEI(); //re-enable interrupts
	sei
	.dbline -2
L48:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e display _display fV
;        led_sel -> R20
;              i -> R22
	.even
_display::
	xcall push_xgsetF000
	.dbline -1
	.dbline 177
;  //all peripherals are now initialized
; }
; 
; /*动态扫描显示程序*/
; void display()  
; {
	.dbline 179
;   unsigned char i,led_sel;
;   led_sel=0xdf;
	ldi R20,223
	.dbline 180
;   for(i=0;i<6;i++)
	clr R22
	xjmp L53
L50:
	.dbline 181
;   {
	.dbline 182
;    PORTA=led_tab[time_group[i]];
	ldi R24,<_time_group
	ldi R25,>_time_group
	mov R30,R22
	clr R31
	add R30,R24
	adc R31,R25
	ldd R30,z+0
	clr R31
	lsl R30
	rol R31
	ldi R24,<_led_tab
	ldi R25,>_led_tab
	add R30,R24
	adc R31,R25
	lpm R2,Z+
	lpm R3,Z
	out 0x1b,R2
	.dbline 183
;    PORTB=led_sel;
	out 0x18,R20
	.dbline 184
;    led_sel=(led_sel>>1)+0x80;
	lsr R20
	subi R20,128    ; addi 128
	.dbline 185
;    delay_ms(10);
	ldi R16,10
	xcall _delay_ms
	.dbline 186
;    PORTB=0xff;
	ldi R24,255
	out 0x18,R24
	.dbline 187
;   }
L51:
	.dbline 180
	inc R22
L53:
	.dbline 180
	cpi R22,6
	brlo L50
X17:
	.dbline -2
L49:
	.dbline 0 ; func end
	xjmp pop_xgsetF000
	.dbsym r led_sel 20 c
	.dbsym r i 22 c
	.dbend
	.dbfunc e delay_ms _delay_ms fV
;              a -> R20
;              b -> R22
;              i -> R16
	.even
_delay_ms::
	st -y,R20
	st -y,R22
	.dbline -1
	.dbline 192
; }
; 
; /*毫秒延时程序*/
; void delay_ms(unsigned char i)
;  { 
	.dbline 194
;  unsigned char a, b;
;   for (a = 1; a < i; a++) 
	ldi R20,1
	xjmp L58
L55:
	.dbline 195
;   {  
	.dbline 196
;    for (b = 1; b; b++) 
	ldi R22,1
	xjmp L62
L59:
	.dbline 197
;    {   
	.dbline 198
;     ;   
	.dbline 199
;    } 
L60:
	.dbline 196
	inc R22
L62:
	.dbline 196
	tst R22
	brne L59
X18:
	.dbline 200
;   }
L56:
	.dbline 194
	inc R20
L58:
	.dbline 194
	cp R20,R16
	brlo L55
X19:
	.dbline -2
L54:
	.dbline 0 ; func end
	ld R22,y+
	ld R20,y+
	ret
	.dbsym r a 20 c
	.dbsym r b 22 c
	.dbsym r i 16 c
	.dbend
	.dbfunc e main _main fV
	.even
_main::
	.dbline -1
	.dbline 205
; }
; 
; /*主程序*/
; void main(void)
; {
	.dbline 207
; 
;   init_devices();
	xcall _init_devices
	xjmp L65
L64:
	.dbline 209
;   while(1)
;   {
	.dbline 210
;    set_detect();
	xcall _set_detect
	.dbline 211
;    data_split();
	xcall _data_split
	.dbline 212
;    display();
	xcall _display
	.dbline 213
;   }
L65:
	.dbline 208
	xjmp L64
X20:
	.dbline -2
L63:
	.dbline 0 ; func end
	ret
	.dbend
	.area bss(ram, con, rel)
	.dbfile F:\avr单片机学习\我自编程序\定时器数码管显示\timer1leddisplay.c
_time_group::
	.blkb 6
	.dbsym e time_group _time_group A[6:6]c
_hour::
	.blkb 1
	.dbsym e hour _hour c
_minute::
	.blkb 1
	.dbsym e minute _minute c
_second::
	.blkb 1
	.dbsym e second _second c
; }

⌨️ 快捷键说明

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