📄 ds1820.lst
字号:
__text_start:
__start:
0034 E5CF LDI R28,0x5F
0035 E0D4 LDI R29,4
0036 BFCD OUT 0x3D,R28
0037 BFDE OUT 0x3E,R29
0038 51C0 SUBI R28,0x10
0039 40D0 SBCI R29,0
003A EA0A LDI R16,0xAA
003B 8308 STD Y+0,R16
003C 2400 CLR R0
003D E7E3 LDI R30,0x73
003E E0F0 LDI R31,0
003F E010 LDI R17,0
0040 37E4 CPI R30,0x74
0041 07F1 CPC R31,R17
0042 F011 BEQ 0x0045
0043 9201 ST R0,Z+
0044 CFFB RJMP 0x0040
0045 8300 STD Z+0,R16
0046 E5E4 LDI R30,0x54
0047 E0F0 LDI R31,0
0048 E6A0 LDI R26,0x60
0049 E0B0 LDI R27,0
004A E010 LDI R17,0
004B 36E7 CPI R30,0x67
004C 07F1 CPC R31,R17
004D F021 BEQ 0x0052
004E 95C8 LPM
004F 9631 ADIW R30,1
0050 920D ST R0,X+
0051 CFF9 RJMP 0x004B
0052 940E01F6 CALL _main
_exit:
0054 CFFF RJMP _exit
FILE: D:\avr\+++精华+++\+M16范例+\18b20\delay.h
(0001) /*-----------------------------------------------------------------------
(0002) 延时函数
(0003) 编译器:ICC-AVR v6.31A
(0004) 目标芯片 : M16
(0005) 时钟: 8.0000Mhz
(0006) -----------------------------------------------------------------------*/
(0007) #ifndef __delay_h
(0008) #define __delay_h
(0009) void delay_nus(unsigned int n);
(0010) void delay_nms(unsigned int n);
(0011) void delay_1us(void);
(0012) void delay_1ms(void) ;
(0013)
(0014) void delay_1us(void) //1us延时函数
(0015) {
(0016) asm("nop");
_delay_1us:
0055 0000 NOP
0056 9508 RET
_delay_nus:
i --> R20
n --> R22
0057 940E0252 CALL push_gset2
0059 01B8 MOVW R22,R16
(0017) }
(0018)
(0019) void delay_nus(unsigned int n) //N us延时函数
(0020) {
(0021) unsigned int i=0;
005A 2744 CLR R20
005B 2755 CLR R21
(0022) for (i=0;i<n;i++)
005C C003 RJMP 0x0060
(0023) delay_1us();
005D DFF7 RCALL _delay_1us
005E 5F4F SUBI R20,0xFF
005F 4F5F SBCI R21,0xFF
0060 1746 CP R20,R22
0061 0757 CPC R21,R23
0062 F3D0 BCS 0x005D
0063 940E0246 CALL pop_gset2
0065 9508 RET
(0024) }
(0025)
(0026) void delay_1ms(void) //1ms延时函数
(0027) {
(0028) unsigned int i;
(0029) for (i=0;i<1140;i++);
_delay_1ms:
i --> R16
0066 2700 CLR R16
0067 2711 CLR R17
0068 C002 RJMP 0x006B
0069 5F0F SUBI R16,0xFF
006A 4F1F SBCI R17,0xFF
006B 3704 CPI R16,0x74
006C E0E4 LDI R30,4
006D 071E CPC R17,R30
006E F3D0 BCS 0x0069
006F 9508 RET
_delay_nms:
i --> R20
n --> R22
0070 940E0252 CALL push_gset2
0072 01B8 MOVW R22,R16
(0030) }
(0031)
(0032) void delay_nms(unsigned int n) //N ms延时函数
(0033) {
(0034) unsigned int i=0;
0073 2744 CLR R20
0074 2755 CLR R21
(0035) for (i=0;i<n;i++)
0075 C003 RJMP 0x0079
(0036) delay_1ms();
0076 DFEF RCALL _delay_1ms
0077 5F4F SUBI R20,0xFF
0078 4F5F SBCI R21,0xFF
0079 1746 CP R20,R22
007A 0757 CPC R21,R23
007B F3D0 BCS 0x0076
007C 940E0246 CALL pop_gset2
007E 9508 RET
FILE: D:\avr\+++精华+++\+M16范例+\18b20\1602.h
(0001)
(0002) /* 用法:
(0003) LCD_init();
(0004) LCD_write_string(列,行,"字符串");
(0005) LCD_write_char(列,行,'字符');
(0006) ---------------------------------------------------------------
(0007) 下面是AVR与LCD连接信息
(0008) PC4 ->RS
(0009) PC5 ->EN
(0010) 地 ->RW
(0011) PC0 ->D4
(0012) PC1 ->D5
(0013) PC2 ->D6
(0014) PC3 ->D7
(0015) 要使用本驱动,改变下面配置信息即可
(0016) -----------------------------------------------------------------*/
(0017) #define LCD_EN_PORT PORTC //以下2个要设为同一个口
(0018) #define LCD_EN_DDR DDRC
(0019) #define LCD_RS_PORT PORTC //以下2个要设为同一个口
(0020) #define LCD_RS_DDR DDRC
(0021) #define LCD_DATA_PORT PORTA //以下3个要设为同一个口
(0022) #define LCD_DATA_DDR DDRA //默认情况下连线必须使用高四位端口,如果不是请注意修改
(0023) #define LCD_DATA_PIN PINA
(0024) #define LCD_RS (1<<PC6) //0x20 portC6 out
(0025) #define LCD_EN (1<<PC7) //0x40 portC7 out
(0026) #define LCD_DATA ((1<<PA4)|(1<<PA5)|(1<<PA6)|(1<<PA7)) //0xf0 portA 4/5/6/7 out
(0027) /*--------------------------------------------------------------------------------------------------
(0028) 函数说明
(0029) --------------------------------------------------------------------------------------------------*/
(0030) void LCD_init(void);
(0031) void LCD_en_write(void);
(0032) void LCD_write_command(unsigned char command) ;
(0033) void LCD_write_data(unsigned char data);
(0034) void LCD_set_xy (unsigned char x, unsigned char y);
(0035) void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s);
(0036) void LCD_write_char(unsigned char X,unsigned char Y,unsigned char data);
(0037)
(0038) //-----------------------------------------------------------------------------------------
(0039)
(0040) #include <macros.h>
(0041) #include "delay.h"
(0042)
(0043) void LCD_init(void) //液晶初始化
(0044) {
(0045) LCD_DATA_DDR|=LCD_DATA; //数据口方向为输出
_LCD_init:
007F B38A IN R24,0x1A
0080 6F80 ORI R24,0xF0
0081 BB8A OUT 0x1A,R24
(0046) LCD_EN_DDR|=LCD_EN; //设置EN方向为输出
0082 9AA7 SBI 0x14,7
(0047) LCD_RS_DDR|=LCD_RS; //设置RS方向为输出
0083 9AA6 SBI 0x14,6
(0048) LCD_write_command(0x28);
0084 E208 LDI R16,0x28
0085 D014 RCALL _LCD_write_command
(0049) LCD_en_write();
0086 D00D RCALL _LCD_en_write
(0050) delay_nus(40);
0087 E208 LDI R16,0x28
0088 E010 LDI R17,0
0089 DFCD RCALL _delay_nus
(0051) LCD_write_command(0x28); //4位显示
008A E208 LDI R16,0x28
008B D00E RCALL _LCD_write_command
(0052) LCD_write_command(0x0c); //显示开
008C E00C LDI R16,0xC
008D D00C RCALL _LCD_write_command
(0053) LCD_write_command(0x01); //清屏
008E E001 LDI R16,1
008F D00A RCALL _LCD_write_command
(0054) delay_nms(2);
0090 E002 LDI R16,2
0091 E010 LDI R17,0
0092 DFDD RCALL _delay_nms
0093 9508 RET
(0055)
(0056)
(0057)
(0058) }
(0059)
(0060) void LCD_en_write(void) //液晶使能
(0061) {
(0062) LCD_EN_PORT|=LCD_EN;
_LCD_en_write:
0094 9AAF SBI 0x15,7
(0063) delay_nus(1);
0095 E001 LDI R16,1
0096 E010 LDI R17,0
0097 DFBF RCALL _delay_nus
(0064) LCD_EN_PORT&=~LCD_EN;
0098 98AF CBI 0x15,7
0099 9508 RET
_LCD_write_command:
command --> R20
009A 940E0254 CALL push_gset1
009C 2F40 MOV R20,R16
(0065) }
(0066)
(0067) void LCD_write_command(unsigned char command) //写指令
(0068) {
(0069) //连线为高4位的写法
(0070) delay_nus(16);
009D E100 LDI R16,0x10
009E E010 LDI R17,0
009F DFB7 RCALL _delay_nus
(0071) LCD_RS_PORT&=~LCD_RS; //RS=0
00A0 98AE CBI 0x15,6
(0072) LCD_DATA_PORT&=0X0f; //清高四位
00A1 B38B IN R24,0x1B
00A2 708F ANDI R24,0xF
00A3 BB8B OUT 0x1B,R24
(0073) LCD_DATA_PORT|=command&0xf0; //写高四位
00A4 2F84 MOV R24,R20
00A5 7F80 ANDI R24,0xF0
00A6 B22B IN R2,0x1B
00A7 2A28 OR R2,R24
00A8 BA2B OUT 0x1B,R2
(0074) LCD_en_write();
00A9 DFEA RCALL _LCD_en_write
(0075) command=command<<4; //低四位移到高四位
00AA 2F84 MOV R24,R20
00AB 708F ANDI R24,0xF
00AC 9582 SWAP R24
00AD 2F48 MOV R20,R24
(0076) LCD_DATA_PORT&=0x0f; //清高四位
00AE B38B IN R24,0x1B
00AF 708F ANDI R24,0xF
00B0 BB8B OUT 0x1B,R24
(0077) LCD_DATA_PORT|=command&0xf0; //写低四位
00B1 2F84 MOV R24,R20
00B2 7F80 ANDI R24,0xF0
00B3 B22B IN R2,0x1B
00B4 2A28 OR R2,R24
00B5 BA2B OUT 0x1B,R2
(0078) LCD_en_write();
00B6 DFDD RCALL _LCD_en_write
00B7 940E0257 CALL pop_gset1
00B9 9508 RET
_LCD_write_data:
data --> R20
00BA 940E0254 CALL push_gset1
00BC 2F40 MOV R20,R16
(0079)
(0080) /*
(0081) //连线为低四位的写法
(0082) delay_nus(16);
(0083) LCD_RS_PORT&=~LCD_RS; //RS=0
(0084) LCD_DATA_PORT&=0xf0; //清高四位
(0085) LCD_DATA_PORT|=(command>>4)&0x0f; //写高四位
(0086) LCD_en_write();
(0087) LCD_DATA_PORT&=0xf0; //清高四位
(0088) LCD_DATA_PORT|=command&0x0f; //写低四位
(0089) LCD_en_write();
(0090) */
(0091)
(0092) }
(0093)
(0094) void LCD_write_data(unsigned char data) //写数据
(0095) {
(0096) //连线为高4位的写法
(0097) delay_nus(16);
00BD E100 LDI R16,0x10
00BE E010 LDI R17,0
00BF DF97 RCALL _delay_nus
(0098) LCD_RS_PORT|=LCD_RS; //RS=1
00C0 9AAE SBI 0x15,6
(0099) LCD_DATA_PORT&=0X0f; //清高四位
00C1 B38B IN R24,0x1B
00C2 708F ANDI R24,0xF
00C3 BB8B OUT 0x1B,R24
(0100) LCD_DATA_PORT|=data&0xf0; //写高四位
00C4 2F84 MOV R24,R20
00C5 7F80 ANDI R24,0xF0
00C6 B22B IN R2,0x1B
00C7 2A28 OR R2,R24
00C8 BA2B OUT 0x1B,R2
(0101) LCD_en_write();
00C9 DFCA RCALL _LCD_en_write
(0102) data=data<<4; //低四位移到高四位
00CA 2F84 MOV R24,R20
00CB 708F ANDI R24,0xF
00CC 9582 SWAP R24
00CD 2F48 MOV R20,R24
(0103) LCD_DATA_PORT&=0X0f; //清高四位
00CE B38B IN R24,0x1B
00CF 708F ANDI R24,0xF
00D0 BB8B OUT 0x1B,R24
(0104) LCD_DATA_PORT|=data&0xf0; //写低四位
00D1 2F84 MOV R24,R20
00D2 7F80 ANDI R24,0xF0
00D3 B22B IN R2,0x1B
00D4 2A28 OR R2,R24
00D5 BA2B OUT 0x1B,R2
(0105) LCD_en_write();
00D6 DFBD RCALL _LCD_en_write
00D7 940E0257 CALL pop_gset1
00D9 9508 RET
_LCD_set_xy:
address --> R20
y --> R20
x --> R22
00DA 940E0252 CALL push_gset2
00DC 2F42 MOV R20,R18
00DD 2F60 MOV R22,R16
(0106)
(0107) /*
(0108) //连线为低四位的写法
(0109) delay_nus(16);
(0110) LCD_RS_PORT|=LCD_RS; //RS=1
(0111) LCD_DATA_PORT&=0Xf0; //清高四位
(0112) LCD_DATA_PORT|=(data>>4)&0x0f; //写高四位
(0113) LCD_en_write();
(0114)
(0115) LCD_DATA_PORT&=0Xf0; //清高四位
(0116) LCD_DATA_PORT|=data&0x0f; //写低四位
(0117) LCD_en_write();
(0118) */
(0119)
(0120) }
(0121)
(0122)
(0123) void LCD_set_xy( unsigned char x, unsigned char y ) //写地址函数
(0124) {
(0125) unsigned char address;
(0126) if (y == 0) address = 0x80 + x;
00DE 2344 TST R20
00DF F419 BNE 0x00E3
00E0 2F46 MOV R20,R22
00E1 5840 SUBI R20,0x80
00E2 C002 RJMP 0x00E5
(0127) else address = 0xc0 + x;
00E3 2F46 MOV R20,R22
00E4 5440 SUBI R20,0x40
(0128) LCD_write_command( address);
00E5 2F04 MOV R16,R20
00E6 DFB3 RCALL _LCD_write_command
00E7 940E0246 CALL pop_gset2
00E9 9508 RET
_LCD_write_string:
s --> R20
Y --> R10
X --> R22
00EA 940E0250 CALL push_gset3
00EC 2EA2 MOV R10,R18
00ED 2F60 MOV R22,R16
00EE 814E LDD R20,Y+6
00EF 815F LDD R21,Y+7
(0129) }
(0130)
(0131) void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s) //列x=0~15,行y=0,1
(0132) {
(0133) LCD_set_xy( X, Y ); //写地址
00F0 2D2A MOV R18,R10
00F1 2F06 MOV R16,R22
00F2 DFE7 RCALL _LCD_set_xy
00F3 C005 RJMP 0x00F9
(0134) while (*s) // 写显示字符
(0135) {
(0136) LCD_write_data( *s );
00F4 01FA MOVW R30,R20
00F5 8100 LDD R16,Z+0
00F6 DFC3 RCALL _LCD_write_data
(0137) s ++;
00F7 5F4F SUBI R20,0xFF
00F8 4F5F SBCI R21,0xFF
00F9 01FA MOVW R30,R20
00FA 8020 LDD R2,Z+0
00FB 2022 TST R2
00FC F7B9 BNE 0x00F4
00FD 940E0249 CALL pop_gset3
00FF 9508 RET
_LCD_write_char:
data --> Y+4
Y --> R22
X --> R20
0100 940E0252 CALL push_gset2
0102 2F62 MOV R22,R18
0103 2F40 MOV R20,R16
(0138) }
(0139)
(0140) }
(0141)
(0142) void LCD_write_char(unsigned char X,unsigned char Y,unsigned char data) //列x=0~15,行y=0,1
(0143) {
(0144) LCD_set_xy( X, Y ); //写地址
0104 2F26 MOV R18,R22
0105 2F04 MOV R16,R20
0106 DFD3 RCALL _LCD_set_xy
(0145) LCD_write_data( data);
0107 810C LDD R16,Y+4
0108 DFB1 RCALL _LCD_write_data
0109 940E0246 CALL pop_gset2
010B 9508 RET
FILE: D:\avr\+++精华+++\+M16范例+\18b20\DS1820.h
(0001) /*
(0002) DS18B20操作模块,在1M环境下使用,如果不是要修改延时函数
(0003) */
(0004)
(0005) #include <iom16v.h>
(0006) #include <macros.h>
(0007)
(0008) #define DQ_IN DDRA &= ~(1 << PA3) /*设置输入*/
(0009) #define DQ_OUT DDRA |= (1 << PA3) /*设置输出*/
(0010) #define DQ_CLR PORTA &= ~(1 << PA3) /*置低电平*/
(0011) #define DQ_SET PORTA |= (1 << PA3) /*置高电平*/
(0012) #define DQ_R PINA & (1 << PA3) /*读了电平*/
(0013) #define delay4us {NOP();NOP();NOP();NOP();}
(0014) #define delay10us {NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();}
(0015) //--------函数声明----------------------
(0016) void ds1820_start(void);
(0017) unsigned char ds1820_reset(void);
(0018) unsigned int ds1820_read_temp(void);
(0019) void ds1820(void);
(0020) //--------------------------------------
(0021) unsigned char flag; /*中断标志缓存*/
(0022) unsigned char temp_1820[7]={0,0,0,'.',0,'C',0};//温度数据
(0023) /*
(0024) 延时函数
(0025)
(0026) 延时时间:i X 10 + 16uS。
(0027) CPU频率为:1MHz。
(0028) */
(0029) void delay_10us(unsigned char i) {
(0030)
(0031) if (i == 0) {
_delay_10us:
i --> R16
010C 2300 TST R16
010D F429 BNE 0x0113
(0032) return ;
010E C009 RJMP 0x0118
(0033) }
(0034) while (i--) {
(0035) delay4us;
010F 0000 NOP
0110 0000 NOP
0111 0000 NOP
0112 0000 NOP
0113 2E20 MOV R2,R16
0114 2433 CLR R3
0115 5001 SUBI R16,1
0116 2022 TST R2
0117 F7B9 BNE 0x010F
0118 9508 RET
_ds1820_reset:
i --> R20
0119 940E0254 CALL push_gset1
(0036) }
(0037) }
(0038)
(0039) /*DS18B20复位函数*/
(0040) unsigned char ds1820_reset(void) {
(0041)
(0042) unsigned char i;
(0043) flag = SREG; /*中断保护*/
011B B62F IN R2,0x3F
011C 92200073 STS flag,R2
(0044) CLI(); /*关中断*/
011E 94F8 BCLR 7
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -