ST7920 LIBRARY

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


Hi. I want to write a library for St7920 in Xmega but I have problem in reading data from GLCD. It's part of my code.

Read function should read pixels and because of "write_word(0,0,0XC000);" it should return 0xc000 but when I ran my code with atxmega128a1u (Harware). On GLCD it displayed just "set_pixel(2,0);". Why? And how can I fix it.

And it's part of datasheet.

 

main()
{
    write_word(0,0,0XC000);
    set_pixel(2,0);
}

uint16_t read_word(uint8_t type)    // read data byte(type=1) or command register(type=0)
{
    uint8_t i, j = 0;
	uint16_t temp;
	PORTJ.DIR = 0x00;    // set data port for input
	//PORTJ.OUT = 0x00;
	e_lo();
	if (type == 0)
	{
		rs_lo();
	}
	else
	{
		rs_hi();
	}
	rw_hi();
	e_hi();            // toggle byte in
	i = PORTJ.IN;    // need I read this twice?
	e_lo();
	delay_ms(1);
	e_hi();
	j = PORTJ.IN;
	e_lo();

	temp = j;
	temp = temp | (i << 8);

	return(temp);    // return byte read
}

void write_word(int x, int y, uint16_t data)   // x=0-7 (8 words per line), y=0-63, starting from top left
{
    PORTJ.DIR = 0xff;    // set data port for output
    e_lo();//?
    rs_lo();//?
    rw_lo();
    // convert coordinates to weirdly-arranged 128x64 screen (the ST7920 is mapped for 256x32 displays).
    if (y > 31)
    {
        y -= 32;    // because there are only 31 addressable lines in the ST7920
        x += 8;        // so we overflow x (7 visible bytes per line) to reach the bottom half
    }
    x |= 0x80;    // bit 7 signals that this is a data address write
    y |= 0x80;
    DATA_PORT.OUT = y;    // Set vertical DDRAM address
    toggle_E();
    DATA_PORT.OUT = x;    // Set horizontal DDRAM address
    toggle_E();
    rs_hi();    //   signal for WRITE
    DATA_PORT.OUT = (data >> 8);    // Set horizontal DDRAM address
    toggle_E();
    DATA_PORT.OUT = data;    // Set vertical DDRAM address
    toggle_E();
}

void gotoxy(uint8_t x, uint8_t y)    // x=0-7, y=0-63  (for 128 x 64 display)
{
    PORTJ.DIR = 0xff;    // set data port for output
    e_lo();
    rs_lo();
    rw_lo();
    // convert coordinates to weirdly-arranged 128x64 screen (the ST7920 is mapped for 256x32 displays).
    if (y > 31)
    {
        y -= 32;    // because there are only 31 addressable lines in the ST7920
        x += 8;        // so we overflow x (7 visible bytes per line) to reach the bottom half
    }
    x |= 0x80;    // bit 7 signals that this is a data address write
    y |= 0x80;
    DATA_PORT.OUT = y;    // Set vertical DDRAM address
    toggle_E();
    DATA_PORT.OUT = x;    // Set horizontal DDRAM address
    toggle_E();
}

void set_pixel(uint8_t x, uint8_t y)
{
	uint8_t x_wd, x_pixel;
	uint16_t temp=0;
	uint16_t dot = 0x8000;    // this will be rotated into it's correct position in the word
	x_wd = x / 16;        // find address of word with our pixel (x; 0-7)
	x_pixel = x - (x_wd * 16);        // get the modulo remainder; that's our pixel's position in the word
	//gotoxy(x_wd, y); it makes trouble
	temp = read_word(1);    // read word from screen at that position   
    //temp should be 0xC000 but it isn't
	temp = (temp | (dot >> x_pixel));    // convert x_pixel into a bit position, 0-16
	write_word(x_wd, y, temp);
}

Thank you for your help.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I strongly advise you to use the existing CodeVision library.   It supports ST7920 in 8-bit parallel or 4-bit parallel.

 

Build the examples.   If you are unsure how to do something,  quote the "nearest" example and say what the problem is.   Or what function you can't find.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi actually I used that library 2 or 3 months ago and I sent my code for you but it didn't work for me on my xmega (we had different type of xmega), even it didn't show a simple word like "Hi".

I tried to use 4bit and 8 bit and both of them didn't work. So I try to use another library and actually now it shows word (in lcd font), it sets a pixel (in graphic mode) and all. But I have problem in reading data.

Last Edited: Mon. Sep 13, 2021 - 12:07 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I seem to remember running the CV example on an ATxmega128A4U but I might have used 32A4U or even 128A1.

Anyway the example ran fine.

 

Obviously I had different data and control pins to you.

But you simply edit the GUI to match your wiring.

 

If I had attached a CV project or AS7.0 to a previous message thread,  please post a link.

 

I am happy to step you through a library example.   It is not much good to be told 3 months later that it "did not work".

 

There is no point in attempting "your custom project" until you have run examples successfully.

 

David.