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

📄 ds1302_mega16.s

📁 这是一个用温度计和时钟程序,芯片是ATmega16,电路稳定,绝对好用而且易懂
💻 S
📖 第 1 页 / 共 4 页
字号:
	.module DS1302_Mega16.c
	.area text(rom, con, rel)
	.dbfile E:\MyDesign\ICCAVR\ATmega16_DEV\DS1302\DS1302_Mega16.c
	.dbfile E:\MyDesign\ICCAVR\ATmega16_DEV\DS1302\LCD_1602_4wires.h
	.dbfunc e LCD_init _LCD_init fV
	.even
_LCD_init::
	.dbline -1
	.dbline 51
; /*============================================================
; 工程:字符型液晶通用六线驱动
; 作者:朱海峰		
; 日期:2007.02.28
; E_mail:ntzhf100@163.com
; 液晶指令说明:
; 0x08==============>关闭显示
; 0x0c==============>开显示
; 0x01==============>清除LCD的显示内容
; 0x06==============>移动光标
; 0x0c==============>显示开,光标关
; 0x28==============>16*2显示,5*7点阵,4位数据
; 0x1c==============>字符右移一格
; 0x18==============>字符左移一格
; 0x10==============>光标右移一格
; 0x14==============>光标左移一格
; 显示地址:
; ===============================================================
; =0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 ................ 0x27=
; =0x40 0x41 0x42 0x43 0x44 0x45 0x46 0x47 ................ 0x67=
; ===============================================================
; 每行可以显示40个字符,可以看到的只有16个字符,可以通过指令使字符
; 整体移动来显示所有字符。
; LCD_write_byte函数功能:当cmd=0时,向LCD写入数据,否则向LCD写
;                    入命令
; 四线控制的方式:先送字节的高四位,在送低四位。
; 值得注意的是当使用的I/O口为高四位时数据先给另一个变量,变量再将
; 数据高四位送到I/O口,接着是将变量左移四位,再送到I/O口上去。
; 当使用的I/O口为低四位时数据先给另一个变量,变量右移四位后送到I/O
; 口上去,接着将数据给变量直接送入I/O口。
; 使用时注意一下。
; ============================================================*/
; #include <iom16v.h>
; #include <macros.h>
; #include "def.h"
; /*-----------------------------------------------------
; Public function prototypes
; -------------------------------------------------------*/
; void LCD_init         		(void);
; void LCD_write_byte         (uint8_t cmd,uint8_t data);
; void LCD_Write_half_byte    (void);
; void LCD_set_xy             (uint8_t x, uint8_t y);
; void LCD_write_string       (uint8_t X,uint8_t Y,uint8_t *s);
; void Move					(uint8_t step,uint8_t dirction,uint16_t time);
; void Flash_lcd				(uint16_t delay_t,uint8_t times);
; void Delay_nms				(uint16_t ms);
; 
; uint8_t data_temp;
; //==================================================
; void LCD_init(void)
;   {
	.dbline 52
; 	Delay_nms(50);                 
	ldi R16,50
	ldi R17,0
	xcall _Delay_nms
	.dbline 53
;     Delay_nms(1); 
	ldi R16,1
	ldi R17,0
	xcall _Delay_nms
	.dbline 54
;     LCD_write_byte(1,0x28); 	  //4bit test    显示模式设置(不检测忙信号) 
	ldi R18,40
	ldi R16,1
	xcall _LCD_write_byte
	.dbline 55
;     Delay_nms(1);  
	ldi R16,1
	ldi R17,0
	xcall _Delay_nms
	.dbline 56
;     LCD_write_byte(1,0x08);         // 显示关闭 
	ldi R18,8
	ldi R16,1
	xcall _LCD_write_byte
	.dbline 57
;     Delay_nms(1); 
	ldi R16,1
	ldi R17,0
	xcall _Delay_nms
	.dbline 58
;     LCD_write_byte(1,0x01);         // 显示清屏 
	ldi R18,1
	ldi R16,1
	xcall _LCD_write_byte
	.dbline 59
;     Delay_nms(1); 
	ldi R16,1
	ldi R17,0
	xcall _Delay_nms
	.dbline 60
;     LCD_write_byte(1,0x06);         // 显示光标移动设置 
	ldi R18,6
	ldi R16,1
	xcall _LCD_write_byte
	.dbline 61
;     Delay_nms(1); 
	ldi R16,1
	ldi R17,0
	xcall _Delay_nms
	.dbline 62
;     LCD_write_byte(1,0x0C);         // 显示开及光标设置 
	ldi R18,12
	ldi R16,1
	xcall _LCD_write_byte
	.dbline 63
;     Delay_nms(10);
	ldi R16,10
	ldi R17,0
	xcall _Delay_nms
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e LCD_write_byte _LCD_write_byte fV
;           data -> R10
;            cmd -> R20
	.even
_LCD_write_byte::
	st -y,R10
	st -y,R20
	mov R10,R18
	mov R20,R16
	.dbline -1
	.dbline 71
;   }
; /*--------------------------------------------------
; LCD_write_byte    : 英文字符显示函数
; 输入参数:*s      :英文字符串指针;
;           X、Y    : 显示字符串的位置,X:1-16,Y:1-2 		
; ---------------------------------------------------*/
; void LCD_write_byte(uint8_t cmd,uint8_t data)
;   {       
	.dbline 72
;     if (cmd==1)
	cpi R20,1
	brne L3
X0:
	.dbline 73
; 	{
	.dbline 74
; 	   CLR_RS();
	cbi 0x1b,2
	.dbline 75
; 	}
L3:
	.dbline 76
; 	if (cmd==0)
	tst R20
	brne L5
X1:
	.dbline 77
; 	{
	.dbline 78
; 	   SET_RS();
	sbi 0x1b,2
	.dbline 79
; 	}
L5:
	.dbline 80
; 	data_temp=data;
	sts _data_temp,R10
	.dbline 81
; 	data_temp=data_temp>>4;
	mov R24,R10
	swap R24
	andi R24,#0x0F
	sts _data_temp,R24
	.dbline 82
;     LCD_Write_half_byte();
	xcall _LCD_Write_half_byte
	.dbline 83
; 	data_temp=data;
	sts _data_temp,R10
	.dbline 84
;     LCD_Write_half_byte();
	xcall _LCD_Write_half_byte
	.dbline 85
; 	Delay_nms(1);	 
	ldi R16,1
	ldi R17,0
	xcall _Delay_nms
	.dbline -2
L2:
	.dbline 0 ; func end
	ld R20,y+
	ld R10,y+
	ret
	.dbsym r data 10 c
	.dbsym r cmd 20 c
	.dbend
	.dbfunc e LCD_Write_half_byte _LCD_Write_half_byte fV
	.even
_LCD_Write_half_byte::
	.dbline -1
	.dbline 89
;   }
; /*----------------写高4bit到LCD------------------------*/
; void LCD_Write_half_byte(void)
;   {  
	.dbline 90
;   	 LCD_DATA_PORT&=0xf0;	  //pc0~pc3=0
	in R24,0x18
	andi R24,240
	out 0x18,R24
	.dbline 91
;    	 LCD_DATA_PORT=data_temp;//send high 4bit
	lds R2,_data_temp
	out 0x18,R2
	.dbline 92
; 	 SET_EN();
	sbi 0x1b,3
	.dbline 93
; 	 NOP();
	nop
	.dbline 94
; 	 CLR_EN(); 
	cbi 0x1b,3
	.dbline 95
; 	 NOP();
	nop
	.dbline -2
L7:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e LCD_set_xy _LCD_set_xy fV
;        address -> R20
;              y -> R20
;              x -> R22
	.even
_LCD_set_xy::
	xcall push_xgsetF000
	mov R20,R18
	mov R22,R16
	.dbline -1
	.dbline 103
;    }
; 
; /*----------------------------------------------------
; LCD_set_xy        : 设置LCD显示的起始位置
; 输入参数:x、y    : 显示字符串的位置,X:1-16,Y:1-2		
; -----------------------------------------------------*/
; void LCD_set_xy( uint8_t x, uint8_t y )
;   {
	.dbline 105
;     unsigned char address;
;     if (y==1) 
	cpi R20,1
	brne L9
X2:
	.dbline 106
; 	{
	.dbline 107
; 	   address=0x80-1+x;
	mov R20,R22
	subi R20,129    ; addi 127
	.dbline 108
; 	}
	xjmp L10
L9:
	.dbline 110
;     else 
;     {
	.dbline 111
; 	   address=0xc0-1+x;
	mov R20,R22
	subi R20,65    ; addi 191
	.dbline 112
; 	}
L10:
	.dbline 113
;     LCD_write_byte(1,address);
	mov R18,R20
	ldi R16,1
	xcall _LCD_write_byte
	.dbline -2
L8:
	.dbline 0 ; func end
	xjmp pop_xgsetF000
	.dbsym r address 20 c
	.dbsym r y 20 c
	.dbsym r x 22 c
	.dbend
	.dbfunc e LCD_write_string _LCD_write_string fV
;              s -> R20,R21
;              Y -> R12
;              X -> R10
	.even
_LCD_write_string::
	xcall push_xgset303C
	mov R12,R18
	mov R10,R16
	ldd R20,y+6
	ldd R21,y+7
	.dbline -1
	.dbline 121
;   }
; /*---------------------------------------------------
; LCD_write_string  : 英文字符串显示函数
; 输入参数:*s      :英文字符串指针;
;           X、Y    : 显示字符串的位置		
; ---------------------------------------------------*/
; void LCD_write_string(uint8_t X,uint8_t Y,uint8_t *s)
;   {
	.dbline 122
;     LCD_set_xy( X, Y );   
	mov R18,R12
	mov R16,R10
	xcall _LCD_set_xy
	xjmp L13
L12:
	.dbline 124
;     while (*s) 
;       {
	.dbline 125
;         LCD_write_byte(0,*s);
	movw R30,R20
	ldd R18,z+0
	clr R16
	xcall _LCD_write_byte
	.dbline 126
; 		s++;
	subi R20,255  ; offset = 1
	sbci R21,255
	.dbline 127
;       }
L13:
	.dbline 123
	movw R30,R20
	ldd R2,z+0
	tst R2
	brne L12
X3:
	.dbline -2
L11:
	.dbline 0 ; func end
	xjmp pop_xgset303C
	.dbsym r s 20 pc
	.dbsym r Y 12 c
	.dbsym r X 10 c
	.dbend
	.dbfunc e Move _Move fV
;              i -> R10
;           time -> y+6
;       dirction -> R12
;           step -> R20
	.even
_Move::
	xcall push_xgset303C
	mov R12,R18
	mov R20,R16
	.dbline -1
	.dbline 131
;   }
; //=======================================================
; void Move(uint8_t step,uint8_t dirction,uint16_t time)
; {
	.dbline 133
;  	 uint8_t i;
; 	 for(i=0;i<step-1;i++)
	clr R10
	xjmp L19
L16:
	.dbline 134
; 	 {
	.dbline 135
; 	  	 LCD_write_byte(1,dirction);      //字符移动方向                                    
	mov R18,R12
	ldi R16,1
	xcall _LCD_write_byte
	.dbline 136
;          Delay_nms(time);                //控制移动时间
	ldd R16,y+6
	ldd R17,y+7
	xcall _Delay_nms
	.dbline 137
; 	 }
L17:
	.dbline 133
	inc R10
L19:
	.dbline 133
	mov R24,R20
	subi R24,1
	cp R10,R24
	brlo L16
X4:
	.dbline -2
L15:
	.dbline 0 ; func end
	xjmp pop_xgset303C
	.dbsym r i 10 c
	.dbsym l time 6 i
	.dbsym r dirction 12 c
	.dbsym r step 20 c
	.dbend
	.dbfunc e Flash_lcd _Flash_lcd fV
;              j -> R10
;          times -> R14
;        delay_t -> R12,R13
	.even
_Flash_lcd::
	xcall push_xgset00FC
	mov R14,R18
	movw R12,R16
	.dbline -1
	.dbline 141
; }
; //=========================================================
; void Flash_lcd(uint16_t delay_t,uint8_t times)
; {
	.dbline 143
;  	 uint8_t j;
; 	 for(j=0;j<times;j++)
	clr R10
	xjmp L24
L21:
	.dbline 144
; 	 {
	.dbline 145
; 	  	LCD_write_byte(1,0x08);
	ldi R18,8
	ldi R16,1
	xcall _LCD_write_byte
	.dbline 146
; 		Delay_nms(delay_t);
	movw R16,R12
	xcall _Delay_nms
	.dbline 147
; 		LCD_write_byte(1,0x0c);
	ldi R18,12
	ldi R16,1
	xcall _LCD_write_byte
	.dbline 148
; 		Delay_nms(delay_t);
	movw R16,R12
	xcall _Delay_nms
	.dbline 149
; 	 }
L22:
	.dbline 143
	inc R10
L24:
	.dbline 143
	cp R10,R14
	brlo L21
X5:
	.dbline -2
L20:
	.dbline 0 ; func end
	xjmp pop_xgset00FC
	.dbsym r j 10 c
	.dbsym r times 14 c
	.dbsym r delay_t 12 i
	.dbend
	.dbfunc e Delay_nms _Delay_nms fV
;              i -> R20,R21
;             ms -> R16,R17
	.even
_Delay_nms::
	st -y,R20
	st -y,R21
	.dbline -1
	.dbline 153
; }
; //========================================================
; void Delay_nms(uint16_t ms) 
; { 
	xjmp L27
L26:
	.dbline 156
;     uint16_t i; 
;     while(ms--)    
;    { 
	.dbline 157
;      for(i=1;i<(uint16_t)(xtal*143-2);i++) 
	ldi R20,1
	ldi R21,0
	xjmp L32
L29:
	.dbline 158
;          ; 
L30:
	.dbline 157
	subi R20,255  ; offset = 1
	sbci R21,255
L32:
	.dbline 157
	ldi R24,1142
	ldi R25,4
	cp R20,R24
	cpc R21,R25
	brlo L29
X6:
	.dbline 159
;    }   
L27:
	.dbline 155
	movw R2,R16
	subi R16,1
	sbci R17,0
	tst R2
	brne L26
	tst R3
	brne L26
X7:
	.dbline -2
L25:
	.dbline 0 ; func end
	ld R21,y+
	ld R20,y+
	ret
	.dbsym r i 20 i
	.dbsym r ms 16 i
	.dbend
	.dbfile E:\MyDesign\ICCAVR\ATmega16_DEV\DS1302\DS18B20.h
	.dbfunc e Temp_display _Temp_display fV
	.area  func_lit(rom, con, rel)
L69:
	.word `L37
	.word `L39
	.word `L41
	.word `L43
	.word `L45
	.word `L47
	.word `L49
	.word `L51
	.word `L53
	.word `L55
	.word `L57
	.word `L59
	.word `L61
	.word `L63
	.word `L65
	.word `L67
	.area text(rom, con, rel)
;   temp_decimal -> R20
;       temp_num -> R12
;         temp_l -> R22
;         temp_h -> R10
;             Th -> R22
;             Tl -> R12
	.even
_Temp_display::
	xcall push_xgsetF03C
	mov R22,R18
	mov R12,R16
	sbiw R28,2
	.dbline -1
	.dbline 18
; /**************************************************
; *Progect: Temperature measure with DS18B20
; */
; #include <iom16v.h>
; #include <macros.h>
; #include "def.h"
; 
; void Delay_us(uint16_t us);
; uint8_t Init_18b20(void);
; uint8_t Read_1_byte(void);
; void Write_1_byte(uint8_t cmd);
; void Write_1(void);
; void Write_0(void);
; void Temperature(uint8_t Th,uint8_t Tl);
; void Temp_display(uint8_t Tl,uint8_t Th);
; /*************************************************/
; void Temp_display(uint8_t Tl,uint8_t Th)
; {
	.dbline 20
;  	 	uint8_t temp_h,temp_l,temp_num,temp_decimal;
; 		temp_decimal=Tl;
	mov R20,R12
	.dbline 21
; 		temp_h=Th<<4;
	mov R24,R22
	andi R24,#0x0F
	swap R24
	.dbline 22
; 		temp_l=Tl>>4;
	mov R22,R12
	swap R22
	andi R22,#0x0F
	.dbline 23
; 		temp_num=(temp_h|temp_l);
	mov R12,R24
	or R12,R22
	.dbline 24
; 		temp_decimal&=0x0f;
	andi R20,15
	.dbline 25
; 		temp_h=(temp_num/10);
	ldi R17,10
	mov R16,R12
	xcall div8u
	mov R10,R16
	.dbline 26
; 		temp_l=(temp_num%10);
	ldi R17,10
	mov R16,R12
	xcall mod8u
	mov R22,R16
	.dbline 27
; 		LCD_write_byte(0,temp_h+48);
	mov R18,R10
	subi R18,208    ; addi 48
	clr R16
	xcall _LCD_write_byte
	.dbline 28
; 		LCD_write_byte(0,temp_l+48);
	mov R18,R22
	subi R18,208    ; addi 48
	clr R16
	xcall _LCD_write_byte
	.dbline 29
; 		switch(temp_decimal)
	clr R21
	cpi R20,0
	ldi R30,0
	cpc R21,R30
	brge X11
	xjmp L34
X11:
X8:
	ldi R24,15
	ldi R25,0
	cp R24,R20
	cpc R25,R21
	brge X12
	xjmp L34
X12:
X9:
	ldi R24,<L69
	ldi R25,>L69
	movw R30,R20
	lsl R30
	rol R31
	add R30,R24
	adc R31,R25
	lpm R2,Z+
	lpm R3,Z
	movw R30,R2
	 ijmp
X10:
	.dbfile E:\MyDesign\ICCAVR\ATmega16_DEV\DS1302\DS18B20.h
	.dbline 30
; 		{
L37:
	.dbline 31
; 		 	case 0  : LCD_write_string(12,2,".00");break;
	ldi R24,<L38
	ldi R25,>L38
	std y+1,R25
	std y+0,R24
	ldi R18,2
	ldi R16,12

⌨️ 快捷键说明

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