📄 24cxx_test.s
字号:
mov R12,R2
L69:
L71:
.dbline 129
; Ragain2:
; if(ICerror<10)
cpi R20,10
brsh L74
X27:
.dbline 130
; ICerror++;
inc R20
.dbline 132
; else
; goto Rstop;
L73:
.dbline 133
; twi_start(); //
xcall _twi_start
.dbline 134
; if(twi_writebyte(temp|1)==0)
mov R16,R12
ori R16,1
xcall _twi_writebyte
tst R16
brne L78
X28:
.dbline 135
; goto Ragain2;
xjmp L71
L77:
.dbline 137
; while(num--)
; {
.dbline 138
; twi_readbyte(p,num);
mov R18,R10
movw R16,R22
xcall _twi_readbyte
.dbline 139
; p++;
subi R22,255 ; offset = 1
sbci R23,255
.dbline 140
; }
L78:
.dbline 136
mov R12,R10
clr R13
mov R24,R12
subi R24,1
mov R10,R24
tst R12
brne L77
X29:
L74:
.dbline 142
; Rstop:
; Stop();
ldi R24,148
out 0x36,R24
.dbline 143
; return(ICerror);
mov R16,R20
.dbline -2
L68:
.dbline 0 ; func end
adiw R28,5
xjmp pop_xgsetF0FC
.dbsym r temp 12 c
.dbsym r ICerror 20 c
.dbsym r p 22 pc
.dbsym r num 10 c
.dbsym l P_data 17 pc
.dbsym l addr 15 i
.dbsym r DevAddr 12 c
.dbsym r model 14 i
.dbend
.dbfile D:\mega16_32实验板资料\ICCAVR源程序\twi\24c64\连续读写\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
L80:
.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 L82
X30:
.dbline 56
; address=0x80+x; //the first line
mov R20,R22
subi R20,128 ; addi 128
xjmp L83
L82:
.dbline 58
; else
; address=0xc0+x; //the second line
mov R20,R22
subi R20,64 ; addi 192
L83:
.dbline 59
; LCD_write_char(address,0);
clr R18
clr R19
mov R16,R20
clr R17
xcall _LCD_write_char
.dbline -2
L81:
.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
L84:
.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 L86
X31:
.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 L87
L86:
.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
; }
L87:
.dbline -2
L85:
.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 L92
L89:
.dbline 112
; LCD_write_char(0,' ');
ldi R18,32
ldi R19,0
clr R16
clr R17
xcall _LCD_write_char
L90:
.dbline 111
inc R20
L92:
.dbline 111
cpi R20,16
brlo L89
X32:
.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 L96
L93:
.dbline 115
; LCD_write_char(0,' ');
ldi R18,32
ldi R19,0
clr R16
clr R17
xcall _LCD_write_char
L94:
.dbline 114
inc R20
L96:
.dbline 114
cpi R20,16
brlo L93
X33:
.dbline -2
L88:
.dbline 0 ; func end
ld R20,y+
ret
.dbsym r i 20 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 123
; }
; /*-------------------------------------------------------------
; 函数: 写字符串
; 参数:列---X=0~15,行---Y=0~1 写地址
; s为所要写的字符串
; ---------------------------------------------------------------*/
; void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s)
; {
.dbline 124
; LCD_set_xy(X,Y);
mov R18,R12
mov R16,R10
xcall _LCD_set_xy
xjmp L99
L98:
.dbline 126
; while(*s)
; {
.dbline 127
; LCD_write_char(0,*s);
movw R30,R20
ldd R18,z+0
clr R19
clr R16
clr R17
xcall _LCD_write_char
.dbline 128
; s++;
subi R20,255 ; offset = 1
sbci R21,255
.dbline 129
; }
L99:
.dbline 125
movw R30,R20
ldd R2,z+0
tst R2
brne L98
X34:
.dbline -2
L97:
.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 LCD_write_data _LCD_write_data fV
; data -> y+0
; i -> R20
; dat -> R14,R15
; Y -> R12
; X -> R10
.even
_LCD_write_data::
xcall push_xgset30FC
mov R12,R18
mov R10,R16
sbiw R28,4
ldd R14,y+12
ldd R15,y+13
.dbline -1
.dbline 138
; }
;
; /*-------------------------------------------------------------
; 函数: 写数字
; 参数:列---X=0~15,行---Y=0~1 写地址
; dat为所要写的数字
; ---------------------------------------------------------------*/
; void LCD_write_data(unsigned char X,unsigned char Y,int dat)
; {
.dbline 151
; //unsigned char fuhao;
; unsigned char data[4];
; unsigned char i;
;
; /*if(dat<0)
; {
; fuhao='-';
; dat=0-dat;
; }
; else
; fuhao=' ';
; data[0]=fuhao;*/
; data[0]=dat/1000+0x30; dat%=1000;
ldi R18,1000
ldi R19,3
movw R16,R14
xcall div16s
movw R24,R16
adiw R24,48
std y+0,R24
.dbline 151
ldi R18,1000
ldi R19,3
movw R16,R14
xcall mod16s
movw R14,R16
.dbline 152
; data[1]=dat/100+0x30; dat%=100;
ldi R18,100
ldi R19,0
xcall div16s
movw R24,R16
adiw R24,48
std y+1,R24
.dbline 152
ldi R18,100
ldi R19,0
movw R16,R14
xcall mod16s
movw R14,R16
.dbline 153
; data[2]=dat/10+0x30;
ldi R18,10
ldi R19,0
xcall div16s
movw R24,R16
adiw R24,48
std y+2,R24
.dbline 154
; data[3]=dat%10+0x30;
ldi R18,10
ldi R19,0
movw R16,R14
xcall mod16s
movw R24,R16
adiw R24,48
std y+3,R24
.dbline 156
;
; LCD_set_xy(X,Y);
mov R18,R12
mov R16,R10
xcall _LCD_set_xy
.dbline 157
; for(i=0;i<4;i++)
clr R20
xjmp L108
L105:
.dbline 158
; LCD_write_char(0,data[i]);
movw R24,R28
mov R30,R20
clr R31
add R30,R24
adc R31,R25
ldd R18,z+0
clr R19
clr R16
clr R17
xcall _LCD_write_char
L106:
.dbline 157
inc R20
L108:
.dbline 157
cpi R20,4
brlo L105
X35:
.dbline -2
L101:
.dbline 0 ; func end
adiw R28,4
xjmp pop_xgset30FC
.dbsym l data 0 A[4:4]c
.dbsym r i 20 c
.dbsym r dat 14 I
.dbsym r Y 12 c
.dbsym r X 10 c
.dbend
.area lit(rom, con, rel)
L110:
.byte 18,17
.byte 16,15
.byte 14,13
.byte 12,11
.byte 10,9
.byte 8,7
.byte 6,5
.byte 4,3
.byte 2,1
.byte 0
L111:
.byte 0
.word 0,0,0,0,0
.byte 0,0,0,0,0,0,0,0
.area text(rom, con, rel)
.dbfile D:\mega16_32实验板资料\ICCAVR源程序\twi\24c64\连续读写\lcd1602.h
.dbfile D:\mega16_32实验板资料\ICCAVR源程序\twi\24c64\连续读写\24cxx_test.c
.dbfunc e main _main fV
; temp1 -> y+24
; temp2 -> y+5
; i -> R20
.even
_main::
sbiw R28,43
.dbline -1
.dbline 15
; //ICC-AVR application builder : 2008-11-10 11:10:06
; // Target : M16
; // Crystal: 8.0000Mhz
;
; #include <iom16v.h>
; #include <macros.h>
;
;
; #include "delay.h"
; #include "24cxx.h"
; #include "lcd1602.h"
;
; //
; void main(void)
; {
.dbline 16
; unsigned char temp1[19]={18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0};
ldi R24,<L110
ldi R25,>L110
movw R30,R28
adiw R30,24
ldi R16,19
ldi R17,0
st -y,R31
st -y,R30
st -y,R25
st -y,R24
xcall asgncblk
.dbline 17
; unsigned char temp2[19]={0};
ldi R24,<L111
ldi R25,>L111
movw R30,R28
adiw R30,5
ldi R16,19
ldi R17,0
st -y,R31
st -y,R30
st -y,R25
st -y,R24
xcall asgncblk
.dbline 19
; unsigned char i;
; LCD_init();
xcall _LCD_init
.dbline 21
; //insert your functional code here...
; LCD_write_string(0,0," AT24C64 TEST ");
ldi R24,<L112
ldi R25,>L112
std y+1,R25
std y+0,R24
clr R18
clr R16
xcall _LCD_write_string
.dbline 22
; AT24CxxWrite(64,0,1000,temp1,19);
ldi R24,19
std y+4,R24
movw R24,R28
adiw R24,24
std y+3,R25
std y+2,R24
ldi R24,1000
ldi R25,3
std y+1,R25
std y+0,R24
clr R18
ldi R16,64
ldi R17,0
xcall _AT24CxxWrite
.dbline 23
; AT24CxxRead(64,0,1000,temp2,19);
ldi R24,19
std y+4,R24
movw R24,R28
adiw R24,5
std y+3,R25
std y+2,R24
ldi R24,1000
ldi R25,3
std y+1,R25
std y+0,R24
clr R18
ldi R16,64
ldi R17,0
xcall _AT24CxxRead
xjmp L114
L113:
.dbline 25
; while(1)
; {
.dbline 26
; for(i=0;i<19;i++)
clr R20
xjmp L119
L116:
.dbline 27
; {
.dbline 28
; LCD_write_data(5,1,temp2[i]);
movw R24,R28
adiw R24,5
mov R30,R20
clr R31
add R30,R24
adc R31,R25
ldd R2,z+0
clr R3
std y+1,R3
std y+0,R2
ldi R18,1
ldi R16,5
xcall _LCD_write_data
.dbline 29
; delay_ms(1000);
ldi R16,1000
ldi R17,3
xcall _delay_ms
.dbline 30
; }
L117:
.dbline 26
inc R20
L119:
.dbline 26
cpi R20,19
brlo L116
X36:
.dbline 31
; }
L114:
.dbline 24
xjmp L113
X37:
.dbline -2
L109:
.dbline 0 ; func end
adiw R28,43
ret
.dbsym l temp1 24 A[19:19]c
.dbsym l temp2 5 A[19:19]c
.dbsym r i 20 c
.dbend
.area data(ram, con, rel)
.dbfile D:\mega16_32实验板资料\ICCAVR源程序\twi\24c64\连续读写\24cxx_test.c
L112:
.blkb 17
.area idata
.byte 32,32,'A,'T,50,52,'C,54,52,32,'T,'E,'S,'T,32,32
.byte 0
.area data(ram, con, rel)
.dbfile D:\mega16_32实验板资料\ICCAVR源程序\twi\24c64\连续读写\24cxx_test.c
; }
;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -