Jump to content

tanh

Members
  • Content Count

    4
  • Joined

  • Last visited


Reputation Activity

  1. Like
    tanh reacted to RobG in Nokia 5110 display   
    I see couple of problems, I will comment once I get my coffee.
     
     
    OK, remove
    // setup USIB P1SEL |= LCD5110_SCLK_PIN + LCD5110_DN_PIN; P2SEL |= LCD5110_SCLK_PIN + LCD5110_DN_PIN;  
    Then change while in writeToLCD to
    while(!(USICTL1 & USIIFG)) ; You may also want to remove USIIE from config
    USICTL1 |= USICKPH + USICKPL;  
    I don't have access to 2231 right now, so this is all untested.
  2. Like
    tanh reacted to RobG in Nokia 5110 display   
    You need to do 3 things to use USI
     
    1. remove USCI configuration and add USI config (here's an example)
    USICTL0 |= USIPE6 + USIPE5 + USIMST + USIOE; USICTL1 |= USICKPH + USICKPL + USIIE; USICKCTL = USIDIV_7 + USISSEL_2; USICTL0 &= ~USISWRST;  
    2. swap data pin from P1.7 to P1.6
    3. instead of writing to TX buffer, write to 2 registers below
    USISRL = data; USICNT |= 8;
  3. Like
    tanh reacted to timotet in Nokia 5110 display   
    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
  4. Like
    tanh reacted to RobG in Nokia 5110 display   
    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.





    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
×