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

📄 app.s

📁 AVR单片机C语言程序设计实例精粹
💻 S
字号:
	.module app.c
	.area text(rom, con, rel)
	.dbfile E:\Steaven2000\AVR\AVR_Book\PROGRA~1\SOURCE~1\Code\交通灯控制系统设计\app.c
	.dbfunc e Hardware_Init _Hardware_Init fV
	.even
_Hardware_Init::
	.dbline -1
	.dbline 20
; //***************************************************************
; // File Name : Gpio.c
; // Author    : Steaven
; // Created   : 2008-06-09
; // Modified  : 
; // Revision  : V0.0
; //***************************************************************
; 
; #include "iom16v.h" 
; #include "DataType.h"
; #include "app.h"
; 
; //***************************************************************
; // Function    : Hardware_Init
; // Input       : none
; // Output      : none
; // Description : ATmega16 Hardware Initialization
; //***************************************************************
; void Hardware_Init(void)
; {
	.dbline 21
;     Gpio_Init();
	xcall _Gpio_Init
	.dbline 22
;     Timer0_Init();
	xcall _Timer0_Init
	.dbline 23
;     Timer1_Init();
	xcall _Timer1_Init
	.dbline 24
;     Interrupt_Init();
	.dbline -2
	.dbline 25
; }
L1:
	.dbline 0 ; func end
	xjmp _Interrupt_Init
	.dbend
	.dbfunc e Gpio_Init _Gpio_Init fV
	.even
_Gpio_Init::
	.dbline -1
	.dbline 34
; 
; //***************************************************************
; // Function    : Gpio_Init
; // Input       : none
; // Output      : none
; // Description : ATmega16 GPIO Initialization
; //***************************************************************
; void Gpio_Init(void)
; {
	.dbline 35
;  	 DDRA  = 0xFF;
	ldi R24,255
	out 0x1a,R24
	.dbline 36
;     PORTA = 0x00;
	clr R2
	out 0x1b,R2
	.dbline 37
;     DDRB  = 0xFF;
	out 0x17,R24
	.dbline 38
;     PORTB = 0x00;
	out 0x18,R2
	.dbline 39
;     DDRC  = 0xFF;
	out 0x14,R24
	.dbline 40
;     PORTC = 0x00;
	out 0x15,R2
	.dbline 41
;     DDRD  = 0xFF;
	out 0x11,R24
	.dbline 42
;     PORTD = 0x00;
	out 0x12,R2
	.dbline -2
	.dbline 44
; 	 //while(1) {;}
; }
L2:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e Timer0_Init _Timer0_Init fV
	.even
_Timer0_Init::
	.dbline -1
	.dbline 53
; 
; //***************************************************************
; // Function    : Timer0_Init
; // Input       : none
; // Output      : none
; // Description : ATmega16 Timer0 Initialization,10ms Interval
; //***************************************************************
; void Timer0_Init(void)
; {
	.dbline 54
; 	TCCR0 = 0x0D;   //1024 division,8M/1024,CTC Mode
	ldi R24,13
	out 0x33,R24
	.dbline 55
; 	TCNT0 = 0x00;   //Clear Counter
	clr R2
	out 0x32,R2
	.dbline 56
; 	OCR0  = 78;     //78 * 1024/8M = 10ms 
	ldi R24,78
	out 0x3c,R24
	.dbline 57
; 	TIMSK |= 0x02;  //Enable OCIE0
	in R24,0x39
	ori R24,2
	out 0x39,R24
	.dbline 58
; 	TIFR  |= 0x02;  //Clear OCIF0
	in R24,0x38
	ori R24,2
	out 0x38,R24
	.dbline -2
	.dbline 59
; }
L3:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e Timer1_Init _Timer1_Init fV
	.even
_Timer1_Init::
	.dbline -1
	.dbline 68
; 
; //***************************************************************
; // Function    : Timer1_Init
; // Input       : none
; // Output      : none
; // Description : ATmega16 Timer1 Initialization,1s Interval
; //***************************************************************
; void Timer1_Init(void)
; {
	.dbline 69
; 	TCCR1A = 0x00;  //WGM1[3:0]=0100,OCR1A
	clr R2
	out 0x2f,R2
	.dbline 70
;    TCCR1B = 0x0D;  //1024 division,8M/1024,CTC Mode	
	ldi R24,13
	out 0x2e,R24
	.dbline 71
;    TCNT1  = 0x00;  //Clear Counter
	clr R3
	out 0x2d,R3
	out 0x2c,R2
	.dbline 72
; 	OCR1A  = 7813;  //7813 * 1024/8M = 1s 
	ldi R24,7813
	ldi R25,30
	out 0x2b,R25
	out 0x2a,R24
	.dbline 73
; 	TIMSK |= 0x10;  //Enable OCIE1A
	in R24,0x39
	ori R24,16
	out 0x39,R24
	.dbline 74
; 	TIFR  |= 0x10;  //Clear OCIF1A
	in R24,0x38
	ori R24,16
	out 0x38,R24
	.dbline -2
	.dbline 75
; }
L4:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e Interrupt_Init _Interrupt_Init fV
	.even
_Interrupt_Init::
	.dbline -1
	.dbline 84
; 
; //***************************************************************
; // Function    : Interrupt_Init
; // Input       : none
; // Output      : none
; // Description : ATmega16 Interrupt Initialization
; //***************************************************************
; void Interrupt_Init(void)
; {
	.dbline 85
; 	SREG |= 0x80;   //Enable Global Interrupt
	bset 7
	.dbline -2
	.dbline 86
; }
L5:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e LED_ON_OFF _LED_ON_OFF fV
;         Action -> R22
;          Index -> R20
	.even
_LED_ON_OFF::
	xcall push_gset2
	mov R22,R18
	mov R20,R16
	.dbline -1
	.dbline 95
; 
; //***************************************************************
; // Function    : Interrupt_Init
; // Input       : none
; // Output      : none
; // Description : ATmega16 Interrupt Initialization
; //***************************************************************
; void LED_ON_OFF(INT8U Index,INT8U Action)
; {
	.dbline 96
;     if(Action == cLED_ON)
	cpi R22,1
	brne L7
	.dbline 97
;     {
	.dbline 98
;         PORTC |= (1 << Index);
	ldi R16,1
	mov R17,R20
	xcall lsl8
	in R2,0x15
	or R2,R16
	out 0x15,R2
	.dbline 99
;     }
	xjmp L8
L7:
	.dbline 101
	.dbline 102
	ldi R16,1
	mov R17,R20
	xcall lsl8
	mov R2,R16
	com R2
	in R3,0x15
	and R3,R2
	out 0x15,R3
	.dbline 103
L8:
	.dbline -2
	.dbline 104
;     else
;     {
;         PORTC &= ~(1 << Index);
;     }
; }
L6:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r Action 22 c
	.dbsym r Index 20 c
	.dbend
	.dbfunc e INT2BCD _INT2BCD fV
;          pdata -> R20,R21
;           Data -> R22
	.even
_INT2BCD::
	xcall push_gset2
	movw R20,R18
	mov R22,R16
	.dbline -1
	.dbline 114
; 
; //***************************************************************
; // Function    : Interrupt_Init
; // Input       : Data - Integer Type Data
; //               pdata - Pointer to BCD Data Array
; // Output      : none
; // Description : Convert Integer Data to BCD Type Data
; //***************************************************************
; void INT2BCD(INT8U Data,INT8U *pdata)
; {
	.dbline 115
;     *pdata++ = Data % 10;
	ldi R17,10
	mov R16,R22
	xcall mod8u
	movw R30,R20
	st Z+,R16
	movw R20,R30
	.dbline 116
;     *pdata   = Data / 10;
	ldi R17,10
	mov R16,R22
	xcall div8u
	movw R30,R20
	std z+0,R16
	.dbline -2
	.dbline 117
; }
L9:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r pdata 20 pc
	.dbsym r Data 22 c
	.dbend
	.dbfunc e DataConvert _DataConvert fc
;           Data -> R16
	.even
_DataConvert::
	.dbline -1
	.dbline 120
; 
; INT8U DataConvert(INT8U Data)
; {
	.dbline 121
;     if(Data <= 9)
	ldi R24,9
	cp R24,R16
	brlo L11
	.dbline 122
; 		{
	.dbline 123
; 		    return(SegTable[Data]);
	ldi R24,<_SegTable
	ldi R25,>_SegTable
	mov R30,R16
	clr R31
	add R30,R24
	adc R31,R25
	lpm R16,Z
	xjmp L10
L11:
	.dbline 125
; 		}
; 		return(0);
	clr R16
	.dbline -2
L10:
	.dbline 0 ; func end
	ret
	.dbsym r Data 16 c
	.dbend

⌨️ 快捷键说明

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