tanh reacted to
timotet in Nokia 5110 display
February 27, 2013
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
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.pl/bitmap_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