📄 project.lst
字号:
__text_start:
__start:
009C E5CF LDI R28,0x5F
009D E0D4 LDI R29,4
009E BFCD OUT 0x3D,R28
009F BFDE OUT 0x3E,R29
00A0 51C0 SUBI R28,0x10
00A1 40D0 SBCI R29,0
00A2 EA0A LDI R16,0xAA
00A3 8308 STD Y+0,R16
00A4 2400 CLR R0
00A5 E3E4 LDI R30,0x34
00A6 E0F1 LDI R31,1
00A7 E011 LDI R17,1
00A8 3CED CPI R30,0xCD
00A9 07F1 CPC R31,R17
00AA F011 BEQ 0x00AD
00AB 9201 ST R0,Z+
00AC CFFB RJMP 0x00A8
00AD 8300 STD Z+0,R16
00AE E6E4 LDI R30,0x64
00AF E0F0 LDI R31,0
00B0 E6A0 LDI R26,0x60
00B1 E0B0 LDI R27,0
00B2 E011 LDI R17,1
00B3 33E8 CPI R30,0x38
00B4 07F1 CPC R31,R17
00B5 F021 BEQ 0x00BA
00B6 95C8 LPM
00B7 9631 ADIW R30,1
00B8 920D ST R0,X+
00B9 CFF9 RJMP 0x00B3
00BA 940E00EB CALL _main
_exit:
00BC CFFF RJMP _exit
FILE: E:\Steaven2000\AVR\AVR_Book\PROGRA~1\SOURCE~1\Code\RS232通信协议应用设计\app.c
(0001) //***************************************************************
(0002) // File Name : app.c
(0003) // Author : Steaven
(0004) // Created : 2008-06-09
(0005) // Modified :
(0006) // Revision : V0.0
(0007) //***************************************************************
(0008)
(0009) #include "includes.h"
(0010)
(0011) //local function declaration
(0012) void Gpio_Init(void);
(0013) void Timer0_Init(void);
(0014) void Timer1_Init(void);
(0015) void Interrupt_Init(void);
(0016) void Adc_Init(void);
(0017)
(0018) //***************************************************************
(0019) // Function : Hardware_Init
(0020) // Input : none
(0021) // Output : none
(0022) // Description : ATmega16 Hardware Initialization
(0023) //***************************************************************
(0024) void Hardware_Init(void)
(0025) {
(0026) Gpio_Init();
_Hardware_Init:
00BD D004 RCALL _Gpio_Init
(0027) Adc_Init();
00BE D025 RCALL _Adc_Init
(0028) Timer0_Init();
00BF D00C RCALL _Timer0_Init
(0029) Timer1_Init();
00C0 D018 RCALL _Timer1_Init
(0030) Interrupt_Init();
(0031) }
00C1 C027 RJMP _Interrupt_Init
(0032)
(0033) //***************************************************************
(0034) // Function : Gpio_Init
(0035) // Input : none
(0036) // Output : none
(0037) // Description : ATmega16 GPIO Initialization
(0038) //***************************************************************
(0039) void Gpio_Init(void)
(0040) {
(0041) DDRA = 0x00; //PortA - Input without internal pull-up
_Gpio_Init:
00C2 2422 CLR R2
00C3 BA2A OUT 0x1A,R2
(0042) PORTA = 0x00;
00C4 BA2B OUT 0x1B,R2
(0043) DDRB = 0x00; //PortB - Input without internal pull-up
00C5 BA27 OUT 0x17,R2
(0044) PORTB = 0x00;
00C6 BA28 OUT 0x18,R2
(0045) DDRC = 0x00; //PortC - Input without internal pull-up
00C7 BA24 OUT 0x14,R2
(0046) PORTC = 0x00;
00C8 BA25 OUT 0x15,R2
(0047) DDRD = 0x00; //PortD - Input without internal upll-up
00C9 BA21 OUT 0x11,R2
(0048) PORTD = 0x00;
00CA BA22 OUT 0x12,R2
(0049) }
00CB 9508 RET
(0050)
(0051) //***************************************************************
(0052) // Function : Timer0_Init
(0053) // Input : none
(0054) // Output : none
(0055) // Description : ATmega16 Timer0 Initialization,10ms Interval
(0056) //***************************************************************
(0057) void Timer0_Init(void)
(0058) {
(0059) TCCR0 = 0x0B; //64 division,8M/64,CTC Mode
_Timer0_Init:
00CC E08B LDI R24,0xB
00CD BF83 OUT 0x33,R24
(0060) TCNT0 = 0x00; //Clear Counter
00CE 2422 CLR R2
00CF BE22 OUT 0x32,R2
(0061) OCR0 = 63; //125 * 64/8M = 1ms/1kHz
00D0 E38F LDI R24,0x3F
00D1 BF8C OUT 0x3C,R24
(0062) TIMSK |= 0x02; //Enable OCIE0
00D2 B789 IN R24,0x39
00D3 6082 ORI R24,2
00D4 BF89 OUT 0x39,R24
(0063) TIFR |= 0x02; //Clear OCIF0
00D5 B788 IN R24,0x38
00D6 6082 ORI R24,2
00D7 BF88 OUT 0x38,R24
(0064) }
00D8 9508 RET
(0065)
(0066) //***************************************************************
(0067) // Function : Timer1_Init
(0068) // Input : none
(0069) // Output : none
(0070) // Description : ATmega16 Timer1 Initialization,capture enabled
(0071) //***************************************************************
(0072) void Timer1_Init(void)
(0073) {
(0074) TCCR1A = 0x00; //Normal Mode
_Timer1_Init:
00D9 2422 CLR R2
00DA BC2F OUT 0x2F,R2
(0075) TCCR1B = 0x82; //8 division,rising-edge capture
00DB E882 LDI R24,0x82
00DC BD8E OUT 0x2E,R24
(0076) TIMSK |= 0x20; //Enbale Input Capture Interrupt.
00DD B789 IN R24,0x39
00DE 6280 ORI R24,0x20
00DF BF89 OUT 0x39,R24
(0077) TIFR |= 0x20; //Clear TIFR Interrupt Flag.
00E0 B788 IN R24,0x38
00E1 6280 ORI R24,0x20
00E2 BF88 OUT 0x38,R24
(0078) }
00E3 9508 RET
(0079)
(0080) //***************************************************************
(0081) // Function : Adc_Init
(0082) // Input : none
(0083) // Output : none
(0084) // Description : ATmega16 ADC Initialization,free run
(0085) //***************************************************************
(0086) void Adc_Init(void)
(0087) {
(0088) ADMUX = 0x00; //Select CH_0
_Adc_Init:
00E4 2422 CLR R2
00E5 B827 OUT 0x07,R2
(0089) ADCSRA = 0xE0; //Automatic Conversion
00E6 EE80 LDI R24,0xE0
00E7 B986 OUT 0x06,R24
(0090) }
00E8 9508 RET
(0091)
(0092) //***************************************************************
(0093) // Function : Interrupt_Init
(0094) // Input : none
(0095) // Output : none
(0096) // Description : ATmega16 Interrupt Initialization
(0097) //***************************************************************
(0098) void Interrupt_Init(void)
(0099) {
(0100) SREG |= 0x80; //Enable Global Interrupt
_Interrupt_Init:
00E9 9478 BSET 7
(0101) }
00EA 9508 RET
FILE: E:\Steaven2000\AVR\AVR_Book\PROGRA~1\SOURCE~1\Code\RS232通信协议应用设计\main.c
(0001) //***************************************************************
(0002) // File Name : main.c
(0003) // Author : Steaven
(0004) // Created : 2008-07-26
(0005) // Modified :
(0006) // Revision : V0.0
(0007) //***************************************************************
(0008)
(0009) #include "includes.h"
(0010)
(0011) //constant definition
(0012) #define cLineRatio 9333
(0013)
(0014) //global variables definition
(0015) INT8U bLine_Event = 0; //Line Calculation Event
(0016) INT8U bLineCnt = 0; //Line Sampling Count
(0017) INT8U bLineCntTemp = 0; //Line Sampling Count(temporary)
(0018) INT16S wLineVoltSample = 0; //Line Sampling Value
(0019) INT16S wLineVoltReal = 0; //Line Instant Value
(0020) INT16S wLineVoltRMS = 0; //Line RMS Value
(0021) INT16U wLinePeriod = 0; //Line Period
(0022) INT16U wLinePeriodTemp = 0; //Line Period(temporary)
(0023) INT16U wLineCaptureTime = 0; //Line Capature Time
(0024) INT16U wLineCaptureTimeLast = 0; //Line Last Capature Time
(0025) INT32U dwLineVoltSum = 0; //Line S-I Accumulation
(0026) INT32U dwLineVoltSumTemp = 0; //Line S-I Accumulation(temporary)
(0027)
(0028) //local function declaration
(0029) INT16U swRoot(INT32U dwNumber);
(0030)
(0031) void main(void)
(0032) {
(0033) Hardware_Init();
_main:
00EB 940E00BD CALL _Hardware_Init
(0034) Init_UART();
00ED 940E02E8 CALL _Init_UART
00EF C023 RJMP 0x0113
(0035) while(1)
(0036) {
(0037) if(bLine_Event == 1)
00F0 91800060 LDS R24,0x60
00F2 3081 CPI R24,1
00F3 F4F9 BNE 0x0113
(0038) {
(0039) bLine_Event = 0;
00F4 2422 CLR R2
00F5 92200060 STS 0x60,R2
(0040) if(bLineCnt != 0)
00F7 90200061 LDS R2,0x61
00F9 2022 TST R2
00FA F0C1 BEQ 0x0113
(0041) {
(0042) wLineVoltRMS = swRoot(dwLineVoltSum/bLineCnt);
00FB 2433 CLR R3
00FC 2444 CLR R4
00FD 2455 CLR R5
00FE 90800073 LDS R8,0x73
0100 90900074 LDS R9,0x74
0102 90600071 LDS R6,0x71
0104 90700072 LDS R7,0x72
0106 925A ST R5,-Y
0107 924A ST R4,-Y
0108 923A ST R3,-Y
0109 922A ST R2,-Y
010A 0183 MOVW R16,R6
010B 0194 MOVW R18,R8
010C 940E083F CALL div32u
010E D113 RCALL _swRoot
010F 93100068 STS 0x68,R17
0111 93000067 STS __idata_start+3,R16
0113 CFDC RJMP 0x00F0
(0043) }
(0044) }
(0045) }
(0046) }
0114 9508 RET
_TimeCountr0_Interrupt:
temp2 --> R12
temp1 --> R10
0115 922A ST R2,-Y
0116 923A ST R3,-Y
0117 924A ST R4,-Y
0118 925A ST R5,-Y
0119 926A ST R6,-Y
011A 927A ST R7,-Y
011B 928A ST R8,-Y
011C 929A ST R9,-Y
011D 930A ST R16,-Y
011E 931A ST R17,-Y
011F 932A ST R18,-Y
0120 933A ST R19,-Y
0121 938A ST R24,-Y
0122 939A ST R25,-Y
0123 93AA ST R26,-Y
0124 93BA ST R27,-Y
0125 93EA ST R30,-Y
0126 B62F IN R2,0x3F
0127 922A ST R2,-Y
0128 940E0908 CALL push_gset4
(0047)
(0048) //***************************************************************
(0049) // Function : wTimeCountr0_Interrupt
(0050) // Input : none
(0051) // Output : none
(0052) // Description : ATmega16 T/C0 ISR
(0053) //***************************************************************
(0054) #pragma interrupt_handler TimeCountr0_Interrupt:20
(0055) void TimeCountr0_Interrupt(void)
(0056) {
(0057) INT16U temp1,temp2;
(0058)
(0059) //Clear wTimeCountr0 OCIF Flag
(0060) TIFR |= 0x02;
012A B788 IN R24,0x38
012B 6082 ORI R24,2
012C BF88 OUT 0x38,R24
(0061) TCNT0 = 0x00;
012D 2422 CLR R2
012E BE22 OUT 0x32,R2
(0062)
(0063) //Read ADC Conversion
(0064) temp1 = (INT16U)ADCL;
012F B0A4 IN R10,0x04
0130 24BB CLR R11
(0065) temp2 = (INT16U)ADCH;
0131 B0C5 IN R12,0x05
0132 24DD CLR R13
(0066) wLineVoltSample = (temp2 << 8) | temp1;
0133 0116 MOVW R2,R12
0134 2C32 MOV R3,R2
0135 2422 CLR R2
0136 282A OR R2,R10
0137 283B OR R3,R11
0138 92300064 STS __idata_start,R3
013A 92200063 STS 0x63,R2
(0067) wLineVoltReal = (INT16S)(((INT32S)(wLineVoltSample - 512) * cLineRatio) >> 10);
013C 01C1 MOVW R24,R2
013D 5080 SUBI R24,0
013E 4092 SBCI R25,2
013F 011C MOVW R2,R24
0140 2444 CLR R4
0141 FC37 SBRC R3,7
0142 9440 COM R4
0143 2455 CLR R5
0144 FC47 SBRC R4,7
0145 9450 COM R5
0146 E745 LDI R20,0x75
0147 E254 LDI R21,0x24
0148 E060 LDI R22,0
0149 E070 LDI R23,0
014A 925A ST R5,-Y
014B 924A ST R4,-Y
014C 923A ST R3,-Y
014D 922A ST R2,-Y
014E 018A MOVW R16,R20
014F 019B MOVW R18,R22
0150 940E08B0 CALL empy32u
0152 E08A LDI R24,0xA
0153 E090 LDI R25,0
0154 938A ST R24,-Y
0155 940E0833 CALL asr32
0157 93100066 STS __idata_start+2,R17
0159 93000065 STS __idata_start+1,R16
(0068) if(wLineVoltReal < 0)
015B 01C8 MOVW R24,R16
015C 3000 CPI R16,0
015D E0E0 LDI R30,0
015E 071E CPC R17,R30
015F F444 BGE 0x0168
(0069) {
(0070) wLineVoltReal = -wLineVoltReal;
0160 9580 COM R24
0161 9590 COM R25
0162 5F8F SUBI R24,0xFF
0163 4F9F SBCI R25,0xFF
0164 93900066 STS __idata_start+2,R25
0166 93800065 STS __idata_start+1,R24
(0071) }
(0072) dwLineVoltSumTemp += (INT32S)wLineVoltReal * (INT32S)wLineVoltReal;
0168 90200065 LDS R2,__idata_start+1
016A 90300066 LDS R3,__idata_start+2
016C 2444 CLR R4
016D FC37 SBRC R3,7
016E 9440 COM R4
016F 2455 CLR R5
0170 FC47 SBRC R4,7
0171 9450 COM R5
0172 90600065 LDS R6,__idata_start+1
0174 90700066 LDS R7,__idata_start+2
0176 2488 CLR R8
0177 FC77 SBRC R7,7
0178 9480 COM R8
0179 2499 CLR R9
017A FC87 SBRC R8,7
017B 9490 COM R9
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -