Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 0:60800820b5a8, committed 2012-02-16
- Comitter:
- tylerjw
- Date:
- Thu Feb 16 14:28:40 2012 +0000
- Commit message:
Changed in this revision
| bsp.cpp | Show annotated file Show diff for this revision Revisions of this file |
| bsp.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 60800820b5a8 bsp.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bsp.cpp Thu Feb 16 14:28:40 2012 +0000
@@ -0,0 +1,99 @@
+#include "mbed.h"
+#include "TextLCD.h"
+#include "bsp.h"
+
+TextLCD lcd(p10, p11, p17, p18, p19, p20); // rs, e, d4-d7
+AnalogIn joystick(p16);
+DigitalIn selectPin(p13);
+
+//............................................................................
+int BSP_joyUpdate() {
+ int pos = joystick.read()*100;
+ if (pos < 40)
+ return JOY_DOWN; // going down
+ else if (pos > 60)
+ return JOY_UP; // going up
+ else
+ return JOY_CENTER;
+}
+//............................................................................
+void BSP_lcdScrollIn(char* line1, char* line2) {
+// scroller algorithm
+ lcd.cls();
+ char output1[17];
+ char output2[17];
+ for ( int i = 0; i < 17; i++) {
+ output1[i] = ' ';
+ output2[i] = ' ';
+ }
+ for (int i = 0; i < 17; i++) {
+ for (int col = 0; col < 17; col++) {
+
+ if (col >= i) {
+ output1[col] = ' ';
+ output2[col] = ' ';
+ } else {
+ output1[col] = (line1[col+(16-i)]);
+ output2[col] = (line2[col+(16-i)]);
+ }
+ lcd.locate(col,0);
+ lcd.putc(output1[col]);
+ lcd.locate(col,1);
+ lcd.putc(output2[col]);
+ }
+ wait(0.4);
+ }
+}
+//............................................................................
+void BSP_lcdUpdate(char* line1,char* line2) {
+TextLCD lcd(p10, p11, p17, p18, p19, p20); // rs, e, d4-d7
+ uint8_t length1 = strlen(line1);
+ uint8_t length2 = strlen(line2);
+ lcd.cls();
+ for (int col = 0; col < 17; col++) {
+ if (col < length1) {
+ lcd.locate(col,0);
+ lcd.putc(*(line1+col));
+ }
+ if (col < length2) {
+ lcd.locate(col,1);
+ lcd.putc(*(line2+col));
+ }
+ }
+}
+//............................................................................
+char* itoa(int val, int base) {
+ static char buf[BUFF_LEN] = {0};
+ int i = BUFF_LEN-2;
+ for (; val && i ; --i, val /= base)
+ buf[i] = "0123456789abcdef"[val % base];
+
+ return &buf[i+1];
+}
+//............................................................................
+char* cat(char* first, char* second, char* output) {
+ size_t len1 = strlen(first);
+ size_t len2 = strlen(second);
+ size_t outlen = strlen(output);
+ bool done = false;
+ int i = 0;
+
+ static char buf[BUFF_LEN] = {0};
+ for(; i < len1 && !done; i++)
+ {
+ if(i == (BUFF_LEN-1)){ done = true; break; }
+ buf[i] = first[i];
+ }
+ for(int b = 0; b < len2 && !done; i++, b++)
+ {
+ if(i == (BUFF_LEN-1)){ done = true; break; }
+ buf[i] = second[b];
+ }
+ for(;i < outlen && !done; i++)
+ {
+ if(i == (BUFF_LEN-1)){ done = true; break; }
+ buf[i] = ' ';
+ }
+ return &buf[0];
+}
+//............................................................................
\ No newline at end of file
diff -r 000000000000 -r 60800820b5a8 bsp.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bsp.h Thu Feb 16 14:28:40 2012 +0000 @@ -0,0 +1,20 @@ +#ifndef bsp_h +#define bsp_h + +#define BSP_TICKS_PER_SEC 100 // system clock tick rate + +#define JOYSTICK_INPUT_PIN p16 +#define JOYSTICK_SELECT_PIN p13 + +#define JOY_UP 1 +#define JOY_DOWN 2 +#define JOY_CENTER 3 + +void BSP_lcdScrollIn(char*, char*); // display functions +void BSP_lcdUpdate(char*,char*); +int BSP_joyUpdate(void); // returns joystick value + +char* itoa(int, int); // int to char, number and base +char* cat(char*, char*, char*); // concatonate, first, second, output(for filling with ' ' if lenght of first+second<output ) + +#endif \ No newline at end of file