📄 test.s
字号:
.module test.c
.area text(rom, con, rel)
.dbfile E:\WaveShare\微雪电子CD1\开发板试验器\SD系列\M16SD\试验教程\外围模块相关试验\NOKIA3~1\Nokia3510i\test\test.c
.dbfunc e port_init _port_init fV
.even
_port_init::
.dbline -1
.dbline 28
; //ICC-AVR application builder : 2005-4-16 21:20:40
; // Target : M8
; // Crystal: 8.0000Mhz
;
; #include <iom16v.h>
; #include <macros.h>
;
; #define csl asm("cbi 0x18,0") //PB0
; #define csh asm("sbi 0x18,0")
;
; #define restl asm("cbi 0x12,1") //PB4
; #define resth asm("sbi 0x12,1")
;
; #define sclkl asm("cbi 0x18,7") //PB5
; #define sclkh asm("sbi 0x18,7")
;
; #define sdatal asm("cbi 0x18,5") //PB3
; #define sdatah asm("sbi 0x18,5")
; #define CS 3
; #define SCLK 7
; #define SDATA 5
; #define RESET 2
;
; #define CMD 0
; #define DATA 1
;
; void port_init(void)
; {
.dbline 29
; PORTB = 0xFF;
ldi R24,255
out 0x18,R24
.dbline 30
; DDRB = 0x00;
clr R2
out 0x17,R2
.dbline 31
; PORTC = 0x7F; //m103 output only
ldi R24,127
out 0x15,R24
.dbline 32
; DDRC = 0x00;
out 0x14,R2
.dbline 33
; PORTD = 0xFF;
ldi R24,255
out 0x12,R24
.dbline 34
; DDRD = 0x00;
out 0x11,R2
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbend
.dbfunc e init_devices _init_devices fV
.even
_init_devices::
.dbline -1
.dbline 39
; }
;
; //call this routine to initialise all peripherals
; void init_devices(void)
; {
.dbline 42
; //stop errant interrupts until set up
; //CLI(); //disable all interrupts
; port_init();
xcall _port_init
.dbline 44
;
; MCUCR = 0x00;
clr R2
out 0x35,R2
.dbline 45
; GICR = 0x00;
out 0x3b,R2
.dbline 46
; TIMSK = 0x00; //timer interrupt sources
out 0x39,R2
.dbline -2
L2:
.dbline 0 ; func end
ret
.dbend
.dbfunc e delay5ms _delay5ms fV
; i -> y+0
.even
_delay5ms::
sbiw R28,2
.dbline -1
.dbline 59
; //SEI(); //re-enable interrupts
; //all peripherals are now initialised
; }
;
; //
; //ICC-AVR application builder : 2005-4-16 21:20:40
; // Target : M8
; // Crystal: 8.0000Mhz
;
;
;
;
; void delay5ms(void) {
.dbline 61
clr R2
clr R3
std y+1,R3
std y+0,R2
L4:
.dbline 61
L5:
.dbline 61
; volatile int i;
; for(i=0; i<2200; i++);
ldd R24,y+0
ldd R25,y+1
adiw R24,1
std y+1,R25
std y+0,R24
.dbline 61
cpi R24,152
ldi R30,8
cpc R25,R30
brlt L4
.dbline -2
L3:
adiw R28,2
.dbline 0 ; func end
ret
.dbsym l i 0 I
.dbend
.dbfunc e send _send fV
; cd -> R18
; myData -> R16
.even
_send::
.dbline -1
.dbline 69
; }
;
; //----------------------------
; //发送指令或数据 硬件SPI
; //速度快,没有刷屏现象
; //----------------------------
; void send(unsigned char myData,unsigned char cd)
; {
.dbline 70
; if(cd==DATA)
cpi R18,1
brne L9
.dbline 71
; {
.dbline 72
; csl;
cbi 0x18,0
.dbline 73
; sclkl;
cbi 0x18,7
.dbline 74
; sdatah;
sbi 0x18,5
.dbline 75
; sclkh;
sbi 0x18,7
.dbline 76
; }
xjmp L10
L9:
.dbline 78
; else
; {
.dbline 79
; csl;
cbi 0x18,0
.dbline 81
;
; sclkl;
cbi 0x18,7
.dbline 82
; sdatal;
cbi 0x18,5
.dbline 83
; sclkh;
sbi 0x18,7
.dbline 85
;
; }
L10:
.dbline 86
; SPCR = 0x50; //setup SPI
ldi R24,80
out 0xd,R24
.dbline 88
;
; SPDR = myData;
out 0xf,R16
L11:
.dbline 90
L12:
.dbline 90
;
; while(!(SPSR & 0x80));
sbis 0xe,7
rjmp L11
.dbline 92
;
; csh;
sbi 0x18,0
.dbline 93
; SPCR = 0x00;
clr R2
out 0xd,R2
.dbline -2
L8:
.dbline 0 ; func end
ret
.dbsym r cd 18 c
.dbsym r myData 16 c
.dbend
.dbfunc e send2 _send2 fV
; cd -> R18
; data -> R16
.even
_send2::
.dbline -1
.dbline 103
;
;
; }
;
; //----------------------------
; //发送指令或数据 软件模拟SPI
; //速度较慢,有刷屏现象
; //----------------------------
; void send2(char data, char cd)
; {
.dbline 105
; // CS auf Low setzen
; PORTD &= ~(0x01 << CS);
cbi 0x12,3
.dbline 108
;
; // Kommando oder Daten?
; PORTB &= ~(0x01 << SCLK);
cbi 0x18,7
.dbline 109
; if(cd == CMD)
tst R18
brne L15
.dbline 110
; PORTB &= ~(0x01 << SDATA);
cbi 0x18,5
xjmp L16
L15:
.dbline 112
; else
; PORTB |= 0x01 << SDATA;
sbi 0x18,5
L16:
.dbline 113
; PORTB |= 0x01 << SCLK;
sbi 0x18,7
.dbline 116
;
; // 1. Bit (MSB)
; PORTB &= ~(0x01 << SCLK);
cbi 0x18,7
.dbline 117
; if((data & 0x80) == 0x80)
mov R24,R16
andi R24,128
cpi R24,128
brne L17
.dbline 118
; PORTB |= 0x01 << SDATA;
sbi 0x18,5
xjmp L18
L17:
.dbline 120
; else
; PORTB &= ~(0x01 << SDATA);
cbi 0x18,5
L18:
.dbline 121
; PORTB |= 0x01 << SCLK;
sbi 0x18,7
.dbline 124
;
; // 2. Bit (MSB)
; PORTB &= ~(0x01 << SCLK);
cbi 0x18,7
.dbline 125
; if((data & 0x40) == 0x40)
mov R24,R16
andi R24,64
cpi R24,64
brne L19
.dbline 126
; PORTB |= 0x01 << SDATA;
sbi 0x18,5
xjmp L20
L19:
.dbline 128
; else
; PORTB &= ~(0x01 << SDATA);
cbi 0x18,5
L20:
.dbline 129
; PORTB |= 0x01 << SCLK;
sbi 0x18,7
.dbline 132
;
; // 3. Bit (MSB)
; PORTB &= ~(0x01 << SCLK);
cbi 0x18,7
.dbline 133
; if((data & 0x20) == 0x20)
mov R24,R16
andi R24,32
cpi R24,32
brne L21
.dbline 134
; PORTB |= 0x01 << SDATA;
sbi 0x18,5
xjmp L22
L21:
.dbline 136
; else
; PORTB &= ~(0x01 << SDATA);
cbi 0x18,5
L22:
.dbline 137
; PORTB |= 0x01 << SCLK;
sbi 0x18,7
.dbline 140
;
; // 4. Bit (MSB)
; PORTB &= ~(0x01 << SCLK);
cbi 0x18,7
.dbline 141
; if((data & 0x10) == 0x10)
mov R24,R16
andi R24,16
cpi R24,16
brne L23
.dbline 142
; PORTB |= 0x01 << SDATA;
sbi 0x18,5
xjmp L24
L23:
.dbline 144
; else
; PORTB &= ~(0x01 << SDATA);
cbi 0x18,5
L24:
.dbline 145
; PORTB |= 0x01 << SCLK;
sbi 0x18,7
.dbline 148
;
; // 5. Bit (MSB)
; PORTB &= ~(0x01 << SCLK);
cbi 0x18,7
.dbline 149
; if((data & 0x08) == 0x08)
mov R24,R16
andi R24,8
cpi R24,8
brne L25
.dbline 150
; PORTB |= 0x01 << SDATA;
sbi 0x18,5
xjmp L26
L25:
.dbline 152
; else
; PORTB &= ~(0x01 << SDATA);
cbi 0x18,5
L26:
.dbline 153
; PORTB |= 0x01 << SCLK;
sbi 0x18,7
.dbline 156
;
; // 6. Bit (MSB)
; PORTB &= ~(0x01 << SCLK);
cbi 0x18,7
.dbline 157
; if((data & 0x04) == 0x04)
mov R24,R16
andi R24,4
cpi R24,4
brne L27
.dbline 158
; PORTB |= 0x01 << SDATA;
sbi 0x18,5
xjmp L28
L27:
.dbline 160
; else
; PORTB &= ~(0x01 << SDATA);
cbi 0x18,5
L28:
.dbline 161
; PORTB |= 0x01 << SCLK;
sbi 0x18,7
.dbline 164
;
; // 7. Bit (MSB)
; PORTB &= ~(0x01 << SCLK);
cbi 0x18,7
.dbline 165
; if((data & 0x02) == 0x02)
mov R24,R16
andi R24,2
cpi R24,2
brne L29
.dbline 166
; PORTB |= 0x01 << SDATA;
sbi 0x18,5
xjmp L30
L29:
.dbline 168
; else
; PORTB &= ~(0x01 << SDATA);
cbi 0x18,5
L30:
.dbline 169
; PORTB |= 0x01 << SCLK;
sbi 0x18,7
.dbline 172
;
; // 8. Bit (MSB)
; PORTB &= ~(0x01 << SCLK);
cbi 0x18,7
.dbline 173
; if((data & 0x01) == 0x01)
mov R24,R16
andi R24,1
cpi R24,1
brne L31
.dbline 174
; PORTB |= 0x01 << SDATA;
sbi 0x18,5
xjmp L32
L31:
.dbline 176
; else
; PORTB &= ~(0x01 << SDATA);
cbi 0x18,5
L32:
.dbline 177
; PORTB |= 0x01 << SCLK;
sbi 0x18,7
.dbline -2
L14:
.dbline 0 ; func end
ret
.dbsym r cd 18 c
.dbsym r data 16 c
.dbend
.dbfunc e cs _cs fV
.even
_cs::
.dbline -1
.dbline 180
; }
;
; void cs(void) {
.dbline 181
; PORTD |= 0x01 << CS; // CS wieder auf 1
sbi 0x12,3
.dbline -2
L33:
.dbline 0 ; func end
ret
.dbend
.dbfunc e main _main fI
; s -> R22
; i -> R20,R21
.even
_main::
.dbline -1
.dbline 184
; }
;
; int main(void) {
.dbline 187
; int i;
; char s;
; init_devices();
xcall _init_devices
.dbline 188
; DDRB = 0xFF; // PortB = Output
ldi R24,255
out 0x17,R24
.dbline 189
; DDRD = 0xff;
out 0x11,R24
.dbline 191
; // LCD Hardware Reset
; PORTD &= ~(0x01 << 0);
cbi 0x12,0
.dbline 192
; delay5ms();
xcall _delay5ms
.dbline 193
; PORTD |= 0x01 << 0;
sbi 0x12,0
.dbline 195
;
; PORTD |= 0x01 << CS;
sbi 0x12,3
.dbline 196
; PORTB |= 0x01 << SCLK;
sbi 0x18,7
.dbline 197
; PORTB |= 0x01 << SDATA;
sbi 0x18,5
.dbline 199
;
; send(0x01, CMD); // LCD Software Reset
clr R18
ldi R16,1
xcall _send
.dbline 200
; cs();
xcall _cs
.dbline 201
; delay5ms();
xcall _delay5ms
.dbline 203
;
; send(0xC6, CMD); // Initial Escape
clr R18
ldi R16,198
xcall _send
.dbline 204
; cs();
xcall _cs
.dbline 206
;
; send(0xB9, CMD); // Refresh set
clr R18
ldi R16,185
xcall _send
.dbline 207
; send(0x00, DATA);
ldi R18,1
clr R16
xcall _send
.dbline 208
; cs();
xcall _cs
.dbline 210
;
; send(0xB6, CMD); // Display Control
clr R18
ldi R16,182
xcall _send
.dbline 211
; send(128, DATA);
ldi R18,1
ldi R16,128
xcall _send
.dbline 212
; send(128, DATA);
ldi R18,1
ldi R16,128
xcall _send
.dbline 213
; send(129, DATA);
ldi R18,1
ldi R16,129
xcall _send
.dbline 214
; send(84, DATA);
ldi R18,1
ldi R16,84
xcall _send
.dbline 215
; send(69, DATA);
ldi R18,1
ldi R16,69
xcall _send
.dbline 216
; send(82, DATA);
ldi R18,1
ldi R16,82
xcall _send
.dbline 217
; send(67, DATA);
ldi R18,1
ldi R16,67
xcall _send
.dbline 218
; cs();
xcall _cs
.dbline 220
;
; send(0xB3, CMD); // Gray Scale Position
clr R18
ldi R16,179
xcall _send
.dbline 221
; send(1, DATA);
ldi R18,1
ldi R16,1
xcall _send
.dbline 222
; send(2, DATA);
ldi R18,1
ldi R16,2
xcall _send
.dbline 223
; send(4, DATA);
ldi R18,1
ldi R16,4
xcall _send
.dbline 224
; send(8, DATA);
ldi R18,1
ldi R16,8
xcall _send
.dbline 225
; send(16, DATA);
ldi R18,1
ldi R16,16
xcall _send
.dbline 226
; send(30, DATA);
ldi R18,1
ldi R16,30
xcall _send
.dbline 227
; send(40, DATA);
ldi R18,1
ldi R16,40
xcall _send
.dbline 228
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -