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

📄 24cxx_test.s

📁 24IIC的源代码
💻 S
📖 第 1 页 / 共 2 页
字号:
	.module _24cxx_test.c
	.area text(rom, con, rel)
	.dbfile D:\iccavr\mega16\11\24CXX\24cxx_test.c
	.dbfile D:\iccavr\mega16\11\24CXX\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
;             i0 -> 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 i0 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:\iccavr\mega16\11\24CXX\24cxx_twi.h
	.dbfunc e WriteByte _WriteByte fc
	.dbunion 0 2 reccnt
	.dbfield 0 rcnt i
	.dbfield 0 rcntl A[2:2]c
	.dbend
;            ltg -> y+0
;          Wdata -> R10
;     RomAddress -> R12,R13
	.even
_WriteByte::
	xcall push_xgset003C
	mov R10,R18
	movw R12,R16
	sbiw R28,2
	.dbline -1
	.dbline 39
; typedef unsigned char     uint8; 
; typedef unsigned int      uint16; 
; 
; typedef  union reccnt 
; { 
;  uint16 rcnt; 
;  uint8  rcntl[2]; 
; }LngToChar; 
; 
; #define wr_24c64_cmd      0xA0 
; #define rd_24c64_cmd      0xA1 
;          
; #define START 0x08   
; #define RE_START 0x10   
; #define MT_SLA_ACK 0x18   
; //#define MT_SLA_ACK 0x38   
; #define MT_SLA_NOACK 0x20   
; #define MT_DATA_ACK  0x28   
; #define MT_DATA_NOACK 0x30   
; #define MR_SLA_ACK  0x40   
; #define MR_SLA_NOACK 0x48   
; #define MR_DATA_ACK 0x50   
; #define MR_DATA_NOACK 0x58  
;    
; #define Start()         (TWCR=(1<<TWINT)|(1<<TWSTA)|(1<<TWEN))   
; #define Stop()          (TWCR=(1<<TWINT)|(1<<TWSTO)|(1<<TWEN))   
; #define Wait()          {while(!(TWCR&(1<<TWINT)));}   
; #define TestAck()       (TWSR&0xf8)  
; #define SetAck()        (TWCR|=(1<<TWEA))   
; #define SetNoAck()      (TWCR&=~(1<<TWEA))   
; #define Twi()           (TWCR=(1<<TWINT)|(1<<TWEN))  
; #define Write8Bit(x)    {TWDR=(x);TWCR=(1<<TWINT)|(1<<TWEN);} 
;   
; uint8 WriteByte(uint16 RomAddress,uint8 Wdata);
; uint8 ReadByte(uint16 RomAddress);
; 
; //******************************************    
; uint8 WriteByte(uint16 RomAddress,uint8 Wdata)    
; {       
	.dbline 42
;  LngToChar ltg; 
;           
;  ltg.rcnt=RomAddress; 
	std y+1,R13
	std y+0,R12
	.dbline 44
; 
;  _CLI(); 
	cli
	.dbline 45
;  Start();//twi 
	ldi R24,164
	out 0x36,R24
	.dbline 46
;  Wait();   
L16:
	.dbline 46
L17:
	.dbline 46
	in R2,0x36
	sbrs R2,7
	rjmp L16
X3:
	.dbline 46
	.dbline 46
	.dbline 47
;  if(TestAck()!=START) goto wr_exit;//ACK 0x08    
	in R24,0x1
	andi R24,248
	cpi R24,8
	breq L19
X4:
	.dbline 47
	xjmp L21
L19:
	.dbline 49
; 
;  Write8Bit(wr_24c64_cmd);// 
	.dbline 49
	ldi R24,160
	out 0x3,R24
	.dbline 49
	ldi R24,132
	out 0x36,R24
	.dbline 49
	.dbline 49
	.dbline 50
;  Wait();   
L22:
	.dbline 50
L23:
	.dbline 50
	in R2,0x36
	sbrs R2,7
	rjmp L22
X5:
	.dbline 50
	.dbline 50
	.dbline 51
;  if(TestAck()!=MT_SLA_ACK) goto wr_exit;//ACK MT_SLA_ACK 0x18  
	in R24,0x1
	andi R24,248
	cpi R24,24
	breq L25
X6:
	.dbline 51
	xjmp L21
L25:
	.dbline 53
;  
;  Write8Bit(ltg.rcntl[1]);  //写操作单元的高8位地址    
	.dbline 53
	ldd R2,y+1
	out 0x3,R2
	.dbline 53
	ldi R24,132
	out 0x36,R24
	.dbline 53
	.dbline 53
	.dbline 54
;  Wait(); 
L28:
	.dbline 54
L29:
	.dbline 54
	in R2,0x36
	sbrs R2,7
	rjmp L28
X7:
	.dbline 54
	.dbline 54
	.dbline 55
;  if(TestAck()!=MT_DATA_ACK) goto wr_exit;//ACK   
	in R24,0x1
	andi R24,248
	cpi R24,40
	breq L31
X8:
	.dbline 55
	xjmp L21
L31:
	.dbline 57
; 
;  Write8Bit(ltg.rcntl[0]);   //写操作单元的低8位地址    
	.dbline 57
	ldd R2,y+0
	out 0x3,R2
	.dbline 57
	ldi R24,132
	out 0x36,R24
	.dbline 57
	.dbline 57
	.dbline 58
;  Wait(); 
L33:
	.dbline 58
L34:
	.dbline 58
	in R2,0x36
	sbrs R2,7
	rjmp L33
X9:
	.dbline 58
	.dbline 58
	.dbline 59
;  if(TestAck()!=MT_DATA_ACK) goto wr_exit;//ACK   
	in R24,0x1
	andi R24,248
	cpi R24,40
	breq L36
X10:
	.dbline 59
	xjmp L21
L36:
	.dbline 61
;     
;  Write8Bit(Wdata);// 
	.dbline 61
	out 0x3,R10
	.dbline 61
	ldi R24,132
	out 0x36,R24
	.dbline 61
	.dbline 61
	.dbline 62
;  Wait();   
L38:
	.dbline 62
L39:
	.dbline 62
	in R2,0x36
	sbrs R2,7
	rjmp L38
X11:
	.dbline 62
	.dbline 62
	.dbline 63
;  if(TestAck()!=MT_DATA_ACK) goto wr_exit;//ACK      
	in R24,0x1
	andi R24,248
	cpi R24,40
	breq L41
X12:
	.dbline 63
	xjmp L21
L41:
	.dbline 65
;       
;  Stop();// 
	ldi R24,148
	out 0x36,R24
	.dbline 66
;  delay_ms(30);//   
	ldi R16,30
	ldi R17,0
	xcall _delay_ms
	.dbline 67
;  _SEI(); 
	sei
	.dbline 68
;  return 0;   
	clr R16
	xjmp L15
L21:
	.dbline 70
;  wr_exit://出错退出 
;    Stop();// 
	ldi R24,148
	out 0x36,R24
	.dbline 71
;    _SEI(); 
	sei
	.dbline 72
;  return 1; 
	ldi R16,1
	.dbline -2
L15:
	.dbline 0 ; func end
	adiw R28,2
	xjmp pop_xgset003C
	.dbsym l ltg 0 S[reccnt]
	.dbsym r Wdata 10 c
	.dbsym r RomAddress 12 i
	.dbend
	.dbfunc e ReadByte _ReadByte fc
;            ltg -> y+0
;          temp0 -> R10
;     RomAddress -> R16,R17
	.even
_ReadByte::
	st -y,R10
	sbiw R28,2
	.dbline -1
	.dbline 77
; }  
;   
; //******************************************   
; uint8 ReadByte(uint16 RomAddress) 
; {   
	.dbline 80
;  uint8 temp;  
;  LngToChar ltg; 
;  _CLI(); 
	cli
	.dbline 81
;  ltg.rcnt=RomAddress; 
	std y+1,R17
	std y+0,R16
	.dbline 83
; 
;  Start();  
	ldi R24,164
	out 0x36,R24
	.dbline 84
;  Wait();  
L44:
	.dbline 84
L45:
	.dbline 84
	in R2,0x36
	sbrs R2,7
	rjmp L44
X13:
	.dbline 84
	.dbline 84
	.dbline 85
;  if (TestAck()!=START) goto re_exit;//ACK  
	in R24,0x1
	andi R24,248
	cpi R24,8
	breq L47
X14:
	.dbline 85
	xjmp L49
L47:
	.dbline 87
;                         
;  Write8Bit(wr_24c64_cmd);//  
	.dbline 87
	ldi R24,160
	out 0x3,R24
	.dbline 87
	ldi R24,132
	out 0x36,R24
	.dbline 87
	.dbline 87
	.dbline 88
;  Wait();               
L50:
	.dbline 88
L51:
	.dbline 88
	in R2,0x36
	sbrs R2,7
	rjmp L50
X15:
	.dbline 88
	.dbline 88
	.dbline 89
;  if (TestAck()!=MT_SLA_ACK) goto re_exit;//ACK   
	in R24,0x1
	andi R24,248
	cpi R24,24
	breq L53
X16:
	.dbline 89
	xjmp L49
L53:
	.dbline 91
;            
;  Write8Bit(ltg.rcntl[1]); //写操作单元的高8位地址    
	.dbline 91
	ldd R2,y+1
	out 0x3,R2
	.dbline 91
	ldi R24,132
	out 0x36,R24
	.dbline 91
	.dbline 91
	.dbline 92
;  Wait();   
L56:
	.dbline 92
L57:
	.dbline 92
	in R2,0x36
	sbrs R2,7
	rjmp L56
X17:
	.dbline 92
	.dbline 92
	.dbline 93
;  if (TestAck()!=MT_DATA_ACK) goto re_exit;   
	in R24,0x1
	andi R24,248
	cpi R24,40
	breq L59
X18:
	.dbline 93
	xjmp L49
L59:
	.dbline 95
;            
;  Write8Bit(ltg.rcntl[0]);  //写操作单元的低8位地址       
	.dbline 95
	ldd R2,y+0
	out 0x3,R2
	.dbline 95
	ldi R24,132
	out 0x36,R24
	.dbline 95
	.dbline 95
	.dbline 96
;  Wait();   
L61:
	.dbline 96
L62:
	.dbline 96
	in R2,0x36
	sbrs R2,7
	rjmp L61
X19:
	.dbline 96
	.dbline 96
	.dbline 97
;  if (TestAck()!=MT_DATA_ACK) goto re_exit; 
	in R24,0x1
	andi R24,248
	cpi R24,40
	breq L64
X20:
	.dbline 97
	xjmp L49
L64:
	.dbline 99
;            
;  Start();//twi 
	ldi R24,164
	out 0x36,R24
	.dbline 100
;  Wait();   
L66:
	.dbline 100
L67:
	.dbline 100
	in R2,0x36
	sbrs R2,7
	rjmp L66
X21:
	.dbline 100
	.dbline 100
	.dbline 101
;  if (TestAck()!=RE_START)  goto re_exit;   
	in R24,0x1
	andi R24,248
	cpi R24,16
	breq L69
X22:
	.dbline 101
	xjmp L49
L69:
	.dbline 103
;             
;  Write8Bit(rd_24c64_cmd);//   
	.dbline 103
	ldi R24,161
	out 0x3,R24
	.dbline 103
	ldi R24,132
	out 0x36,R24
	.dbline 103
	.dbline 103
	.dbline 104
;  Wait();   
L71:
	.dbline 104
L72:
	.dbline 104
	in R2,0x36
	sbrs R2,7
	rjmp L71
X23:
	.dbline 104
	.dbline 104
	.dbline 105
;  if(TestAck()!=MR_SLA_ACK)  goto re_exit;//ACK   
	in R24,0x1
	andi R24,248
	cpi R24,64
	breq L74
X24:
	.dbline 105
	xjmp L49
L74:
	.dbline 107
;                
;  Twi();//启动主I2C读方式 
	ldi R24,132
	out 0x36,R24
	.dbline 108
;  Wait();   
L76:
	.dbline 108
L77:
	.dbline 108
	in R2,0x36
	sbrs R2,7
	rjmp L76
X25:
	.dbline 108
	.dbline 108
	.dbline 109
;  if(TestAck()!=MR_DATA_NOACK) goto re_exit;//ACK  MR_DATA_NOACK 0x58   
	in R24,0x1
	andi R24,248
	cpi R24,88
	breq L79
X26:
	.dbline 109
	xjmp L49
L79:
	.dbline 111
;    
;  temp=TWDR;// 读取I2C接收的数据      
	in R10,0x3
	.dbline 112
;  Stop();//I2C停止  
	ldi R24,148
	out 0x36,R24
	.dbline 114
; 
;  _SEI(); 
	sei
	.dbline 115
;  return temp; 
	mov R16,R10
	xjmp L43
L49:
	.dbline 118
; 
;  re_exit://出错退出 
;  Stop(); 
	ldi R24,148
	out 0x36,R24
	.dbline 119
;  _SEI(); 
	sei
	.dbline 120
;  return 0;  
	clr R16
	.dbline -2
L43:
	.dbline 0 ; func end
	adiw R28,2
	ld R10,y+
	ret
	.dbsym l ltg 0 S[reccnt]
	.dbsym r temp0 10 c
	.dbsym r RomAddress 16 i
	.dbend
	.dbfile D:\iccavr\mega16\11\24CXX\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

⌨️ 快捷键说明

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