-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathuser-code.c
More file actions
74 lines (63 loc) · 1.66 KB
/
user-code.c
File metadata and controls
74 lines (63 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "stm8sduino.h" //include stm8suduino defs
#define LED PD0 //LED attached to pin 24 (=PD0 on STM8SDiscovery)
#define LED_DLY 100 //waste some time, in ms
#define AIN 0 //ADC ch0
#define BTN PC5 //(8*2+5) //pin 21 = PC5
#define LOOP_CNT 1
//flip led
void led_flp(void) {
if (digitalRead(BTN)==HIGH) digitalWrite(LED, HIGH);
else digitalWrite(LED, LOW);
//digitalWrite(LED, !digitalRead(LED));
}
//user setup
void setup(void) {
pinMode(LED, OUTPUT); digitalWrite(LED, LOW); //set LED as output
pinMode(BTN, INPUT_PULLUP);
//attachInterrupt(BTN, led_flp, CHANGE); //test exti
//DAC1Write(100); //test dac
//serialBegin(9600);
}
volatile uint32_t time0, time1;
//user loop
void loop(void) {
uint16_t i;
#if 0
//test adc
time0=ticks();
for (i=0; i<ADC_CNT; i++) analogRead(A0);
time1=ticks()-time0;
if (time1>10) NOP();
#endif
//test GPIO
time0=ticks();
for(i=0; i<LOOP_CNT; i++) digitalWrite(LED, !digitalRead(LED)); //flip the led
time1=ticks() - time0;
if (time1>10) NOP();
//test timing
time0=ticks();
delay(LED_DLY); //waste sometime
time1=ticks() - time0;
if (time1>10) NOP();
#if 0
//test Uart2
time0=micros();
Serial_print("0123456789012345678901234567890123456789");
time1=micros() - time0;
if (time1>100) NOP();
#endif
#if 0
//test spi
time0=micros();
for (i=0; i<1000; i++) SPIshiftOut(MSBFIRST, 0x55);
time1=micros() - time0;
if (time1>100) NOP();
#endif
#if 0
//test i2c
time0=micros();
for (i=0; i<1000; i++) I2C_write(0x55);
time1=micros() - time0;
if (time1>100) NOP();
#endif
}