]> sigrok.org Git - sigrok-firmware-fx2lafw.git/blame - fx2lib/examples/serial/serial.c
Import fx2lib into fx2lafw directly.
[sigrok-firmware-fx2lafw.git] / fx2lib / examples / serial / serial.c
CommitLineData
3608c106
UH
1/**
2 * Copyright (C) 2009 Ubixum, Inc.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 **/
18
19#include <stdio.h>
20
21#include <fx2regs.h>
22#include <fx2macros.h>
23#include <lights.h>
24#include <serial.h>
25
26
27
28volatile BYTE ctr=0;
29BYTE ctr_repeat=200;
30volatile BOOL on=FALSE;
31
32
33void timer1_isr() interrupt 3 __critical {
34
35 if (ctr == 0) { // timer overflowed ctr_repeat times
36 if (on) {
37 d2on();
38 } else {
39 d2off();
40 }
41 on = !on;
42 }
43
44 ctr = ctr >= ctr_repeat ? 0 : ctr + 1;
45
46}
47
48
49
50void main(void)
51{
52
53 SETCPUFREQ(CLK_48M);
54
55 // if this image is loaded to as iic to
56 // the eeprom
57 // the C2 bit will turn this on
58 // turn it back off so the device can
59 // handle usb requests
60 USBCS &= ~bmRENUM;
61
62 EA=1; // enable interrupts
63
64 sio0_init(57600);
65
66 // timer 0 setup
67
68 TL1=TH1=0; // start at 0
69 ET1=1; // timer 1 interrupts
70 TR1=1; // start timer 1
71
72
73 d5off(); // end init
74
75 while (1) {
76 char r=getchar();
77 putchar(r);
78 }
79
80
81}