TÌnh hình là em vừa mới làm mạch giao tiếp lcd nokia 1100 với board Discovery stm32f4 , em hiện thị được chữ rồi , những nó lại quá mờ , phải nhìn kĩ mới thấy được chữ + thêm chữ bị ngược nữa .
A/e cho em lời khuyên với, em ko nghĩ là thiếu dòng do em làm tren lcd 16x2 thì rất ok.
Mạch em làm là kết nối trực tiếp chân vdk qua luôn , giống mạch này nhưng thay PIC = ARM
lMicrocontroller Projects: Nokia 1100 LCD Interfacing with Microcontroller

CODE :
A/e cho em lời khuyên với, em ko nghĩ là thiếu dòng do em làm tren lcd 16x2 thì rất ok.
Mạch em làm là kết nối trực tiếp chân vdk qua luôn , giống mạch này nhưng thay PIC = ARM
lMicrocontroller Projects: Nokia 1100 LCD Interfacing with Microcontroller
CODE :
Code:
void init(void)
{
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5|GPIO_Pin_6| GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
void spi(char cd, unsigned char myData)
{
char i;
init();
GPIOB->BSRRH = NOKIA_CS;
GPIOB->BSRRH = NOKIA_SCK;
if( cd == 1) // = 1
GPIOB->BSRRL = NOKIA_SDA;
else if( cd == 0)
GPIOB->BSRRH = NOKIA_SDA;
GPIOB->BSRRL = NOKIA_SCK;
for( i=0; i<8; i++)
{
GPIOB->BSRRH = NOKIA_SCK;
if(myData & 0x80)
GPIOB->BSRRL = NOKIA_SDA;
else
GPIOB->BSRRH = NOKIA_SDA;
GPIOB->BSRRL = NOKIA_SCK;
myData <<= 1;
DelayUs(10);
}
GPIOB->BSRRL = NOKIA_CS;
}
void NOKIA_Clear(void)
{
unsigned int i;
init();
spi(CMD,0x40); // Y = 0
spi(CMD,0xb0);
spi(CMD,0x10); // X = 0
spi(CMD,0x0);
spi(CMD,0xAE); // disable display;
for(i=0;i<864;i++)
spi(DATA,0x00);
spi(CMD,0xAF); // enable display;
}
void NOKIA_Init(void)
{
init();
GPIOB->BSRRH = NOKIA_CS; // 0
GPIOB->BSRRH = NOKIA_RST;
DelayMs(5);
GPIOB->BSRRL = NOKIA_RST;
spi(CMD,0x20); // write VOP register
spi(CMD,0x90);
spi(CMD,0xA4); // all on/normal display
spi(CMD,0x2F); // Power control set(charge pump on/off)
spi(CMD,0x40); // set start row address = 0
spi(CMD,0xb0); // set Y-address = 0
spi(CMD,0x10); // set X-address, upper 3 bits
spi(CMD,0x0); // set X-address, lower 4 bits
spi(CMD,0xC8); // mirror Y axis (about X axis)
spi(CMD,0xa1); // Invert screen in horizontal axis
spi(CMD,0xac); // set initial row (R0) of the display
spi(CMD,0x07);
//spi(CMD,0xF9); //
spi(CMD,0xaf); // display ON/OFF
NOKIA_Clear();
spi(CMD,0xa7); // invert display
DelayMs(100); // 1/2 Sec delay
spi(CMD,0xa6); // normal display (non inverted)
DelayMs(100); // 1 Sec delay
}
void SetX(char x)
{
spi(CMD,0x10 | ((x>>4)&0x7));
spi(CMD,x & 0x0f);
}
void SetY(char y)
{
char aux = 0;
while(y>7){
y -=8;
aux ++;
}
bitaddr = y-1;
spi(CMD,0xB0 | (aux & 0x0f));
}
void Gotoxy(char x,char y)
{
spi(CMD,(0xB0|(y&0x0F))); // Y axis initialisation: 0100 yyyy
spi(CMD,(0x00|(x&0x0F))); // X axis initialisation: 0000 xxxx ( x3 x2 x1 x0)
spi(CMD,(0x10|((x>>4)&0x07))); // X axis initialisation: 0010 0xxx ( x6 x5 x4)
}
//x dir > y dir from last line to ^
void VLine(char x,char y,char on)
{
char aux[8];
char i;
for(i=0;i<8;i++)
aux[i] = 0;
i = 7;
while(y > 9)
{
aux[i] = 0xff;
y -= 8;
i--;
}
while(y > 0)
{
aux[i] >>= 1;
aux[i] |= 0x80;
y --;
}
for(y=0;y<8;y++)
{
spi(CMD,0xB0 | y);
SetX(x);
spi(DATA,aux[y]);
}
}
// xdir is > y is always < than y2 can be used for graphs
void Line(unsigned char x,unsigned char y,unsigned char y2,unsigned char on)
{
char aux[8];
char i,o;
char c=1;
char index;
for(i=0;i<8;i++)
aux[i] = 0;
index = 0;
for(i=0;i<64;i++)
{
if(i >= y && i <= y2)
{
aux[index] |= c << o;
}
o ++;
if(o == 8)
{
o = 0;
index ++;
}
}
for(i=0;i<8;i++)
{
spi(CMD,0xB0 | i);
SetX(x);
spi(DATA,aux[i]);
}
}
void print_char(char c)
{
int i;
for ( i = 0; i < 5; i++ )
{
spi(DATA,NOKIA_Fonts[c - 32][i] << 1);
}
spi(DATA,0x00);
spi(DATA,0xAF);
}
void print_string(char * message)
{ // Write message to LCD (C string type)
spi(CMD,0xae); // disable display;
while (*message)
{ // Look for end of string
print_char(*message++);
}
spi(CMD,0xaf); // enable display;
}
