📄 1.lst
字号:
__start:
__text_start:
003C E5CF LDI R28,0x5F
003D E0D4 LDI R29,4
003E BFCD OUT 0x3D,R28
003F BFDE OUT 0x3E,R29
0040 51C0 SUBI R28,0x10
0041 40D0 SBCI R29,0
0042 EA0A LDI R16,0xAA
0043 8308 STD Y+0,R16
0044 2400 CLR R0
0045 E7E6 LDI R30,0x76
0046 E0F0 LDI R31,0
0047 E010 LDI R17,0
0048 37EB CPI R30,0x7B
0049 07F1 CPC R31,R17
004A F011 BEQ 0x004D
004B 9201 ST R0,Z+
004C CFFB RJMP 0x0048
004D 8300 STD Z+0,R16
004E E6E2 LDI R30,0x62
004F E0F0 LDI R31,0
0050 E6A0 LDI R26,0x60
0051 E0B0 LDI R27,0
0052 E010 LDI R17,0
0053 37E8 CPI R30,0x78
0054 07F1 CPC R31,R17
0055 F021 BEQ 0x005A
0056 95C8 LPM
0057 9631 ADIW R30,1
0058 920D ST R0,X+
0059 CFF9 RJMP 0x0053
005A 940E018A CALL _main
_exit:
005C CFFF RJMP _exit
FILE: C:\DOCUME~1\Administrator\桌面\18b20\1.c
(0001) /* m818b20.c 2004-11-19
(0002) 本程序为采用mega8 和18b20的温度采集程序
(0003) 选用mega8内部8M RC震荡,18b20 数据线接pd6,数据线和vcc间接一4.7k上拉电阻
(0004) 感谢dfgeoff 嗜血蜗牛提供的资料*/
(0005)
(0006) #include <iom16v.h> //和单片机类型相对应的头文件,选择Atmega8做实验;
(0007) #include <macros.h>
(0008) #define uchar unsigned char
(0009) #define uint unsigned int
(0010) void init_1820();
(0011) write_1820(uchar x);
(0012) uchar read_1820();
(0013) void send_byte(uchar x);
(0014) void delay(uint x);
(0015) void disp_led(uchar buffer,uchar control);
(0016) uchar disp_table[16] = {
(0017) 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
(0018) 0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
(0019) uchar dp;
(0020) long count;
(0021) #define LCD_EN_PORT PORTA //以下2个要设为同一个口
(0022) #define LCD_EN_DDR DDRA
(0023) #define LCD_RS_PORT PORTA //以下2个要设为同一个口
(0024) #define LCD_RS_DDR DDRA
(0025) #define LCD_DATA_PORT PORTA //以下3个要设为同一个口
(0026) #define LCD_DATA_DDR DDRA //一定要用高4位
(0027) #define LCD_DATA_PIN PINA
(0028) #define LCD_RS (1<<0) // port0 out
(0029) #define LCD_EN (1<<1) // port1 out
(0030) #define LCD_DATA ((1<<4)|(1<<5)|(1<<6)|(1<<7)) //0xf0
(0031) /*函数说明
(0032) ------------------------------------------------------------------------------*/
(0033) void LCD_init(void);
(0034) void LCD_en_write(void);
(0035) void LCD_write_command(unsigned char command) ;
(0036) void LCD_write_data(unsigned char data);
(0037) void LCD_set_xy (unsigned char x, unsigned char y);
(0038) void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s);
(0039) void LCD_write_char(unsigned char X,unsigned char Y,unsigned char data);
(0040) void delay_nus(unsigned int n);
(0041) void delay_nms(unsigned int n);
(0042) /*----------------------------------------------------------------------------*/
(0043) void delay_1us(void) //1us延时函数
(0044) {
(0045) asm("nop");
_delay_1us:
005D 0000 NOP
005E 9508 RET
_delay_nus:
i --> R20
n --> R22
005F 940E020C CALL push_gset2
0061 01B8 MOVW R22,R16
(0046) }
(0047)
(0048) void delay_nus(unsigned int n) //N us延时函数
(0049) {
(0050) unsigned int i=0;
0062 2744 CLR R20
0063 2755 CLR R21
(0051) for (i=0;i<n;i++)
0064 C003 RJMP 0x0068
(0052) delay_1us();
0065 DFF7 RCALL _delay_1us
0066 5F4F SUBI R20,0xFF
0067 4F5F SBCI R21,0xFF
0068 1746 CP R20,R22
0069 0757 CPC R21,R23
006A F3D0 BCS 0x0065
006B 940E0200 CALL pop_gset2
006D 9508 RET
(0053) }
(0054)
(0055) void delay_1ms(void) //1ms延时函数
(0056) {
(0057) unsigned int i;
(0058) for (i=0;i<1140;i++);
_delay_1ms:
i --> R16
006E 2700 CLR R16
006F 2711 CLR R17
0070 C002 RJMP 0x0073
0071 5F0F SUBI R16,0xFF
0072 4F1F SBCI R17,0xFF
0073 3704 CPI R16,0x74
0074 E0E4 LDI R30,4
0075 071E CPC R17,R30
0076 F3D0 BCS 0x0071
0077 9508 RET
_delay_nms:
i --> R20
n --> R22
0078 940E020C CALL push_gset2
007A 01B8 MOVW R22,R16
(0059) }
(0060)
(0061) void delay_nms(unsigned int n) //N ms延时函数
(0062) {
(0063) unsigned int i=0;
007B 2744 CLR R20
007C 2755 CLR R21
(0064) for (i=0;i<n;i++)
007D C003 RJMP 0x0081
(0065) delay_1ms();
007E DFEF RCALL _delay_1ms
007F 5F4F SUBI R20,0xFF
0080 4F5F SBCI R21,0xFF
0081 1746 CP R20,R22
0082 0757 CPC R21,R23
0083 F3D0 BCS 0x007E
0084 940E0200 CALL pop_gset2
0086 9508 RET
(0066) }
(0067)
(0068)
(0069) /*----------------------------------------------------------------------------*/
(0070) void LCD_init(void) //液晶初始化
(0071) {
(0072) LCD_DATA_DDR|=LCD_DATA; //数据口方向为输出
_LCD_init:
0087 B38A IN R24,0x1A
0088 6F80 ORI R24,0xF0
0089 BB8A OUT 0x1A,R24
(0073) LCD_EN_DDR|=LCD_EN; //设置EN方向为输出
008A 9AD1 SBI 0x1A,1
(0074) LCD_RS_DDR|=LCD_RS; //设置RS方向为输出
008B 9AD0 SBI 0x1A,0
(0075) LCD_write_command(0x28);
008C E208 LDI R16,0x28
008D D014 RCALL _LCD_write_command
(0076) LCD_en_write();
008E D00D RCALL _LCD_en_write
(0077) delay_nus(40);
008F E208 LDI R16,0x28
0090 E010 LDI R17,0
0091 DFCD RCALL _delay_nus
(0078) LCD_write_command(0x28); //4位显示
0092 E208 LDI R16,0x28
0093 D00E RCALL _LCD_write_command
(0079) LCD_write_command(0x0c); //显示开
0094 E00C LDI R16,0xC
0095 D00C RCALL _LCD_write_command
(0080) LCD_write_command(0x01); //清屏
0096 E001 LDI R16,1
0097 D00A RCALL _LCD_write_command
(0081) delay_nms(2);
0098 E002 LDI R16,2
0099 E010 LDI R17,0
009A DFDD RCALL _delay_nms
009B 9508 RET
(0082) }
(0083)
(0084) /*----------------------------------------------------------------------------*/
(0085) void LCD_en_write(void) //液晶使能
(0086) {
(0087) LCD_EN_PORT|=LCD_EN;
_LCD_en_write:
009C 9AD9 SBI 0x1B,1
(0088) delay_nus(1);
009D E001 LDI R16,1
009E E010 LDI R17,0
009F DFBF RCALL _delay_nus
(0089) LCD_EN_PORT&=~LCD_EN;
00A0 98D9 CBI 0x1B,1
00A1 9508 RET
_LCD_write_command:
command --> R20
00A2 940E020E CALL push_gset1
00A4 2F40 MOV R20,R16
(0090) }
(0091)
(0092) /*----------------------------------------------------------------------------*/
(0093) void LCD_write_command(unsigned char command) //写指令
(0094) {
(0095) delay_nus(16);
00A5 E100 LDI R16,0x10
00A6 E010 LDI R17,0
00A7 DFB7 RCALL _delay_nus
(0096) LCD_RS_PORT&=~LCD_RS; //RS=0
00A8 98D8 CBI 0x1B,0
(0097) LCD_DATA_PORT&=0X0f; //清高四位
00A9 B38B IN R24,0x1B
00AA 708F ANDI R24,0xF
00AB BB8B OUT 0x1B,R24
(0098) LCD_DATA_PORT|=command&0xf0; //写高四位
00AC 2F84 MOV R24,R20
00AD 7F80 ANDI R24,0xF0
00AE B22B IN R2,0x1B
00AF 2A28 OR R2,R24
00B0 BA2B OUT 0x1B,R2
(0099) LCD_en_write();
00B1 DFEA RCALL _LCD_en_write
(0100) command=command<<4; //低四位移到高四位
00B2 2F84 MOV R24,R20
00B3 708F ANDI R24,0xF
00B4 9582 SWAP R24
00B5 2F48 MOV R20,R24
(0101) LCD_DATA_PORT&=0x0f; //清高四位
00B6 B38B IN R24,0x1B
00B7 708F ANDI R24,0xF
00B8 BB8B OUT 0x1B,R24
(0102) LCD_DATA_PORT|=command&0xf0; //写低四位
00B9 2F84 MOV R24,R20
00BA 7F80 ANDI R24,0xF0
00BB B22B IN R2,0x1B
00BC 2A28 OR R2,R24
00BD BA2B OUT 0x1B,R2
(0103) LCD_en_write();
00BE DFDD RCALL _LCD_en_write
00BF 940E0211 CALL pop_gset1
00C1 9508 RET
_LCD_write_data:
data --> R20
00C2 940E020E CALL push_gset1
00C4 2F40 MOV R20,R16
(0104)
(0105) }
(0106) /*----------------------------------------------------------------------------*/
(0107) void LCD_write_data(unsigned char data) //写数据
(0108) {
(0109) delay_nus(16);
00C5 E100 LDI R16,0x10
00C6 E010 LDI R17,0
00C7 DF97 RCALL _delay_nus
(0110) LCD_RS_PORT|=LCD_RS; //RS=1
00C8 9AD8 SBI 0x1B,0
(0111) LCD_DATA_PORT&=0X0f; //清高四位
00C9 B38B IN R24,0x1B
00CA 708F ANDI R24,0xF
00CB BB8B OUT 0x1B,R24
(0112) LCD_DATA_PORT|=data&0xf0; //写高四位
00CC 2F84 MOV R24,R20
00CD 7F80 ANDI R24,0xF0
00CE B22B IN R2,0x1B
00CF 2A28 OR R2,R24
00D0 BA2B OUT 0x1B,R2
(0113) LCD_en_write();
00D1 DFCA RCALL _LCD_en_write
(0114) data=data<<4; //低四位移到高四位
00D2 2F84 MOV R24,R20
00D3 708F ANDI R24,0xF
00D4 9582 SWAP R24
00D5 2F48 MOV R20,R24
(0115) LCD_DATA_PORT&=0X0f; //清高四位
00D6 B38B IN R24,0x1B
00D7 708F ANDI R24,0xF
00D8 BB8B OUT 0x1B,R24
(0116) LCD_DATA_PORT|=data&0xf0; //写低四位
00D9 2F84 MOV R24,R20
00DA 7F80 ANDI R24,0xF0
00DB B22B IN R2,0x1B
00DC 2A28 OR R2,R24
00DD BA2B OUT 0x1B,R2
(0117) LCD_en_write();
00DE DFBD RCALL _LCD_en_write
00DF 940E0211 CALL pop_gset1
00E1 9508 RET
_LCD_set_xy:
address --> R20
y --> R20
x --> R22
00E2 940E020C CALL push_gset2
00E4 2F42 MOV R20,R18
00E5 2F60 MOV R22,R16
(0118) }
(0119) /*----------------------------------------------------------------------------*/
(0120) void LCD_set_xy( unsigned char x, unsigned char y ) //写地址函数
(0121) {
(0122) unsigned char address;
(0123) if (y == 0) address = 0x80 + x;
00E6 2344 TST R20
00E7 F419 BNE 0x00EB
00E8 2F46 MOV R20,R22
00E9 5840 SUBI R20,0x80
00EA C002 RJMP 0x00ED
(0124) else address = 0xc0 + x;
00EB 2F46 MOV R20,R22
00EC 5440 SUBI R20,0x40
(0125) LCD_write_command( address);
00ED 2F04 MOV R16,R20
00EE DFB3 RCALL _LCD_write_command
00EF 940E0200 CALL pop_gset2
00F1 9508 RET
_LCD_write_string:
s --> R20
Y --> R10
X --> R22
00F2 940E020A CALL push_gset3
00F4 2EA2 MOV R10,R18
00F5 2F60 MOV R22,R16
00F6 814E LDD R20,Y+6
00F7 815F LDD R21,Y+7
(0126) }
(0127) /*----------------------------------------------------------------------------*/
(0128) void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s) //列x=0~15,行y=0,1
(0129) {
(0130) LCD_set_xy( X, Y ); //写地址
00F8 2D2A MOV R18,R10
00F9 2F06 MOV R16,R22
00FA DFE7 RCALL _LCD_set_xy
00FB C005 RJMP 0x0101
(0131) while (*s) // 写显示字符
(0132) {
(0133) LCD_write_data( *s );
00FC 01FA MOVW R30,R20
00FD 8100 LDD R16,Z+0
00FE DFC3 RCALL _LCD_write_data
(0134) s ++;
00FF 5F4F SUBI R20,0xFF
0100 4F5F SBCI R21,0xFF
0101 01FA MOVW R30,R20
0102 8020 LDD R2,Z+0
0103 2022 TST R2
0104 F7B9 BNE 0x00FC
0105 940E0203 CALL pop_gset3
0107 9508 RET
_LCD_write_char:
data --> Y+4
Y --> R22
X --> R20
0108 940E020C CALL push_gset2
010A 2F62 MOV R22,R18
010B 2F40 MOV R20,R16
(0135) }
(0136)
(0137) }
(0138)
(0139) /*----------------------------------------------------------------------------*/
(0140) void LCD_write_char(unsigned char X,unsigned char Y,unsigned char data) //列x=0~15,行y=0,1
(0141) {
(0142) LCD_set_xy( X, Y ); //写地址
010C 2F26 MOV R18,R22
010D 2F04 MOV R16,R20
010E DFD3 RCALL _LCD_set_xy
(0143) LCD_write_data( data);
010F 810C LDD R16,Y+4
0110 DFB1 RCALL _LCD_write_data
0111 940E0200 CALL pop_gset2
0113 9508 RET
(0144)
(0145) }
(0146)
(0147)
(0148)
(0149)
(0150)
(0151)
(0152)
(0153) /////////////////////////////////////////
(0154) void delay(uint x) //1.5us左右
(0155) {
_delay:
x --> R16
0114 C002 RJMP 0x0117
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -