📄 touch.s
字号:
.module touch.c
.area data(ram, con, rel)
_touch_count::
.blkb 1
.area idata
.byte 0
.area data(ram, con, rel)
.dbfile F:\Relations\sf6_system\measure\LCDtest\touch.c
.dbsym e touch_count _touch_count c
_touch_flag::
.blkb 1
.area idata
.byte 1
.area data(ram, con, rel)
.dbfile F:\Relations\sf6_system\measure\LCDtest\touch.c
.dbsym e touch_flag _touch_flag c
.area text(rom, con, rel)
.dbfile F:\Relations\sf6_system\measure\LCDtest\touch.c
.dbfunc e Init_Touch _Init_Touch fV
.even
_Init_Touch::
.dbline -1
.dbline 24
; #include <iom128v.h>
; #include "touch.h"
; #include <macros.h>
; #include "display.h"
; #include "lcd.h"
;
; #define DELAY_TOUCH 20
; struct Touch cursor;
;
; /*
; mega128单片机驱动ADS7846/ADS7843芯片
; ADS7846/7843芯片 适合用在4线制触摸屏,它通过标准SPI协议和CPU通信,操作简单,精度高,当
; 触摸屏被按下时(即有触摸事件发生)则ADS7846向CPU发中断请求,CPU接到请求后,应延时一下再响应其请求,目的是为了消除抖动使得采样更准确。如果一次采样不准确。
; ADS7846 触摸屏中断 外部中断6(INT6)
; DCLK PD4
; DIN PD5
; READY PD6
; DOUT PD7
;
; */
; unsigned char touch_count = 0;
; unsigned char touch_flag = 1; //显示屏关闭时为0,打开时为1
; void Init_Touch(void)
; {
.dbline 25
; DDRD |= 0x70;
in R24,0x11
ori R24,112
out 0x11,R24
.dbline 26
; T_CS_1;
sbi 0x12,6
.dbline 26
.dbline 27
; DDRD &=~0x80;
cbi 0x11,7
.dbline 28
; PIND &= ~0x60;
in R24,0x10
andi R24,159
out 0x10,R24
.dbline 29
; EIFR |= 0x40;
in R24,0x38
ori R24,64
out 0x38,R24
.dbline 33
; //EICRB = 0x02;
; //DDRE &= ~0x40;
; //PORTE |= 0x40;
; Touch_Int_ON;
in R24,0x39
ori R24,64
out 0x39,R24
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbend
.dbfunc e start _start fV
.even
_start::
.dbline -1
.dbline 38
; //WriteCharTo7843(0x98);
;
; }
; void start(void)
; {
.dbline 39
; DCLK_0;
cbi 0x12,4
.dbline 40
; T_CS_1;
sbi 0x12,6
.dbline 40
.dbline 41
; DIN_1;
sbi 0x12,5
.dbline 42
; DCLK_1;
sbi 0x12,4
.dbline 43
; T_CS_0;
cbi 0x12,6
.dbline 43
.dbline -2
L2:
.dbline 0 ; func end
ret
.dbend
.dbfunc e delay _delay fV
; i -> R16
.even
_delay::
.dbline -1
.dbline 46
; }
; void delay(unsigned char i)
; {
L4:
.dbline 47
L5:
.dbline 47
; while(i--);
mov R2,R16
clr R3
subi R16,1
tst R2
brne L4
.dbline -2
L3:
.dbline 0 ; func end
ret
.dbsym r i 16 c
.dbend
.dbfunc e Delayx10ms _Delayx10ms fV
; i -> R20,R21
; j -> R22,R23
; k -> R10,R11
; count -> R16,R17
.even
_Delayx10ms::
xcall push_gset3
.dbline -1
.dbline 50
; }
; void Delayx10ms(unsigned int count)
; { unsigned int i,j,k;
.dbline 51
; for(i=0;i<count;i++)
clr R20
clr R21
xjmp L11
L8:
.dbline 52
; for (j=0;j<1950;j++)
clr R22
clr R23
xjmp L15
L12:
.dbline 53
; for (k=0;k<10;k++)
clr R10
clr R11
xjmp L19
L16:
.dbline 54
L17:
.dbline 53
movw R24,R10
adiw R24,1
movw R10,R24
L19:
.dbline 53
movw R24,R10
cpi R24,10
ldi R30,0
cpc R25,R30
brlo L16
L13:
.dbline 52
subi R22,255 ; offset = 1
sbci R23,255
L15:
.dbline 52
cpi R22,158
ldi R30,7
cpc R23,R30
brlo L12
L9:
.dbline 51
subi R20,255 ; offset = 1
sbci R21,255
L11:
.dbline 51
cp R20,R16
cpc R21,R17
brlo L8
.dbline -2
L7:
xcall pop_gset3
.dbline 0 ; func end
ret
.dbsym r i 20 i
.dbsym r j 22 i
.dbsym r k 10 i
.dbsym r count 16 i
.dbend
.dbfunc e WriteCharTo7843 _WriteCharTo7843 fV
; count -> R20
; num -> R22
.even
_WriteCharTo7843::
xcall push_gset2
mov R22,R16
.dbline -1
.dbline 57
; ;
; }
; void WriteCharTo7843(unsigned char num) //SPI写数据
; {
.dbline 58
; unsigned char count=0;
clr R20
.dbline 59
; DCLK_0;
cbi 0x12,4
.dbline 60
; delay(DELAY_TOUCH);
ldi R16,20
xcall _delay
.dbline 61
; for(count=0;count<8;count++)
xjmp L24
L21:
.dbline 62
; {
.dbline 63
; if(num&0x80)
sbrs R22,7
rjmp L25
.dbline 64
; {
.dbline 65
; DIN_1;
sbi 0x12,5
.dbline 66
; }
xjmp L26
L25:
.dbline 68
; else
; { DIN_0;
.dbline 68
cbi 0x12,5
.dbline 69
; }
L26:
.dbline 70
lsl R22
.dbline 71
ldi R16,20
xcall _delay
.dbline 72
sbi 0x12,4
.dbline 73
ldi R16,20
xcall _delay
.dbline 74
cbi 0x12,4
.dbline 75
ldi R16,20
xcall _delay
.dbline 77
L22:
.dbline 61
inc R20
L24:
.dbline 61
cpi R20,8
brlo L21
.dbline 78
; num<<=1;
; delay(DELAY_TOUCH);
; DCLK_1;
; delay(DELAY_TOUCH); //上升沿有效
; DCLK_0;
; delay(DELAY_TOUCH);
;
; }
; DIN_0;
cbi 0x12,5
.dbline -2
L20:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r count 20 c
.dbsym r num 22 c
.dbend
.dbfunc e ReadFromCharFrom7843 _ReadFromCharFrom7843 fi
; Num -> R20,R21
; count -> R22
.even
_ReadFromCharFrom7843::
xcall push_gset2
.dbline -1
.dbline 83
; }
;
;
; unsigned int ReadFromCharFrom7843(void) //SPI 读数据
; {
.dbline 84
; unsigned char count=0;
clr R22
.dbline 85
; unsigned int Num=0;
clr R20
clr R21
.dbline 86
; for(count=0;count<8;count++)
xjmp L31
L28:
.dbline 87
; {
.dbline 88
; Num<<=1;
lsl R20
rol R21
.dbline 89
; DCLK_0;
cbi 0x12,4
.dbline 90
; delay(DELAY_TOUCH); //下降沿有效
ldi R16,20
xcall _delay
.dbline 91
; DCLK_1;
sbi 0x12,4
.dbline 92
; delay(DELAY_TOUCH);
ldi R16,20
xcall _delay
.dbline 93
; if(DOUT) Num++;
in R24,0x10
andi R24,128
out 0x10,R24
tst R24
breq L32
.dbline 93
subi R20,255 ; offset = 1
sbci R21,255
L32:
.dbline 94
L29:
.dbline 86
inc R22
L31:
.dbline 86
cpi R22,8
brlo L28
.dbline 95
; }
; return(Num);
movw R16,R20
.dbline -2
L27:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r Num 20 i
.dbsym r count 22 c
.dbend
.area vector(rom, abs)
.org 28
jmp _Touch
.area text(rom, con, rel)
.dbfile F:\Relations\sf6_system\measure\LCDtest\touch.c
.dbfunc e Touch _Touch fV
; i -> <dead>
; max -> R10,R11
; min -> R10,R11
; temp -> y+0
.even
_Touch::
xcall push_lset
xcall push_gset3
sbiw R28,4
.dbline -1
.dbline 99
; }
; #pragma interrupt_handler Touch:8
; void Touch(void)//外部中断0 用来接受键盘发来的数据
; {
.dbline 100
; unsigned long temp = 0;
ldi R20,0
ldi R21,0
ldi R22,0
ldi R23,0
movw R30,R28
std z+0,R20
std z+1,R21
std z+2,R22
std z+3,R23
.dbline 101
; unsigned int min=0xffff,max=0;
.dbline 101
clr R10
clr R11
.dbline 103
; unsigned char i;
; BEEPON;
lds R24,98
andi R24,247
sts 98,R24
.dbline 104
; cursor.old_x = cursor.x;
lds R2,_cursor
lds R3,_cursor+1
sts _cursor+3+1,R3
sts _cursor+3,R2
.dbline 105
; cursor.old_y = cursor.y;
lds R2,_cursor+2
sts _cursor+5,R2
.dbline 106
; delay(100);
ldi R16,100
xcall _delay
.dbline 107
; start();
xcall _start
.dbline 109
; //T_CS_0;
; delay(20);
ldi R16,20
xcall _delay
.dbline 110
; WriteCharTo7843(0x98); //送控制字 10010000 即用差分方式读X坐标 详细请见有关资料
ldi R16,152
xcall _WriteCharTo7843
.dbline 111
; delay(20);
ldi R16,20
xcall _delay
.dbline 112
; DCLK_1;
sbi 0x12,4
.dbline 113
; delay(DELAY_TOUCH);
ldi R16,20
xcall _delay
.dbline 114
; DCLK_0;
cbi 0x12,4
.dbline 115
; delay(DELAY_TOUCH);
ldi R16,20
xcall _delay
.dbline 116
; cursor.y= ReadFromCharFrom7843();
xcall _ReadFromCharFrom7843
sts _cursor+2,R16
.dbline 118
;
; WriteCharTo7843(0xD8);
ldi R16,216
xcall _WriteCharTo7843
.dbline 119
; DCLK_1;
sbi 0x12,4
.dbline 120
; delay(DELAY_TOUCH);
ldi R16,20
xcall _delay
.dbline 121
; DCLK_0;
cbi 0x12,4
.dbline 122
; delay(DELAY_TOUCH);
ldi R16,20
xcall _delay
.dbline 123
; cursor.x = ReadFromCharFrom7843();
xcall _ReadFromCharFrom7843
sts _cursor+1,R17
sts _cursor,R16
.dbline 127
;
;
;
; temp = 0;
ldi R20,0
ldi R21,0
ldi R22,0
ldi R23,0
movw R30,R28
std z+0,R20
std z+1,R21
std z+2,R22
std z+3,R23
.dbline 128
; Delayx10ms(8);
ldi R16,8
ldi R17,0
xcall _Delayx10ms
.dbline 129
; if(cursor.x>=15)
lds R24,_cursor
lds R25,_cursor+1
cpi R24,15
ldi R30,0
cpc R25,R30
brlo L39
.dbline 130
; {
.dbline 131
; temp = cursor.x-15;
sbiw R24,15
movw R2,R24
clr R4
clr R5
movw R30,R28
std z+0,R2
std z+1,R3
std z+2,R4
std z+3,R5
.dbline 132
; }
xjmp L40
L39:
.dbline 134
; else
; {
.dbline 135
; temp = 0;
ldi R20,0
ldi R21,0
ldi R22,0
ldi R23,0
movw R30,R28
std z+0,R20
std z+1,R21
std z+2,R22
std z+3,R23
.dbline 136
; }
L40:
.dbline 137
; cursor.x = temp*320/224;
movw R30,R28
ldd R2,z+0
ldd R3,z+1
ldd R4,z+2
ldd R5,z+3
ldi R20,64
ldi R21,1
ldi R22,0
ldi R23,0
st -y,R5
st -y,R4
st -y,R3
st -y,R2
movw R16,R20
movw R18,R22
xcall empy32u
ldi R20,224
ldi R21,0
ldi R22,0
ldi R23,0
st -y,R23
st -y,R22
st -y,R21
st -y,R20
xcall div32u
sts _cursor+1,R17
sts _cursor,R16
.dbline 138
; if(cursor.x>320)
ldi R24,320
ldi R25,1
cp R24,R16
cpc R25,R17
brsh L41
.dbline 139
; {
.dbline 140
; cursor.x = 320;
sts _cursor+1,R25
sts _cursor,R24
.dbline 141
; }
L41:
.dbline 142
; if(cursor.y>= 15)
lds R24,_cursor+2
cpi R24,15
brlo L43
.dbline 143
; {
.dbline 144
; temp = cursor.y-15;
clr R25
sbiw R24,15
movw R2,R24
clr R4
sbrc R3,7
com R4
clr R5
sbrc R4,7
com R5
movw R30,R28
std z+0,R2
std z+1,R3
std z+2,R4
std z+3,R5
.dbline 145
; }
xjmp L44
L43:
.dbline 147
; else
; {
.dbline 148
; temp = 0;
ldi R20,0
ldi R21,0
ldi R22,0
ldi R23,0
movw R30,R28
std z+0,R20
std z+1,R21
std z+2,R22
std z+3,R23
.dbline 149
; }
L44:
.dbline 150
; cursor.y = temp*240/221;
movw R30,R28
ldd R2,z+0
ldd R3,z+1
ldd R4,z+2
ldd R5,z+3
ldi R20,240
ldi R21,0
ldi R22,0
ldi R23,0
st -y,R5
st -y,R4
st -y,R3
st -y,R2
movw R16,R20
movw R18,R22
xcall empy32u
ldi R20,221
ldi R21,0
ldi R22,0
ldi R23,0
st -y,R23
st -y,R22
st -y,R21
st -y,R20
xcall div32u
sts _cursor+2,R16
.dbline 151
; if(cursor.y > 240)
ldi R24,240
cp R24,R16
brsh L48
.dbline 152
; {
.dbline 153
; cursor.y = 240;
sts _cursor+2,R24
.dbline 154
; }
L48:
.dbline 155
; cursor.flag = 1;
ldi R24,1
sts _cursor+6,R24
.dbline 156
; BEEPOFF;
lds R24,98
ori R24,8
sts 98,R24
.dbline 157
; EIFR |= 0x40;
in R24,0x38
ori R24,64
out 0x38,R24
.dbline 158
; T_CS_1;
sbi 0x12,6
.dbline 158
.dbline -2
L34:
adiw R28,4
xcall pop_gset3
xcall pop_lset
.dbline 0 ; func end
reti
.dbsym l i 1 c
.dbsym r max 10 i
.dbsym r min 10 i
.dbsym l temp 0 l
.dbend
.area bss(ram, con, rel)
.dbfile F:\Relations\sf6_system\measure\LCDtest\touch.c
_cursor::
.blkb 7
.dbstruct 0 7 Touch
.dbfield 0 x i
.dbfield 2 y c
.dbfield 3 old_x i
.dbfield 5 old_y c
.dbfield 6 flag c
.dbend
.dbsym e cursor _cursor S[Touch]
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -