samvirking NOKIA 1100 GLCD

V

vikky

Guest
Hallo,

Jeg prøver å grensesnittet grafisk visning av 1100 (kontrolleren PCF8814) med AT Mega 16.I har limt programmet below.The LCD ikke work.Please fortelle meg hvis noe er galt.

#
include <avr/io.h>
#
include <avr/interrupt.h>
#
include <util/delay.h>
#
include <string.h>

# define BIT (x) (1 <<(x))

# define CHECKBIT (x, b) x & b
# define SETBIT (x, b) x | = b;
# define CLEARBIT (x, b) x & = ~ b;
# define TOGGLEBIT (x, b) x ^ = b;

# define SCE 0x08
# define DC 0x04

flyktige char pixel_lookup [8] = (0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80);

static const unsigned char font_lookup [96] [5] =
(
(0x00, 0x00, 0x00, 0x00, 0x00), / / (mellomrom)
(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, 0x30, 0x30, 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), / / t
(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) / / <--
);

void lcd_cmd (unsigned char cmd);
void lcd_data (unsigned char cmd);

void lcd_goto_xy (char x, char y)
(
y = y | 0x40;
lcd_cmd (y);
x = (x * 6) | 0x80;
lcd_cmd (x);
)

void lcd_char (unsigned char tegn)
(
unsigned char j = 0;
for (j = 0; j <5; j )
lcd_data ((font_lookup [karakter-32] [J] <<1));

)void lcd_string (unsigned char skrift, unsigned char * streng)
(
if (font == 1)
(
unsigned char j;
lcd_cmd (0xae);
while (* string! = '\ 0')
(
for (j = 0; j <5; j )
lcd_data ((font_lookup [* string-32] [J] <<1));
lcd_data (0x00);
string ;
)
)

lcd_cmd (0xaf);

)

void lcd_num_char (unsigned char num)
(
unsigned char H = 0, T = 0, O = 0, j = 0;
H = num/100;
T = (num - (H * 100)) / 10;
O = (num - (H * 100) - (T * 10));

for (j = 0; j <5; j )
lcd_data (font_lookup [H 16] [J]);
for (j = 0; j <5; j )
lcd_data (font_lookup [T 16] [J]);
for (j = 0; j <5; j )
lcd_data (font_lookup [O 16] [J]);

)

void lcd_num_int (unsigned int num)
(
unsigned char TT = 0, TH = 0, H = 0, T = 0, O = 0, j = 0;

TT = num/10000;
TH = (num-(TT * 10000)) / 1000;
H = (num-(TT * 10000) - (TH * 1000)) / 100;
T = (num - (TT * 10000) - (TH * 1000) - (H * 100)) / 10;
O = (num - (TT * 10000) - (TH * 1000) - (H * 100) - (T * 10));
for (j = 0; j <5; j )
lcd_data (font_lookup [TT 16] [J]);
for (j = 0; j <5; j )
lcd_data (font_lookup [TH 16] [J]);
for (j = 0; j <5; j )
lcd_data (font_lookup [H 16] [J]);
for (j = 0; j <5; j )
lcd_data (font_lookup [T 16] [J]);
for (j = 0; j <5; j )
lcd_data (font_lookup [O 16] [J]);
)
char x_line = 0, y_line = 0;

void Gotoxy (char x, char y) (
lcd_cmd (0xB0 | (y & 0x0F)); / / Y-akse initialisation: 0100 yyyy
lcd_cmd (0x00 | (x & 0x0F)); / / X-aksen initialisation: 0000 xxxx (x3 x2 x1 x0)
lcd_cmd (0x10 | ((x>> 4) & 0x07)); / / X-aksen initialisation: 0010 0xxx (x6 x5 x4)
lcd_data (pixel_lookup [y]);
)

void lcd_pixel (char x, char y) / / 40,36
(
unsigned char x_block = 0, y_block = 0;
/ / x_block = x/16;
y_block = y / 8;
y = y% 8;

y_block = y_block | 0x40;
lcd_cmd (y_block);
x = x | 0x80;
lcd_cmd (x);
lcd_data (pixel_lookup [y]);
)

void lcd_clear (void) (
unsigned int i;
lcd_cmd (0x40); / / Y = 0
lcd_cmd (0xb0);
lcd_cmd (0x10); / / X = 0
lcd_cmd (0x0);
lcd_cmd (0xae); / / deaktivere display;
for (i = 0; i <864; i )
lcd_data (0x00);
lcd_cmd (0xaf); / / aktivere display;
)
void lcd_init (void)
(

CLEARBIT (Porta, SCE)
CLEARBIT (Porta, DC)
_delay_ms (5); / / 5mS så sier stopp watch (mindre enn 5ms vil ikke fungere)
SETBIT (Porta, DC)
lcd_cmd (0x20); / / skrive VOP register
lcd_cmd (0x90);
lcd_cmd (0xA4); / / alle på / normal skjerm
lcd_cmd (0xAf); / / visning på
lcd_cmd (0x2F); / / Power kontroll angi (charge pumpen på / av)
lcd_cmd (0x40); / / angir start rad adresse = 0
lcd_cmd (0xb0); / / sett Y-adresse = 0
lcd_cmd (0x10); / / sett X-adresse, øvre 3 biter
lcd_cmd (0x00); / / sett X-adresse, lavere 4 biter
lcd_cmd (0xC8); / / speil Y-aksen (om X-aksen)
lcd_cmd (0xad); / / a1 / / Invert skjermen i horisontal akse
lcd_cmd (0xac); / / sett første rad (R0) i displayet
lcd_cmd (0x07);
/ / lcd_cmd (0xF9); / /
lcd_cmd (0xaf); / / display ON / OFF
lcd_cmd (0xa9);
/ / lcd_cmd (0xE8);
lcd_clear (); / / klar LCD
lcd_cmd (0xa7); / / inverterer display
_delay_ms (500); / / 1 / 2 Sec forsinkelse
lcd_cmd (0xa6); / / normal skjerm (ikke omvendt)
_delay_ms (1000); / / 1 sek forsinkelse / / lcd_cmd (0x21);
/ / lcd_cmd (0xc8);
/ / lcd_cmd (0x06);
/ / Lcd_cmd (0x13);
/ / lcd_cmd (0x20);
/ / Lcd_cmd (0x0c);
)void lcd_cmd (unsigned char cmd)
(
CLEARBIT (Porta, DC)
CLEARBIT (Porta, SCE)
/ / SPDR = 0xFE;
/ / while (! (CHECKBIT (SPSR, BIT (7)))) ()

SPDR = cmd;
while (! (CHECKBIT (SPSR, BIT (7)))) ()

SETBIT (Porta, SCE)

)
void lcd_cmd1 (unsigned char cmd)
(
CLEARBIT (Porta, DC)
CLEARBIT (Porta, SCE)
SPDR = 0xFF;
while (! (CHECKBIT (SPSR, BIT (7)))) ()

SPDR = cmd;
while (! (CHECKBIT (SPSR, BIT (7)))) ()SETBIT(PORTA, SCE) )void lcd_data (unsigned char DAT)
(
SETBIT (Porta, DC)
CLEARBIT (Porta, SCE)

SPDR = dat;
while (! (CHECKBIT (SPSR, BIT (7)))) ()

SETBIT (Porta, SCE)
)void spi_write (unsigned char senddata)
(

SPDR = senddata;
while (! (CHECKBIT (SPSR, BIT (7)))) ()

)

void lcd_circle (unsigned char cx, unsigned char no, unsigned char radius)
(
int x, y, xchange, ychange, radiusError;
x = radius;
y = 0;
xchange = 1 - 2 * radius;
ychange = 1;
radiusError = 0;
while (x> = y)
(
lcd_pixel (cx x, no y);
lcd_pixel (cx-x, no y);
lcd_pixel (cx-x, CY-y);
lcd_pixel (cx-x, no y);
/ / lcd_pixel (cx-x, CY-y);
/ / lcd_pixel (cx x, CY-y);
lcd_pixel (cx y, no x);
lcd_pixel (cx-y, no x);lcd_pixel(cx-y, cy-x); lcd_pixel (cx y, no-x);
y ;
radiusError = ychange;
ychange = 2;
hvis (2 * radiusError xchange> 0)
(
x -;
radiusError = xchange;
xchange = 2;
)
)
)

int main (void)
(
unsigned int i = 0;
DDRB = 0xff;
DDRA = 0xff;
Porta = 0xff;
SETBIT (SPSR, 0)
SPCR = BIT (6) BIT (4) BIT (3) BIT (2) BIT (0);

lcd_init ();Gotoxy (10,20);
lcd_string (1, "vikky");

mens (1) ()
return 0;
)Maskinvaren tilkoblinger som under

XRES -----------> PA2
SCE -------------> PA3
SDIN -------------> PB5
SCK --------------> PB7
VDD og VDD1 gis 3.1V tilførsel
VSS er bakken.

Behage hjelpe meg å finne ut problemet.

Med takk og hilsen

Vikky

 

Welcome to EDABoard.com

Sponsor

Back
Top