Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

240X240 LCD monocrome dot matrix SAP3305 controller

Status
Not open for further replies.

london

Member level 4
Joined
Jun 30, 2006
Messages
79
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,945
Hi Every body,
I am using MSP430F5435A to interface with SAP3305 LCD controller. I could not able to light up the LCD, Coud any one help me to see my code and correct. I am not sure it is because of timing issue. The SAP3305 controller and RA8835 are same.
the code is bellow,


#include <msp430x54xA.h>

#include "SAP3305.h"

#define LCD_PIN_CS 0x01 /* Chip Slect P2.0 O/P */
#define LCD_PIN_A0 0x02 /* Command/Data Select P2.1 O/P */
#define LCD_PIN_E 0x04 /* Chip enable P2.2 O/P */
#define LCD_PIN_RW 0x08 /* Chip Read/Write P2.3 O/P */
#define LCD_PIN_RST 0x10 /* reset P2.4 O/P */

#define LCD_PIN_D0 0x01 /* Register select P1.0 O/P */
#define LCD_PIN_D1 0x02 /* Register select P1.1 O/P */
#define LCD_PIN_D2 0x04 /* Register select P1.2 O/P */
#define LCD_PIN_D3 0x08 /* Register select P1.3 O/P */
#define LCD_PIN_D4 0x10 /* Register select P1.4 O/P */
#define LCD_PIN_D5 0x20 /* Register select P1.5 O/P */
#define LCD_PIN_D6 0x40 /* Register select P1.6 O/P */
#define LCD_PIN_D7 0x80 /* Register select P1.7 O/P */

#define LCD_DATA 0xFF /* P10.0 to 10.7 */

/* Writing value to DATA pins */
#define LCD_DATA_OUT(x) P1OUT &= ~LCD_DATA; P1OUT = (x & 0xFF)

/* pin LCD_PIN_CS setting to 0 or 1 */
#define LCD_CS(x) ((x) ? (P2OUT |= LCD_PIN_CS) : (P2OUT &= ~LCD_PIN_CS))

/* pin LCD_PIN_A0 setting to 0 or 1 */
#define LCD_A0(x) ((x) ? (P2OUT |= LCD_PIN_A0) : (P2OUT &= ~LCD_PIN_A0))

/* pin LCD_PIN_E setting to 0 or 1 enable Clock/ disable clock */
#define LCD_E(x) ((x) ? (P2OUT |= LCD_PIN_E) : (P2OUT &= ~LCD_PIN_E))

/* pin LCD_PIN_RW setting to 0 or 1 Data is write when RW low read when high */
#define LCD_RW(x) ((x) ? (P2OUT |= LCD_PIN_RW) : (P2OUT &= ~LCD_PIN_RW))

/* pin LCD_PIN_RST setting to 0 or 1 */
#define LCD_RST(x) ((x) ? (P2OUT |= LCD_PIN_RST) : (P2OUT &= ~LCD_PIN_RST))

#define MAX_KEY_COUNT 20

#define BYTE_PER_LINE 30
#define NUMBER_OF_LINE 240 //240X240

#define LCD_CD_CODE 1
#define LCD_CD_DATA 0

#define TIMER_COUNT 1000

//#define LCD_DATA P0
//sbit LCD_WR = P2^0; // R/W & CS
//sbit LCD_RD = P2^1;
//sbit LCD_CE = P2^2; // E
//sbit LCD_CD = P2^3; // A0
//sbit LCD_RST = P2^4; // RESET
//sbit SW_REV_SEQ1 = P2^6;
//sbit SW_SEQ1 = P2^7;
//sbit SW_REV_SEQ2 = P3^2;
//sbit SW_SEQ2 = P3^3;

#define MAXINITLCD 19 // 19 26
#define INIT_GRAPHICS 5

const unsigned char InitLcdCode [MAXINITLCD][2] =
{
LCD_CD_CODE, 0x40, //System Set
LCD_CD_DATA, 0x31, //P1 30
LCD_CD_DATA, 0x87, //P2 FX 8 pixel
LCD_CD_DATA, 0x07, //P3 FY 8 pixel
LCD_CD_DATA, 0x1D, //P4
LCD_CD_DATA, 0x25, //P5
LCD_CD_DATA, BYTE_PER_LINE, //P7 APL
LCD_CD_DATA, 0x00, //P8 APH

LCD_CD_CODE, SCROLL, //Scroll
LCD_CD_DATA, 0x00, //P1
LCD_CD_DATA, 0x00, //P2
LCD_CD_DATA, 0xF0, //P3 C0

LCD_CD_CODE, HDOT, //Scroll
LCD_CD_DATA, 0x00, //P1

LCD_CD_CODE, OVLAY, //ovlay
LCD_CD_DATA, OVLAY_P1+DM1, //P1 +DM1

LCD_CD_CODE, DISP_ON_OFF + DISP_OFF, //disp on off
LCD_CD_DATA, 0x00, //P1

};

const unsigned char InitGraphic [INIT_GRAPHICS][2] =
{
LCD_CD_CODE, CSRW,
LCD_CD_DATA, 0x00, //P1
LCD_CD_DATA, 0x00, //P2

LCD_CD_CODE, DISP_ON_OFF + DISP_ON, //disp on off
LCD_CD_DATA, 0x16, //P1
};

enum LcdDisp
{
LCD_SQUARE,
LCD_WHITE,
LCD_BLACK,
LCD_LETTER,
LCD_MAX
} LcdDisplay;

//---------------------------------------------

int OldLcdDisp;
int NewLcdDisp;
int timer;
unsigned char uData0, uData1, uData2;

void InitLcd (void);
void LcdOutCommand (unsigned char ucData);
void LcdOutData (unsigned char ucData);
void InitReg (void);
void process (void);

void LcdSetAddress (unsigned char LcdAddrH, unsigned char LcdAddrL);
void UpdateLcd (void);

void LcdSquare (void);
void LcdSameGraphData (unsigned char ucData);
void LcdLetter (void);

//*********************************************
int __low_level_init(void){
WDTCTL = WDTPW+WDTHOLD; // Stop WDT
return 0;
}

void main(void)
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
InitReg ();
InitLcd ();
//LcdOutCommand(0x53);
process ();

__no_operation(); // For debugger
}

void process (void)
{
while (1)
{
UpdateLcd ();
//__bis_SR_register(LPM0_bits + GIE); // Enter LPM0, enable interrupts
};
}

//---------------------------------------------

void UpdateLcd (void)
{
//if (OldLcdDisp != NewLcdDisp)
//{
OldLcdDisp = NewLcdDisp;

switch (NewLcdDisp)
{
case LCD_SQUARE:
// LcdSameGraphData (0xff);
LcdSquare ();
break;

case LCD_WHITE:
LcdSameGraphData (0x55);
break;

case LCD_BLACK:
LcdSameGraphData (0xaa);
break;

case LCD_LETTER:
// LcdLetter ();
LcdSameGraphData (0x17);
break;
}
//}
}

//---------------------------------------------

void LcdSquare (void)
{
int count1;

LcdSetAddress (InitGraphic [2][1] , InitGraphic [1][1]);
LcdOutCommand (MWRITE);
for (count1 = 0; count1 < 1000 ; count1++)
{
LcdOutData (0x0ff);
//LcdOutData (count1);
}
_NOP();
}

//---------------------------------------------

void LcdLetter (void)
{
int nCharRow, nCharCol, nHeight;
int nCharacter;

LcdSetAddress (InitGraphic [2][1] , InitGraphic [1][1]);
LcdOutCommand (MWRITE);

for (nCharCol = 0; nCharCol < NUMBER_OF_LINE/8; nCharCol++)
{

for (nHeight = 0; nHeight < 8; nHeight++)
{
nCharacter = 0x30;
for (nCharRow = 0; nCharRow < BYTE_PER_LINE; nCharRow++) // mono no /3
{

LcdOutData(0x01); // mono char

nCharacter++;
}
}
}
}


//---------------------------------------------

void LcdSameGraphData (unsigned char ucData)
{
unsigned char countCol, countSeg;

LcdSetAddress (InitGraphic [2][1] , InitGraphic [1][1]);
LcdOutCommand (MWRITE);
for (countCol = 0; countCol < 240; countCol++)
{
for (countSeg = 0; countSeg < 30; countSeg++)
{
LcdOutData (ucData);
// LcdOutData (countCol);
}
}
}

//---------------------------------------------

void LcdSetAddress (unsigned char LcdAddrH, unsigned char LcdAddrL)
{
LcdOutCommand (CSRW);
LcdOutData (LcdAddrL);
LcdOutData (LcdAddrH);
LcdOutCommand (CSDIR);
}

//---------------------------------------------

void InitReg (void)
{

//P2 = 0xff;
//P0 = 0xff;
P2DIR |= (LCD_PIN_CS + LCD_PIN_A0 + LCD_PIN_E + LCD_PIN_RW + LCD_PIN_RST); //Set Control ports as Outputs
P1DIR |= (LCD_PIN_D0 + LCD_PIN_D1 + LCD_PIN_D2 + LCD_PIN_D3 + LCD_PIN_D4
+ LCD_PIN_D5 + LCD_PIN_D6 + LCD_PIN_D7); //Set Data ports as Outputs
P1OUT = 0x00;
NewLcdDisp = 0;
OldLcdDisp = LCD_MAX;

timer = 0;
}

//---------------------------------------------

void InitLcd (void)
{
int i;

LCD_RST(0);
for (i=0;i<100;i++);
LCD_RST(1);
for (i=0;i<100;i++);

//Init
for (i = 0; i < MAXINITLCD; i++)
{
if (InitLcdCode [0] == LCD_CD_CODE)
LcdOutCommand (InitLcdCode [1]);
else
LcdOutData (InitLcdCode [1]);
}

//Graphics
for (i = 0; i < INIT_GRAPHICS; i++)
{
if (InitGraphic [0] == LCD_CD_CODE)
LcdOutCommand (InitGraphic [1]);
else
LcdOutData (InitGraphic [1]);
}

//clear all data for 4 layers
LcdOutCommand (MWRITE);
for (i=0;i<0x5000;i++)
LcdOutData (0x00);

for (i = 0; i < INIT_GRAPHICS; i++)
{
if (InitGraphic [0] == LCD_CD_CODE)
LcdOutCommand (InitGraphic [1]);
else
LcdOutData (InitGraphic [1]);
}
}

//---------------------------------------------

void LcdOutCommand (unsigned char ucData)
{
LCD_DATA_OUT(ucData);

LCD_A0(1);
LCD_RW(0);

LCD_E(0);
LCD_E(0);
LCD_E(0);
LCD_E(0);
LCD_E(1);
LCD_E(1);
LCD_E(1);
LCD_E(1);
LCD_RW(1);
}

//---------------------------------------------

void LcdOutData (unsigned char ucData)
{
LCD_DATA_OUT(ucData);

LCD_A0(0);
LCD_RW(0);

LCD_E(0);
LCD_E(0);
LCD_E(0);
LCD_E(0);
LCD_E(1);
LCD_E(1);
LCD_E(1);
LCD_E(1);
LCD_RW(0);
}



sap3305.h

#ifndef sap3305_h
#define sap3305_h

#define SYSTEM_SET 0x40
#define SLEEP_IN 0x53
#define DISP_ON_OFF 0x58
#define SCROLL 0x44
#define CSRFORM 0x5d
#define CGRAM_ADR 0x5c
#define CSDIR 0x4c
#define HDOT 0x5a
#define OVLAY 0x5b
#define CSRW 0x46
#define CSRR 0x47
#define MWRITE 0x42
#define MREAD 0x43

//system set
//P1
#define SYSTEM_SET_P1 0x10
#define IV 0x20
#define WS 0x08
#define M2 0x04
#define M1 0x02
#define M0 0x01
//P2
#define WF 0x80

//Ovlay
#define OVLAY_P1 0x40
#define MX0 0x00
#define MX1 0x01
#define MX2 0x02
#define MX3 0x03
#define DM0 0x00
#define DM1 0x0c
#define OV 0x10

//Disp on off
#define DISP_OFF 0x00
#define DISP_ON 0x01

#endif
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top