Brought over the files from the Freescale site and modified for mbed.

This code is only partially working for me. Not every download seems to be successful on Mac OS X. I just took the example files and hacked them around to get it working with mbed. If you want working code I think Erik Olieman's SLCD project is probably a better source.

main.cpp

//KL46Z try out
#include "mbed.h"
#include "TSISensor.h"
#include "MMA8451Q.h"
#include "MAG3110.h"
#include "vfnLCD.h"
#include <cstdlib>
#include <iostream>

Serial pc(USBTX, USBRX);

TSISensor tsi;
MMA8451Q acc51(PTE25, PTE24, 0x1D<<1);
MAG3110 mag(PTE25, PTE24, 0x0E<<1);
vfnLCD lcd;

PwmOut rled(PTE29);
PwmOut gled(PTD5);
AnalogIn lightSensor(PTE22);
//DigitalIn SW1(PTC3);
//DigitalIn SW3(PTC12);
//AnalogOut lcd03(PTB23);
//PwmOut lcd07(PTB7);

char chBufDisp[10];

int main()
{
    using namespace std;

    float onTime = 1.0;
    float offTime = 0.0;
    float holdTime = 1.0;
    bool on = true;
    bool off = false;
    int magX = 0, magY = 0, magZ = 0;
    int count=100;
 
    uint8_t message[]="1234";
    lcd.vfnLCD_All_Segments_ON();     

    while(true) {  
        cout << "I'm alive and running\n\r";              
        rled = onTime - abs(acc51.getAccX());
        gled = onTime - abs(acc51.getAccY());
        mag.getValues(&magX, &magY, &magZ);
        
        cout << "MMA8451: " << acc51.getAccX() << "\t" << acc51.getAccY() << "\t" << acc51.getAccZ() << "\n\r" << endl;
        cout << "MAG3110: " << magX << "\t" << magY << "\t" << magZ << "\n\r" << endl;
        cout << "MAG3110: " << mag.getHeading() << "\n\r" << endl;
        wait(holdTime);
        
        rled = tsi.readPercentage();
        gled = tsi.readPercentage();
        
        cout << "Touch: " << tsi.readPercentage() << "\n\r" << endl;
        cout << "SW1: " << SW1 << "\n\r" << endl;
        cout << "SW3: " << SW3 << "\n\r" << endl;
        cout << "Light Sensor: " << lightSensor << "\n\r" << endl;
        sprintf(chBufDisp,"%04i",count);
        lcd.vfnLCD_Write_Msg((uint8_t *)chBufDisp);
        count++;
        if (count>9999) count=0;
        wait(holdTime);
    }
    return 0;
}

Committer:
highroads
Date:
Mon Jan 13 22:32:43 2014 +0000
Revision:
0:c5fea5b6b339
Partially working version.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
highroads 0:c5fea5b6b339 1 //#include "common.h"
highroads 0:c5fea5b6b339 2 #include "mbed.h"
highroads 0:c5fea5b6b339 3 #include "LCDConfig.h" // indicates how LCD module is configured and what type of LCD is going to be used 7seg, 14-seg, 16 seg, DotMatrix etc
highroads 0:c5fea5b6b339 4
highroads 0:c5fea5b6b339 5 #define LCD_ALTERNATE_MODE 4 // Write message to Alternate Backplanes
highroads 0:c5fea5b6b339 6 #define LCD_NORMAL_MODE 0 // Write message to Original BackPlanes
highroads 0:c5fea5b6b339 7
highroads 0:c5fea5b6b339 8
highroads 0:c5fea5b6b339 9 /* variables */
highroads 0:c5fea5b6b339 10 extern uint32_t __VECTOR_RAM[]; //Get vector table that was copied to RAM
highroads 0:c5fea5b6b339 11
highroads 0:c5fea5b6b339 12 extern const uint32_t MASK_BIT[];
highroads 0:c5fea5b6b339 13 extern const uint32_t *LCD_TO_PORT[];
highroads 0:c5fea5b6b339 14
highroads 0:c5fea5b6b339 15
highroads 0:c5fea5b6b339 16 #if _LCDINTENABLE == 1
highroads 0:c5fea5b6b339 17 extern void LcdInterruptCallBack(void);
highroads 0:c5fea5b6b339 18 #endif
highroads 0:c5fea5b6b339 19
highroads 0:c5fea5b6b339 20 class vfnLCD {
highroads 0:c5fea5b6b339 21
highroads 0:c5fea5b6b339 22 public:
highroads 0:c5fea5b6b339 23 /*|||||||||||||||||||||| vfnLCD_Init ||||||||||||||||||||||
highroads 0:c5fea5b6b339 24 brief: Initialize all the registers on the mcu module
highroads 0:c5fea5b6b339 25 param: void return: void
highroads 0:c5fea5b6b339 26 */
highroads 0:c5fea5b6b339 27 vfnLCD(void);
highroads 0:c5fea5b6b339 28
highroads 0:c5fea5b6b339 29 void vfnLCD_Home (void);
highroads 0:c5fea5b6b339 30 /*|||||||||||||||||||||| vfnLCD_Write_Char ||||||||||||||||||||||
highroads 0:c5fea5b6b339 31 brief: Writes on char after the last character was write
highroads 0:c5fea5b6b339 32 param: uint8 --- Ascii to write return: void
highroads 0:c5fea5b6b339 33 */
highroads 0:c5fea5b6b339 34 void vfnLCD_Write_Char (uint8_t lbValue);
highroads 0:c5fea5b6b339 35
highroads 0:c5fea5b6b339 36 /*
highroads 0:c5fea5b6b339 37 Send a message until a end of char or max number of characters
highroads 0:c5fea5b6b339 38 if the message size is greater than LCD character the message is cut ad the size of LCD Characters
highroads 0:c5fea5b6b339 39 If the message lenght is minor than Display character is filled with Blanks
highroads 0:c5fea5b6b339 40 */
highroads 0:c5fea5b6b339 41 void vfnLCD_Write_Msg (uint8_t *lbpMessage);
highroads 0:c5fea5b6b339 42
highroads 0:c5fea5b6b339 43
highroads 0:c5fea5b6b339 44
highroads 0:c5fea5b6b339 45 /*|||||||||||||||||||||| vfnLCD_Write_Msg ||||||||||||||||||||||
highroads 0:c5fea5b6b339 46 brief: Writes on message on the LCD if the message is longer than the number of character is send to the Scroll function
highroads 0:c5fea5b6b339 47 param: uint8 pointer --- the first character on the array to write
highroads 0:c5fea5b6b339 48 param: uint8 --- the numbers of characterts to write
highroads 0:c5fea5b6b339 49 return: void
highroads 0:c5fea5b6b339 50 */
highroads 0:c5fea5b6b339 51 void vfnLCD_Write_MsgPlace (uint8_t *lbpMessage, uint8_t lbSize );
highroads 0:c5fea5b6b339 52
highroads 0:c5fea5b6b339 53 /*|||||||||||||||||||||| vfnLCD_Scroll ||||||||||||||||||||||
highroads 0:c5fea5b6b339 54 brief: Moves the message on the LCD
highroads 0:c5fea5b6b339 55 param: uint8 pointer --- the first character on the array to write
highroads 0:c5fea5b6b339 56 param: uint8 --- the size of the character
highroads 0:c5fea5b6b339 57 return: void
highroads 0:c5fea5b6b339 58 */
highroads 0:c5fea5b6b339 59
highroads 0:c5fea5b6b339 60 void vfnLCD_Scroll (uint8_t *lbpMessage,uint8_t lbSize);
highroads 0:c5fea5b6b339 61
highroads 0:c5fea5b6b339 62 /*|||||||||||||||||||||| vfnLCD_All_Segments_ON ||||||||||||||||||||||
highroads 0:c5fea5b6b339 63 brief: Turns on all the segments on the LCD
highroads 0:c5fea5b6b339 64 param: uint8 pointer --- the first character on the array to write
highroads 0:c5fea5b6b339 65 param: uint8 --- the size of the character
highroads 0:c5fea5b6b339 66 return: void
highroads 0:c5fea5b6b339 67 */
highroads 0:c5fea5b6b339 68
highroads 0:c5fea5b6b339 69 void vfnLCD_All_Segments_ON (void);
highroads 0:c5fea5b6b339 70
highroads 0:c5fea5b6b339 71 /*Same as clear dispay */
highroads 0:c5fea5b6b339 72 void vfnLCD_All_Segments_OFF (void);
highroads 0:c5fea5b6b339 73
highroads 0:c5fea5b6b339 74 void vfnLCD_Contrast (uint8_t lbContrast);
highroads 0:c5fea5b6b339 75 void vfnLCD_isrv(void) ;
highroads 0:c5fea5b6b339 76
highroads 0:c5fea5b6b339 77
highroads 0:c5fea5b6b339 78 /* functions for DOT matrix LCD panel only*/
highroads 0:c5fea5b6b339 79 void vfnLCD_All_Segments_Char (uint8_t val);
highroads 0:c5fea5b6b339 80 void PutPoint(uint8_t x, uint8_t y);
highroads 0:c5fea5b6b339 81 void ClrPoint(uint8_t x, uint8_t y);
highroads 0:c5fea5b6b339 82 void SetX(uint8_t x, uint8_t value);
highroads 0:c5fea5b6b339 83
highroads 0:c5fea5b6b339 84 private:
highroads 0:c5fea5b6b339 85 char lcdBuffer[];
highroads 0:c5fea5b6b339 86
highroads 0:c5fea5b6b339 87
highroads 0:c5fea5b6b339 88 uint8_t lcd_alternate_mode;
highroads 0:c5fea5b6b339 89
highroads 0:c5fea5b6b339 90
highroads 0:c5fea5b6b339 91 void LCD_vector_interrupt_init(void);
highroads 0:c5fea5b6b339 92 void lcd_pinmux(uint8_t mux_val); //only 0 or 7 is allowed
highroads 0:c5fea5b6b339 93
highroads 0:c5fea5b6b339 94 void vfnBP_VScroll(int8_t scroll_count);
highroads 0:c5fea5b6b339 95
highroads 0:c5fea5b6b339 96 // LCD call samples
highroads 0:c5fea5b6b339 97 // vfnLCD_Home();
highroads 0:c5fea5b6b339 98 // vfnLCD_Write_Char ('0');
highroads 0:c5fea5b6b339 99 // vfnLCD_All_Segments_ON();
highroads 0:c5fea5b6b339 100 // vfnLCD_All_Segments_OFF();
highroads 0:c5fea5b6b339 101 // vfnLCD_Write_Msg("@@@@@@@@@"); // TURN ON all characters
highroads 0:c5fea5b6b339 102 // vfnLCD_All_Segments_OFF();
highroads 0:c5fea5b6b339 103
highroads 0:c5fea5b6b339 104
highroads 0:c5fea5b6b339 105
highroads 0:c5fea5b6b339 106 /*{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{ Macros }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}*/
highroads 0:c5fea5b6b339 107 /*{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{ ---------------------------- }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}*/
highroads 0:c5fea5b6b339 108
highroads 0:c5fea5b6b339 109 #define LCD_ENABLE() (LCD_GCR |= LCD_GCR_LCDEN_MASK)
highroads 0:c5fea5b6b339 110 #define LCD_DISABLE() (LCD_GCR &= ~LCD_GCR_LCDEN_MASK)
highroads 0:c5fea5b6b339 111 #define LCD_VTRIM(x) (LCD_GCR &= ~LCD_GCR_RVTRIM_MASK; LCD_GCR |= LCD_GCR_RVTRIM(x));
highroads 0:c5fea5b6b339 112
highroads 0:c5fea5b6b339 113
highroads 0:c5fea5b6b339 114
highroads 0:c5fea5b6b339 115
highroads 0:c5fea5b6b339 116
highroads 0:c5fea5b6b339 117
highroads 0:c5fea5b6b339 118
highroads 0:c5fea5b6b339 119 /*{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{ Functions }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}*/
highroads 0:c5fea5b6b339 120 /*{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{ ---------------------------- }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}*/
highroads 0:c5fea5b6b339 121
highroads 0:c5fea5b6b339 122
highroads 0:c5fea5b6b339 123
highroads 0:c5fea5b6b339 124 /*|||||||||||||||||||||| vfnLCD_EnablePins ||||||||||||||||||||
highroads 0:c5fea5b6b339 125 brief: Enable all the pins of the mcu directly connected to the LCD on use
highroads 0:c5fea5b6b339 126 param: void return: void
highroads 0:c5fea5b6b339 127 */
highroads 0:c5fea5b6b339 128 void vfnEnablePins (void);
highroads 0:c5fea5b6b339 129
highroads 0:c5fea5b6b339 130 /*|||||||||||||||||||||| vfnLCD_SetBackplanes ||||||||||||||
highroads 0:c5fea5b6b339 131 brief: Set as a backplane and give the number of COM that corresponds
highroads 0:c5fea5b6b339 132 param: void return: void
highroads 0:c5fea5b6b339 133 */
highroads 0:c5fea5b6b339 134 void vfnSetBackplanes (void);
highroads 0:c5fea5b6b339 135
highroads 0:c5fea5b6b339 136 /*|||||||||||||||||||||| vfnLCD_Home ||||||||||||||||||||||
highroads 0:c5fea5b6b339 137 brief: Reset the counter to the first position
highroads 0:c5fea5b6b339 138 param: void
highroads 0:c5fea5b6b339 139 return: void
highroads 0:c5fea5b6b339 140 */
highroads 0:c5fea5b6b339 141
highroads 0:c5fea5b6b339 142
highroads 0:c5fea5b6b339 143
highroads 0:c5fea5b6b339 144 void vfnLCD_interrupt_init(void);
highroads 0:c5fea5b6b339 145 };
highroads 0:c5fea5b6b339 146