📄 ac15-1.s
字号:
.module ac15-1.c
.area lit(rom, con, rel)
_str0::
.byte 'W,'r,'i,'t,'e,32,58,32,0
.dbfile d:\MYDOCU~1\ac15-1\ac15-1.c
.dbsym e str0 _str0 A[9:9]kc
_str1::
.byte 'R,'e,'a,'d,32,58,32,0
.dbsym e str1 _str1 A[8:8]kc
.area text(rom, con, rel)
.dbfile d:\MYDOCU~1\ac15-1\ac15-1.c
.dbfunc e ePutstr _ePutstr fV
; l -> R20
; i -> R22
; ptr -> R10,R11
; y -> R12
; x -> R14
.even
_ePutstr::
xcall push_gset5
mov R12,R18
mov R14,R16
sbiw R28,1
ldd R10,y+11
ldd R11,y+12
.dbline -1
.dbline 39
; #include <iom16v.h>
; #include <macros.h>
; //-----------------------------------------------
; #define uchar unsigned char
; #define uint unsigned int
; //-------------------引脚电平的宏定义---------
; #define LCM_RS_1 PORTB|=BIT(PB0)
; #define LCM_RS_0 PORTB&=~BIT(PB0)
; #define LCM_RW_1 PORTB|=BIT(PB1)
; #define LCM_RW_0 PORTB&=~BIT(PB1)
; #define LCM_EN_1 PORTB|=BIT(PB2)
; #define LCM_EN_0 PORTB&=~BIT(PB2)
; #define SCL_1 PORTC|=BIT(PC0)
; #define SCL_0 PORTC&=~BIT(PC0)
; #define SDA_1 PORTC|=BIT(PC1)
; #define SDA_0 PORTC&=~BIT(PC1)
; //======================================
; #define PIN_SDA (PINC&0x02)
; #define DataPort PORTA
; #define Busy 0x80
; #define xtal 8
; #define Some_NOP(); _NOP();_NOP();_NOP();_NOP();_NOP();_NOP();_NOP();_NOP();
; //=====================================
; const uchar str0[]={"Write : "};//待显字符串
; const uchar str1[]={"Read : "};//待显字符串
; //========函数声明=========
; void Delay_1ms(void);
; void Delay_nms(uint n);
; void WaitForEnable(void);
; void LcdWriteData(uchar W);
; void LcdWriteCommand(uchar CMD,uchar Attribc);
; void InitLcd(void);
; void Display(uchar dd);
; void DisplayOneChar(uchar x,uchar y,uchar Wdata);
; void ePutstr(uchar x,uchar y,uchar const *ptr);
; void port_init(void);
; //**********************显示指定座标的一串字符子函数**************
; void ePutstr(uchar x,uchar y,uchar const *ptr)
; {
.dbline 40
; uchar i,l=0;
clr R20
xjmp L3
L2:
.dbline 41
.dbline 41
inc R20
.dbline 41
L3:
.dbline 41
; while(ptr[l]>31){l++;}
mov R30,R20
clr R31
add R30,R10
adc R31,R11
lpm R30,Z
ldi R24,31
cp R24,R30
brlo L2
.dbline 42
clr R22
xjmp L8
L5:
.dbline 42
; for(i=0;i<l;i++){
.dbline 43
; DisplayOneChar(x++,y,ptr[i]);
mov R30,R22
clr R31
add R30,R10
adc R31,R11
lpm R30,Z
std y+0,R30
mov R18,R12
mov R2,R14
mov R24,R2
subi R24,255 ; addi 1
mov R14,R24
mov R16,R2
xcall _DisplayOneChar
.dbline 44
; if(x==16){
mov R24,R14
cpi R24,16
brne L9
.dbline 44
.dbline 45
; x=0;y^=1;
clr R14
.dbline 45
ldi R24,1
eor R12,R24
.dbline 46
; }
L9:
.dbline 47
L6:
.dbline 42
inc R22
L8:
.dbline 42
cp R22,R20
brlo L5
.dbline -2
L1:
adiw R28,1
xcall pop_gset5
.dbline 0 ; func end
ret
.dbsym r l 20 c
.dbsym r i 22 c
.dbsym r ptr 10 pkc
.dbsym r y 12 c
.dbsym r x 14 c
.dbend
.dbfunc e LocateXY _LocateXY fV
; temp -> R20
; posy -> R22
; posx -> R10
.even
_LocateXY::
xcall push_gset3
mov R22,R18
mov R10,R16
.dbline -1
.dbline 51
; }
; }
; //*******************显示光标定位子函数******************
; void LocateXY(char posx,char posy)
; {
.dbline 53
; uchar temp;
; temp&=0x7f;
andi R20,127
.dbline 54
; temp=posx&0x0f;
mov R20,R10
andi R20,15
.dbline 55
; posy&=0x01;
andi R22,1
.dbline 56
; if(posy)temp|=0x40;
breq L12
.dbline 56
ori R20,64
L12:
.dbline 57
; temp|=0x80;
ori R20,128
.dbline 58
; LcdWriteCommand(temp,0);
clr R18
mov R16,R20
xcall _LcdWriteCommand
.dbline -2
L11:
xcall pop_gset3
.dbline 0 ; func end
ret
.dbsym r temp 20 c
.dbsym r posy 22 c
.dbsym r posx 10 c
.dbend
.dbfunc e DisplayOneChar _DisplayOneChar fV
; Wdata -> y+4
; y -> R22
; x -> R20
.even
_DisplayOneChar::
xcall push_gset2
mov R22,R18
mov R20,R16
.dbline -1
.dbline 62
; }
; //*******************显示指定座标的一个字符子函数*******************
; void DisplayOneChar(uchar x,uchar y,uchar Wdata)
; {
.dbline 63
; LocateXY(x,y);
mov R18,R22
mov R16,R20
xcall _LocateXY
.dbline 64
; LcdWriteData(Wdata);
ldd R16,y+4
xcall _LcdWriteData
.dbline -2
L14:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym l Wdata 4 c
.dbsym r y 22 c
.dbsym r x 20 c
.dbend
.dbfunc e InitLcd _InitLcd fV
.even
_InitLcd::
.dbline -1
.dbline 68
; }
; //*******************LCD初始化子函数*********************
; void InitLcd(void)
; {
.dbline 69
; LcdWriteCommand(0x38,0);
clr R18
ldi R16,56
xcall _LcdWriteCommand
.dbline 70
; Delay_nms(5);
ldi R16,5
ldi R17,0
xcall _Delay_nms
.dbline 71
; LcdWriteCommand(0x38,0);
clr R18
ldi R16,56
xcall _LcdWriteCommand
.dbline 72
; Delay_nms(5);
ldi R16,5
ldi R17,0
xcall _Delay_nms
.dbline 73
; LcdWriteCommand(0x38,0);
clr R18
ldi R16,56
xcall _LcdWriteCommand
.dbline 74
; Delay_nms(5);
ldi R16,5
ldi R17,0
xcall _Delay_nms
.dbline 75
; LcdWriteCommand(0x38,1);
ldi R18,1
ldi R16,56
xcall _LcdWriteCommand
.dbline 76
; LcdWriteCommand(0x08,1);
ldi R18,1
ldi R16,8
xcall _LcdWriteCommand
.dbline 77
; LcdWriteCommand(0x01,1);
ldi R18,1
ldi R16,1
xcall _LcdWriteCommand
.dbline 78
; LcdWriteCommand(0x06,1);
ldi R18,1
ldi R16,6
xcall _LcdWriteCommand
.dbline 79
; LcdWriteCommand(0x0c,1);
ldi R18,1
ldi R16,12
xcall _LcdWriteCommand
.dbline -2
L15:
.dbline 0 ; func end
ret
.dbend
.dbfunc e LcdWriteCommand _LcdWriteCommand fV
; Attribc -> R22
; CMD -> R20
.even
_LcdWriteCommand::
xcall push_gset2
mov R22,R18
mov R20,R16
.dbline -1
.dbline 83
; }
; //********************写命令到LCM子函数********************
; void LcdWriteCommand(uchar CMD,uchar Attribc)
; {
.dbline 84
; if(Attribc)WaitForEnable();
tst R22
breq L17
.dbline 84
xcall _WaitForEnable
L17:
.dbline 85
; LCM_RS_0;LCM_RW_0;_NOP();
cbi 0x18,0
.dbline 85
cbi 0x18,1
.dbline 85
nop
.dbline 86
; DataPort=CMD;_NOP();
out 0x1b,R20
.dbline 86
nop
.dbline 87
; LCM_EN_1;_NOP();_NOP();LCM_EN_0;
sbi 0x18,2
.dbline 87
nop
.dbline 87
nop
.dbline 87
cbi 0x18,2
.dbline -2
L16:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r Attribc 22 c
.dbsym r CMD 20 c
.dbend
.dbfunc e LcdWriteData _LcdWriteData fV
; dataW -> R20
.even
_LcdWriteData::
xcall push_gset1
mov R20,R16
.dbline -1
.dbline 91
; }
; //*******************写数据到LCM子函数********************
; void LcdWriteData(uchar dataW)
; {
.dbline 92
; WaitForEnable();
xcall _WaitForEnable
.dbline 93
; LCM_RS_1;LCM_RW_0;_NOP();
sbi 0x18,0
.dbline 93
cbi 0x18,1
.dbline 93
nop
.dbline 94
; DataPort=dataW;_NOP();
out 0x1b,R20
.dbline 94
nop
.dbline 95
; LCM_EN_1;_NOP();_NOP();LCM_EN_0;
sbi 0x18,2
.dbline 95
nop
.dbline 95
nop
.dbline 95
cbi 0x18,2
.dbline -2
L19:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r dataW 20 c
.dbend
.dbfunc e WaitForEnable _WaitForEnable fV
; val -> R16
.even
_WaitForEnable::
.dbline -1
.dbline 99
; }
; //*******************检测LCD忙信号子函数*********************
; void WaitForEnable(void)
; {
.dbline 101
; uchar val;
; DataPort=0xff;
ldi R24,255
out 0x1b,R24
.dbline 102
; LCM_RS_0;LCM_RW_1;_NOP();
cbi 0x18,0
.dbline 102
sbi 0x18,1
.dbline 102
nop
.dbline 103
; LCM_EN_1;_NOP();_NOP();
sbi 0x18,2
.dbline 103
nop
.dbline 103
nop
.dbline 104
; DDRA=0x00;
clr R2
out 0x1a,R2
.dbline 105
; val=PINA;
in R16,0x19
xjmp L22
L21:
.dbline 106
in R16,0x19
L22:
.dbline 106
; while(val&Busy)val=PINA;
sbrc R16,7
rjmp L21
.dbline 107
; LCM_EN_0;
cbi 0x18,2
.dbline 108
; DDRA=0xff;
ldi R24,255
out 0x1a,R24
.dbline -2
L20:
.dbline 0 ; func end
ret
.dbsym r val 16 c
.dbend
.dbfunc e Delay_1ms _Delay_1ms fV
; i -> R16,R17
.even
_Delay_1ms::
.dbline -1
.dbline 112
; }
; //****************************************
; void Delay_1ms(void) //1mS延时子函数
; { uint i;
.dbline 113
; for(i=1;i<(uint)(xtal*143-2);i++)
ldi R16,1
ldi R17,0
xjmp L28
L25:
.dbline 114
L26:
.dbline 113
subi R16,255 ; offset = 1
sbci R17,255
L28:
.dbline 113
cpi R16,118
ldi R30,4
cpc R17,R30
brlo L25
.dbline -2
L24:
.dbline 0 ; func end
ret
.dbsym r i 16 i
.dbend
.dbfunc e Delay_nms _Delay_nms fV
; i -> R20,R21
; n -> R22,R23
.even
_Delay_nms::
xcall push_gset2
movw R22,R16
.dbline -1
.dbline 118
; ;
; }
; //====================================
; void Delay_nms(uint n) //n*1mS延时子函数
; {
.dbline 119
; uint i=0;
clr R20
clr R21
xjmp L31
L30:
.dbline 121
.dbline 121
xcall _Delay_1ms
.dbline 122
subi R20,255 ; offset = 1
sbci R21,255
.dbline 123
L31:
.dbline 120
; while(i<n)
cp R20,R22
cpc R21,R23
brlo L30
.dbline -2
L29:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r i 20 i
.dbsym r n 22 i
.dbend
.dbfunc e port_init _port_init fV
.even
_port_init::
.dbline -1
.dbline 127
; {Delay_1ms();
; i++;
; }
; }
; /*****************端口初始化********************/
; void port_init(void)
; {
.dbline 128
; PORTA = 0x00;
clr R2
out 0x1b,R2
.dbline 129
; DDRA = 0xFF;
ldi R24,255
out 0x1a,R24
.dbline 130
; PORTB = 0x00;
out 0x18,R2
.dbline 131
; DDRB = 0xFF;
out 0x17,R24
.dbline 132
; PORTC = 0x00;
out 0x15,R2
.dbline 133
; DDRC = 0x03;
ldi R24,3
out 0x14,R24
.dbline 134
; PORTD = 0xFF;
ldi R24,255
out 0x12,R24
.dbline 135
; DDRD = 0x00;
out 0x11,R2
.dbline -2
L33:
.dbline 0 ; func end
ret
.dbend
.dbfunc e scan_key _scan_key fc
; temp -> R16
.even
_scan_key::
.dbline -1
.dbline 145
; }
; /*************************************/
; char com_data;
; uchar cnt;
; void delay_iic(int n);
; uchar rd_24c01(char a);
; void wr_24c01(char a,char b);
; /******************扫描按键***************/
; uchar scan_key(void)
; {
.dbline 147
; uchar temp;
; temp=PIND;
in R16,0x10
.dbline 148
; return temp;
.dbline -2
L34:
.dbline 0 ; func end
ret
.dbsym r temp 16 c
.dbend
.dbfunc e delay _delay fV
; i -> R20,R21
; j -> R22,R23
; k -> R16,R17
.even
_delay::
xcall push_gset2
.dbline -1
.dbline 152
; }
; /***************延时子函数******************/
; void delay(uint k)
; {
.dbline 154
; uint i,j;
; for(i=0;i<k;i++)
clr R20
clr R21
xjmp L39
L36:
.dbline 155
; {for(j=0;j<121;j++)
.dbline 155
clr R22
clr R23
xjmp L43
L40:
.dbline 156
.dbline 156
.dbline 156
L41:
.dbline 155
subi R22,255 ; offset = 1
sbci R23,255
L43:
.dbline 155
cpi R22,121
ldi R30,0
cpc R23,R30
brlo L40
.dbline 156
L37:
.dbline 154
subi R20,255 ; offset = 1
sbci R21,255
L39:
.dbline 154
cp R20,R16
cpc R21,R17
brlo L36
.dbline -2
L35:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r i 20 i
.dbsym r j 22 i
.dbsym r k 16 i
.dbend
.dbfunc e start _start fV
.even
_start::
.dbline -1
.dbline 160
; {;}}
; }
; /*****************启动读写时序子函数******************/
; void start(void)
; {DDRC=0x03;
.dbline 160
ldi R24,3
out 0x14,R24
.dbline 161
; SDA_1;Some_NOP();
sbi 0x15,1
.dbline 161
.dbline 161
nop
.dbline 161
nop
.dbline 161
nop
.dbline 161
nop
.dbline 161
nop
.dbline 161
nop
.dbline 161
nop
.dbline 161
nop
.dbline 161
.dbline 162
; SCL_1;Some_NOP();
sbi 0x15,0
.dbline 162
.dbline 162
nop
.dbline 162
nop
.dbline 162
nop
.dbline 162
nop
.dbline 162
nop
.dbline 162
nop
.dbline 162
nop
.dbline 162
nop
.dbline 162
.dbline 163
; SDA_0;Some_NOP();
cbi 0x15,1
.dbline 163
.dbline 163
nop
.dbline 163
nop
.dbline 163
nop
.dbline 163
nop
.dbline 163
nop
.dbline 163
nop
.dbline 163
nop
.dbline 163
nop
.dbline 163
.dbline 164
; SCL_0;Some_NOP();
cbi 0x15,0
.dbline 164
.dbline 164
nop
.dbline 164
nop
.dbline 164
nop
.dbline 164
nop
.dbline 164
nop
.dbline 164
nop
.dbline 164
nop
.dbline 164
nop
.dbline 164
.dbline -2
L44:
.dbline 0 ; func end
ret
.dbend
.dbfunc e stop _stop fV
.even
_stop::
.dbline -1
.dbline 168
; }
; //********************停止操作子函数*********************
; void stop(void)
; { DDRC=0x03;
.dbline 168
ldi R24,3
out 0x14,R24
.dbline 169
; SDA_0;Some_NOP();
cbi 0x15,1
.dbline 169
.dbline 169
nop
.dbline 169
nop
.dbline 169
nop
.dbline 169
nop
.dbline 169
nop
.dbline 169
nop
.dbline 169
nop
.dbline 169
nop
.dbline 169
.dbline 170
; SCL_1;Some_NOP();
sbi 0x15,0
.dbline 170
.dbline 170
nop
.dbline 170
nop
.dbline 170
nop
.dbline 170
nop
.dbline 170
nop
.dbline 170
nop
.dbline 170
nop
.dbline 170
nop
.dbline 170
.dbline 171
; SDA_1;Some_NOP();
sbi 0x15,1
.dbline 171
.dbline 171
nop
.dbline 171
nop
.dbline 171
nop
.dbline 171
nop
.dbline 171
nop
.dbline 171
nop
.dbline 171
nop
.dbline 171
nop
.dbline 171
.dbline -2
L45:
.dbline 0 ; func end
ret
.dbend
.dbfunc e ack _ack fV
.even
_ack::
.dbline -1
.dbline 175
; }
; //************应答子函数*************
; void ack(void)
; { DDRC=0x03;
.dbline 175
ldi R24,3
out 0x14,R24
.dbline 176
; SCL_1;Some_NOP();
sbi 0x15,0
.dbline 176
.dbline 176
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -