Stefan Schuermans commited on 2012-02-20 14:17:12
Showing 3 changed files, with 41 additions and 10 deletions.
| ... | ... |
@@ -4,10 +4,10 @@ |
| 4 | 4 |
#include "uart.h" |
| 5 | 5 |
#include "switches.h" |
| 6 | 6 |
|
| 7 |
-//#define CFG_DELAY |
|
| 8 |
-//#define CFG_LCD |
|
| 7 |
+#define CFG_DELAY |
|
| 8 |
+#define CFG_LCD |
|
| 9 | 9 |
#define CFG_UART |
| 10 |
-#define CFG_UART_CHK |
|
| 10 |
+//#define CFG_UART_CHK |
|
| 11 | 11 |
|
| 12 | 12 |
const int myconst = 0x12345678; |
| 13 | 13 |
|
| ... | ... |
@@ -54,6 +54,7 @@ void delay(void) |
| 54 | 54 |
int main() |
| 55 | 55 |
{
|
| 56 | 56 |
unsigned int i; |
| 57 |
+ unsigned char leds; |
|
| 57 | 58 |
|
| 58 | 59 |
for (i = 0; i < sizeof(data) / sizeof(data[0]); ++i) |
| 59 | 60 |
data[i] = i; |
| ... | ... |
@@ -88,16 +89,16 @@ int main() |
| 88 | 89 |
#endif |
| 89 | 90 |
#endif |
| 90 | 91 |
|
| 92 |
+ leds = 0x11; |
|
| 91 | 93 |
while (1) {
|
| 92 |
- for (i = 0x1; i < 0x80; i <<= 1) {
|
|
| 93 |
- leds_set_state(i); |
|
| 94 |
- delay(); |
|
| 95 |
- } |
|
| 96 |
- for (i = 0x80; i > 0x1; i >>= 1) {
|
|
| 97 |
- leds_set_state(i); |
|
| 94 |
+#ifdef CFG_UART |
|
| 95 |
+ if (uart_can_rx()) |
|
| 96 |
+ leds = uart_rx(); |
|
| 97 |
+#endif |
|
| 98 |
+ leds_set_state(leds); |
|
| 99 |
+ leds = leds << 1 | leds >> 7; |
|
| 98 | 100 |
delay(); |
| 99 | 101 |
} |
| 100 |
- } |
|
| 101 | 102 |
|
| 102 | 103 |
return 0; |
| 103 | 104 |
} |
| ... | ... |
@@ -30,6 +30,15 @@ void uart_cfg_stop(unsigned char stop) |
| 30 | 30 |
*(uart_ptr + 3) = stop; |
| 31 | 31 |
} |
| 32 | 32 |
|
| 33 |
+/** |
|
| 34 |
+ * @brief check if transmitting a character is possible |
|
| 35 |
+ * @return if transmitting a character is possible |
|
| 36 |
+ */ |
|
| 37 |
+int uart_can_tx(void) |
|
| 38 |
+{
|
|
| 39 |
+ return *(uart_ptr + 4); |
|
| 40 |
+} |
|
| 41 |
+ |
|
| 33 | 42 |
/** |
| 34 | 43 |
* @brief transmit a character |
| 35 | 44 |
* @param[in] chr character to transmit |
| ... | ... |
@@ -40,6 +49,15 @@ void uart_tx(unsigned short chr) |
| 40 | 49 |
*(unsigned short *)(uart_ptr + 8) = chr; /* write data */ |
| 41 | 50 |
} |
| 42 | 51 |
|
| 52 |
+/** |
|
| 53 |
+ * @brief check if receiving a character is possible |
|
| 54 |
+ * @return if receiving a character is possible |
|
| 55 |
+ */ |
|
| 56 |
+int uart_can_rx(void) |
|
| 57 |
+{
|
|
| 58 |
+ return *(uart_ptr + 5); |
|
| 59 |
+} |
|
| 60 |
+ |
|
| 43 | 61 |
/** |
| 44 | 62 |
* @brief receive a character |
| 45 | 63 |
* @return character received |
| ... | ... |
@@ -19,12 +19,24 @@ void uart_cfg_bits(unsigned char bits); |
| 19 | 19 |
*/ |
| 20 | 20 |
void uart_cfg_stop(unsigned char stop); |
| 21 | 21 |
|
| 22 |
+/** |
|
| 23 |
+ * @brief check if transmitting a character is possible |
|
| 24 |
+ * @return if transmitting a character is possible |
|
| 25 |
+ */ |
|
| 26 |
+int uart_can_tx(void); |
|
| 27 |
+ |
|
| 22 | 28 |
/** |
| 23 | 29 |
* @brief transmit a character |
| 24 | 30 |
* @param[in] chr character to transmit |
| 25 | 31 |
*/ |
| 26 | 32 |
void uart_tx(unsigned short chr); |
| 27 | 33 |
|
| 34 |
+/** |
|
| 35 |
+ * @brief check if receiving a character is possible |
|
| 36 |
+ * @return if receiving a character is possible |
|
| 37 |
+ */ |
|
| 38 |
+int uart_can_rx(void); |
|
| 39 |
+ |
|
| 28 | 40 |
/** |
| 29 | 41 |
* @brief receive a character |
| 30 | 42 |
* @return character received |
| 31 | 43 |