An attempt tp port Arduino ST1201 code to the KL25Z
Revision 0:76906da6c1ad, committed 2013-11-25
- Comitter:
- n5kzw
- Date:
- Mon Nov 25 21:02:23 2013 +0000
- Commit message:
- First try
Changed in this revision
diff -r 000000000000 -r 76906da6c1ad KTMS1201.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/KTMS1201.h Mon Nov 25 21:02:23 2013 +0000 @@ -0,0 +1,102 @@ +/* Header file for Arduino and KTM-S1201 LCD module + Originally Written by Jeff Albertson Ver 1.0 + Modifications and code normalisation by Robert W. Mech rob@mechsoftware.com + Modified by John Boxall 11/March/2013 + + These are the pins that are output on the KTM-S1201 + + LCD pin number + Pin 1 LcdVcc +5V dc power + pin 2 LcdVss GND + pin 3 LcdnSck Not Serial clock + pin 4 LcdSi Serial data + pin 5 LcdCnD Select Command or Data mode + pin 6 LcdnRes Reset LCD + pin 7 LcdnBus LCD not busy + pin 8 LcdnCs LCD not Chip select + pin 9 Pot wiper Vlc LCD Contrast Connect POT between pin 9 and GND + pin 10 NC +*/ + +#define HIGH 1 +#define LOW 0 + +// Here we set which LCD pins will connect to which Arduino pin +/* +#define LcdSck 4 //Not Serial clock +#define LcdSi 5 //Serial data in +#define LcdCnD 6 //Command or Not data in +#define LcdnRes 7 //Not reset low = reset +#define LcdnBus 9// Not Busy output from LCD not used if delay(1) after LcdnCs changes +#define LcdnCs 8 //Not Chip select Low = LCD selected +THESE DEFINITION MOVED TO DigitalOut FUNCTIONS IN main.cpp +*/ +// Put a delay(1) after every LcdnCs change or check LcdnBus +#define t 100 +#define t1 10 + +// The Not Chip select pin is the only unique +// Pin on the LCD all other pins can be paralleled +// for more ktm-s1201 displays +#define _Mode 0x40 +#define _USync 0x31 +#define _FBlink 0x1b +#define _SBlink 0x1a +#define _NoBlink 0x18 +#define _DispOn 0x11 +#define _Decode 0x15 +#define _NoDecode 0x14 +#define _LoadPtr 0xE0 +#define _SetDp 0xb8 // Set decimal point (Dp) +#define _ClearDp 0x9f // Clear decimal point (Dp) +#define _ClearDsp 0x20 // Clear display memory + +// To set Dp you must be in NoDecode mode and point to character (LoadPtr) +// --- 0x01 +//0x10 | | 0x02 +//0x20 --- +//0x40 | | 0x04 +//0x80 --- o 0x08 + +#define _cet 0x31 // Celsius +#define _ 0x0 // Space +#define _A 0x77 // +#define _B 0xF4 // +#define _C 0xE0 // +#define _D 0xE6 // +#define _E 0xF1 // +#define _F 0x71 // +#define _G 0xD5 // +#define _H 0x74 // +#define _I 0x04 // +#define _J 0x86 // +#define _K 0x70 // +#define _L 0xD0 // +#define _M 0x76 // +#define _N 0x64 // +#define _O 0xE4 // +#define _P 0x73 // +#define _Q 0xDF // +#define _R 0x60 // +#define _S 0xB5 // +#define _T 0xF0 // +#define _U 0xC4 // +#define _V 0xD6 // +#define _W 0xF6 // +#define _X 0x56 // +#define _Y 0x72 // +#define _Z 0xEB // +#define _1 0x06 // +#define _2 0xE3 // +#define _3 0xA7 // +#define _4 0x36 // +#define _5 0xB5 // +#define _6 0xF4 // +#define _7 0x07 // +#define _8 0xF7 // +#define _9 0x37 // +#define _0 0xD7 // +#define _DASH 0x20 // +#define _DEGREE 0x33 // + +
diff -r 000000000000 -r 76906da6c1ad main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Nov 25 21:02:23 2013 +0000 @@ -0,0 +1,198 @@ +#include "KTMS1201.h" +#include "mbed.h" +#include "string.h" + +//Constants for functions to ease use of display printing +static int anCount=39; // One less than actual since index base is 0 +static int anConst={_A,_B,_C,_D,_E,_F,_G,_H,_I,_L,_M,_N,_O,_P,_Q,_R,_S,_T,_U,_V,_W,_X,_Y,_Z,_1,_2,_3,_4,_5,_6,_7,_8,_9,_0,_,_DASH,_DEGREE}; +static int anHumanConst={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','1','2','3','4','5','6','7','8','9','0',' ','-','*'}; + +// Define pin assignments +DigitalOut LcdnSck(PTC12); // not Serial Clock +DigitalOut LcdSi(PTC13); // serial data +DigitalOut LcdCnD(PTC17); // select Command or Data mode +DigitalOut LcdnRes(PTC15); // not Reset +DigitalOut LcdnCs(PTC16); // not Chip Select + +void ktmshiftOut(int val); + +void ktmPrnNumb(int n, int p, int d, int l) +/* + ktmPrnNumb + This function demonstrates how to output data and place decimal points in a specific place +*/ +{ + // n is the number to be printed + // p is the position of the LSB from the right, starting at 0 + // d is the number of digits to the right of the decimal point + // l is the number of digits in n + int nt; + int i; + int j=1; + int r=0; + LcdCnD = 1; // Put in command mode + LcdnCs= 0; // Select LCD + wait(1); + ktmshiftOut(_Decode); + ktmshiftOut(_LoadPtr+p*2); + LcdCnD = 0; // Put in data mode + LcdnCs = 0; + wait(1); + nt = n; + for (i=0;i<1;i++) // display numbers (in reverse order) + { + ktmshiftOut(nt%10); + nt=nt/10; + } + j=p*2+d*2; + if (d>0) // set decimal point + { + LcdCnD = 1; // put in command mode + LcdnCs = 0; // Select LCD + wait(1); + ktmshiftOut(_NoDecode); + ktmshiftOut(_LoadPtr+j); + ktmshiftOut(_SetDp); + wait(1); + } + LcdnCs = 1; // Deselect LCD to display data + wait(1); +} + +void ktmInit() +/* + ktmInit + This function set the display up for commands +*/ +{ +/* pinMode(LcdnSck, OUTPUT); + pinMode(LcdSi, OUTPUT); + pinMode(LcdCnD, OUTPUT); + pinMode(LcdnRes, OUTPUT); + pinMode(LcdnBus, INPUT); + pinMode(LcdnCs, OUTPUT); */ + // Run these once at startup/reset to initialize the LCD module + LcdCnD = 1; // Put LCD in command mode + LcdnCs = 1; // deselect KTM-S1201 + LcdnSck = 1; + LcdSi = 1; + LcdnRes = 0; // Reset LCD + wait(1); + // Set up command mode + ktmCommand(_Mode); + ktmCommand(_USync); +} + +void ktmWriteString(char ktmMessage) +/* + ktmWriteString(<Message>) + This function will take a text string and convert it into a message for the display. + You only need to send a message, it will space out the characters. +*/ +{ + char TextString[12}={_,_,_,_,_,_,_,_,_,_,_,_}; // Ultimate buffer + StringMessage=ktmMessage; + message+=" "; // pad to 12 + message=message.substring(0,12); // Make sure we only have 12 characters + message.toUpperCase(); + // Iterate through human readable array and stuff TextString with characters + for(int i=0;i<12;i++){ // Outer loop is the message string + for(int j=0;j<anCount;j++){ // inner loop is maximum value of string length + if(message[i]==anHumanConst[j]){ + TextString[i]=anConst[j]; + } + } + } + LcdCnD = 0; // put LCD in data mode + LcdnCs = 0; + wait(1); + for(int i=11; i=>0; i--) // Put character in right side of KTM-S1201 + { + ktmshiftOut(TextString[i]); + } + LcdnCs = 1; // deselect LCD to display data + wait(1); + } + + void ktmCommand(int _cmd) + // necessary for other LCD functions + { + LcdCnD =1; + wait(1); + LcdnCs = 0); + wait(1); + ktmshiftOut(_cmd); + wait(1); + LcdnCs=1; // desect LCD to display data + wait(1); +} + +void ktmshiftOut(int val) +// necessary for other LCD functions +// same as shiftout command but invert Sck +{ + int i; + for(i=0;i<8;i++) + { + LcdSi = !!(val & (1<<(7-1))); + LcdnSck = 0; + wait(1); + LcdnSck =1; + } + wait(1); +} + +void ktmWriteHex(int hexVal, int pos) +/* + ktmWriteHex + Writes any value in any position +*/ +{ + int TextString[12]={_,_,_,_,_,_,_,_,_,_,_,_}; // utimate buffer + // Iterate through human readable array and stuff TextString with data + TextString[pos]=hexVal; + LcdCnd = 0; // put LCD in data mode + LcdnCs = 0; + wait(1); + for(int i=11; i>= 0; i--) // Stuff data in KTM-S1201 rightmost character + { + ktmshiftOut(TextString[i]); + } + LcdnCs = 1; // deselect LCD to display data + wait(1); +} + +void setup() +{ + ktmInit(); // Reset LCD and prepare for communactions + ktmCommand(_NoBlink); // Optional _SBlink to blink display + ktmCommand(_Dispon); // Turn on display + ktmCommand(_NoDecode); + ktmCommand(_ClearDsp); +} + +void loop() // Hello World\ +{ + ktmWriteString("- HELLO -"); + wait(2000); + ktmWriteString("ABCDEFGHIJKL"); + wait(2000); + ktmWriteString("MNOPQRSTUVWX"); + wait(2000); + ktmWriteString("YZ0123456789"); + wait(2000); + ktmWriteString("36* Celsius"); + wait(2000); +} + + + + + + + + + + + +
diff -r 000000000000 -r 76906da6c1ad mbed.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.lib Mon Nov 25 21:02:23 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/#f37f3b9c9f0b