1 | ' -----------------------------------------------------------------------
|
2 | ' PIN CHANGE INTERRUPTS / ATMEGA168 / BASCOM
|
3 | ' siehe auch ATMEL-Datenblatt Seiten 70 und 345
|
4 | ' -----------------------------------------------------------------------
|
5 |
|
6 | $regfile = "m168def.dat"
|
7 | $crystal = 20000000
|
8 | $hwstack = 80
|
9 | $swstack = 80
|
10 | $framesize = 80
|
11 | ' -----------------------
|
12 | Dim Countx As Integer
|
13 | Dim Iportval As Byte
|
14 | Dim Iportvalold As Byte
|
15 | Dim Iportdif As Byte
|
16 | ' -----------------------
|
17 | Declare Sub Blinksig
|
18 | ' -----------------------
|
19 | Config Lcdpin = Pin , Db4 = Portb.0 , Db5 = Portb.1 , Db6 = Portb.2 , Db7 = Portb.3 , E = Portb.4 , Rs = Portb.5
|
20 | Config Lcd = 16 * 1a ' LCD-Modul 1x16
|
21 |
|
22 |
|
23 | ' ------------------------
|
24 | ' Port-Settings (Beispiel)
|
25 | ' ------------------------
|
26 | Sensor_1 Alias Portc.3 ' PCINT 11
|
27 | Sensor_2 Alias Portc.2 ' PCINT 10
|
28 | Sensor_3 Alias Portc.1 ' PCINT 9
|
29 | Sensor_4 Alias Portc.0 ' PCINT 8
|
30 | Config Sensor_1 = Input
|
31 | Config Sensor_2 = Input
|
32 | Config Sensor_3 = Input
|
33 | Config Sensor_4 = Input
|
34 | Sensor_1 = 1 ' Pullups
|
35 | Sensor_2 = 1
|
36 | Sensor_3 = 1
|
37 | Sensor_4 = 1
|
38 | ' ------------------------
|
39 | Actor_1 Alias Portc.5
|
40 | Config Actor_1 = Output
|
41 | ' ------------------------
|
42 |
|
43 |
|
44 |
|
45 | ' ---------------------------
|
46 | ' Interrupt settings mit
|
47 | ' Besonderheiten in Bascom
|
48 | ' ---------------------------
|
49 | ' PCINT1 ist NICHT der IC-Pin "PcInt1",
|
50 | ' sondern der "reaction Block" für logiclevel-changes
|
51 | ' an PortC (aktive Pins siehe PCMSK1)
|
52 |
|
53 | On Pcint1 Isr_1
|
54 | Enable Pcint1
|
55 |
|
56 | ' PCINT8..11 als ext. Interrupt-Pins maskieren.
|
57 | ' Wenn an einem dieser Pins ein Logiklevel WECHSELT,
|
58 | ' dann wird der Interrupt "Pcint1" ausgelöst
|
59 |
|
60 | Pcmsk1 = &B00001111
|
61 |
|
62 |
|
63 |
|
64 | ' PCIE1-Block enable
|
65 | ' Die Pins PCINT8..14 werden hier als Block freigeschaltet
|
66 |
|
67 | Pcicr = &B00000010
|
68 |
|
69 |
|
70 |
|
71 |
|
72 | ' -----------------------
|
73 | ' Initialisieren
|
74 | ' -----------------------
|
75 | Countx = 0
|
76 | Iportval = 0
|
77 | Iportvalold = 0
|
78 | ' -----------------------
|
79 |
|
80 | ' +++++++++++++++++++++++++++++
|
81 | ' Main loop
|
82 | ' +++++++++++++++++++++++++++++
|
83 | Cls
|
84 | Lcd "<Bereit>"
|
85 | Enable Interrupts
|
86 | Do
|
87 | ' godot...
|
88 | Loop
|
89 | End
|
90 | ' +++++++++++++++++++++++++++++
|
91 |
|
92 |
|
93 | ' -----------------------
|
94 | ' Subroutine
|
95 | ' -----------------------
|
96 | Sub Blinksig
|
97 | Actor_1 = 0
|
98 | Waitms 5
|
99 | Actor_1 = 1
|
100 | End Sub
|
101 | ' -----------------------
|
102 |
|
103 |
|
104 | ' ---------------------------*******************************************
|
105 | ' Interrupt service routine
|
106 | ' ---------------------------*******************************************
|
107 | Isr_1:
|
108 |
|
109 | Disable Interrupts
|
110 |
|
111 | ' Wert vom Port holen und Mögl. betroffene Bits ausfiltern
|
112 | Iportval = Portc And &B00001111
|
113 |
|
114 | ' Änderungen zum vorherigen Wert ermitteln
|
115 | Iportdif = Iportvalold Xor Iportval
|
116 |
|
117 | ' Info
|
118 | Call Blinksig
|
119 | Countx = Countx + 1
|
120 | If Countx > 299 Then
|
121 | Countx = 0
|
122 | End If
|
123 | Cls
|
124 | Lcd ">" ; Bin(iportdif) ; " >" ; Countx
|
125 |
|
126 | ' Aktuellen Portwert für nächsten Interrupt merken
|
127 | Iportvalold = Iportval
|
128 |
|
129 | Enable Interrupts
|
130 |
|
131 | Return
|
132 |
|
133 | ' -----------------------
|