summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAstrid Smith2011-09-11 15:21:54 -0700
committerAstrid Smith2011-09-11 15:21:54 -0700
commit1963e89a7907b56d4914aa7855d5bdfd12ddd1f6 (patch)
tree82247c2a3deecc4197c5b9a9a692bf876b7f20c3
parent528d0ce2918a23e53d2c69887da0aa6e88761cde (diff)
It prints 1s and 0s now at the top and bottom of the wave
-rw-r--r--example.c69
1 files changed, 21 insertions, 48 deletions
diff --git a/example.c b/example.c
index 1d3fba3..129b6eb 100644
--- a/example.c
+++ b/example.c
@@ -36,68 +36,41 @@ void send_str(const char *s);
uint8_t recv_str(char *buf, uint8_t size);
void parse_and_execute_command(const char *buf, uint8_t num);
-#if 0
// Very simple character echo test
int main(void)
{
+ int changed = 0;
+ int port = 'B' - 'A';
+ int pin = '0' - '0';
+ int val;
CPU_PRESCALE(0);
usb_init();
- while (1) {
- int n = usb_serial_getchar();
- if (n >= 0) usb_serial_putchar(n);
- }
-}
+ LED_CONFIG;
+ while (!usb_configured()) /* wait */ ;
+ _delay_ms(1000);
-#else
+ LED_ON;
-// Basic command interpreter for controlling port pins
-int main(void)
-{
- char buf[32];
- uint8_t n;
- // set for 16 MHz clock, and turn on the LED
- CPU_PRESCALE(0);
- LED_CONFIG;
- LED_ON;
+ uint8_t *portload = 0x20 + port * 3;
+
+ *(uint8_t *)(0x21 + port * 3) &= ~(1 << pin);
- // initialize the USB, and then wait for the host
- // to set configuration. If the Teensy is powered
- // without a PC connected to the USB port, this
- // will wait forever.
- usb_init();
- while (!usb_configured()) /* wait */ ;
- _delay_ms(1000);
while (1) {
- // wait for the user to run their terminal emulator program
- // which sets DTR to indicate it is ready to receive.
- while (!(usb_serial_get_control() & USB_SERIAL_DTR)) /* wait */ ;
-
- // discard anything that was received prior. Sometimes the
- // operating system or other software will send a modem
- // "AT command", which can still be buffered.
- usb_serial_flush_input();
-
- // print a nice welcome message
- send_str(PSTR("\r\nTeensy USB Serial Example, "
- "Simple Pin Control Shell\r\n\r\n"
- "Example Commands\r\n"
- " B0? Read Port B, pin 0\r\n"
- " C2=0 Write Port C, pin 1 LOW\r\n"
- " D6=1 Write Port D, pin 6 HIGH (D6 is LED pin)\r\n\r\n"));
-
- // and then listen for commands and process them
- while (1) {
- send_str(PSTR("> "));
- n = recv_str(buf, sizeof(buf));
- if (n == 255) break;
- send_str(PSTR("\r\n"));
- parse_and_execute_command(buf, n);
+ val = *portload & (1 << pin);
+// usb_serial_putchar(val + '0');
+ if ((val == 1) && (changed == 0)) {
+ changed = 1;
+ usb_serial_putchar(val ? '1' : '0');
+ LED_ON;
+ } else if ((val == 0) && (changed == 1)) {
+ changed = 0;
+ usb_serial_putchar(val ? '1' : '0');
+ LED_OFF;
}
}
}
-#endif
// Send a string to the USB serial port. The string must be in
// flash memory, using PSTR