• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqt誰得cocoawindowspythonrubyphpgameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdombtronvb.netdirectxarduinopreviewerゲームエンジン

Commit MetaInfo

Révisionb8bd0508955703a4fba163e25601346b80f22e9f (tree)
l'heure2013-06-11 05:25:53
AuteurK.Ohta <whatisthis.sowhat@gmai...>
CommiterK.Ohta

Message de Log

[Initial] Add idle-routine, using interrupt.

Change Summary

Modification

--- /dev/null
+++ b/idle.c
@@ -0,0 +1,44 @@
1+/*
2+ * OpenI2CRADIO
3+ * Idle routine.
4+ * Using timer0.
5+ * (C) 2013-06-10 K.Ohta <whatisthis.sowhat ai gmail.com>
6+ * License: GPL2
7+ */
8+#include <sdcc-lib.h>
9+#include <pic18fregs.h> /* ONLY FOR PIC18x */
10+#include <signal.h>
11+#include "iodef.h"
12+
13+
14+void idle_init(void)
15+{
16+ INTCON = _TMR0IE & ~(_TMR0IF | _INT0IF | _RBIF); // Enable tmr0 as interrupt and clear interrupt flags.
17+ INTCON2 = ~_TMR0IP & _TMR0IP; // Interrupt is lower.
18+ WDTCON = 0; // OK? WDT=Disabled.
19+}
20+
21+
22+void stop_idle(void)
23+{
24+ T0CONbits.TMR0ON = 0;
25+}
26+
27+
28+void idle(unsigned int initial)
29+{
30+ unsigned char osccon;
31+ unsigned char contword;
32+
33+ /* Set TMR0 for interrupt*/
34+ /* Pre-scaler: 1/16, PSA=0(ON), TOSE=0, T0CS=0(INTERNAL), T08BIT=1(8bit), TMR0ON=1(START) */
35+ contword = _T0PS0 | _T0PS1 | _T08BIT | _TMR0ON; // _T0PS2
36+ TMR0H = initial >> 8;
37+ TMR0L = initial & 0xff;
38+ T0CON = contword;
39+
40+ osccon = OSCCON;
41+ osccon = osccon | _IDLEN | _SCS1 | _SCS0;
42+ OSCCON = osccon;
43+ Sleep();
44+}
--- /dev/null
+++ b/idle.h
@@ -0,0 +1,23 @@
1+/*
2+ * File: idle.h
3+ * Author: whatisthis
4+ *
5+ * Created on 2013/06/11, 5:06
6+ */
7+
8+#ifndef IDLE_H
9+#define IDLE_H
10+
11+#ifdef __cplusplus
12+extern "C" {
13+#endif
14+extern void idle(unsigned int initial);
15+extern void idle_init(void);
16+extern void idle_stop(void); // Stop TMR0.
17+
18+#ifdef __cplusplus
19+}
20+#endif
21+
22+#endif /* IDLE_H */
23+
--- a/iodef.h
+++ b/iodef.h
@@ -97,10 +97,10 @@ enum {
9797 charcode_e,
9898 charcode_f,
9999 charcode_0,
100- charcode_s0,
101- charcode_s1,
102- charcode_s2,
103- charcode_s3,
100+ charcode_s0, // RB1
101+ charcode_s1, // RB2
102+ charcode_s2, // RB3
103+ charcode_s3, // Reserve
104104 };
105105
106106 extern keyin_defs keyin_old[2];
--- a/main.c
+++ b/main.c
@@ -9,8 +9,10 @@
99 #include <stdlib.h>
1010 #include <sdcc-lib.h>
1111 #include <pic18fregs.h> /* ONLY FOR PIC18x */
12+#include <signal.h>
1213
1314 #include "iodef.h"
15+#include "idle.h"
1416
1517 /*
1618 * Config words.
@@ -28,14 +30,74 @@ __at(__CONFIG7L) _config7l = _EBTR0_OFF_7L & _EBTR1_OFF_7L;
2830 __at(__CONFIG7H) _config7h = _EBTRB_OFF_7H;
2931
3032
33+
34+SIGHANDLER(TMR0_handler)
35+{
36+ unsigned char tmr0f;
37+
38+ readkey_io();
39+ tmr0f = INTCON;
40+ tmr0f &= ~(_TMR0IF);
41+ INTCON = tmr0f;
42+
43+ return;
44+}
45+
46+
47+DEF_INTLOW(intlow_handler)
48+ DEF_HANDLER(SIG_TMR0, TMR0_handler)
49+END_DEF
50+
51+
3152 /*
3253 *
3354 */
34-int main(void) {
55+int main(void)
56+{
57+ char readchar;
58+ unsigned char input_flag;
3559
3660 keyin_init();
3761 keyin_ioinit();
38-
62+ idle_init();
63+
64+ /* Init I2C*/
65+ /* Init LCD */
66+ /* Check EEPROM */
67+ /* Push default parameters to AKC6955*/
68+ /* Power on AKC6955 */
69+ do {
70+ /* Main routine*/
71+ input_flag = readkey_compare();
72+ if(input_flag != 0){
73+ readchar = pop_keyinfifo();
74+ switch(readchar) {
75+ // Top of input-tree.
76+ case charcode_s0:
77+ // Change band
78+ break;
79+ case charcode_s1:
80+ // MODE
81+ break;
82+ case charcode_s2:
83+ // ENTER
84+ break;
85+ case charcode_s3:
86+ // Reserve
87+ break;
88+ case charcode_null: // None
89+ break;
90+ default:
91+ // Numeric 0to9, or a to f.
92+ break;
93+ }
94+ }
95+ // Check battery (include idle?)
96+ // Read AKJC6955's status
97+ // Putstring to LCD.
98+ idle(0xff00);
99+ } while(1);
100+
39101
40102 }
41103