File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include <iostm8s103.h>
2
+
3
+ #define SW1 1
4
+ #define SW_DDR PA_DDR
5
+ #define SW_CR1 PA_CR1
6
+ #define SW_CR2 PA_CR2
7
+ #define SW_IDR PA_IDR
8
+
9
+
10
+ #define SW1_HIGH ((SW_IDR)&(1<<SW1))
11
+
12
+
13
+ #define LED_HIGH PB_ODR |= (1<<5) //ON BOARD LED
14
+ #define LED_LOW PB_ODR &= ~(1<<5)
15
+
16
+
17
+ void delay (long x );
18
+
19
+ main ()
20
+ {
21
+ unsigned int d ;
22
+
23
+ CLR_BIT (SW_DDR ,SW1 ); //SET SW1 AS INPUT
24
+ SET_BIT (SW_CR1 ,SW1 ); //input pullup without interrupt
25
+ PB_DDR = 255 ; //PORTB AS OUTPUT
26
+ PB_CR1 = 255 ;
27
+ while (1 ){
28
+ int cnt = 0 ;
29
+ if (!SW1_HIGH ){
30
+ LED_HIGH ; //LED OFF
31
+ do {
32
+ delay (10 );
33
+ }while (!SW1_HIGH );
34
+ LED_LOW ; //LED ON
35
+ }
36
+ delay (100 );
37
+ }
38
+
39
+ }
40
+
41
+
42
+ void delay (long x ){
43
+ char d = 0 ;
44
+ for (;x > 0 ;x -- )
45
+ for (d = 0 ; d < 10 ; d ++ ); //Delay ~ 1 second
46
+
47
+ }
You can’t perform that action at this time.
0 commit comments