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

📄 ds18b20.lst

📁 利用AVRM16和DX18B20温度传感器通信
💻 LST
📖 第 1 页 / 共 4 页
字号:
__text_start:
__start:
    003D E5CF      LDI	R28,0x5F
    003E E0D4      LDI	R29,4
    003F BFCD      OUT	0x3D,R28
    0040 BFDE      OUT	0x3E,R29
    0041 51C0      SUBI	R28,0x10
    0042 40D0      SBCI	R29,0
    0043 EA0A      LDI	R16,0xAA
    0044 8308      STD	Y+0,R16
    0045 2400      CLR	R0
    0046 E6E8      LDI	R30,0x68
    0047 E0F0      LDI	R31,0
    0048 E010      LDI	R17,0
    0049 36E8      CPI	R30,0x68
    004A 07F1      CPC	R31,R17
    004B F011      BEQ	0x004E
    004C 9201      ST	R0,Z+
    004D CFFB      RJMP	0x0049
    004E 8300      STD	Z+0,R16
    004F E7E2      LDI	R30,0x72
    0050 E0F0      LDI	R31,0
    0051 E6A0      LDI	R26,0x60
    0052 E0B0      LDI	R27,0
    0053 E010      LDI	R17,0
    0054 37EA      CPI	R30,0x7A
    0055 07F1      CPC	R31,R17
    0056 F021      BEQ	0x005B
    0057 95C8      LPM
    0058 9631      ADIW	R30,1
    0059 920D      ST	R0,X+
    005A CFF9      RJMP	0x0054
    005B 940E0279  CALL	_main
_exit:
    005D CFFF      RJMP	_exit
FILE: E:\单片机\AVR程序\温度传感器\1820.c
(0001) 
(0002)  #include <iom16v.h>
(0003)     #include <macros.h>
(0004) 
(0005) #define LCD_RS_PORT    PORTA  //以下2个要设为同一个口,4脚
(0006) #define LCD_RS_DDR     DDRA
(0007) #define LCD_RW_PORT    PORTA //以下2个要设为同一个口,5脚
(0008) #define LCD_RW_DDR     DDRA
(0009) #define LCD_EN_PORT    PORTA //以下2个要设为同一个口,6脚
(0010) #define LCD_EN_DDR     DDRA
(0011) 
(0012) 
(0013) #define LCD_DATA_PORT  PORTA  //以下3个要设为同一个口
(0014) #define LCD_DATA_DDR   DDRA    //一定要用高4位
(0015) #define LCD_DATA_PIN   PINA
(0016) 
(0017) 
(0018) #define LCD_RS         (1<<PA1) //
(0019) #define LCD_RW         (1<<PA2)
(0020) #define LCD_EN         (1<<PA3) //
(0021) #define LCD_DATA       ((1<<PA4)|(1<<PA5)|(1<<PA6)|(1<<PA7)) //
(0022) 
(0023) 
(0024) /*--------------------------------------------------------------------------------------------------
(0025)                                   液晶函数说明
(0026) --------------------------------------------------------------------------------------------------*/
(0027) void LCD_init(void);
(0028) void LCD_en_write(void);
(0029) void LCD_write_command(unsigned  char command) ;
(0030) void LCD_write_data(unsigned char data);
(0031) void LCD_set_xy (unsigned char x, unsigned char y);
(0032) void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s);
(0033) void LCD_write_char(unsigned char X,unsigned char Y,unsigned char data);
(0034) void delay_nus(unsigned int n);
(0035) void delay_nms(unsigned int n);
(0036) 
(0037) /*--------------------------------------------------------------------------------------------------
(0038)                                   液晶驱动程序
(0039) --------------------------------------------------------------------------------------------------*/
(0040)   
(0041) void LCD_init(void)         //液晶初始化
(0042) {
(0043)   LCD_DATA_DDR|=LCD_DATA;   //数据口方向为输出
_LCD_init:
    005E B38A      IN	R24,0x1A
    005F 6F80      ORI	R24,0xF0
    0060 BB8A      OUT	0x1A,R24
(0044)   LCD_EN_DDR|=LCD_EN;       //设置EN方向为输出
    0061 9AD3      SBI	0x1A,3
(0045)   LCD_RS_DDR|=LCD_RS;       //设置RS方向为输出
    0062 9AD1      SBI	0x1A,1
(0046)   
(0047)   LCD_RW_DDR|=LCD_RW;////////////////////////////////////
    0063 9AD2      SBI	0x1A,2
(0048)   LCD_RW_PORT&=~LCD_RW;/////////////////////////////////
    0064 98DA      CBI	0x1B,2
(0049)   
(0050)   LCD_write_command(0x28); 
    0065 E208      LDI	R16,0x28
    0066 D017      RCALL	_LCD_write_command
(0051)   LCD_en_write();
    0067 D00D      RCALL	_LCD_en_write
(0052)   delay_nus(40);
    0068 E208      LDI	R16,0x28
    0069 E010      LDI	R17,0
    006A D1DC      RCALL	_delay_nus
(0053)   LCD_write_command(0x28);  //4位显示
    006B E208      LDI	R16,0x28
    006C D011      RCALL	_LCD_write_command
(0054)   LCD_write_command(0x0c);  //显示开
    006D E00C      LDI	R16,0xC
    006E D00F      RCALL	_LCD_write_command
(0055)   LCD_write_command(0x01);  //清屏
    006F E001      LDI	R16,1
    0070 D00D      RCALL	_LCD_write_command
(0056)   delay_nms(10);
    0071 E00A      LDI	R16,0xA
    0072 E010      LDI	R17,0
    0073 D1EC      RCALL	_delay_nms
    0074 9508      RET
(0057)  
(0058) }
(0059) 
(0060) void LCD_en_write(void)  //液晶使能
(0061) {
(0062)   LCD_EN_PORT|=LCD_EN;
_LCD_en_write:
    0075 9ADB      SBI	0x1B,3
(0063)   delay_nus(1);
    0076 E001      LDI	R16,1
    0077 E010      LDI	R17,0
    0078 D1CE      RCALL	_delay_nus
(0064)   LCD_EN_PORT&=~LCD_EN;
    0079 98DB      CBI	0x1B,3
(0065)   delay_nus(1);
    007A E001      LDI	R16,1
    007B E010      LDI	R17,0
    007C D1CA      RCALL	_delay_nus
    007D 9508      RET
_LCD_write_command:
  command              --> R20
    007E 940E02D6  CALL	push_gset1
    0080 2F40      MOV	R20,R16
(0066)   
(0067) }
(0068) 
(0069) void LCD_write_command(unsigned char command) 
(0070) //_write_command(0x0b)不显示
(0071) //LCD_write_command(0x0c)开显示
(0072) //LCD_write_command(0x0d)开显示闪且闪
(0073) //LCD_write_command(0x0e)开显示闪且不闪
(0074) {
(0075)   delay_nus(16);
    0081 E100      LDI	R16,0x10
    0082 E010      LDI	R17,0
    0083 D1C3      RCALL	_delay_nus
(0076)   LCD_RS_PORT&=~LCD_RS;        //RS=0
    0084 98D9      CBI	0x1B,1
(0077)   LCD_DATA_PORT&=0X0f;         //清高四位
    0085 B38B      IN	R24,0x1B
    0086 708F      ANDI	R24,0xF
    0087 BB8B      OUT	0x1B,R24
(0078)   LCD_DATA_PORT|=command&0xf0; //写高四位
    0088 2F84      MOV	R24,R20
    0089 7F80      ANDI	R24,0xF0
    008A B22B      IN	R2,0x1B
    008B 2A28      OR	R2,R24
    008C BA2B      OUT	0x1B,R2
(0079)   LCD_en_write();
    008D DFE7      RCALL	_LCD_en_write
(0080)   command=command<<4;          //低四位移到高四位
    008E 2F84      MOV	R24,R20
    008F 708F      ANDI	R24,0xF
    0090 9582      SWAP	R24
    0091 2F48      MOV	R20,R24
(0081)   LCD_DATA_PORT&=0x0f;         //清高四位
    0092 B38B      IN	R24,0x1B
    0093 708F      ANDI	R24,0xF
    0094 BB8B      OUT	0x1B,R24
(0082)   LCD_DATA_PORT|=command&0xf0; //写低四位
    0095 2F84      MOV	R24,R20
    0096 7F80      ANDI	R24,0xF0
    0097 B22B      IN	R2,0x1B
    0098 2A28      OR	R2,R24
    0099 BA2B      OUT	0x1B,R2
(0083)   LCD_en_write();
    009A DFDA      RCALL	_LCD_en_write
    009B 940E02D9  CALL	pop_gset1
    009D 9508      RET
_LCD_write_data:
  data                 --> R20
    009E 940E02D6  CALL	push_gset1
    00A0 2F40      MOV	R20,R16
(0084)   
(0085) }
(0086) 
(0087) void LCD_write_data(unsigned char data) //写数据
(0088) {
(0089)   delay_nus(16);
    00A1 E100      LDI	R16,0x10
    00A2 E010      LDI	R17,0
    00A3 D1A3      RCALL	_delay_nus
(0090)   LCD_RS_PORT|=LCD_RS;       //RS=1
    00A4 9AD9      SBI	0x1B,1
(0091)   LCD_DATA_PORT&=0X0f;       //清高四位
    00A5 B38B      IN	R24,0x1B
    00A6 708F      ANDI	R24,0xF
    00A7 BB8B      OUT	0x1B,R24
(0092)   LCD_DATA_PORT|=data&0xf0;  //写高四位
    00A8 2F84      MOV	R24,R20
    00A9 7F80      ANDI	R24,0xF0
    00AA B22B      IN	R2,0x1B
    00AB 2A28      OR	R2,R24
    00AC BA2B      OUT	0x1B,R2
(0093)   LCD_en_write();
    00AD DFC7      RCALL	_LCD_en_write
(0094)   data=data<<4;               //低四位移到高四位
    00AE 2F84      MOV	R24,R20
    00AF 708F      ANDI	R24,0xF
    00B0 9582      SWAP	R24
    00B1 2F48      MOV	R20,R24
(0095)   LCD_DATA_PORT&=0X0f;        //清高四位
    00B2 B38B      IN	R24,0x1B
    00B3 708F      ANDI	R24,0xF
    00B4 BB8B      OUT	0x1B,R24
(0096)   LCD_DATA_PORT|=data&0xf0;   //写低四位
    00B5 2F84      MOV	R24,R20
    00B6 7F80      ANDI	R24,0xF0
    00B7 B22B      IN	R2,0x1B
    00B8 2A28      OR	R2,R24
    00B9 BA2B      OUT	0x1B,R2
(0097)   LCD_en_write();
    00BA DFBA      RCALL	_LCD_en_write
    00BB 940E02D9  CALL	pop_gset1
    00BD 9508      RET
_LCD_set_xy:
  address              --> R20
  y                    --> R20
  x                    --> R22
    00BE 940E02D4  CALL	push_gset2
    00C0 2F42      MOV	R20,R18
    00C1 2F60      MOV	R22,R16
(0098)   
(0099) }
(0100) 
(0101) 
(0102) void LCD_set_xy( unsigned char x, unsigned char y )  //写地址函数
(0103) {
(0104)     unsigned char address;
(0105)     if (y == 0) address = 0x80 + x;
    00C2 2344      TST	R20
    00C3 F419      BNE	0x00C7
    00C4 2F46      MOV	R20,R22
    00C5 5840      SUBI	R20,0x80
    00C6 C002      RJMP	0x00C9
(0106)     else   address = 0xc0 + x;
    00C7 2F46      MOV	R20,R22
    00C8 5440      SUBI	R20,0x40
(0107)     LCD_write_command( address);
    00C9 2F04      MOV	R16,R20
    00CA DFB3      RCALL	_LCD_write_command
    00CB 940E02C5  CALL	pop_gset2
    00CD 9508      RET
_LCD_write_string:
  s                    --> R20
  Y                    --> R10
  X                    --> R22
    00CE 940E02D2  CALL	push_gset3
    00D0 2EA2      MOV	R10,R18
    00D1 2F60      MOV	R22,R16
    00D2 814E      LDD	R20,Y+6
    00D3 815F      LDD	R21,Y+7
(0108) 	
(0109) }
(0110)   
(0111) void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s) //列x=0~15,行y=0,1
(0112) {
(0113)     LCD_set_xy( X, Y ); //写地址    
    00D4 2D2A      MOV	R18,R10
    00D5 2F06      MOV	R16,R22
    00D6 DFE7      RCALL	_LCD_set_xy
    00D7 C005      RJMP	0x00DD
(0114)     while (*s)  // 写显示字符
(0115)     {
(0116)       LCD_write_data( *s );
    00D8 01FA      MOVW	R30,R20
    00D9 8100      LDD	R16,Z+0
    00DA DFC3      RCALL	_LCD_write_data
(0117)       s ++;
    00DB 5F4F      SUBI	R20,0xFF
    00DC 4F5F      SBCI	R21,0xFF
    00DD 01FA      MOVW	R30,R20
    00DE 8020      LDD	R2,Z+0
    00DF 2022      TST	R2
    00E0 F7B9      BNE	0x00D8
    00E1 940E02C8  CALL	pop_gset3
    00E3 9508      RET
_LCD_write_char:
  data                 --> Y+4
  Y                    --> R22
  X                    --> R20
    00E4 940E02D4  CALL	push_gset2
    00E6 2F62      MOV	R22,R18
    00E7 2F40      MOV	R20,R16
(0118)     }
(0119)    
(0120) }
(0121) 
(0122) void LCD_write_char(unsigned char X,unsigned char Y,unsigned char data) //列x=0~15,行y=0,1
(0123) {
(0124)   LCD_set_xy( X, Y ); //写地址
    00E8 2F26      MOV	R18,R22
    00E9 2F04      MOV	R16,R20
    00EA DFD3      RCALL	_LCD_set_xy
(0125)   LCD_write_data( data);
    00EB 810C      LDD	R16,Y+4
    00EC DFB1      RCALL	_LCD_write_data
    00ED 940E02C5  CALL	pop_gset2
    00EF 9508      RET
(0126)    
(0127) }
(0128) 
(0129) /*--------------------------------------------------------------------------------------------------
(0130)                                   液晶驱动程序
(0131) --------------------------------------------------------------------------------------------------*/
(0132) 
(0133) 
(0134) 
(0135) 
(0136) 
(0137) 
(0138) 
(0139) #define uchar	unsigned char
(0140) #define uint	unsigned int
(0141) #define ulong	unsigned long
(0142) /******************************************************************************
(0143)                          //全局变量
(0144) ******************************************************************************/
(0145) 
(0146) 
(0147) 
(0148) /******************************************************************************
(0149)                           DS18B20驱动程序
(0150) ******************************************************************************/
(0151) 
(0152) /********************************************************************************/
(0153) //                           下面为DS18B20温度传感模块                                     //
(0154) /********************************************************************************/
(0155) /********************************************************************************
(0156)                             	位变量操作宏定义
(0157) ********************************************************************************/
(0158) #define		BIT_SET(a,b)	a|=BIT(b)
(0159) #define		BIT_CLR(a,b)	a&=~BIT(b)
(0160) #define		BIT_INV(a,b)   	a^=BIT(b)
(0161) #define		BIT_STATUS(a,b) a&BIT(b)
(0162) /********************************************************************************
(0163)                             	DS18B20操作定义
(0164) ********************************************************************************/
(0165) #define		CLR_DS18B20		BIT_CLR(PORTB,PB1)		//数据线强制拉低
(0166) #define		SET_DS18B20		BIT_SET(PORTB,PB1)		//数据线强制拉高,上拉
(0167) #define		HLD_DS18B20		BIT_SET(DDRB,PB1)		//Mega16控制总线
(0168) #define		RLS_DS18B20		BIT_CLR(DDRB,PB1)   	 	//释放总线
(0169) #define		STU_DS18B20		BIT_STATUS(PINB,PB1)		//数据线的状态
(0170) 
(0171) 
(0172) /**********************************************************************
(0173) functionName: void delayUs(BYTE temp)
(0174) description :延时函数 晶振频率:7.3728MHZ
(0175) delayUs(1);	 	//2.71us
(0176) delayUs(2);	 	//3.53us
(0177) delayUs(4);	 	//5.15us
(0178) delayUs(8);	 	//8.41us
(0179) delayUs(16);	 	//14.92us
(0180) delayUs(32);	 	//27.94us
(0181) delayUs(64);	 	//53.98us
(0182) delayUs(128);	 	//106.07us
(0183) delayUs(255);		//209.42us
(0184) delayUs(18);	 	//16.55us
(0185) delayUs(34);	 	//29.57us
(0186) delayUs(35);	 	//30.38us
(0187) delayUs(100);	 	//83.28
(0188) _NOP();			//0.14us  
(0189) **********************************************************************/
(0190) void delayUs(unsigned char temp)
(0191) {
(0192)  	 while(temp--);
_delayUs:
  temp                 --> R16
    00F0 2E20      MOV	R2,R16
    00F1 2433      CLR	R3
    00F2 5001      SUBI	R16,1
    00F3 2022      TST	R2
    00F4 F7D9      BNE	0x00F0
    00F5 9508      RET
_resetDS18B20:
  errTime              --> R20
    00F6 940E02D6  CALL	push_gset1
(0193) }
(0194) 
(0195) /**********************************************************************
(0196) functionName: BYTE resetDS18B20(void)
(0197) description :DS18B20初始化1
(0198) **********************************************************************/
(0199) unsigned char resetDS18B20(void)
(0200) {
(0201) 	unsigned char errTime=0;
    00F8 2744      CLR	R20
(0202) 	RLS_DS18B20;		//释放总线
    00F9 98B9      CBI	0x17,1
(0203) 	_NOP();
    00FA 0000      NOP
(0204) 	HLD_DS18B20;		//Maga16控制总线
    00FB 9AB9      SBI	0x17,1
(0205) 	CLR_DS18B20;		//强制拉低
    00FC 98C1      CBI	0x18,1
(0206) 	delayUs(255);		//209.42us
    00FD EF0F      LDI	R16,0xFF
    00FE DFF1      RCALL	_delayUs

⌨️ 快捷键说明

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