📄 ac15-3.s
字号:
.module ac15-3.c
.area lit(rom, con, rel)
_str0::
.byte 'W,'r,'i,'t,'e,32,58,32,0
.dbfile d:\MYDOCU~1\ac15-3\ac15-3.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-3\ac15-3.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 63
; #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 rd_device_add 0xa1
; #define wr_device_add 0xa0
;
; //======================================
; //TWI状态定义
; //MT 主方式传输 MR 主方式接收
; #define START 0x08
; #define RE_START 0x10
; #define MT_SLA_ACK 0x18
; #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
;
; //常用TWI操作(主模式写和主模式读)
; #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);}
;
; #define DataPort PORTA
; #define Busy 0x80
; #define xtal 8
;
; //=====================================
; const uchar str0[]={"Write : "};//待显字符串
; const uchar str1[]={"Read : "};//待显字符串
;
; //========函数声明=========
; 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 delay_ms(unsigned int time);
; void delay_us(int time);
;
; //**********************显示指定座标的一串字符子函数**************
; void ePutstr(uchar x,uchar y,uchar const *ptr)
; {
.dbline 64
; uchar i,l=0;
clr R20
xjmp L3
L2:
.dbline 65
.dbline 65
inc R20
.dbline 65
L3:
.dbline 65
; 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 66
clr R22
xjmp L8
L5:
.dbline 66
; for(i=0;i<l;i++){
.dbline 67
; 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 68
; if(x==16){
mov R24,R14
cpi R24,16
brne L9
.dbline 68
.dbline 69
; x=0;y^=1;
clr R14
.dbline 69
ldi R24,1
eor R12,R24
.dbline 70
; }
L9:
.dbline 71
L6:
.dbline 66
inc R22
L8:
.dbline 66
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 76
; }
; }
;
; //*******************显示光标定位子函数******************
; void LocateXY(char posx,char posy)
; {
.dbline 78
; uchar temp;
; temp&=0x7f;
andi R20,127
.dbline 79
; temp=posx&0x0f;
mov R20,R10
andi R20,15
.dbline 80
; posy&=0x01;
andi R22,1
.dbline 81
; if(posy)temp|=0x40;
breq L12
.dbline 81
ori R20,64
L12:
.dbline 82
; temp|=0x80;
ori R20,128
.dbline 83
; 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 88
; }
;
; //*******************显示指定座标的一个字符子函数*******************
; void DisplayOneChar(uchar x,uchar y,uchar Wdata)
; {
.dbline 89
; LocateXY(x,y);
mov R18,R22
mov R16,R20
xcall _LocateXY
.dbline 90
; 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 95
; }
;
; //*******************LCD初始化子函数*********************
; void InitLcd(void)
; {
.dbline 96
; LcdWriteCommand(0x38,0);
clr R18
ldi R16,56
xcall _LcdWriteCommand
.dbline 97
; delay_ms(5);
ldi R16,5
ldi R17,0
xcall _delay_ms
.dbline 98
; LcdWriteCommand(0x38,0);
clr R18
ldi R16,56
xcall _LcdWriteCommand
.dbline 99
; delay_ms(5);
ldi R16,5
ldi R17,0
xcall _delay_ms
.dbline 100
; LcdWriteCommand(0x38,0);
clr R18
ldi R16,56
xcall _LcdWriteCommand
.dbline 101
; delay_ms(5);
ldi R16,5
ldi R17,0
xcall _delay_ms
.dbline 102
; LcdWriteCommand(0x38,1);
ldi R18,1
ldi R16,56
xcall _LcdWriteCommand
.dbline 103
; LcdWriteCommand(0x08,1);
ldi R18,1
ldi R16,8
xcall _LcdWriteCommand
.dbline 104
; LcdWriteCommand(0x01,1);
ldi R18,1
ldi R16,1
xcall _LcdWriteCommand
.dbline 105
; LcdWriteCommand(0x06,1);
ldi R18,1
ldi R16,6
xcall _LcdWriteCommand
.dbline 106
; 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 111
; }
;
; //********************写命令到LCM子函数********************
; void LcdWriteCommand(uchar CMD,uchar Attribc)
; {
.dbline 112
; if(Attribc)WaitForEnable();
tst R22
breq L17
.dbline 112
xcall _WaitForEnable
L17:
.dbline 113
; LCM_RS_0;LCM_RW_0;_NOP();
cbi 0x18,0
.dbline 113
cbi 0x18,1
.dbline 113
nop
.dbline 114
; DataPort=CMD;_NOP();
out 0x1b,R20
.dbline 114
nop
.dbline 115
; LCM_EN_1;_NOP();_NOP();LCM_EN_0;
sbi 0x18,2
.dbline 115
nop
.dbline 115
nop
.dbline 115
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 120
; }
;
; //*******************写数据到LCM子函数********************
; void LcdWriteData(uchar dataW)
; {
.dbline 121
; WaitForEnable();
xcall _WaitForEnable
.dbline 122
; LCM_RS_1;LCM_RW_0;_NOP();
sbi 0x18,0
.dbline 122
cbi 0x18,1
.dbline 122
nop
.dbline 123
; DataPort=dataW;_NOP();
out 0x1b,R20
.dbline 123
nop
.dbline 124
; LCM_EN_1;_NOP();_NOP();LCM_EN_0;
sbi 0x18,2
.dbline 124
nop
.dbline 124
nop
.dbline 124
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 129
; }
;
; //*******************检测LCD忙信号子函数*********************
; void WaitForEnable(void)
; {
.dbline 131
; uchar val;
; DataPort=0xff;
ldi R24,255
out 0x1b,R24
.dbline 132
; LCM_RS_0;LCM_RW_1;_NOP();
cbi 0x18,0
.dbline 132
sbi 0x18,1
.dbline 132
nop
.dbline 133
; LCM_EN_1;_NOP();_NOP();
sbi 0x18,2
.dbline 133
nop
.dbline 133
nop
.dbline 134
; DDRA=0x00;
clr R2
out 0x1a,R2
.dbline 135
; val=PINA;
in R16,0x19
xjmp L22
L21:
.dbline 136
in R16,0x19
L22:
.dbline 136
; while(val&Busy)val=PINA;
sbrc R16,7
rjmp L21
.dbline 137
; LCM_EN_0;
cbi 0x18,2
.dbline 138
; DDRA=0xff;
ldi R24,255
out 0x1a,R24
.dbline -2
L20:
.dbline 0 ; func end
ret
.dbsym r val 16 c
.dbend
.dbfunc e port_init _port_init fV
.even
_port_init::
.dbline -1
.dbline 143
; }
;
; /********************端口初始化******************/
; void port_init(void)
; {
.dbline 144
; PORTA = 0x00;
clr R2
out 0x1b,R2
.dbline 145
; DDRA = 0xFF;
ldi R24,255
out 0x1a,R24
.dbline 146
; PORTB = 0x00;
out 0x18,R2
.dbline 147
; DDRB = 0xFF;
out 0x17,R24
.dbline 148
; PORTC = 0x00;
out 0x15,R2
.dbline 149
; DDRC = 0x03;
ldi R24,3
out 0x14,R24
.dbline 150
; PORTD = 0xFF;
ldi R24,255
out 0x12,R24
.dbline 151
; DDRD = 0x00;
out 0x11,R2
.dbline -2
L24:
.dbline 0 ; func end
ret
.dbend
.dbfunc e scan_key _scan_key fc
; temp -> R16
.even
_scan_key::
.dbline -1
.dbline 156
; }
;
; /*******************扫描按键******************/
; uchar scan_key(void)
; {
.dbline 158
; uchar temp;
; temp=PIND;
in R16,0x10
.dbline 159
; return temp;
.dbline -2
L25:
.dbline 0 ; func end
ret
.dbsym r temp 16 c
.dbend
.dbfunc e i2c_Read _i2c_Read fc
; temp -> R20
; RomAddress -> R16
.even
_i2c_Read::
xcall push_gset1
.dbline -1
.dbline 167
; }
;
; /******************************************
; I2C总线读一个字节
; 如果读失败返回0
; *******************************************/
; unsigned char i2c_Read(unsigned char RomAddress)
; {
.dbline 169
; unsigned char temp;
; Start();
ldi R24,164
out 0x36,R24
.dbline 170
L27:
.dbline 170
L28:
.dbline 170
; Wait();
in R2,0x36
sbrs R2,7
rjmp L27
.dbline 170
.dbline 170
.dbline 171
; if (TestAck()!=START) return 0;
in R24,0x1
andi R24,248
cpi R24,8
breq L30
.dbline 171
clr R16
xjmp L26
L30:
.dbline 172
; Write8Bit(wr_device_add);
.dbline 172
ldi R24,160
out 0x3,R24
.dbline 172
ldi R24,132
out 0x36,R24
.dbline 172
.dbline 172
.dbline 173
L32:
.dbline 173
L33:
.dbline 173
; Wait();
in R2,0x36
sbrs R2,7
rjmp L32
.dbline 173
.dbline 173
.dbline 174
; if (TestAck()!=MT_SLA_ACK) return 0;
in R24,0x1
andi R24,248
cpi R24,24
breq L35
.dbline 174
clr R16
xjmp L26
L35:
.dbline 175
; Write8Bit(RomAddress);
.dbline 175
out 0x3,R16
.dbline 175
ldi R24,132
out 0x36,R24
.dbline 175
.dbline 175
.dbline 176
L37:
.dbline 176
L38:
.dbline 176
; Wait();
in R2,0x36
sbrs R2,7
rjmp L37
.dbline 176
.dbline 176
.dbline 177
; if (TestAck()!=MT_DATA_ACK) return 0;
in R24,0x1
andi R24,248
cpi R24,40
breq L40
.dbline 177
clr R16
xjmp L26
L40:
.dbline 178
; Start();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -