some reference exercise of C language

源代码在线查看: main.src

软件大小: 105 K
上传用户: foreverlovely
关键词: reference exercise language some
下载地址: 免注册下载 普通下载 VIP

相关代码

				; .\Main.SRC generated from: Main.c
				; COMPILER INVOKED BY:
				;        C:\Keil\C51\BIN\C51.EXE Main.c BROWSE DEBUG OBJECTEXTEND TABS(8) SRC(.\Main.SRC)
				
				$NOMOD51
				
				NAME	MAIN
				
				P0	DATA	080H
				P1	DATA	090H
				P2	DATA	0A0H
				P3	DATA	0B0H
				AC	BIT	0D0H.6
				T0	BIT	0B0H.4
				T1	BIT	0B0H.5
				EA	BIT	0A8H.7
				T2	BIT	090H.0
				IE	DATA	0A8H
				P0_0	BIT	080H.0
				P1_0	BIT	090H.0
				P0_1	BIT	080H.1
				FL	BIT	0D0H.1
				P2_0	BIT	0A0H.0
				P1_1	BIT	090H.1
				P0_2	BIT	080H.2
				P3_0	BIT	0B0H.0
				P2_1	BIT	0A0H.1
				P1_2	BIT	090H.2
				P0_3	BIT	080H.3
				P3_1	BIT	0B0H.1
				P2_2	BIT	0A0H.2
				P1_3	BIT	090H.3
				P0_4	BIT	080H.4
				P3_2	BIT	0B0H.2
				P2_3	BIT	0A0H.3
				P1_4	BIT	090H.4
				P0_5	BIT	080H.5
				EXF2	BIT	0C8H.6
				RD	BIT	0B0H.7
				P3_3	BIT	0B0H.3
				P2_4	BIT	0A0H.4
				P1_5	BIT	090H.5
				P0_6	BIT	080H.6
				P3_4	BIT	0B0H.4
				P2_5	BIT	0A0H.5
				P1_6	BIT	090H.6
				P0_7	BIT	080H.7
				P3_5	BIT	0B0H.5
				ES	BIT	0A8H.4
				P2_6	BIT	0A0H.6
				P1_7	BIT	090H.7
				P3_6	BIT	0B0H.6
				P2_7	BIT	0A0H.7
				IP	DATA	0B8H
				P3_7	BIT	0B0H.7
				RI	BIT	098H.0
				CY	BIT	0D0H.7
				INT0	BIT	0B0H.2
				INT1	BIT	0B0H.3
				TI	BIT	098H.1
				RCAP2H	DATA	0CBH
				PS	BIT	0B8H.4
				SP	DATA	081H
				T2EX	BIT	090H.1
				OV	BIT	0D0H.2
				RCAP2L	DATA	0CAH
				C_T2	BIT	0C8H.1
				WR	BIT	0B0H.6
				RCLK	BIT	0C8H.5
				TCLK	BIT	0C8H.4
				SBUF	DATA	099H
				PCON	DATA	087H
				SCON	DATA	098H
				TMOD	DATA	089H
				TCON	DATA	088H
				IE0	BIT	088H.1
				IE1	BIT	088H.3
				B	DATA	0F0H
				CP_RL2	BIT	0C8H.0
				ACC	DATA	0E0H
				ET0	BIT	0A8H.1
				ET1	BIT	0A8H.3
				TF0	BIT	088H.5
				ET2	BIT	0A8H.5
				TF1	BIT	088H.7
				TF2	BIT	0C8H.7
				RB8	BIT	098H.2
				TH0	DATA	08CH
				EX0	BIT	0A8H.0
				IT0	BIT	088H.0
				TH1	DATA	08DH
				EX1	BIT	0A8H.2
				TB8	BIT	098H.3
				IT1	BIT	088H.2
				TH2	DATA	0CDH
				P	BIT	0D0H.0
				SM0	BIT	098H.7
				TL0	DATA	08AH
				SM1	BIT	098H.6
				TL1	DATA	08BH
				SM2	BIT	098H.5
				TL2	DATA	0CCH
				PT0	BIT	0B8H.1
				RS0	BIT	0D0H.3
				PT1	BIT	0B8H.3
				RS1	BIT	0D0H.4
				PT2	BIT	0B8H.5
				TR0	BIT	088H.4
				TR1	BIT	088H.6
				TR2	BIT	0C8H.2
				PX0	BIT	0B8H.0
				PX1	BIT	0B8H.2
				DPH	DATA	083H
				DPL	DATA	082H
				EXEN2	BIT	0C8H.3
				REN	BIT	098H.4
				T2MOD	DATA	0C9H
				T2CON	DATA	0C8H
				RXD	BIT	0B0H.0
				TXD	BIT	0B0H.1
				F0	BIT	0D0H.5
				PSW	DATA	0D0H
				?PR?InitSystem?MAIN  SEGMENT CODE 
				?PR?_Delay?MAIN      SEGMENT CODE 
				?PR?DelayShort?MAIN  SEGMENT CODE 
				?PR?InitLCD?MAIN     SEGMENT CODE 
				?PR?DisplayText?MAIN SEGMENT CODE 
				?PR?_WriteLCD?MAIN   SEGMENT CODE 
				?PR?_WriteCommand?MAIN                   SEGMENT CODE 
				?PR?_WriteCharacter?MAIN                 SEGMENT CODE 
				?PR?_SendString2LCD?MAIN                 SEGMENT CODE 
				?DT?_SendString2LCD?MAIN                 SEGMENT DATA OVERLAYABLE 
				?PR?Convert?MAIN     SEGMENT CODE 
				?PR?Calculate?MAIN   SEGMENT CODE 
				?PR?DisplayVoltage?MAIN                  SEGMENT CODE 
				?PR?main?MAIN        SEGMENT CODE 
				?CO?MAIN             SEGMENT CODE 
				?DT?MAIN             SEGMENT DATA 
					EXTRN	CODE (?C?UIDIV)
					EXTRN	CODE (?C_STARTUP)
					PUBLIC	voltage
					PUBLIC	digit3
					PUBLIC	digit2
					PUBLIC	digit1
					PUBLIC	string2
					PUBLIC	string1
					PUBLIC	main
					PUBLIC	DisplayVoltage
					PUBLIC	Calculate
					PUBLIC	Convert
					PUBLIC	_SendString2LCD
					PUBLIC	_WriteCharacter
					PUBLIC	_WriteCommand
					PUBLIC	_WriteLCD
					PUBLIC	DisplayText
					PUBLIC	InitLCD
					PUBLIC	DelayShort
					PUBLIC	_Delay
					PUBLIC	InitSystem
				
					RSEG  ?DT?_SendString2LCD?MAIN
				?_SendString2LCD?BYTE:
				          p?846:   DS   2
				
					RSEG  ?DT?MAIN
				         digit1:   DS   1
				         digit2:   DS   1
				         digit3:   DS   1
				        voltage:   DS   1
				
					RSEG  ?CO?MAIN
				string1:
					DB  '8' ,'0' ,'5' ,'1' ,' ' ,'S' ,'t' ,'a' ,'r' ,'t' 
					DB  'e' ,'r' ,' ' ,'K' ,'i' ,'t' ,000H
				
				
				string2:
					DB  'D' ,'i' ,'e' ,'p' ,' ' ,'a' ,'p' ,' ' ,'=' ,' ' 
					DB  000H
				
				
				; // Khai bao cac file header
				; #include	
				; #include	
				; 
				; // Khai bao cac bien toan cuc
				; unsigned char code string1[] = "8051 Starter Kit";
				; unsigned char code string2[] = "Diep ap = ";
				; unsigned char voltage,digit1,digit2,digit3;
				; 
				; // Khai bao cac ham
				; void InitSystem(void);
				; void Delay(unsigned int n);
				; void DelayShort(void);
				; void InitLCD(void);
				; void WriteCommand(unsigned char command);
				; void WriteCharacter(unsigned char character);
				; void WriteLCD(unsigned char x);
				; void SendString2LCD(unsigned char code *p);
				; void DisplayText(void);
				; void DisplayVoltage(void);
				; void Convert();
				; void Calculate();
				; 
				; // Dinh nghia cac ham
				; void InitSystem(void)
				
					RSEG  ?PR?InitSystem?MAIN
				InitSystem:
					USING	0
							; SOURCE LINE # 25
				; {
							; SOURCE LINE # 26
				; 	// Cam LCD
				; 	LCD_E = 0;
							; SOURCE LINE # 28
					CLR  	P3_5
				; 	// Sang den backlight
				; 	LCD_BL = 0;
							; SOURCE LINE # 30
					CLR  	P3_6
				; 	// Tre de LCD tu khoi tao ben trong (it nhat 15ms)
				; 	Delay(100);
							; SOURCE LINE # 32
					MOV  	R7,#064H
					MOV  	R6,#00H
					LCALL	_Delay
				; 	// Tat den backlight
				; 	LCD_BL = 1;
							; SOURCE LINE # 34
					SETB 	P3_6
				; 	InitLCD();
							; SOURCE LINE # 35
					LJMP 	InitLCD
				; END OF InitSystem
				
				; }
				; void Delay(unsigned int n)
				
					RSEG  ?PR?_Delay?MAIN
				_Delay:
					USING	0
							; SOURCE LINE # 37
				;---- Variable 'n?140' assigned to Register 'R6/R7' ----
				; {
							; SOURCE LINE # 38
				; 	unsigned int i,j;
				; 	for(i=0;i							; SOURCE LINE # 40
				;---- Variable 'i?141' assigned to Register 'R4/R5' ----
					CLR  	A
					MOV  	R5,A
					MOV  	R4,A
				?C0002:
					CLR  	C
					MOV  	A,R5
					SUBB 	A,R7
					MOV  	A,R4
					SUBB 	A,R6
					JNC  	?C0008
				; 		for(j=0;j							; SOURCE LINE # 41
				;---- Variable 'j?142' assigned to Register 'R2/R3' ----
					CLR  	A
					MOV  	R3,A
					MOV  	R2,A
				?C0005:
					INC  	R3
					CJNE 	R3,#00H,?C0024
					INC  	R2
				?C0024:
					MOV  	A,R3
					XRL  	A,#064H
					ORL  	A,R2
					JNZ  	?C0005
				?C0004:
					INC  	R5
					CJNE 	R5,#00H,?C0025
					INC  	R4
				?C0025:
					SJMP 	?C0002
				; }
							; SOURCE LINE # 42
				?C0008:
					RET  	
				; END OF _Delay
				
				; void DelayShort(void)
				
					RSEG  ?PR?DelayShort?MAIN
				DelayShort:
							; SOURCE LINE # 43
				; {
							; SOURCE LINE # 44
				; 	#pragma asm
				; 	nop
					  nop
				; 	nop
					  nop
				; 	nop
					  nop
				; 	nop
					  nop
				; 	nop
					  nop
				; 	#pragma endasm
				; }
							; SOURCE LINE # 52
					RET  	
				; END OF DelayShort
				
				; void InitLCD(void)
				
					RSEG  ?PR?InitLCD?MAIN
				InitLCD:
					USING	0
							; SOURCE LINE # 53
				; {
							; SOURCE LINE # 54
				; 	WriteCommand(0x30);
							; SOURCE LINE # 55
					MOV  	R7,#030H
					LCALL	_WriteCommand
				; 	WriteCommand(0x30);
							; SOURCE LINE # 56
					MOV  	R7,#030H
					LCALL	_WriteCommand
				; 	WriteCommand(0x30);
							; SOURCE LINE # 57
					MOV  	R7,#030H
					LCALL	_WriteCommand
				; 	
				; 	// 8 bit, 2 lines, font 5x7
				; 	WriteCommand(0x38);
							; SOURCE LINE # 60
					MOV  	R7,#038H
					LCALL	_WriteCommand
				; 	// Display on, hide cursor
				; 	WriteCommand(0x0C);
							; SOURCE LINE # 62
					MOV  	R7,#0CH
					LCALL	_WriteCommand
				; 
				; 	// Xoa man hinh
				; 	WriteCommand(0x01);
							; SOURCE LINE # 65
					MOV  	R7,#01H
					LJMP 	_WriteCommand
				; END OF InitLCD
				
				; }
				; void DisplayText(void)
				
					RSEG  ?PR?DisplayText?MAIN
				DisplayText:
					USING	0
							; SOURCE LINE # 67
				; {
							; SOURCE LINE # 68
				; 	// Dich con tro den dau dong thu nhat
				; 	WriteCommand(0x80);
							; SOURCE LINE # 70
					MOV  	R7,#080H
					LCALL	_WriteCommand
				; 	SendString2LCD(string1);
							; SOURCE LINE # 71
					MOV  	R6,#HIGH (string1)
					MOV  	R7,#LOW (string1)
					LCALL	_SendString2LCD
				; 	// Dich con tro den dau dong thu hai
				; 	WriteCommand(0xC3);
							; SOURCE LINE # 73
					MOV  	R7,#0C3H
					LCALL	_WriteCommand
				; 	SendString2LCD(string2);
							; SOURCE LINE # 74
					MOV  	R6,#HIGH (string2)
					MOV  	R7,#LOW (string2)
					LCALL	_SendString2LCD
				; 	// Dich con tro den vi tri don vi do
				; 	WriteCommand(0xD0);
							; SOURCE LINE # 76
					MOV  	R7,#0D0H
					LCALL	_WriteCommand
				; 	WriteCharacter('V');
							; SOURCE LINE # 77
					MOV  	R7,#056H
					LJMP 	_WriteCharacter
				; END OF DisplayText
				
				; }
				; void WriteLCD(unsigned char x)
				
					RSEG  ?PR?_WriteLCD?MAIN
				_WriteLCD:
					USING	0
							; SOURCE LINE # 79
				;---- Variable 'x?543' assigned to Register 'R7' ----
				; {
							; SOURCE LINE # 80
				; 	LCD_RW = 0;
							; SOURCE LINE # 81
					CLR  	P2_7
				; 	LCD_DATA = x;
							; SOURCE LINE # 82
					MOV  	P0,R7
				; 
				; 	LCD_E = 1;
							; SOURCE LINE # 84
					SETB 	P3_5
				; 	LCD_E = 0;
							; SOURCE LINE # 85
					CLR  	P3_5
				; 	Delay(5);
							; SOURCE LINE # 86
					MOV  	R7,#05H
					MOV  	R6,#00H
					LJMP 	_Delay
				; END OF _WriteLCD
				
				; }
				; void WriteCommand(unsigned char command)
				
					RSEG  ?PR?_WriteCommand?MAIN
				_WriteCommand:
					USING	0
							; SOURCE LINE # 88
				;---- Variable 'command?644' assigned to Register 'R7' ----
				; {
							; SOURCE LINE # 89
				; 	LCD_RS = 0;
							; SOURCE LINE # 90
					CLR  	P2_6
				; 	WriteLCD(command);
							; SOURCE LINE # 91
					LJMP 	_WriteLCD
				; END OF _WriteCommand
				
				; }
				; void WriteCharacter(unsigned char character)
				
					RSEG  ?PR?_WriteCharacter?MAIN
				_WriteCharacter:
					USING	0
							; SOURCE LINE # 93
				;---- Variable 'character?745' assigned to Register 'R7' ----
				; {
							; SOURCE LINE # 94
				; 	LCD_RS = 1;
							; SOURCE LINE # 95
					SETB 	P2_6
				; 	WriteLCD(character);
							; SOURCE LINE # 96
					LJMP 	_WriteLCD
				; END OF _WriteCharacter
				
				; }
				; void SendString2LCD(unsigned char code *p)
				
					RSEG  ?PR?_SendString2LCD?MAIN
				_SendString2LCD:
					USING	0
							; SOURCE LINE # 98
					MOV  	p?846,R6
					MOV  	p?846+01H,R7
				; {
							; SOURCE LINE # 99
				; 	unsigned char i=0;
							; SOURCE LINE # 100
				;---- Variable 'i?847' assigned to Register 'R1' ----
					CLR  	A
					MOV  	R1,A
				?C0015:
				; 	while(p[i]!=0)
							; SOURCE LINE # 101
					MOV  	A,p?846+01H
					ADD  	A,R1
					MOV  	DPL,A
					CLR  	A
					ADDC 	A,p?846
					MOV  	DPH,A
					CLR  	A
					MOVC 	A,@A+DPTR
					MOV  	R7,A
					JZ   	?C0017
				; 	{
							; SOURCE LINE # 102
				; 		WriteCharacter(p[i]);
							; SOURCE LINE # 103
					LCALL	_WriteCharacter
				; 		i++;
							; SOURCE LINE # 104
					INC  	R1
				; 		Delay(200);
							; SOURCE LINE # 105
					MOV  	R7,#0C8H
					MOV  	R6,#00H
					LCALL	_Delay
				; 	}
							; SOURCE LINE # 106
					SJMP 	?C0015
				; }
							; SOURCE LINE # 107
				?C0017:
					RET  	
				; END OF _SendString2LCD
				
				; void Convert(void)
				
					RSEG  ?PR?Convert?MAIN
				Convert:
					USING	0
							; SOURCE LINE # 108
				; {
							; SOURCE LINE # 109
				; 	ADC_CS = 0;
							; SOURCE LINE # 110
					CLR  	P3_7
				; 	DelayShort();
							; SOURCE LINE # 111
					LCALL	DelayShort
				; 	ADC_WR = 0;
							; SOURCE LINE # 112
					CLR  	P2_7
				; 	DelayShort();
							; SOURCE LINE # 113
					LCALL	DelayShort
				; 	ADC_WR = 1;
							; SOURCE LINE # 114
					SETB 	P2_7
				; 	DelayShort();
							; SOURCE LINE # 115
					LCALL	DelayShort
				; 	ADC_CS = 1;
							; SOURCE LINE # 116
					SETB 	P3_7
				; 
				; 	// Tre cho chuyen doi xong
				; 	Delay(10);
							; SOURCE LINE # 119
					MOV  	R7,#0AH
					MOV  	R6,#00H
					LCALL	_Delay
				; 	// Chuyen Port thanh cong vao de chuan bi doc du lieu
				; 	ADC_DATA = 0xFF;
							; SOURCE LINE # 121
					MOV  	P0,#0FFH
				; 	ADC_CS = 0;
							; SOURCE LINE # 122
					CLR  	P3_7
				; 	DelayShort();
							; SOURCE LINE # 123
					LCALL	DelayShort
				; 	ADC_RD = 0;
							; SOURCE LINE # 124
					CLR  	P2_6
				; 	DelayShort();
							; SOURCE LINE # 125
					LCALL	DelayShort
				; 	// Doc du lieu vao
				; 	voltage = ADC_DATA;
							; SOURCE LINE # 127
					MOV  	voltage,P0
				; 	ADC_RD = 1;
							; SOURCE LINE # 128
					SETB 	P2_6
				; 	DelayShort();
							; SOURCE LINE # 129
					LCALL	DelayShort
				; 	ADC_CS = 1;
							; SOURCE LINE # 130
					SETB 	P3_7
				; }
							; SOURCE LINE # 131
					RET  	
				; END OF Convert
				
				; void Calculate(void)
				
					RSEG  ?PR?Calculate?MAIN
				Calculate:
					USING	0
							; SOURCE LINE # 132
				; {
							; SOURCE LINE # 133
				; 	unsigned int temp;
				; 	// tach lay phan nguyen va phan thap phan
				; 	temp = voltage*10/51;
							; SOURCE LINE # 136
					MOV  	A,voltage
					MOV  	B,#0AH
					MUL  	AB
					MOV  	B,#033H
					DIV  	AB
				;---- Variable 'temp?1048' assigned to Register 'R2/R3' ----
					MOV  	R3,A
				; 	digit1 = (unsigned char)(temp/10);
							; SOURCE LINE # 137
					MOV  	R4,#00H
					MOV  	R5,#0AH
					MOV  	R7,A
					MOV  	R6,#00H
					LCALL	?C?UIDIV
					MOV  	digit1,R7
				; 	digit2 = (unsigned char)(temp%10);
							; SOURCE LINE # 138
					MOV  	R6,#00H
					MOV  	R7,AR3
					MOV  	R4,#00H
					MOV  	R5,#0AH
					LCALL	?C?UIDIV
					MOV  	digit2,R5
				; 	// chuyen sang ma ASCII
				; 	digit1 = digit1 + 0x30;
							; SOURCE LINE # 140
					MOV  	A,#030H
					ADD  	A,digit1
					MOV  	digit1,A
				; 	digit2 = digit2 + 0x30;
							; SOURCE LINE # 141
					MOV  	A,#030H
					ADD  	A,digit2
					MOV  	digit2,A
				; }
							; SOURCE LINE # 142
					RET  	
				; END OF Calculate
				
				; void DisplayVoltage(void)
				
					RSEG  ?PR?DisplayVoltage?MAIN
				DisplayVoltage:
					USING	0
							; SOURCE LINE # 143
				; {
							; SOURCE LINE # 144
				; 	// Dua con tro den vi tri can hien thi
				; 	WriteCommand(0xCD);
							; SOURCE LINE # 146
					MOV  	R7,#0CDH
					LCALL	_WriteCommand
				; 	WriteCharacter(digit1);
							; SOURCE LINE # 147
					MOV  	R7,digit1
					LCALL	_WriteCharacter
				; 	WriteCharacter('.');
							; SOURCE LINE # 148
					MOV  	R7,#02EH
					LCALL	_WriteCharacter
				; 	WriteCharacter(digit2);
							; SOURCE LINE # 149
					MOV  	R7,digit2
					LJMP 	_WriteCharacter
				; END OF DisplayVoltage
				
				; }
				; // Chuong trinh chinh
				; void main(void)
				
					RSEG  ?PR?main?MAIN
				main:
					USING	0
							; SOURCE LINE # 152
				; {
							; SOURCE LINE # 153
				; 	// Khoi tao he thong
				; 	InitSystem();
							; SOURCE LINE # 155
					LCALL	InitSystem
				; 	DisplayText();
							; SOURCE LINE # 156
					LCALL	DisplayText
				?C0021:
				; 	// Vong lap vo tan
				; 	while(1)
							; SOURCE LINE # 158
				; 	{
							; SOURCE LINE # 159
				; 		Convert();
							; SOURCE LINE # 160
					LCALL	Convert
				; 		Calculate();
							; SOURCE LINE # 161
					LCALL	Calculate
				; 		DisplayVoltage();
							; SOURCE LINE # 162
					LCALL	DisplayVoltage
				; 	}
							; SOURCE LINE # 163
					SJMP 	?C0021
				; END OF main
				
					END
							

相关资源