Jump to content


Photo

Nokia 5110 display


  • Please log in to reply
58 replies to this topic

#1 RobG

RobG

    Level 5

  • Members
  • 2,999 posts
  • LocationCary, NC, US


Posted 23 October 2011 - 04:32 AM

Here's the code I am using to control 5110. It uses USCIB (2553) but USI (2231) can also be use without any problem or major updates.
There is still a lot of work to be done, but basic text and some graphics can be displayed with the current version.


5110sch.png

main.c

#include "msp430g2553.h"
#include "PCD8544.h"

#define LCD5110_SCLK_PIN BIT5
#define LCD5110_DN_PIN BIT7
#define LCD5110_SCE_PIN BIT0
#define LCD5110_DC_PIN BIT1
#define LCD5110_SELECT P1OUT &= ~LCD5110_SCE_PIN
#define LCD5110_DESELECT P1OUT |= LCD5110_SCE_PIN
#define LCD5110_SET_COMMAND P1OUT &= ~LCD5110_DC_PIN
#define LCD5110_SET_DATA P1OUT |= LCD5110_DC_PIN
#define LCD5110_COMMAND 0
#define LCD5110_DATA 1

#define SPI_MSB_FIRST UCB0CTL0 |= UCMSB // or UCA0CTL0 |= UCMSB (USCIA) or USICTL0 &= ~USILSB (USI)
#define SPI_LSB_FIRST UCB0CTL0 &= ~UCMSB // or UCA0CTL0 &= ~UCMSB or USICTL0 |= USILSB (USI)

void writeStringToLCD(const char *string);
void writeCharToLCD(char c);
void writeBlockToLCD(char *byte, unsigned char length);
void writeGraphicToLCD(char *byte, unsigned char transform);
void writeToLCD(unsigned char dataCommand, unsigned char data);
void clearLCD();
void clearBank(unsigned char bank);
void setAddr(unsigned char xAddr, unsigned char yAddr);
void initLCD();

unsigned char currXAddr = 0; //TODO this will be used for tracking current addr
unsigned char currYAddr = 0; //not implemented

//char testBlock[8] = {0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF};
char testBlock[8] = {0x00, 0x7F, 0x7F, 0x33, 0x33, 0x03, 0x03, 0x03};
char testBlock2[8] = {0x00, 0x18, 0x18, 0x18, 0x7E, 0x3C, 0x18, 0x00};

void main(void) {

WDTCTL = WDTPW + WDTHOLD; // disable WDT
BCSCTL1 = CALBC1_1MHZ; // 1MHz clock
DCOCTL = CALDCO_1MHZ;

P1OUT |= LCD5110_SCE_PIN + LCD5110_DC_PIN;
P1DIR |= LCD5110_SCE_PIN + LCD5110_DC_PIN;

// setup USIB
P1SEL |= LCD5110_SCLK_PIN + LCD5110_DN_PIN;
P1SEL2 |= LCD5110_SCLK_PIN + LCD5110_DN_PIN;

UCB0CTL0 |= UCCKPH + UCMSB + UCMST + UCSYNC; // 3-pin, 8-bit SPI master
UCB0CTL1 |= UCSSEL_2; // SMCLK
UCB0BR0 |= 0x01; // 1:1
UCB0BR1 = 0;
UCB0CTL1 &= ~UCSWRST; // clear SW

_delay_cycles(500000);
initLCD();
clearLCD();

// LCD test
writeStringToLCD("Nokia 5110");

_delay_cycles(2000000);
setAddr(0, 0);

int c = 0x20;
while(c < (65 + 0x20)) {
writeCharToLCD(c);
c++;
}

_delay_cycles(2000000);
clearLCD();

c = 65 + 0x20;

while(c < (96 + 0x20)) {
writeCharToLCD(c);
c++;
}

_delay_cycles(2000000);

c = 0;
clearBank(3);
while(c < 64) {
writeToLCD(LCD5110_DATA, 0xFF);
c++;
_delay_cycles(20000);
}
clearBank(4);
while(c < 100) {
writeToLCD(LCD5110_DATA, 0xFF);
c++;
_delay_cycles(20000);
}
clearBank(5);
while(c < 184) {
writeToLCD(LCD5110_DATA, 0xFF);
c++;
_delay_cycles(20000);
}

_delay_cycles(2000000);

clearBank(3);
writeGraphicToLCD(testBlock, NONE);
writeGraphicToLCD(testBlock, FLIP_V);
writeGraphicToLCD(testBlock, FLIP_H);
writeGraphicToLCD(testBlock, ROTATE);
writeGraphicToLCD(testBlock, FLIP_V | ROTATE);
writeGraphicToLCD(testBlock, FLIP_H | ROTATE);
writeGraphicToLCD(testBlock, ROTATE_90_CCW);
writeGraphicToLCD(testBlock, ROTATE_180);

clearBank(4);
writeGraphicToLCD(testBlock2, NONE);
writeGraphicToLCD(testBlock2, FLIP_H);
writeGraphicToLCD(testBlock2, ROTATE);
writeGraphicToLCD(testBlock2, ROTATE_90_CCW);



clearBank(0);
writeStringToLCD("For details,");
clearBank(1);
writeStringToLCD("visit 43oh.com");
clearBank(2);
}

void writeStringToLCD(const char *string) {
while(*string) {
writeCharToLCD(*string++);
}
}

void writeCharToLCD(char c) {
unsigned char i;
for(i = 0; i < 5; i++) {
writeToLCD(LCD5110_DATA, font[c - 0x20][i]);
}
writeToLCD(LCD5110_DATA, 0);
}

void writeBlockToLCD(char *byte, unsigned char length) {
unsigned char c = 0;
while(c < length) {
writeToLCD(LCD5110_DATA, *byte++);
c++;
}
}

void writeGraphicToLCD(char *byte, unsigned char transform) {
int c = 0;
char block[8];

if(transform & FLIP_V) {
SPI_LSB_FIRST;
}
if(transform & ROTATE) {
c = 1;
while(c != 0) {
(*byte & 0x01) ? (block[7] |= c) : (block[7] &= ~c);
(*byte & 0x02) ? (block[6] |= c) : (block[6] &= ~c);
(*byte & 0x04) ? (block[5] |= c) : (block[5] &= ~c);
(*byte & 0x08) ? (block[4] |= c) : (block[4] &= ~c);
(*byte & 0x10) ? (block[3] |= c) : (block[3] &= ~c);
(*byte & 0x20) ? (block[2] |= c) : (block[2] &= ~c);
(*byte & 0x40) ? (block[1] |= c) : (block[1] &= ~c);
(*byte & 0x80) ? (block[0] |= c) : (block[0] &= ~c);
*byte++;
c <<= 1;
}
} else {
while(c < 8) {
block[c++] = *byte++;
}
}

if(transform & FLIP_H) {
c = 7;
while(c > -1) {
writeToLCD(LCD5110_DATA, block[c--]);
}
} else {
c = 0;
while(c < 8) {
writeToLCD(LCD5110_DATA, block[c++]);
}
}
SPI_MSB_FIRST;
}

void writeToLCD(unsigned char dataCommand, unsigned char data) {
LCD5110_SELECT;
if(dataCommand) {
LCD5110_SET_DATA;
} else {
LCD5110_SET_COMMAND;
}
UCB0TXBUF = data;
while(!(IFG2 & UCB0TXIFG))
;
LCD5110_DESELECT;
}

void clearLCD() {
setAddr(0, 0);
int c = 0;
while(c < PCD8544_MAXBYTES) {
writeToLCD(LCD5110_DATA, 0);
c++;
}
setAddr(0, 0);
}

void clearBank(unsigned char bank) {
setAddr(0, bank);
int c = 0;
while(c < PCD8544_HPIXELS) {
writeToLCD(LCD5110_DATA, 0);
c++;
}
setAddr(0, bank);
}

void setAddr(unsigned char xAddr, unsigned char yAddr) {
writeToLCD(LCD5110_COMMAND, PCD8544_SETXADDR | xAddr);
writeToLCD(LCD5110_COMMAND, PCD8544_SETYADDR | yAddr);
}

void initLCD() {
writeToLCD(LCD5110_COMMAND, PCD8544_FUNCTIONSET | PCD8544_EXTENDEDINSTRUCTION);
writeToLCD(LCD5110_COMMAND, PCD8544_SETVOP | 0x3F);
writeToLCD(LCD5110_COMMAND, PCD8544_SETTEMP | 0x02);
writeToLCD(LCD5110_COMMAND, PCD8544_SETBIAS | 0x03);
writeToLCD(LCD5110_COMMAND, PCD8544_FUNCTIONSET);
writeToLCD(LCD5110_COMMAND, PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYNORMAL);
}

PCD8544.h
#ifndef PCD8544_H_
#define PCD8544_H_

#define PCD8544_POWERDOWN 0x04
#define PCD8544_ENTRYMODE 0x02
#define PCD8544_EXTENDEDINSTRUCTION 0x01

#define PCD8544_DISPLAYBLANK 0x0
#define PCD8544_DISPLAYNORMAL 0x4
#define PCD8544_DISPLAYALLON 0x1
#define PCD8544_DISPLAYINVERTED 0x5

// H = 0
#define PCD8544_FUNCTIONSET 0x20
#define PCD8544_DISPLAYCONTROL 0x08
#define PCD8544_SETYADDR 0x40
#define PCD8544_SETXADDR 0x80
#define PCD8544_HPIXELS 84
#define PCD8544_VBANKS 6
#define PCD8544_MAXBYTES 504 // PCD8544_HPIXELS * PCD8544_VBANKS

// H = 1
#define PCD8544_SETTEMP 0x04
#define PCD8544_SETBIAS 0x10
#define PCD8544_SETVOP 0x80

//transform
#define NONE 0x00
#define FLIP_H 0x01
#define FLIP_V 0x02
#define ROTATE 0x04 // 90 deg CW
#define ROTATE_90_CW ROTATE
#define ROTATE_90_CCW (FLIP_H | FLIP_V | ROTATE)
#define ROTATE_180 (FLIP_H | FLIP_V)

static const char font[][5] = { // basic font
{0x00, 0x00, 0x00, 0x00, 0x00} // 20
,{0x00, 0x00, 0x5f, 0x00, 0x00} // 21 !
,{0x00, 0x07, 0x00, 0x07, 0x00} // 22 "
,{0x14, 0x7f, 0x14, 0x7f, 0x14} // 23 #
,{0x24, 0x2a, 0x7f, 0x2a, 0x12} // 24 $
,{0x23, 0x13, 0x08, 0x64, 0x62} // 25 %
,{0x36, 0x49, 0x55, 0x22, 0x50} // 26 &
,{0x00, 0x05, 0x03, 0x00, 0x00} // 27 '
,{0x00, 0x1c, 0x22, 0x41, 0x00} // 28 (
,{0x00, 0x41, 0x22, 0x1c, 0x00} // 29 )
,{0x14, 0x08, 0x3e, 0x08, 0x14} // 2a *
,{0x08, 0x08, 0x3e, 0x08, 0x08} // 2b +
,{0x00, 0x50, 0x30, 0x00, 0x00} // 2c ,
,{0x08, 0x08, 0x08, 0x08, 0x08} // 2d -
,{0x00, 0x60, 0x60, 0x00, 0x00} // 2e .
,{0x20, 0x10, 0x08, 0x04, 0x02} // 2f /
,{0x3e, 0x51, 0x49, 0x45, 0x3e} // 30 0
,{0x00, 0x42, 0x7f, 0x40, 0x00} // 31 1
,{0x42, 0x61, 0x51, 0x49, 0x46} // 32 2
,{0x21, 0x41, 0x45, 0x4b, 0x31} // 33 3
,{0x18, 0x14, 0x12, 0x7f, 0x10} // 34 4
,{0x27, 0x45, 0x45, 0x45, 0x39} // 35 5
,{0x3c, 0x4a, 0x49, 0x49, 0x30} // 36 6
,{0x01, 0x71, 0x09, 0x05, 0x03} // 37 7
,{0x36, 0x49, 0x49, 0x49, 0x36} // 38 8
,{0x06, 0x49, 0x49, 0x29, 0x1e} // 39 9
,{0x00, 0x36, 0x36, 0x00, 0x00} // 3a :
,{0x00, 0x56, 0x36, 0x00, 0x00} // 3b ;
,{0x08, 0x14, 0x22, 0x41, 0x00} // 3c <
,{0x14, 0x14, 0x14, 0x14, 0x14} // 3d =
,{0x00, 0x41, 0x22, 0x14, 0x08} // 3e >
,{0x02, 0x01, 0x51, 0x09, 0x06} // 3f ?
,{0x32, 0x49, 0x79, 0x41, 0x3e} // 40 @
,{0x7e, 0x11, 0x11, 0x11, 0x7e} // 41 A
,{0x7f, 0x49, 0x49, 0x49, 0x36} // 42 B
,{0x3e, 0x41, 0x41, 0x41, 0x22} // 43 C
,{0x7f, 0x41, 0x41, 0x22, 0x1c} // 44 D
,{0x7f, 0x49, 0x49, 0x49, 0x41} // 45 E
,{0x7f, 0x09, 0x09, 0x09, 0x01} // 46 F
,{0x3e, 0x41, 0x49, 0x49, 0x7a} // 47 G
,{0x7f, 0x08, 0x08, 0x08, 0x7f} // 48 H
,{0x00, 0x41, 0x7f, 0x41, 0x00} // 49 I
,{0x20, 0x40, 0x41, 0x3f, 0x01} // 4a J
,{0x7f, 0x08, 0x14, 0x22, 0x41} // 4b K
,{0x7f, 0x40, 0x40, 0x40, 0x40} // 4c L
,{0x7f, 0x02, 0x0c, 0x02, 0x7f} // 4d M
,{0x7f, 0x04, 0x08, 0x10, 0x7f} // 4e N
,{0x3e, 0x41, 0x41, 0x41, 0x3e} // 4f O
,{0x7f, 0x09, 0x09, 0x09, 0x06} // 50 P
,{0x3e, 0x41, 0x51, 0x21, 0x5e} // 51 Q
,{0x7f, 0x09, 0x19, 0x29, 0x46} // 52 R
,{0x46, 0x49, 0x49, 0x49, 0x31} // 53 S
,{0x01, 0x01, 0x7f, 0x01, 0x01} // 54 T
,{0x3f, 0x40, 0x40, 0x40, 0x3f} // 55 U
,{0x1f, 0x20, 0x40, 0x20, 0x1f} // 56 V
,{0x3f, 0x40, 0x38, 0x40, 0x3f} // 57 W
,{0x63, 0x14, 0x08, 0x14, 0x63} // 58 X
,{0x07, 0x08, 0x70, 0x08, 0x07} // 59 Y
,{0x61, 0x51, 0x49, 0x45, 0x43} // 5a Z
,{0x00, 0x7f, 0x41, 0x41, 0x00} // 5b [
,{0x02, 0x04, 0x08, 0x10, 0x20} // 5c ¥
,{0x00, 0x41, 0x41, 0x7f, 0x00} // 5d ]
,{0x04, 0x02, 0x01, 0x02, 0x04} // 5e ^
,{0x40, 0x40, 0x40, 0x40, 0x40} // 5f _
,{0x00, 0x01, 0x02, 0x04, 0x00} // 60 `
,{0x20, 0x54, 0x54, 0x54, 0x78} // 61 a
,{0x7f, 0x48, 0x44, 0x44, 0x38} // 62 b
,{0x38, 0x44, 0x44, 0x44, 0x20} // 63 c
,{0x38, 0x44, 0x44, 0x48, 0x7f} // 64 d
,{0x38, 0x54, 0x54, 0x54, 0x18} // 65 e
,{0x08, 0x7e, 0x09, 0x01, 0x02} // 66 f
,{0x0c, 0x52, 0x52, 0x52, 0x3e} // 67 g
,{0x7f, 0x08, 0x04, 0x04, 0x78} // 68 h
,{0x00, 0x44, 0x7d, 0x40, 0x00} // 69 i
,{0x20, 0x40, 0x44, 0x3d, 0x00} // 6a j
,{0x7f, 0x10, 0x28, 0x44, 0x00} // 6b k
,{0x00, 0x41, 0x7f, 0x40, 0x00} // 6c l
,{0x7c, 0x04, 0x18, 0x04, 0x78} // 6d m
,{0x7c, 0x08, 0x04, 0x04, 0x78} // 6e n
,{0x38, 0x44, 0x44, 0x44, 0x38} // 6f o
,{0x7c, 0x14, 0x14, 0x14, 0x08} // 70 p
,{0x08, 0x14, 0x14, 0x18, 0x7c} // 71 q
,{0x7c, 0x08, 0x04, 0x04, 0x08} // 72 r
,{0x48, 0x54, 0x54, 0x54, 0x20} // 73 s
,{0x04, 0x3f, 0x44, 0x40, 0x20} // 74 t
,{0x3c, 0x40, 0x40, 0x20, 0x7c} // 75 u
,{0x1c, 0x20, 0x40, 0x20, 0x1c} // 76 v
,{0x3c, 0x40, 0x30, 0x40, 0x3c} // 77 w
,{0x44, 0x28, 0x10, 0x28, 0x44} // 78 x
,{0x0c, 0x50, 0x50, 0x50, 0x3c} // 79 y
,{0x44, 0x64, 0x54, 0x4c, 0x44} // 7a z
,{0x00, 0x08, 0x36, 0x41, 0x00} // 7b {
,{0x00, 0x00, 0x7f, 0x00, 0x00} // 7c |
,{0x00, 0x41, 0x36, 0x08, 0x00} // 7d }
,{0x10, 0x08, 0x08, 0x10, 0x08} // 7e ~
,{0x00, 0x06, 0x09, 0x09, 0x06} // 7f Deg Symbol
};

#endif /*PCD8544_H_*/

******************************************************
****** Original post, now irrelevant **********
******************************************************

I have finally found some time to work on my 5110, but I am having some issues with it (I think my display might be faulty.)
Anyone else worked with 5110?

Other than that, this display is very easy to work with and there are few libraries already written for it.

.jpeg
  • gwdeveloper, nuetron, username and 8 others like this

#2 DanAndDusty

DanAndDusty

    Level 1

  • Members
  • 120 posts
  • LocationSussex, UK

Posted 23 October 2011 - 07:02 AM

Ive used the 5510. I didn't use hardware SPI, just bit banging. The code I wrote is pasted on the forums Here
  • RobG likes this

#3 RobG

RobG

    Level 5

  • Members
  • 2,999 posts
  • LocationCary, NC, US


Posted 23 October 2011 - 12:48 PM

Thanks, those Vop, Temp Coef, and Bias settings are perfect.
I'm still experiencing some random behavior though, someone did a really lousy job on the header so it could be cold solder or basically poor build quality of the display. I will get another one and see if this is just a problem with this unit.

BTW,
LCD_write(LCD_CMD, 0x20); // LCD in Normal mode (non inversed) /// This is set basic instruction set
LCD_write(LCD_CMD, 0x08); // ** TODO ** Unsure of this command here /// This is set display to "blank"
LCD_write(LCD_CMD, 0x0C); // ** TODO ** Unsure of this command here /// This is set display to "normal"
  • DanAndDusty likes this

#4 RobG

RobG

    Level 5

  • Members
  • 2,999 posts
  • LocationCary, NC, US


Posted 24 October 2011 - 01:20 AM

Updated first post, added code and video.

#5 gwdeveloper

gwdeveloper

    Level 3

  • Members
  • 580 posts


Posted 24 October 2011 - 01:44 AM

Nice work! I just grabbed a few of these from ebay on the cheap. Good timing!

#6 RobG

RobG

    Level 5

  • Members
  • 2,999 posts
  • LocationCary, NC, US


Posted 24 October 2011 - 08:49 PM

Updated original post with new code.
Added simple graphic stuff, 8 x 8 pixel graphics can be displayed, rotated, and flipped.
Rotating is not very efficient, maybe there is another way of doing it. Alternatively, two images can be stored, normal and rotated 90, all other combinations can be achieved with flips.

.jpeg
  • bluehash, richardamullens and pkonzak like this

#7 bluehash

bluehash

    Site Admin

  • Administrators
  • 6,429 posts

Posted 24 October 2011 - 10:02 PM

Looks good Rob. I have something coming up close to this, which will coincide with the opening of the store.
Should be done in a week.
What is the resolution on this display?

43oh - MSP430, TivaC, ARM-Sitara and C2000 Discussion, News, Projects and Hacks

 

 


#8 bluehash

bluehash

    Site Admin

  • Administrators
  • 6,429 posts

Posted 24 October 2011 - 10:12 PM

Are the 5110 and 5510 different displays? D&D replies to a 5510 here.

43oh - MSP430, TivaC, ARM-Sitara and C2000 Discussion, News, Projects and Hacks

 

 


#9 DanAndDusty

DanAndDusty

    Level 1

  • Members
  • 120 posts
  • LocationSussex, UK

Posted 24 October 2011 - 10:54 PM

Are the 5110 and 5510 different displays? D&D replies to a 5510 here.


Hmm.. Good catch BH.. Never noticed before.. I believe the code comes from the Nokia phones and they use the same LCD display in the 5110 and the 5510 models... We actually get to talk to the PCD8544 chip which does the actual heavy lifting which is what I named my library.

One of the suppliers of the screens is ideadstudio and they say..

Nokia 5110 LCD is low-cost, monochrome LCD with 84x48 display. It is popular for 8-bit AVR/PIC projects, search google for 'Nokia 5510 LCD', and you will find lots of resources.


My screen came from ebay aeons back and they called it 5110 and thats how I refer to it in my head. (My wifes eyes glaze over when I mention my electronics.. so it tends to be in my head)

#10 bluehash

bluehash

    Site Admin

  • Administrators
  • 6,429 posts

Posted 24 October 2011 - 11:06 PM

:lol: Np Thanks!

43oh - MSP430, TivaC, ARM-Sitara and C2000 Discussion, News, Projects and Hacks

 

 


#11 RobG

RobG

    Level 5

  • Members
  • 2,999 posts
  • LocationCary, NC, US


Posted 25 October 2011 - 04:13 AM

Some of my header stuff is based on Adafruit's 5110 library and I will take a closer look at their graphics functions to create my own.

#12 timotet

timotet

    Level 2

  • Members
  • 172 posts

Posted 26 October 2011 - 07:49 PM

I wrote some code for the nokia lcd using spi a couple of months ago and after seeing Robs post I thought I'd post mine as well.

sorry about the video quality I lost my good camera in a drift boat accident

http://www.youtube.com/watch?v=SRNnLgSyRtg


here's the code:
 

/*
* 4/5/11
* talk to nokia 5011 LCD with spi
*/

#include 

#define PIN_SCLK BIT5 //display pin 7 / msp430 pin 7 //port p1.5
#define PIN_DNMOSI BIT6 //display pin 6 / msp430 pin 14 //port p1.6 these are used for USI SPI mode
#define PIN_DC BIT4 //display pin 5 / msp430 pin 12 //port P2.4
#define PIN_RESET BIT3 //display pin 4 / msp430 pin 11 //port p2.3
#define PIN_SCE BIT1 //display pin 3 / msp430 pin 9 //port p2.1
#define PIN_VCC BIT0 //display pin 1 / msp430 pin 8 //port p2.0

#define LCD_X 84 //columns
#define LCD_Y 48 //rows

#define cmd 0 //for command data
#define info 1 //for character data

unsigned char * Flash_ptr = (unsigned char *) 0x1040;
unsigned char * Flash_pOnes = (unsigned char *) 0x1042;
unsigned char * Flash_pTens = (unsigned char *) 0x1044;
unsigned char * Flash_pHunds = (unsigned char *) 0x1046;

volatile char data = 0; //char for data to lcd
volatile char pressCount = 0; //keep track of button presses
volatile char number = 0; //char for data to lcd
volatile char ones = 0; //used as placeholder for counting
volatile char tens = 0;
volatile char hunds = 0;

const unsigned char table [][5] = {
{0x00, 0x00, 0x00, 0x00, 0x00}// (space)
,{0x00, 0x00, 0x5F, 0x00, 0x00}// !
,{0x00, 0x07, 0x00, 0x07, 0x00}// "
,{0x14, 0x7F, 0x14, 0x7F, 0x14}// #
,{0x24, 0x2A, 0x7F, 0x2A, 0x12}// $
,{0x23, 0x13, 0x08, 0x64, 0x62}// %
,{0x36, 0x49, 0x55, 0x22, 0x50}// &
,{0x00, 0x05, 0x03, 0x00, 0x00}// '
,{0x00, 0x1C, 0x22, 0x41, 0x00}// (
,{0x00, 0x41, 0x22, 0x1C, 0x00}// )
,{0x08, 0x2A, 0x1C, 0x2A, 0x08}// *
,{0x08, 0x08, 0x3E, 0x08, 0x08}// +
,{0x00, 0x50, 0x30, 0x00, 0x00}// ,
,{0x08, 0x08, 0x08, 0x08, 0x08}// -
,{0x00, 0x60, 0x60, 0x00, 0x00}// .
,{0x20, 0x10, 0x08, 0x04, 0x02}// /
,{0x3E, 0x51, 0x49, 0x45, 0x3E}// 0
,{0x00, 0x42, 0x7F, 0x40, 0x00}// 1
,{0x42, 0x61, 0x51, 0x49, 0x46}// 2
,{0x21, 0x41, 0x45, 0x4B, 0x31}// 3
,{0x18, 0x14, 0x12, 0x7F, 0x10}// 4
,{0x27, 0x45, 0x45, 0x45, 0x39}// 5
,{0x3C, 0x4A, 0x49, 0x49, 0x30}// 6
,{0x01, 0x71, 0x09, 0x05, 0x03}// 7
,{0x36, 0x49, 0x49, 0x49, 0x36}// 8
,{0x06, 0x49, 0x49, 0x29, 0x1E}// 9
,{0x00, 0x36, 0x36, 0x00, 0x00}// :
,{0x00, 0x56, 0x36, 0x00, 0x00}// ;
,{0x00, 0x08, 0x14, 0x22, 0x41}// <
,{0x14, 0x14, 0x14, 0x14, 0x14}// =
,{0x41, 0x22, 0x14, 0x08, 0x00}// >
,{0x02, 0x01, 0x51, 0x09, 0x06}// ?
,{0x32, 0x49, 0x79, 0x41, 0x3E}// @
,{0x7E, 0x11, 0x11, 0x11, 0x7E}// A
,{0x7F, 0x49, 0x49, 0x49, 0x36}// B
,{0x3E, 0x41, 0x41, 0x41, 0x22}// C
,{0x7F, 0x41, 0x41, 0x22, 0x1C}// D
,{0x7F, 0x49, 0x49, 0x49, 0x41}// E
,{0x7F, 0x09, 0x09, 0x01, 0x01}// F
,{0x3E, 0x41, 0x41, 0x51, 0x32}// G
,{0x7F, 0x08, 0x08, 0x08, 0x7F}// H
,{0x00, 0x41, 0x7F, 0x41, 0x00}// I
,{0x20, 0x40, 0x41, 0x3F, 0x01}// J
,{0x7F, 0x08, 0x14, 0x22, 0x41}// K
,{0x7F, 0x40, 0x40, 0x40, 0x40}// L
,{0x7F, 0x02, 0x04, 0x02, 0x7F}// M
,{0x7F, 0x04, 0x08, 0x10, 0x7F}// N
,{0x3E, 0x41, 0x41, 0x41, 0x3E}// O
,{0x7F, 0x09, 0x09, 0x09, 0x06}// P
,{0x3E, 0x41, 0x51, 0x21, 0x5E}// Q
,{0x7F, 0x09, 0x19, 0x29, 0x46}// R
,{0x46, 0x49, 0x49, 0x49, 0x31}// S
,{0x01, 0x01, 0x7F, 0x01, 0x01}// T
,{0x3F, 0x40, 0x40, 0x40, 0x3F}// U
,{0x1F, 0x20, 0x40, 0x20, 0x1F}// V
,{0x7F, 0x20, 0x18, 0x20, 0x7F}// W
,{0x63, 0x14, 0x08, 0x14, 0x63}// X
,{0x03, 0x04, 0x78, 0x04, 0x03}// Y
,{0x61, 0x51, 0x49, 0x45, 0x43}// Z
,{0x00, 0x00, 0x7F, 0x41, 0x41}// [
,{0x02, 0x04, 0x08, 0x10, 0x20}// "\"
,{0x41, 0x41, 0x7F, 0x00, 0x00}// ]
,{0x04, 0x02, 0x01, 0x02, 0x04}// ^
,{0x40, 0x40, 0x40, 0x40, 0x40}// _
,{0x00, 0x01, 0x02, 0x04, 0x00}// `
,{0x20, 0x54, 0x54, 0x54, 0x78}// a
,{0x7F, 0x48, 0x44, 0x44, 0x38}// b
,{0x38, 0x44, 0x44, 0x44, 0x20}// c
,{0x38, 0x44, 0x44, 0x48, 0x7F}// d
,{0x38, 0x54, 0x54, 0x54, 0x18}// e
,{0x08, 0x7E, 0x09, 0x01, 0x02}// f
,{0x08, 0x14, 0x54, 0x54, 0x3C}// g
,{0x7F, 0x08, 0x04, 0x04, 0x78}// h
,{0x00, 0x44, 0x7D, 0x40, 0x00}// i
,{0x20, 0x40, 0x44, 0x3D, 0x00}// j
,{0x00, 0x7F, 0x10, 0x28, 0x44}// k
,{0x00, 0x41, 0x7F, 0x40, 0x00}// l
,{0x7C, 0x04, 0x18, 0x04, 0x78}// m
,{0x7C, 0x08, 0x04, 0x04, 0x78}// n
,{0x38, 0x44, 0x44, 0x44, 0x38}// o
,{0x7C, 0x14, 0x14, 0x14, 0x08}// p
,{0x08, 0x14, 0x14, 0x18, 0x7C}// q
,{0x7C, 0x08, 0x04, 0x04, 0x08}// r
,{0x48, 0x54, 0x54, 0x54, 0x20}// s
,{0x04, 0x3F, 0x44, 0x40, 0x20}// t
,{0x3C, 0x40, 0x40, 0x20, 0x7C}// u
,{0x1C, 0x20, 0x40, 0x20, 0x1C}// v
,{0x3C, 0x40, 0x30, 0x40, 0x3C}// w
,{0x44, 0x28, 0x10, 0x28, 0x44}// x
,{0x0C, 0x50, 0x50, 0x50, 0x3C}// y
,{0x44, 0x64, 0x54, 0x4C, 0x44}// z
,{0x00, 0x08, 0x36, 0x41, 0x00}// {
,{0x00, 0x00, 0x7F, 0x00, 0x00}// |
,{0x00, 0x41, 0x36, 0x08, 0x00}// }
,{0x08, 0x08, 0x2A, 0x1C, 0x08}// ->
,{0x08, 0x1C, 0x2A, 0x08, 0x08} // <-
};

const unsigned char nice [] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x80, 0x00, 0x00, 0x00,
0x00, 0x00, 0x10, 0x60, 0x80, 0x00, 0x18, 0xE0, 0x80, 0x80, 0x80, 0x8E, 0x70, 0x00, 0x00, 0xE0,
0x1C, 0x00, 0x00, 0x00, 0x80, 0x60, 0x18, 0x00, 0x00, 0x80, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
0x61, 0x12, 0x14, 0x08, 0x04, 0x02, 0x02, 0x41, 0x41, 0x81, 0x81, 0x00, 0x01, 0x00, 0x00, 0x00,
0x01, 0x01, 0x01, 0x01, 0x82, 0x82, 0x04, 0x0E, 0x11, 0x10, 0x60, 0x98, 0x06, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xFE, 0x18, 0x60, 0x80, 0xFE, 0x02, 0x00, 0x00, 0x10, 0xF2,
0x00, 0x00, 0x00, 0x00, 0xE0, 0x10, 0x10, 0x10, 0x20, 0x00, 0x00, 0xE0, 0x90, 0x90, 0x90, 0xE0,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x80, 0x7C, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x40, 0x42, 0x82, 0x84, 0x05,
0x09, 0x08, 0x02, 0x02, 0x11, 0x91, 0x89, 0x49, 0x44, 0x84, 0x82, 0x02, 0x00, 0x00, 0x00, 0x01,
0x02, 0x7C, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x07, 0x04, 0x00, 0x01, 0x07, 0x00,
0x00, 0x00, 0x04, 0x07, 0x04, 0x00, 0x00, 0x00, 0x03, 0x04, 0x04, 0x04, 0x02, 0x00, 0x00, 0x03,
0x04, 0x04, 0x04, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x19, 0x10, 0x26,
0x22, 0x10, 0x19, 0x06, 0x00, 0x00, 0x00, 0x00, 0x06, 0x19, 0x10, 0x22, 0x26, 0x10, 0x19, 0x06,
0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x0C, 0x30, 0x40, 0x40, 0x82,
0x06, 0x06, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0x40, 0x40, 0x30, 0x0C, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x02, 0x04, 0x04, 0x04, 0x04, 0x08, 0x08, 0x08, 0x08, 0x08,
0x04, 0x04, 0x04, 0x04, 0x02, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

const unsigned char button [] = {
0x00, 0x00, 0x00, 0xC0, 0x30, 0x10, 0x08, 0x08, 0x10, 0x30, 0xC0, 0x00, 0x00, 0x00, 0x80, 0x80,
0x80, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x10, 0x10,
0x10, 0x10, 0x10, 0x10, 0x10, 0x08, 0x08, 0x08, 0x08, 0x08, 0x48, 0x68, 0x64, 0x54, 0x54, 0x4C,
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0xE0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0xE0, 0x03, 0x02, 0x04, 0x04, 0x02, 0x03, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 0x04, 0x04, 0x04, 0x04,
0x04, 0x08, 0x08, 0x08, 0x08, 0x08, 0x10, 0x10, 0x10, 0x10, 0x10, 0x20, 0x20, 0x20, 0x2C, 0x34,
0x54, 0x64, 0x44, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0x04, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x3F, 0x21, 0x01, 0x3E, 0x20,
0x00, 0x1E, 0x25, 0x25, 0x25, 0x16, 0x00, 0x61, 0x47, 0x38, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
0xF8, 0x88, 0x88, 0x70, 0x00, 0x08, 0xF8, 0x10, 0x08, 0x18, 0x00, 0xF0, 0x28, 0x28, 0x28, 0xB0,
0x00, 0x90, 0x28, 0x28, 0x48, 0x98, 0x00, 0x90, 0x28, 0x28, 0x48, 0x98, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0xFF, 0x88, 0x08, 0xF0, 0x08, 0xF8, 0x00, 0x08, 0xF8, 0x00, 0x00, 0x08,
0xFF, 0x08, 0x88, 0x00, 0x00, 0x08, 0xFF, 0x08, 0x88, 0x00, 0x00, 0xF0, 0x08, 0x08, 0x08, 0xF0,
0x08, 0xF0, 0x08, 0x08, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x02, 0x03, 0x02, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x81, 0x80,
0x80, 0x80, 0x00, 0x00, 0x00, 0x10, 0xF0, 0x00, 0x01, 0x00, 0x01, 0x80, 0x80, 0x80, 0x01, 0x01,
0x00, 0x81, 0x80, 0x00, 0x00, 0x01, 0x00, 0x80, 0x80, 0x80, 0x80, 0x01, 0x00, 0x80, 0x80, 0x80,
0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x20, 0x3F, 0x28, 0x08, 0x07, 0x00, 0x00, 0x10, 0x1F, 0x10, 0x00, 0x00, 0x0F, 0x12,
0x12, 0x12, 0x0B, 0x00, 0x0D, 0x12, 0x12, 0x0F, 0x10, 0x00, 0x19, 0x12, 0x12, 0x14, 0x09, 0x00,
0x0F, 0x12, 0x12, 0x12, 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

////////////////////////////function prototypes/////////////////////////
void LcdWrite(char CMD,char data);
void LcdInit();
void LcdClear();
void LcdString(char *characters);
void LcdCharacter(const char character);
void LcdNumber();
void gotoXY(char x, char y);
void LcdBmp(const unsigned char my_array[]);
void sendArray(const unsigned char digit[], char length);
void delay(int ms);
void loadFlash();
////////////////////////////main///////////////////////////////////
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT

BCSCTL1 = CALBC1_1MHZ; // calibrate basic clock system control 1 to 1mhz
DCOCTL = CALDCO_1MHZ; // calibrate DCO to 1mhz

IE1 |= WDTIE; //enable watchdog timer interrupt

P1SEL &= ~(BIT0 + BIT3); //enable port 1.0 and 1.3
P1IN &= ~BIT3; //input signal == low
P1DIR |= BIT0; //set p1.0 red led to output
P1DIR &= ~BIT3; // set p1.3 as an input
P1OUT |= BIT0 + BIT3; // p1.0 high led is on //pullup for p1.3
P1REN |= BIT3; // Resistor Enable for p1.3 pull up
P1IES |= BIT3; // Interrupt Edge Select - 0: trigger on rising edge, 1: trigger on falling edge
P1IFG &= ~BIT3; //interrupt flag for p1.3 is off
P1IE |= BIT3; // enable interrupt

P2SEL &= ~(BIT1 + BIT4 + BIT3 + BIT0); //turns on port 2
P2DIR |= (BIT1 + BIT4 + BIT3 + BIT0); //set as outputs
P2OUT &= ~(BIT4 + BIT3 + BIT1 + BIT0); //set pins low

USICTL0 |= 0x6B;
USICTL1 |= 0X91;
//USICKCTL |= 0xE8; //divide by 128
USICKCTL |= 0xA8; // divide by 32
USICTL0 &= ~USISWRST; // Reset & release USI
USICNT |= 8; // send 8 bits

FCTL2 = FWKEY + FSSEL0 + FN1; // MCLK/3 for Flash Timing Generator


//_bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupt
_BIS_SR(GIE); //enable interrupts
LcdInit();
loadFlash(); //load counter values from before power down

for(;;) { //infinite loop

do{
LcdWrite(cmd , 0x0C); // LCD 0x0C for black on white //0x0d for inverse
P1OUT |= BIT0; // turn on port 1.0 led
gotoXY(0,0);
LcdBmp(button);
}

while(0x08 & P1IN);
}

}

//////////////////////ISR's//////////////////////////////////
// USI interrupt service routine
#pragma vector = USI_VECTOR
__interrupt void USI_TXRX (void)
{
USICTL1 &= ~USIIFG; // Clear pending flag
P2OUT |= PIN_SCE; //SCE pin high
}

#pragma vector=PORT1_VECTOR
__interrupt void PORT1_ISR(void)
{
P1IFG &= ~BIT3; // clear interrupt flag
WDTCTL = WDT_MDLY_32; //watchdog delay for debounce 32milli seconds// interval timer mode
pressCount++; //increment button presses
P1OUT &= ~BIT0; //turn off led
LcdClear();
LcdWrite(cmd , 0x0D); // LCD 0x0C for black on white //0x0d for inverse
gotoXY(0,0);
LcdBmp(nice);
delay(1000);
LcdClear();
gotoXY(0,0);
LcdString("************");
gotoXY(10,1);
LcdString("now was'nt");
gotoXY(25,3);
LcdString("that");
gotoXY(12,5);
LcdString("exciting");
delay(700);
LcdClear();
gotoXY(20,0);
LcdString("Number");
gotoXY(10,2);
LcdString("of button");
gotoXY(0,4); //locate cursor
LcdString("press's");

ones = pressCount;

if(ones > 9){ //write # of press's to lcd
tens++;
ones = 0;
pressCount = 0;

if(tens > 9){
hunds++;
tens = 0;
ones = 0;
pressCount = 0;

if(hunds > 9){
pressCount = 0;
hunds = 0;
tens = 0;
ones = 0;
}
}
}
number = ones; //write the ones column
gotoXY(67,5);
LcdNumber();
number = tens;
gotoXY(61,5);
LcdNumber();
number = hunds;
gotoXY(55,5);
LcdNumber();
delay(1000);
LcdClear();
//gotoXY(0,0);
//LcdBmp(finger);
//delay(500);

FCTL1 = FWKEY + ERASE; // Set Erase bit
FCTL3 = FWKEY; // Clear Lock bit

*Flash_ptr = 0; // Dummy write to erase Flash segment
// *Flash_pOnes = 0;
// *Flash_pTens = 0;
// *Flash_pHunds = 0;

FCTL1 = FWKEY + WRT; // Set WRT bit for write operation

*Flash_ptr = pressCount; // Write value to flash
*Flash_pOnes = ones;
*Flash_pTens = tens;
*Flash_pHunds = hunds;

FCTL1 = FWKEY; // Clear WRT bit
FCTL3 = FWKEY + LOCK; // Set LOCK bit
}

#pragma vector=WDT_VECTOR
__interrupt void WDT_ISR(void) //use watchdog for button debounce
{
IFG1 &= ~WDTIFG; // clear interrupt flag
WDTCTL = WDTPW + WDTHOLD; // put WDT back in hold state
// pressCount++; //increment button presses
}

//////////////////////////////functions//////////////////////////

void gotoXY(char x, char y)
{
LcdWrite(cmd ,(0x40 | y & 0x07)); // Y row == 0100 0yyy
LcdWrite(cmd ,(0x80 | x & 0x7F)); // X column == 1xxx xxxx
}

void LcdBmp(const unsigned char my_array[])
{
unsigned short index = 0;
for (index = 0; index < 504; index++)
{
LcdWrite(info,my_array[index]);
}
}

void LcdCharacter(char character)
{
char index = 0;
LcdWrite(info,0x00);
for (index = 0; index < 5; index++)
{
LcdWrite(info,table[character - 0x20][index]);
}
LcdWrite(info,0x00);
}

void LcdString(char *characters)
{
while (*characters){
LcdCharacter(*characters++);
}
}
void LcdNumber(){

switch(number){
case 0:
sendArray(table[16],5);
break;
case 1:
sendArray(table[17],5);
break;
case 2:
sendArray(table[18],5);
break;
case 3:
sendArray(table[19],5);
break;
case 4:
sendArray(table[20],5);
break;
case 5:
sendArray(table[21],5);
break;
case 6:
sendArray(table[22],5);
break;
case 7:
sendArray(table[23],5);
break;
case 8:
sendArray(table[24],5);
break;
case 9:
sendArray(table[25],5);
break;
default:
pressCount = 0; //reset pressCount to 0
}
}

void LcdClear(void) {
int i,j;

LcdWrite(cmd, 0x80);
LcdWrite(cmd, 0x40);

for (i=0;i<6;i++) // number of rows
for (j=0;j LcdWrite(info, 0x00);
}
void delay(int ms)// Delays by the specified Milliseconds
{
while (ms--){
__delay_cycles(1000); //set to 1000 for 1 Mhz
}
}
void sendArray(const unsigned char digit[], char length)
{
char charIndex = 0;
while(charIndex < length) {
LcdWrite(info , digit[charIndex]);
charIndex++;
}
}
void LcdInit(void)
{
P2OUT |= PIN_VCC; //power to LCD
P2OUT |= PIN_RESET; //set RESET high
P2OUT &= ~PIN_RESET; //set RESET low
delay(35);
P2OUT |= PIN_RESET; //set RESET high
P2OUT |= PIN_SCE; //SCE pin high
LcdWrite(cmd , 0x21); // LCD Extended instruction set
LcdWrite(cmd , 0xBF); // Set LCD Vop (Contrast). //0xE0 - BF may have to play with
LcdWrite(cmd , 0x07); // Set Temp coefficent. //0x04 =t0 //0x05=t1 // 0x06=t2 // 0x07=t3
LcdWrite(cmd , 0x13); // LCD bias mode 1:100 0x10 //1:48 0x13
LcdWrite(cmd , 0x20); // LCD basic instruction set
LcdWrite(cmd , 0x08); // lcd blank
LcdWrite(cmd , 0x0C); // LCD 0x0C for black on white //0x0d for inverse
}
void LcdWrite(char CMD, char data)
{
if(CMD == cmd){
P2OUT &= ~PIN_DC; //set LCD to command mode
}
else{
P2OUT |= PIN_DC; //set lcd to data mode
}

P2OUT &= ~PIN_SCE; //SCE pin low
USISRL |= data; // load shift register with data to send
USICNT |= 8; // shift out 8 bits
delay(1);
}

void loadFlash()
{
pressCount = *Flash_ptr; // load values from before power down

if(*Flash_ptr == 0xFF){
pressCount = 0;
}
ones = *Flash_pOnes;

if(*Flash_pOnes == 0xFF){
ones = 0;
}
tens = *Flash_pTens;

if(*Flash_pTens == 0xFF){
tens = 0;
}
hunds = *Flash_pHunds;

if(*Flash_pHunds == 0xFF){
hunds = 0;
}
}

I found a couple of bitmap converters for displaying bitmaps on the lcds

bitmap 2 LCD http://bitmap2lcd.com
lcd assistant http://en.radzio.dxp...tmap_converter/

The program stores the # of button press's in flash so when power is restored the count doesn't start over.
Maybe this will help somebody. :thumbup:
cheers


  • PentiumPC, octavian_rot, flaksirus and 1 other like this

#13 bluehash

bluehash

    Site Admin

  • Administrators
  • 6,429 posts

Posted 26 October 2011 - 08:38 PM

Thanks Timotet.
I'm moving this to Projects.

43oh - MSP430, TivaC, ARM-Sitara and C2000 Discussion, News, Projects and Hacks

 

 


#14 RobG

RobG

    Level 5

  • Members
  • 2,999 posts
  • LocationCary, NC, US


Posted 27 October 2011 - 04:32 AM

After creating a horizontal bar graph, I figured it's time to update my audio spectrum analyzer to 5110.
First step, update volt meter code to display vertical bars (I will post the code in volt meter topic once I optimize it.)

http://www.youtube.com/watch?v=xgInWS5_lQE
  • PentiumPC likes this

#15 bluehash

bluehash

    Site Admin

  • Administrators
  • 6,429 posts

Posted 27 October 2011 - 12:15 PM

Are you doing all hard work that the MSGEQ7 did?

43oh - MSP430, TivaC, ARM-Sitara and C2000 Discussion, News, Projects and Hacks

 

 


#16 RobG

RobG

    Level 5

  • Members
  • 2,999 posts
  • LocationCary, NC, US


Posted 27 October 2011 - 01:29 PM

Unfortunately, I am still using MSGEQ chip. My first attempt at doing this in software on G series has failed, but once I get my newest booster ready, I will revisit (booster will have F51x1 on it.)

#17 bluehash

bluehash

    Site Admin

  • Administrators
  • 6,429 posts

Posted 27 October 2011 - 01:50 PM

An MSP on an MSP? o_O Firepowaah.

43oh - MSP430, TivaC, ARM-Sitara and C2000 Discussion, News, Projects and Hacks

 

 


#18 RobG

RobG

    Level 5

  • Members
  • 2,999 posts
  • LocationCary, NC, US


Posted 27 October 2011 - 02:41 PM

F51x1 will be used as a smart peripheral, so why not to implement MSGEQ's functionality. It would be a horrible waste if that MPY was sitting unused :)

#19 bluehash

bluehash

    Site Admin

  • Administrators
  • 6,429 posts

Posted 27 October 2011 - 03:28 PM

I understand. The F51x1 is for heavy fft.

43oh - MSP430, TivaC, ARM-Sitara and C2000 Discussion, News, Projects and Hacks

 

 


#20 oPossum

oPossum

    Poke me with a Stick

  • Members
  • 904 posts
  • LocationMichigan, USA


Posted 08 November 2011 - 08:25 AM


  • RobG likes this
Think in assembly, write in C. Sent from a bunker in an undisclosed location deep beneath a mountain.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users