1 | $regfile = "m1284pdef.dat" ' specify the used micro
|
2 | $crystal = 20000000 ' used crystal frequency
|
3 | $baud = 38400 ' use baud rate
|
4 | $hwstack = 100 ' default use 32 for the hardware stack
|
5 | $swstack = 100 ' default use 10 for the SW stack
|
6 | $framesize = 40 ' default use 40 for the frame space
|
7 |
|
8 |
|
9 |
|
10 | Waitus 1
|
11 |
|
12 | 'Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 128 , Noss = 1 , Spiin = 0
|
13 |
|
14 | Declare Sub Readtouch
|
15 |
|
16 |
|
17 | Enable Interrupts
|
18 | $include "Config_mmc.bas" ' Does drive init too
|
19 | $include "Config_AVR-DOS.BAS"
|
20 |
|
21 | Tp_cs Alias Portb.3
|
22 | Config Tp_cs = Output
|
23 | Set Tp_cs
|
24 | Spiinit
|
25 |
|
26 | Dim I As Word
|
27 | Dim Temp As Integer
|
28 | Dim Touchx As Integer
|
29 | Dim Touchy As Integer
|
30 | Dim Readtouch_x As Integer
|
31 | Dim Readtouch_y As Integer
|
32 |
|
33 | Do
|
34 |
|
35 | Waitms 100
|
36 |
|
37 | Call Readtouch
|
38 |
|
39 |
|
40 |
|
41 | Print "x: " ; Touchx ; " y " ; Touchy
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | Loop
|
48 | End
|
49 |
|
50 |
|
51 |
|
52 | Sub Readtouch 'Read y value from ads7843
|
53 | Local Tempspi As Byte , Adh As Byte , Adl As Byte
|
54 | Local Spiregister As Byte
|
55 | Spiregister = Spcr 'Save the spi spcr register to a temp variable to restore the settings after
|
56 | Reset Spcr.2 'Set phase to 0
|
57 | Reset Spcr.3
|
58 | Tempspi = &H93 '12bit resolution
|
59 | Reset Tp_cs
|
60 | Spiout Tempspi , 1 'send 1 byte
|
61 | Spiin Adl , 1 'Read the low byte
|
62 | Spiin Adh , 1 'Read the high byte
|
63 | Set Tp_cs
|
64 | Readtouch_x = Makeint(adh , Adl)
|
65 | Readtouch_x = 32760 - Readtouch_x
|
66 | Touchx = Readtouch_x
|
67 | 'If Readtouch_x < 0 Then
|
68 | 'Touchx = 0
|
69 | 'End If
|
70 |
|
71 | 'Touchx = Touchx - 8000
|
72 | 'Touchx = Touchx / 51.25 'Combine the high & low byte and give it back to the function
|
73 | Spcr = Spiregister 'Restore the original spi register settings
|
74 |
|
75 |
|
76 | 'Read x value from ads7843
|
77 |
|
78 |
|
79 | Spiregister = Spcr 'Save the spi spcr register to a temp variable to restore the settings after
|
80 | Reset Spcr.2
|
81 | Reset Spcr.3 'Set phase to 0
|
82 | Tempspi = &HD0 ''12bit resolution
|
83 | Reset Tp_cs
|
84 | Spiout Tempspi , 1 'send 1 byte
|
85 | Spiin Adl , 1 'Read the low byte
|
86 | Spiin Adh , 1 'Read the high byte
|
87 | Set Tp_cs
|
88 | Readtouch_y = Makeint(adh , Adl)
|
89 | Touchy = Readtouch_y
|
90 | 'Combine the high & low byte and give it back to the function
|
91 | Spcr = Spiregister 'Restore the original spi register settings
|
92 | End Sub
|