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

📄 pcf8563_test.s

📁 pcf8563开发
💻 S
📖 第 1 页 / 共 3 页
字号:
	.module pcf8563_test.c
	.area text(rom, con, rel)
	.dbfile D:\mega16_32实验板资料\ICCAVR源程序\twi\pcf8563\pcf8563_test.c
	.dbfile D:\mega16_32实验板资料\ICCAVR源程序\twi\pcf8563\delay.h
	.dbfunc e delay_1us _delay_1us fV
	.even
_delay_1us::
	.dbline -1
	.dbline 6
; /**********延时函数*****************/
; /*-----------------------------------------------
; delay_us	   :1us延时函数
; ------------------------------------------------*/
; void delay_1us(void)
; {
	.dbline 7
;  asm("nop");
	nop
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e delay_us _delay_us fV
;              t -> R20,R21
	.even
_delay_us::
	st -y,R20
	st -y,R21
	movw R20,R16
	.dbline -1
	.dbline 14
; }
; /*-----------------------------------------------
; delay_nus          :长延时函数
; 输入参数: t        :延时时间 us
; ------------------------------------------------*/
; void delay_us(unsigned int t)
; {
	xjmp L4
L3:
	.dbline 16
;  while(t--)
;   delay_1us();
	xcall _delay_1us
L4:
	.dbline 15
	movw R2,R20
	subi R20,1
	sbci R21,0
	tst R2
	brne L3
	tst R3
	brne L3
X0:
	.dbline -2
L2:
	.dbline 0 ; func end
	ld R21,y+
	ld R20,y+
	ret
	.dbsym r t 20 i
	.dbend
	.dbfunc e delay_1ms _delay_1ms fV
;              i -> R16,R17
	.even
_delay_1ms::
	.dbline -1
	.dbline 22
; }
; /*----------------------------------------------
; delay_ms	   :1ms延时函数
; -----------------------------------------------*/
; void delay_1ms(void)
; {
	.dbline 24
;  unsigned int i;
;  for(i=0;i<1140;i++);
	clr R16
	clr R17
	xjmp L10
L7:
	.dbline 24
L8:
	.dbline 24
	subi R16,255  ; offset = 1
	sbci R17,255
L10:
	.dbline 24
	cpi R16,116
	ldi R30,4
	cpc R17,R30
	brlo L7
X1:
	.dbline -2
L6:
	.dbline 0 ; func end
	ret
	.dbsym r i 16 i
	.dbend
	.dbfunc e delay_ms _delay_ms fV
;              t -> R20,R21
	.even
_delay_ms::
	st -y,R20
	st -y,R21
	movw R20,R16
	.dbline -1
	.dbline 31
; }
; /*----------------------------------------------
; delay_nms          :长延时函数
; 输入参数: t        :延时时间 ms
; -----------------------------------------------*/
; void delay_ms(unsigned int t)
; {
	xjmp L13
L12:
	.dbline 33
;  while(t--)
;   delay_1ms();
	xcall _delay_1ms
L13:
	.dbline 32
	movw R2,R20
	subi R20,1
	sbci R21,0
	tst R2
	brne L12
	tst R3
	brne L12
X2:
	.dbline -2
L11:
	.dbline 0 ; func end
	ld R21,y+
	ld R20,y+
	ret
	.dbsym r t 20 i
	.dbend
	.dbfile D:\mega16_32实验板资料\ICCAVR源程序\twi\pcf8563\twi.h
	.dbfunc e Twi_Init _Twi_Init fV
	.even
_Twi_Init::
	.dbline -1
	.dbline 49
; /*******************************************
; *       I2C(TWI)操作函数		   *
; *  文 件 名:TWI.h					   *
; *  函数功能:利用CPU的硬件TWI接口操作	   *
; *  设    计:张子凤					       *
; *  修改日期:2008年11月11日				   *
; *  版    本:V1.0						   *
; *  主控芯片:Mega16						   *
; *******************************************/
; //宏定义
; //状态寄存器TWSR各种状态定义
; //主模式启动状态
; #define START			0x08		//启动总线
; #define RESTART			0x10		//重新启动总线
; 
; //主发送模式各种状态
; #define MT_SLA_ACK		0x18		//SLA_W写地址已发送,收到应答位
; #define MT_SLA_NACK		0x20		//SLA_W写地址已发送,收到非应答位
; #define MT_DATA_ACK		0x28		//写入数据已发送,收到应答位
; #define MT_DATA_NACK	0x30		//写入数据已发送,收到应答位
; #define MT_ARB_LOST		0x38		//SLA_W或数据仲裁失败
; 
; //主接收模式各种状态
; #define MR_ARB_LOST		0x38		//
; #define MR_SLA_ACK		0x40		//SLA_R已发送,收到应答位
; #define MR_SLA_NACK		0x48		//SLA_R已发送,收到非应答位
; #define MR_DATA_ACK		0x50		//接收到数据,应答位已返回
; #define MR_DATA_NACK	0x58		//接收到数据,非应答位已返回
; 
; #define PCF8563_SLA_W	0xA2	   		 //PCF8563写从地址
; #define PCF8563_SLA_R	0xA3			 //PCF8563读从地址
; 
; #define start()    	(TWCR=(1<<TWINT)|(1<<TWSTA)|(1<<TWEN))
; #define stop()     	(TWCR=(1<<TWINT)|(1<<TWSTO)|(1<<TWEN))
; #define waitack()	{while(!(TWCR&(1<<TWINT)));}
; #define chkack() 	(TWSR&0xf8)					//check ack
; #define sendack()	(TWCR|=(1<<TWEA))
; #define sendnack()	(TWCR&=~(1<<TWEA))
; #define sendbyte(x)	{TWDR=(x);TWCR=(1<<TWINT)|(1<<TWEN);} 
; #define rcvnckbyte()(TWCR=(1<<TWINT)|(1<<TWEN))
; #define rcvackbyte()(TWCR=(1<<TWINT)|(1<<TWEN)|(1<<TWEA))
; 
; /* I2C Config */
; #define I2C_ERR			0
; #define I2C_CRR			1
; 
; //TWI初始化
; void Twi_Init(void)
; {
	.dbline 50
;  TWBR=14;
	ldi R24,14
	out 0x0,R24
	.dbline 51
;  TWSR=0;
	clr R2
	out 0x1,R2
	.dbline -2
L15:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfile D:\mega16_32实验板资料\ICCAVR源程序\twi\pcf8563\lcd1602.h
	.dbfunc e LCD_init _LCD_init fV
	.even
_LCD_init::
	.dbline -1
	.dbline 34
; /*-------------------------------------------
;    RS----------PC2
;    RW----------GND
;    EN----------PC3
;    D4-D7-------PC4-PC7
; ---------------------------------------------*/
; //定义MCU与LCD的接口 
; #define LCD_EN_PORT   PORTC
; #define LCD_EN_DDR    DDRC
; #define LCD_RS_PORT   PORTC
; #define LCD_RS_DDR    DDRC
; #define LCD_DATA_PORT PORTC
; #define LCD_DATA_DDR  DDRC
; #define LCD_DATA_PIN  PINC
; #define LCD_EN        0x08   //portc3 out
; #define LCD_RS        0x04   //portc2 out
; #define LCD_DATA      0xf0 //portc4/5/6/7 out
; 
; /*----------------------------------------------------------
; Public function prototypes
; ----------------------------------------------------------*/
; void LCD_init(void);
; void LCD_en_write(void);
; void clear(void);
; void LCD_write_char(unsigned command,unsigned data);
; void LCD_set_xy(unsigned char x, unsigned char y);
; void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s);
; void LCD_write_data(unsigned char X,unsigned char Y,int dat);
; 
; /*------------------------------------------------------------
; 函数: lcd1602口线初始化和液晶初始化
; -------------------------------------------------------------*/
; void LCD_init(void) //液晶初始化
; {
	.dbline 35
;  LCD_DATA_DDR|=LCD_DATA;
	in R24,0x14
	ori R24,240
	out 0x14,R24
	.dbline 36
;  LCD_EN_DDR|=LCD_EN;
	sbi 0x14,3
	.dbline 37
;  LCD_RS_DDR|=LCD_RS;
	sbi 0x14,2
	.dbline 38
;  delay_ms(15);
	ldi R16,15
	ldi R17,0
	xcall _delay_ms
	.dbline 39
;  LCD_write_char(0x28,0); //4位显示
	clr R18
	clr R19
	ldi R16,40
	ldi R17,0
	xcall _LCD_write_char
	.dbline 40
;  delay_ms(15);
	ldi R16,15
	ldi R17,0
	xcall _delay_ms
	.dbline 41
;  LCD_write_char(0x0c,0); //显示开
	clr R18
	clr R19
	ldi R16,12
	ldi R17,0
	xcall _LCD_write_char
	.dbline 42
;  delay_ms(15);
	ldi R16,15
	ldi R17,0
	xcall _delay_ms
	.dbline 43
;  LCD_write_char(0x01,0); //清屏
	clr R18
	clr R19
	ldi R16,1
	ldi R17,0
	xcall _LCD_write_char
	.dbline 44
;  clear();
	xcall _clear
	.dbline -2
L16:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e LCD_set_xy _LCD_set_xy fV
;        address -> R20
;              y -> R10
;              x -> R22
	.even
_LCD_set_xy::
	xcall push_xgsetF00C
	mov R10,R18
	mov R22,R16
	.dbline -1
	.dbline 53
; }
; 
; /*------------------------------------------------------------
; 函数: 设置显示地址
; para: x---the display address of a line limit: 0---15
;       y---the display line limit 0 or 1 
; --------------------------------------------------------------*/
; void LCD_set_xy(unsigned char x, unsigned char y) //写地址函数
; {
	.dbline 55
;   unsigned char address;
;   if(y ==0) 
	tst R10
	brne L18
X3:
	.dbline 56
;    address=0x80+x; //the first line
	mov R20,R22
	subi R20,128    ; addi 128
	xjmp L19
L18:
	.dbline 58
;   else 
;    address=0xc0+x; //the second line
	mov R20,R22
	subi R20,64    ; addi 192
L19:
	.dbline 59
;   LCD_write_char(address,0);
	clr R18
	clr R19
	mov R16,R20
	clr R17
	xcall _LCD_write_char
	.dbline -2
L17:
	.dbline 0 ; func end
	xjmp pop_xgsetF00C
	.dbsym r address 20 c
	.dbsym r y 10 c
	.dbsym r x 22 c
	.dbend
	.dbfunc e LCD_en_write _LCD_en_write fV
	.even
_LCD_en_write::
	.dbline -1
	.dbline 65
; }
; /*-------------------------------------------------------------
; 函数: lcd1602使能
; *--------------------------------------------------------------*/
; void LCD_en_write(void) //液晶使能
; { 
	.dbline 66
;  LCD_EN_PORT|=LCD_EN;
	sbi 0x15,3
	.dbline 67
;  delay_us(5);
	ldi R16,5
	ldi R17,0
	xcall _delay_us
	.dbline 68
;  LCD_EN_PORT&=~LCD_EN;
	cbi 0x15,3
	.dbline -2
L20:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e LCD_write_char _LCD_write_char fV
;      data_temp -> R22,R23
;   command_temp -> R20,R21
;           data -> R12,R13
;        command -> R10,R11
	.even
_LCD_write_char::
	xcall push_xgsetF03C
	movw R12,R18
	movw R10,R16
	.dbline -1
	.dbline 76
; }
; /*------------------------------------------------------------
; 函数: 写命令或数据到lcd1602
; 参数:command: 0---写数据, 1---写命令
;       data: 所要写的命令或数据
; *-------------------------------------------------------------*/
; void LCD_write_char(unsigned command,unsigned data) 
; {
	.dbline 78
;  unsigned command_temp,data_temp;
;  command_temp=command;
	movw R20,R10
	.dbline 79
;  data_temp=data;
	movw R22,R12
	.dbline 80
;  delay_us(25);
	ldi R16,25
	ldi R17,0
	xcall _delay_us
	.dbline 81
;  if(command==0)
	cpi R20,0
	cpc R20,R21
	brne L22
X4:
	.dbline 82
;  {
	.dbline 83
;   LCD_RS_PORT|=LCD_RS; //RS=1
	sbi 0x15,2
	.dbline 84
;   LCD_DATA_PORT&=0X0f;
	in R24,0x15
	andi R24,15
	out 0x15,R24
	.dbline 85
;   LCD_DATA_PORT|=data_temp&0xf0; //写高四位
	movw R24,R22
	andi R24,240
	andi R25,0
	in R2,0x15
	clr R3
	or R2,R24
	or R3,R25
	out 0x15,R2
	.dbline 86
;   LCD_en_write();
	xcall _LCD_en_write
	.dbline 87
;   data_temp=data_temp<<4; 
	lsl R22
	rol R23
	lsl R22
	rol R23
	lsl R22
	rol R23
	lsl R22
	rol R23
	.dbline 88
;   LCD_DATA_PORT&=0X0f;
	in R24,0x15
	andi R24,15
	out 0x15,R24
	.dbline 89
;   LCD_DATA_PORT|=data_temp&0xf0; //写低四位
	movw R24,R22
	andi R24,240
	andi R25,0
	in R2,0x15
	clr R3
	or R2,R24
	or R3,R25
	out 0x15,R2
	.dbline 90
;   LCD_en_write();
	xcall _LCD_en_write
	.dbline 91
;  }
	xjmp L23
L22:
	.dbline 93
;  else
;  {
	.dbline 94
;   LCD_RS_PORT&=~LCD_RS; //RS=0
	cbi 0x15,2
	.dbline 95
;   LCD_DATA_PORT&=0X0f;
	in R24,0x15
	andi R24,15
	out 0x15,R24
	.dbline 96
;   LCD_DATA_PORT|=command_temp&0xf0; //写高四位
	movw R24,R20
	andi R24,240
	andi R25,0
	in R2,0x15
	clr R3
	or R2,R24
	or R3,R25
	out 0x15,R2
	.dbline 97
;   LCD_en_write();
	xcall _LCD_en_write
	.dbline 98
;   command_temp=command_temp<<4;
	lsl R20
	rol R21
	lsl R20
	rol R21
	lsl R20
	rol R21
	lsl R20
	rol R21
	.dbline 99
;   LCD_DATA_PORT&=0x0f;
	in R24,0x15
	andi R24,15
	out 0x15,R24
	.dbline 100
;   LCD_DATA_PORT|=command_temp&0xf0; //写低四位
	movw R24,R20
	andi R24,240
	andi R25,0
	in R2,0x15
	clr R3
	or R2,R24
	or R3,R25
	out 0x15,R2
	.dbline 101
;   LCD_en_write();
	xcall _LCD_en_write
	.dbline 102
;  }
L23:
	.dbline -2
L21:
	.dbline 0 ; func end
	xjmp pop_xgsetF03C
	.dbsym r data_temp 22 i
	.dbsym r command_temp 20 i
	.dbsym r data 12 i
	.dbsym r command 10 i
	.dbend
	.dbfunc e clear _clear fV
;              i -> R20
	.even
_clear::
	st -y,R20
	.dbline -1
	.dbline 108
; }
; /*-------------------------------------------------------------
; 函数: 清屏lcd1602
; ---------------------------------------------------------------*/
; void clear(void)
; {
	.dbline 110
;  unsigned char i;
;  LCD_set_xy(0,0);
	clr R18
	clr R16
	xcall _LCD_set_xy
	.dbline 111
;  for(i=0;i<16;i++)
	clr R20
	xjmp L28
L25:
	.dbline 112
;  LCD_write_char(0,' ');
	ldi R18,32
	ldi R19,0
	clr R16
	clr R17
	xcall _LCD_write_char
L26:
	.dbline 111
	inc R20
L28:
	.dbline 111
	cpi R20,16
	brlo L25
X5:
	.dbline 113
;  LCD_set_xy(0,1);
	ldi R18,1
	clr R16
	xcall _LCD_set_xy
	.dbline 114
;  for(i=0;i<16;i++)
	clr R20
	xjmp L32
L29:

⌨️ 快捷键说明

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