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:18044d748c0c, committed 2012-07-16
- Comitter:
- takeuchi
- Date:
- Mon Jul 16 06:01:40 2012 +0000
- Commit message:
- ???????web mbed?? mbed CW??????10?????????????????????????????????????????????????
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD0420.cpp Mon Jul 16 06:01:40 2012 +0000
@@ -0,0 +1,167 @@
+/* mbed TextLCD Library
+ * Copyright (c) 2007-2009 sford
+ * Released under the MIT License: http://mbed.org/license/mit
+ */
+ // for 04row*20line LCD
+
+#include "TextLCD0420.h"
+
+#include "mbed.h"
+#include "error.h"
+
+using namespace mbed;
+
+/*
+ * useful info found at http://www.a-netz.de/lcd.en.php
+ *
+ *
+ * Initialisation
+ * ==============
+ *
+ * After attaching the supply voltage/after a reset, the display needs to be brought in to a defined state
+ *
+ * - wait approximately 15 ms so the display is ready to execute commands
+ * - Execute the command 0x30 ("Display Settings") three times (wait 1,64ms after each command, the busy flag cannot be queried now).
+ * - The display is in 8 bit mode, so if you have only connected 4 data pins you should only transmit the higher nibble of each command.
+ * - If you want to use the 4 bit mode, now you can execute the command to switch over to this mode now.
+ * - Execute the "clear display" command
+ *
+ * Timing
+ * ======
+ *
+ * Nearly all commands transmitted to the display need 40us for execution.
+ * Exceptions are the commands "Clear Display and Reset" and "Set Cursor to Start Position"
+ * These commands need 1.64ms for execution. These timings are valid for all displays working with an
+ * internal clock of 250kHz. But I do not know any displays that use other frequencies. Any time you
+ * can use the busy flag to test if the display is ready to accept the next command.
+ *
+ * _e is kept high apart from calling clock
+ * _rw is kept 0 (write) apart from actions that uyse it differently
+ * _rs is set by the data/command writes
+ */
+
+TextLCD::TextLCD(PinName rs, PinName rw, PinName e, PinName d0, PinName d1,
+ PinName d2, PinName d3, int columns, int rows) : _rw(rw), _rs(rs),
+ _e(e), _d(d0, d1, d2, d3), _columns(columns), _rows(rows) {
+
+
+ // Mon, 27 Apr 2009 23:32:34 +0200
+ // Kevin Konradt:
+ // When using a LCD with 1 row x 16 characters
+ // instead of 2x16, try changing _columns to 8.
+ // (display seems to split the 16 characters into
+ // 2 virtual rows with 8 characters each.)
+
+ _rw = 0;
+ _e = 1;
+ _rs = 0; // command mode
+
+ // Should theoretically wait 15ms, but most things will be powered up pre-reset
+ // so i'll disable that for the minute. If implemented, could wait 15ms post reset
+ // instead
+ // wait(0.015);
+
+ // send "Display Settings" 3 times (Only top nibble of 0x30 as we've got 4-bit bus)
+ for(int i=0; i<3; i++) {
+ writeNibble(0x3);
+ wait(0.00164); // this command takes 1.64ms, so wait for it
+ }
+ writeNibble(0x2); // 4-bit mode
+
+ writeCommand(0x28); // Function set 001 BW N F - -
+ writeCommand(0x0C);
+ writeCommand(0x6); // Cursor Direction and Display Shift : 0000 01 CD S (CD 0-left, 1-right S(hift) 0-no, 1-yes
+
+ cls();
+}
+
+int TextLCD::_putc(int value) {
+ if(value == '\n') {
+ newline();
+ } else {
+ writeData(value);
+ }
+ return value;
+}
+
+int TextLCD::_getc() {
+ return 0;
+}
+
+void TextLCD::newline() {
+ _column = 0;
+ _row++;
+ if(_row >= _rows) {
+ _row = 0;
+ }
+ locate(_column, _row);
+}
+
+void TextLCD::locate(int column, int row) {
+ int address;
+ if(column < 0 || column >= _columns || row < 0 || row >= _rows) {
+ error("locate(%d,%d) out of range on %dx%d display", column, row, _columns, _rows);
+ return;
+ }
+
+ _row = row;
+ _column = column;
+// 02*20 => int address = 0x80 + (_row * 40) + _column; // memory starts at 0x80, and is 40 chars long per row
+
+
+ if(_row == 0 ){
+ address = 0x80+_column;
+ }
+ else if(_row == 1 ){
+ address = 0x80+ (0x40) + _column;
+ }
+ else if(_row == 2){
+ address = 0x80+(0x14)+_column;
+ }
+ else if(_row == 3){
+ address = 0x80+(0x54)+_column;
+ }
+
+ writeCommand(address);
+}
+
+void TextLCD::cls() {
+ writeCommand(0x01); // Clear Display
+ wait(0.00164f); // This command takes 1.64 ms
+ locate(0, 0);
+}
+
+void TextLCD::reset() {
+ cls();
+}
+
+void TextLCD::clock() {
+ wait(0.000040f);
+ _e = 0;
+ wait(0.000040f); // most instructions take 40us
+ _e = 1;
+}
+
+void TextLCD::writeNibble(int value) {
+ _d = value;
+ clock();
+}
+
+void TextLCD::writeByte(int value) {
+ writeNibble(value >> 4);
+ writeNibble(value >> 0);
+}
+
+void TextLCD::writeCommand(int command) {
+ _rs = 0;
+ writeByte(command);
+}
+
+void TextLCD::writeData(int data) {
+ _rs = 1;
+ writeByte(data);
+ _column++;
+ if(_column >= _columns) {
+ newline();
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD0420.h Mon Jul 16 06:01:40 2012 +0000
@@ -0,0 +1,109 @@
+/* mbed TextLCD Library
+ * Copyright (c) 2007-2009 sford
+ * Released under the MIT License: http://mbed.org/license/mit
+ */
+
+#ifndef MBED_TEXTLCD_H
+#define MBED_TEXTLCD_H
+
+#include "Stream.h"
+#include "DigitalOut.h"
+#include "BusOut.h"
+
+namespace mbed {
+
+/* Class: TextLCD
+ * A 16x2 Text LCD controller
+ *
+ * Allows you to print to a Text LCD screen, and locate/cls. Could be
+ * turned in to a more generic libray.
+ *
+ * If you are connecting multiple displays, you can connect them all in
+ * parallel except for the enable (e) pin, which must be unique for each
+ * display.
+ *
+ * Example:
+ * > #include "mbed.h"
+ * > #include "TextLCD.h"
+ * >
+ * > TextLCD lcd(p24, p25, p26, p27, p28, p29, p30); // rs, rw, e, d0, d1, d2, d3
+ * >
+ * > int main() {
+ * > lcd.printf("Hello World!");
+ * > }
+ */
+class TextLCD : public Stream {
+
+public:
+ /* Constructor: TextLCD
+ * Create a TextLCD object, connected to the specified pins
+ *
+ * All signals must be connected to DigitalIn compatible pins.
+ *
+ * Variables:
+ * rs - Used to specify data or command
+ * rw - Used to determine read or write
+ * e - enable
+ * d0..d3 - The data lines
+ */
+ TextLCD(PinName rs, PinName rw, PinName e, PinName d0, PinName d1,
+ PinName d2, PinName d3, int columns , int rows );
+
+#if 0 // Inhereted from Stream, for documentation only
+ /* Function: putc
+ * Write a character
+ *
+ * Variables:
+ * c - The character to write to the serial port
+ */
+ int putc(int c);
+
+ /* Function: printf
+ * Write a formated string
+ *
+ * Variables:
+ * format - A printf-style format string, followed by the
+ * variables to use in formating the string.
+ */
+ int printf(const char* format, ...);
+#endif
+
+ /* Function: locate
+ * Locate to a certian position
+ *
+ * Variables:
+ * column - the column to locate to, from 0..15
+ * row - the row to locate to, from 0..1
+ */
+ virtual void locate(int column, int row);
+
+ /* Function: cls
+ * Clear the screen, and locate to 0,0
+ */
+ virtual void cls();
+
+ virtual void reset();
+
+protected:
+
+ void clock();
+ void writeData(int data);
+ void writeCommand(int command);
+ void writeByte(int value);
+ void writeNibble(int value);
+ virtual int _putc(int c);
+ virtual int _getc();
+ virtual void newline();
+
+ int _row;
+ int _column;
+ DigitalOut _rw, _rs, _e;
+ BusOut _d;
+ int _columns;
+ int _rows;
+
+};
+
+}
+
+#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Mon Jul 16 06:01:40 2012 +0000
@@ -0,0 +1,418 @@
+// CW11
+// BT AR taiou
+// Wabun
+// SW tuika
+// hore taiou
+// wabun (OUBUN) wabun
+
+#include "mbed.h"
+#include "TextLCD0420.h"
+
+#define ON 1
+#define OFF 0
+#define XON 0
+#define XOFF 1
+#define XHI 0
+#define XLOW 1
+#define HI 1
+#define LOW 0
+#define OUBUN 1
+#define WABUN 0
+#define AUTO 1
+#define MANUAL 0
+#define KN 44
+#define AS 33
+#define CT 52
+#define BT 48
+#define AR 41
+#define HH 255
+#define VA 103
+#define HORE 120
+
+DigitalOut mled1(LED1);
+DigitalOut mled2(LED2);
+DigitalOut mled3(LED3);
+DigitalOut mled4(LED4);
+DigitalIn CW(p5);
+DigitalIn SP_SELECT(p6);
+DigitalIn GENGO_MODE(p7);
+DigitalIn GENGO_SELECT(p8);
+
+TextLCD lcd(p24, p25, p26, p27, p28, p29, p30,20,4); // rs, rw, e, d0, d1, d2, d3
+
+int retu,gyou;
+char g2[20],g3[20];
+int init_flag=ON;
+int min_ms,max_ms;
+
+void lcd_scprintf(char pdata){
+ int i;
+
+ if(init_flag==ON){
+ if(gyou==1){
+ lcd.locate(retu,1);
+ lcd.printf("%c",pdata);
+ retu++;
+ if(retu==20){
+ gyou=2;
+ retu=0;
+ }
+ }
+ else if(gyou==2){
+ lcd.locate(retu,2);
+ lcd.printf("%c",pdata);
+ g2[retu]=pdata;
+ retu++;
+ if(retu==20){
+ retu=0;
+ gyou=3;
+ }
+ }
+ else if(gyou==3){
+ lcd.locate(retu,3);
+ lcd.printf("%c",pdata);
+ g3[retu]=pdata;
+ retu++;
+ if(retu==20){
+ retu=0;
+ gyou=1;
+ for(i=0;i<20;i++){
+ lcd.locate(i,1);
+ lcd.printf("%c",g2[i]);
+ }
+ for(i=0;i<20;i++){
+ lcd.locate(i,2);
+ lcd.printf("%c",g3[i]);
+ g2[i]=g3[i];
+ }
+ lcd.locate(0,3);
+ lcd.printf(" ");
+ init_flag=OFF;
+ }
+ }
+ }
+ if(init_flag==OFF){
+ gyou=3;
+ lcd.locate(retu,3);
+ lcd.printf("%c",pdata);
+ g3[retu]=pdata;
+ retu++;
+ if(retu==20){
+ for(i=0;i<20;i++){
+ lcd.locate(i,1);
+ lcd.printf("%c",g2[i]);
+ lcd.locate(i,2);
+ lcd.printf("%c",g3[i]);
+ g2[i]=g3[i];
+ }
+ lcd.locate(0,3);
+ lcd.printf(" ");
+ retu=0;
+ }
+ }
+}
+
+void set_speed(){
+ if(SP_SELECT==HI){
+ min_ms=30;
+ max_ms=90;
+ lcd.locate(5,0);
+ lcd.printf("H");
+ }
+ else if(SP_SELECT==LOW){
+ min_ms=70;
+ max_ms=210;
+ lcd.locate(5,0);
+ lcd.printf("L");
+ }
+}
+
+void lcd_manual(){
+ lcd.locate(6,0);
+ lcd.printf("M");
+}
+
+void lcd_auto(){
+ lcd.locate(6,0);
+ lcd.printf("A");
+}
+
+void lcd_alpha(){
+ lcd.locate(7,0);
+ lcd.printf("A");
+}
+void lcd_kana(){
+ lcd.locate(7,0);
+ lcd.printf("%c",0xb6);
+}
+
+int main() {
+
+ int i,j,k;
+ int code[8];
+ int scount;
+ char mj[115],mjj[121],c1,c2;
+ int cw_sum,tan_sum,tanten,cpm;
+ int gengo,wabun_temp;
+ char cw_class;
+
+ for(i=0;i<115;i++){
+ mj[i]=' ';
+ }
+ mj[5]='A';mj[16]='B';mj[20]='C';mj[8]='D';mj[1]='E';
+ mj[19]='F';mj[10]='G';mj[15]='H';mj[3]='I';mj[29]='J';
+ mj[12]='K';mj[17]='L';mj[6]='M';mj[4]='N';mj[14]='O';
+ mj[21]='P';mj[26]='Q';mj[9]='R';mj[7]='S';mj[2]='T';
+ mj[11]='U';mj[23]='V';mj[13]='W';mj[24]='X';mj[28]='Y';
+ mj[18]='Z';
+ mj[61]='1';mj[59]='2';mj[55]='3';mj[47]='4';mj[31]='5';
+ mj[32]='6';mj[34]='7';mj[38]='8';mj[46]='9';mj[62]='0';
+ mj[105]='.';mj[114]=',';mj[75]='?';mj[48]='=';mj[96]='-';
+ mj[70]=':';mj[93]='\'';mj[44]='(';mj[108]=')';mj[40]='/';
+ mj[85]='@';
+ //mj[41]='+';
+
+ for(i=0;i<121;i++){
+ mjj[i]=' ';
+ }
+ mjj[58]=0xb1;mjj[5]=0xb2;mjj[11]=0xb3;mjj[60]=0xb4;mjj[33]=0xb5;//a
+ mjj[17]=0xb6;mjj[36]=0xb7;mjj[23]=0xb8;mjj[28]=0xb9;mjj[30]=0xba;//ka
+ mjj[52]=0xbb;mjj[42]=0xbc;mjj[54]=0xbd;mjj[45]=0xbe;mjj[22]=0xbf;//sa
+ mjj[4]=0xc0;mjj[19]=0xc1;mjj[21]=0xc2;mjj[57]=0xc3;mjj[35]=0xc4;//ta
+ mjj[9]=0xc5;mjj[20]=0xc6;mjj[15]=0xc7;mjj[26]=0xc8;mjj[27]=0xc9;//na
+ mjj[16]=0xca;mjj[50]=0xcb;mjj[18]=0xcc;mjj[1]=0xcd;mjj[8]=0xce;//ha
+ mjj[24]=0xcf;mjj[51]=0xd0;mjj[2]=0xd1;mjj[48]=0xd2;mjj[40]=0xd3;//ma
+ mjj[13]=0xd4;mjj[56]=0xd5;mjj[6]=0xd6;//ya
+ mjj[7]=0xd7;mjj[10]=0xd8;mjj[44]=0xd9;mjj[14]=0xda;mjj[25]=0xdb;//ra
+ mjj[12]=0xdc;mjj[49]=0xb2;mjj[37]=0xb4;mjj[29]=0xa6;mjj[41]=0xdd;//wa
+ mjj[53]=0xb0;mjj[43]=0xdf;mjj[105]=',';
+ mjj[3]=0xde;mjj[73]=0xa3;
+ mjj[108]='(';mjj[81]=')';
+ mjj[61]='1';mjj[59]='2';mjj[55]='3';mjj[47]='4';mjj[31]='5';
+ mjj[32]='6';mjj[34]='7';mjj[38]='8';mjj[46]='9';mjj[62]='0';
+
+
+ lcd.cls();
+ lcd.printf("*CW11 ");
+
+ for(i=0;i<8;i++){
+ code[i]=0;
+ }
+
+ i=0;
+ tan_sum=0;
+ set_speed();
+ c1=' ',c2=' ';
+
+ while( i<5 ){//initialize
+ lcd.locate(8,0);
+ lcd.printf("%2d",5-i);
+ scount=0;
+ while(CW==XLOW){
+ }
+ mled1=ON;
+ while(CW==XHI){
+ scount++;
+ wait_ms(1);
+ }
+ mled1=OFF;
+ if(min_ms < scount && scount < max_ms){
+ tan_sum=tan_sum+scount;
+ i++;
+ }
+
+ }//while i
+
+ tanten=tan_sum/5;
+
+ j=0;
+ k=0;
+ tan_sum=0;
+ gyou=1,retu=0;
+ gengo=OUBUN;
+ wabun_temp=OUBUN;
+ while(1){
+ set_speed();
+
+ if(GENGO_MODE==MANUAL){// Manual mode
+ lcd_manual();
+ if(GENGO_SELECT==OUBUN){
+ gengo=OUBUN;
+ }
+ else if(GENGO_SELECT==WABUN){
+ gengo=WABUN;
+ wabun_temp=WABUN;
+ }
+ }
+ else if(GENGO_MODE==AUTO){// Auto mode
+ lcd_auto();
+ }
+
+ while(CW==XLOW){
+ }
+
+ scount=0;
+ mled1=ON;
+ while(CW==XHI){
+ wait_ms(1);
+ scount++;
+ }
+ mled1=OFF;
+
+ if(min_ms < scount && scount < max_ms){
+ //lcd.printf(".");
+ code[k]=1;
+ k++;
+ tan_sum=tan_sum+scount;
+ j++;
+ }
+
+ else if ( scount > tanten*2.0){
+ //lcd.printf("_");
+ code[k]=2;
+ k++;
+ tan_sum=tan_sum+scount/3;
+ j++;
+ }
+
+ lcd.locate(8,0);
+ lcd.printf("%2d",k);
+
+ scount=0;
+ while(CW==XLOW){
+ wait_ms(1);
+ scount++;
+ if(scount > tanten*10){
+ break;
+ }
+ }
+
+ if(k>8){
+ k=0;
+ lcd_scprintf('*');
+ for(i=0;i<=7;i++){
+ code[i]=0;
+ }
+ }
+
+ if(gengo==OUBUN && scount > tanten*2.0){
+ lcd_alpha();
+ cw_sum=0;
+ for(i=0;i<=7;i++){
+ cw_sum=cw_sum+code[i]*int(pow(2.0,i));
+ }
+
+
+ if(GENGO_MODE==AUTO && cw_sum==HORE ){// hore
+ lcd_scprintf('[');lcd_scprintf(0xce);lcd_scprintf( 0xda);lcd_scprintf(']');//ho re
+ gengo=WABUN;
+ }
+ else if(cw_sum==BT){
+ lcd_scprintf('[');lcd_scprintf('B');lcd_scprintf('T');lcd_scprintf(']');
+ }
+ else if(cw_sum==KN){
+ lcd_scprintf('[');lcd_scprintf('K');lcd_scprintf('N');lcd_scprintf(']');
+ }
+ else if(cw_sum==AR){
+ lcd_scprintf('[');lcd_scprintf('A');lcd_scprintf('R');lcd_scprintf(']');
+ }
+ else if(cw_sum==HH){
+ lcd_scprintf('[');lcd_scprintf('H');lcd_scprintf('H');lcd_scprintf(']');
+ }
+ else if(cw_sum==AS){
+ lcd_scprintf('[');lcd_scprintf('A');lcd_scprintf('S');lcd_scprintf(']');
+ }
+ else if(cw_sum==CT){
+ lcd_scprintf('[');lcd_scprintf('C');lcd_scprintf('T');lcd_scprintf(']');
+ }
+ else if(cw_sum==VA){
+ lcd_scprintf('[');lcd_scprintf('V');lcd_scprintf('A');lcd_scprintf(']');
+ }
+ else if(cw_sum > 115){
+ lcd_scprintf('*');
+ cw_sum=0;
+ }
+ else {
+ lcd_scprintf(mj[cw_sum]);
+ c1=c2;
+ c2=mj[cw_sum];
+ }
+ k=0;
+ for(i=0;i<=7;i++){
+ code[i]=0;
+ }
+ }//if oubun
+
+ else if(gengo==WABUN && scount > tanten*2.0){
+ lcd_kana();
+ cw_sum=0;
+ for(i=0;i<=7;i++){
+ cw_sum=cw_sum+code[i]*int(pow(2.0,i));
+ }
+
+ if(GENGO_MODE==AUTO && cw_sum==39){// ra ta
+ lcd_scprintf('[');lcd_scprintf(0xd7);lcd_scprintf(0xc0);lcd_scprintf(']');//ra ta
+ gengo=OUBUN;
+ wabun_temp=OUBUN;
+ }
+ if(cw_sum==81){// )
+ wabun_temp=WABUN;
+ lcd_kana();
+ }
+ else if(cw_sum > 121){
+ cw_sum=0;
+ lcd_scprintf(' ');
+ }
+
+ if(wabun_temp==WABUN){
+ lcd_scprintf(mjj[cw_sum]);
+ c1=c2;
+ c2=mjj[cw_sum];
+ }
+ else if(wabun_temp==OUBUN){
+ lcd_scprintf(mj[cw_sum]);
+ c1=c2;
+ c2=mj[cw_sum];
+ }
+
+ if(cw_sum==108){// (
+ wabun_temp=OUBUN;
+ lcd_alpha();
+ }
+
+ k=0;
+ for(i=0;i<=7;i++){
+ code[i]=0;
+ }
+ }//if wabun
+
+ if(scount > tanten*7){
+ lcd_scprintf(' ');
+ }
+
+ if(j==10){
+ tanten=tan_sum/10;
+ cpm=60000/(tanten*57)*5;
+ tan_sum=0;
+ j=0;
+ if(cpm > 100){
+ cw_class='P';
+ }
+ else if(cpm > 90){
+ cw_class='S';
+ }
+ else if(cpm > 65){
+ cw_class='1';
+ }
+ else if(cpm > 40){
+ cw_class='2';
+ }
+ else if(cpm > 30){
+ cw_class='3';
+ }
+ lcd.locate(11,0);
+ lcd.printf("%3dc(%c)",cpm,cw_class);
+ //lcd.printf("%3dc,%3dm",cpm,tanten);
+ }
+ }//while 1
+}//main
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Jul 16 06:01:40 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/9114680c05da \ No newline at end of file