blob: 021b5cb65c690f9ca60f5c2505ef78ea29d1eff9 (
plain)
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
|
/* global variables */
char a;
bit b1, b2;
/* assign names to port pins */
bit in @ PORTB.0;
bit out @ PORTB.1;
void sub( void)
{
char i; /* a local variable */
/* generate 20 pulses */
for ( i = 0; i < 20; i++) {
out = 1;
nop();
out = 0;
}
}
void main( void)
{
// if (TO == 1 && PD == 1 /* power up */) {
// WARM_RESET:
// clearRAM(); // clear all RAM
// }
/* NOTE 1: some devices have a comparator module
that have to be switched off to use certain
pins as digital IO */
//CMCON = 0x07; // switch comparators off
/* NOTE 2: devices having AD converter may need to
configure the pins assigned to 'in' and 'out' as
digital IO */
//ADCON1 = ..
/* First decide the initial output level on the
output port pins, and then define the input/
output configuration. This avoids spikes at the
output pins. */
PORTB = 0b.0000.0010; /* out = 1 */
TRISB = 0b.1111.0001; /* xxxx 0001 */
a = 9; /* value assigned to global variable */
do {
if (in == 0) /* stop if 'in' is low */
break;
sub();
} while ( -- a > 0); /* 9 iterations */
// if (some condition)
// goto WARM_RESET;
/* main is terminated by a SLEEP instruction */
}
|