Working with LCD ST7920 (graphic mode)

Go To Last Post
55 posts / 0 new

Pages

Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I start to working with LCD ST7920

 

// define pins here
#define DATA_PORT PORTD
#define DATA_IN PIND
#define COMMAND_PORT PORTC
#define DATAPORT_DIR DDRD
#define COMMAND_DIR DDRC
#define RS 0b00000001; // PC0 binary equivalent of pin number
#define RW 0b00000010; // PC1
#define E 0b00000100; // PC2
#define RST 0b00001000; // PC3

#define delay_time 80

void highRS() {
    COMMAND_PORT |= RS;
    _delay_us(delay_time);
}

void lowRS() {
    COMMAND_PORT &= ~RS;
    _delay_us(delay_time);
}

void highRW() {
    COMMAND_PORT |= RW;
    _delay_us(delay_time);
}

void lowRW() {
    COMMAND_PORT &= ~RW;
    _delay_us(delay_time);
}

void highE() {
    COMMAND_PORT |= E;
    _delay_us(delay_time);
}

void lowE() {
    COMMAND_PORT &= ~E;
    _delay_us(delay_time);
}

void toggleE() {
    highE();
    lowE();
}

void highRST() {
    COMMAND_PORT |= RST;
    _delay_us(delay_time);
}

void lowRST() {
    COMMAND_PORT &= ~RST;
    _delay_us(delay_time);
}

// start graphic mode
void ST7920_graphicEnable(void) {
    DATAPORT_DIR = 0xff;
    _delay_ms(110);
    lowE();
    lowRS();
    lowRW();
    highRST();
    DATA_PORT = 0x30;    // set 8-bit interface
    delay_ms(110);
    toggleE();
    _delay_ms(1);
    DATA_PORT = 0x36;    //  Repeat with graphics bit set to on.
    _delay_ms(110);
    toggleE();
    DATA_PORT = 0x0c;    // display ON, cursor and blink OFF
    _delay_ms(110);
    toggleE();
    DATA_PORT = 0x01;    // clear display, reset address
    _delay_ms(110);
    toggleE();
    DATA_PORT = 0x06;    // display ON, no cursor
    _delay_ms(110);
    toggleE();
}

void ST7920_graphicFill(uint16_t value) {
    uint8_t i, j;
    for (i = 0; i < 64; i++) {
        for (j = 0; j < 8; j++) {
            ST7920_write2BytesXY(j, i, value);
        }
    }
}

void ST7920_write2BytesXY(int x, int y, uint16_t data) {
    DATAPORT_DIR = 0xff;	// set data port for output
    lowE();
    lowRS();
    lowRW();
    // 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 = y;  // set vertical DDRAM address
    toggleE();
    DATA_PORT = x;  // set horizontal DDRAM address
    toggleE();
    highRS(); // signal for WRITE
    DATA_PORT = (data >> 8);	// set horizontal DDRAM address
    toggleE();
    DATA_PORT = data;	// set vertical DDRAM address
    toggleE();
}

uint16_t ST7920_read2Bytes(uint8_t type) {
    uint8_t i, j = 0;
    uint16_t temp;
    DATAPORT_DIR = 0x00;	// set data port for input
    DATA_PORT = 0x00;
    lowE();
    if (type == 0) {
        lowRS();
    } else {
        highRS();
    }
    highRW();
    highE();	// toggle byte in
    i = DATA_IN;	// need I read this twice?
    lowE();

    highE();
    i = DATA_IN;
    lowE();
    _delay_ms(1);
    highE();
    j = DATA_IN;
    lowE();

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

    return(temp);    // return byte read
}

void ST7920_gotoXY(uint8_t x, uint8_t y) {
    DATAPORT_DIR = 0xff;	// set data port for output
    lowE();
    lowRS();
    lowRW();
    // 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 = y;  // Set vertical DDRAM address
    toggleE();
    DATA_PORT = x;  // Set horizontal DDRAM address
    toggleE();
}

void ST7920_setPixel(uint8_t x, uint8_t y) {
    uint8_t x_wd, x_pixel;
    uint16_t temp;
    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
    ST7920_gotoXY(x_wd, y);
    temp = ST7920_read2Bytes(1);	// read word from screen at that position
    temp = (temp | (dot >> x_pixel));	// convert x_pixel into a bit position, 0-16
    ST7920_write2BytesXY(x_wd, y, temp);
}

void ST7920_clearPixel(uint8_t x, uint8_t y) {
    uint8_t x_wd, x_pixel;
    uint16_t temp;
    uint16_t dot = 0x7fff;  // 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
    ST7920_gotoXY(x_wd, y);
    temp = ST7920_read2Bytes(1);    // read word from screen at that position
    temp = (temp & (dot >> x_pixel));   // convert x_pixel into a bit position, 0-16
    ST7920_write2BytesXY(x_wd, y, temp);
}

int main(void)
{
    DATAPORT_DIR = 0xff;		// set DATAPORT to output
    DATA_PORT = 0x00;			// set outputs to 0 initially
    COMMAND_DIR = 0x07;			// set command port to output
    COMMAND_PORT = 0x00;		// set outputs to 0 initially

    ST7920_graphicEnable();
    ST7920_graphicFill(0x0000);	

    ST7920_setPixel(0, 0);
    ST7920_setPixel(0, 63);
    ST7920_setPixel(127, 0);
    ST7920_setPixel(127, 127);

    while (1) {

	}
}

 

When I switch power OFF/ON after LCD initializing, LCD displaing not correct view. I guess something wrong with init sequence. I can't find where I am make mistake)

Last Edited: Fri. Mar 6, 2020 - 07:05 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No startup delay perhaps, I don't know your graphics controller, but it may need some time after power up to do it's own internal init before it can be sent commands. 

 

Jim

 

 

FF = PI > S.E.T

 

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

Life is much easier with SPI interface.   Less wires.  Less bit-twiddling.

 

All the same,  the ST7920 works fine in 8-bit parallel or in 4-bit parallel mode.

But I have not got the stamina to study your code.

 

David.

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

Could we use any special library for st7920 when we use Spi?Or could you send me an example for Spi and st7920 in code vision?(no difference for using code wizard or not)

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

Unfortunately Codevision does not support ST7920 in SPI mode.

 

Which AVR and what hardware board are you using?

 

There are several Arduino libraries for SPI.

 

What text or graphics do you want to display?

 

David.

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

Your comments on several lines are just wrong. Did you employ the copy-&-paste method of coding here ?

void ST7920_write2BytesXY(int x, int y, uint16_t data) {
    ...
    DATA_PORT = (data >> 8);	// set horizontal DDRAM address
    // Surely this is a pixel write    ^
    toggleE();
    DATA_PORT = data;	// set vertical DDRAM address
    // Ditto                   ^

 

 

 

Your ST7920_clearPixel also has a bug:

  uint16_t dot = 0x7fff;  // 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
    ST7920_gotoXY(x_wd, y);
    temp = ST7920_read2Bytes(1);    // read word from screen at that position
    temp = (temp & (dot >> x_pixel));   // convert x_pixel into a bit position, 0-16
//                      ^  You need to shift in 1's not zeros.     You mean 15-0   ^

 

Last Edited: Sun. May 30, 2021 - 09:54 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

WARNING the original post is over a year old.

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

Hi David! Thank you for response.

yes I know that Codevision doesn’t support St7920 in spi mode so I tried to write lcd functions in my own way (by using St7920 data sheet) to use st7920 and spi in code vision. But it haven’t worked yet.

I have used Atxmega128a1u (Avr) and St7920 (lcd).

I did a project in Arduino with Spi and St7920 and it worked but now I should work Spi in code vision.

Although I worked with Spi in code vision and I sent data from one micro to another but I have problem with St7920 and Spi. Even in parallel mode, St7920 didn’t work correctly and displayed wrong characters! It’s one of my reason to use Spi.

Actually I don’t have any special text to display, I just want to learn how to work with Spi and St7920.

Parisa.

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

prsbsvrn wrote:
I have used Atxmega128a1u (Avr) and St7920 (lcd).

That Xmega has plenty of GPIO pins for 8-bit Parallel.   So you might just as well use the existing 4-bit or 8-bit Parallel ST7920 CodeVision libraries.

 

I could dig out my old GLCD graphics code and write the corresponding ST7920 driver but that is not the same as using regular Codevision libraries.

Perhaps Pavel will add the SPI ST7920 to a future release.

 

Even in parallel mode, St7920 didn’t work correctly and displayed wrong characters!

Post your program code.  Several members use Codevision.   Either we spot your error or we can reproduce the problem and report it to Pavel.

i.e. it seems wiser to stick with parallel and the regular CV libraries for any Codevision project.

 

David.

 

Edit.  I just ran the ST7920 example in 4-bit and in 8-bit Parallel (on Uno board).   Both worked 100%

 

Please post some text that "goes wrong" and with which Font.

Last Edited: Mon. May 31, 2021 - 08:17 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

js wrote:
WARNING the original post is over a year old.

A candidate for splitting perhaps. (or simply delete my post if possible)

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

I don't see a problem.   If Google search finds an appropriate thread,   there is no harm in adding to the historic thread.

 

prsbsvrn  is asking about a ST7920.   It seems relevant.

 

You can always edit your #6 if you want.   It refers to Darien 's original post.   I suspect that Darien  has moved on.

 

David.

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

Hi David!

Thank you for response!

Here is my code with St7920 in 4-bit parallel.(I don't know that is right or not)

// I/O Registers definitions
#include <io.h>

// Graphic Display functions
#include <glcd.h>

// Font used for displaying text
// on the graphic display
#include <font5x7.h>

void system_clocks_init(void)
{...}
void event_system_init(void)
{...}

// PORTJ initialization
// OUT register
PORTJ.OUT=0x00;
// Pin0: Input
// Pin1: Input
// Pin2: Input
// Pin3: Input
// Pin4: Input
// Pin5: Input
// Pin6: Input
// Pin7: Input
PORTJ.DIR=0x00;
// Pin0 Output/Pull configuration: Totempole/No
// Pin0 Input/Sense configuration: Sense both edges
// Pin0 Inverted: On
// Pin0 Slew Rate Limitation: Off
PORTJ.PIN0CTRL=PORT_INVEN_bm | PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin1 Output/Pull configuration: Totempole/No
// Pin1 Input/Sense configuration: Sense both edges
// Pin1 Inverted: On
// Pin1 Slew Rate Limitation: Off
PORTJ.PIN1CTRL=PORT_INVEN_bm | PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin2 Output/Pull configuration: Totempole/No
// Pin2 Input/Sense configuration: Sense both edges
// Pin2 Inverted: On
// Pin2 Slew Rate Limitation: Off
PORTJ.PIN2CTRL=PORT_INVEN_bm | PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin3 Output/Pull configuration: Totempole/No
// Pin3 Input/Sense configuration: Sense both edges
// Pin3 Inverted: On
// Pin3 Slew Rate Limitation: Off
PORTJ.PIN3CTRL=PORT_INVEN_bm | PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin4 Output/Pull configuration: Totempole/No
// Pin4 Input/Sense configuration: Sense both edges
// Pin4 Inverted: On
// Pin4 Slew Rate Limitation: Off
PORTJ.PIN4CTRL=PORT_INVEN_bm | PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin5 Output/Pull configuration: Totempole/No
// Pin5 Input/Sense configuration: Sense both edges
// Pin5 Inverted: Off
// Pin5 Slew Rate Limitation: Off
PORTJ.PIN5CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin6 Output/Pull configuration: Totempole/No
// Pin6 Input/Sense configuration: Sense both edges
// Pin6 Inverted: Off
// Pin6 Slew Rate Limitation: Off
PORTJ.PIN6CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin7 Output/Pull configuration: Totempole/No
// Pin7 Input/Sense configuration: Sense both edges
// Pin7 Inverted: Off
// Pin7 Slew Rate Limitation: Off
PORTJ.PIN7CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Interrupt 0 level: Disabled
// Interrupt 1 level: Disabled
PORTJ.INTCTRL=(PORTJ.INTCTRL & (~(PORT_INT1LVL_gm | PORT_INT0LVL_gm))) |
    PORT_INT1LVL_OFF_gc | PORT_INT0LVL_OFF_gc;
// Pin0 Pin Change interrupt 0: Off
// Pin1 Pin Change interrupt 0: Off
// Pin2 Pin Change interrupt 0: Off
// Pin3 Pin Change interrupt 0: Off
// Pin4 Pin Change interrupt 0: Off
// Pin5 Pin Change interrupt 0: Off
// Pin6 Pin Change interrupt 0: Off
// Pin7 Pin Change interrupt 0: Off
PORTJ.INT0MASK=0x00;
// Pin0 Pin Change interrupt 1: Off
// Pin1 Pin Change interrupt 1: Off
// Pin2 Pin Change interrupt 1: Off
// Pin3 Pin Change interrupt 1: Off
// Pin4 Pin Change interrupt 1: Off
// Pin5 Pin Change interrupt 1: Off
// Pin6 Pin Change interrupt 1: Off
// Pin7 Pin Change interrupt 1: Off
PORTJ.INT1MASK=0x00;

void vports_init(void)
{...}

void main(void)
{
// Declare your local variables here
unsigned char n;
// Variable used to store Graphic Display
// controller initialization data
GLCDINIT_t glcd_init_data;

// Interrupt system initialization
// Optimize for speed
#pragma optsize-
// Make sure the interrupts are disabled
#asm("cli")
// Low level interrupt: Off
// Round-robin scheduling for low level interrupt: Off
// Medium level interrupt: Off
// High level interrupt: Off
// The interrupt vectors will be placed at the start of the Application FLASH section
n=(PMIC.CTRL & (~(PMIC_RREN_bm | PMIC_IVSEL_bm | PMIC_HILVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_LOLVLEN_bm)));
CCP=CCP_IOREG_gc;
PMIC.CTRL=n;
// Set the default priority for round-robin scheduling
PMIC.INTPRI=0x00;
// Restore optimization for size if needed
#pragma optsize_default

// System clocks initialization
system_clocks_init();

// Event system initialization
event_system_init();

// Ports initialization
ports_init();

// Virtual Ports initialization
vports_init();

// Graphic Display Controller initialization
// The ST7920 connections are specified in the
// Project|Configure|C Compiler|Libraries|Graphic Display menu:
// E - PORTJ Pin 6
// R /W - PORTJ Pin 7
// RS - PORTJ Pin 5
// /RST - PORTJ Pin 0
// DB4 - PORTJ Pin 1
// DB5 - PORTJ Pin 2
// DB6 - PORTJ Pin 3
// DB7 - PORTJ Pin 4

// Specify the current font for displaying text
glcd_init_data.font=font5x7;
// No function is used for reading
// image data from external memory
glcd_init_data.readxmem=NULL;
// No function is used for writing
// image data to external memory
glcd_init_data.writexmem=NULL;

glcd_init(&glcd_init_data);

lcd_putsf("Hello world!");

while (1)
      {
      // Place your code here

      }
}

It shows me wrong character like a square or like this.

And another point is that I don't have enough pins for 8-bit parallel because other pins were reserved for something else.

In addition, I check Lcd pins and I found out that one of them(I think that was Rs had wrong voltage value )(I'm not sure because this code is for 3 weeks ago)

I ran alphabet Lcd with 4-bit parallel and it worked correctly but by St7920 that pin has wrong value.

Prsbsvrn.

Last Edited: Tue. Jun 1, 2021 - 05:18 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You are mixing the "Character LCD" text with the "Graphics LCD" text.   This is unwise.

 

I wrote this and ran in 4-bit on a Uno.

#include <glcd.h>
#include <delay.h>

#include <font5x7.h>

void main()
{
    GLCDINIT_t init;

    /* Set current font */
    init.font = font5x7;
    /* No need for reading data from external memory */
    init.readxmem = NULL;

    /* No need for reading data from external memory */
    init.writexmem = NULL;

    /* Initialize the LCD controller and graphics */
    glcd_init(&init);

    //glcd_setfont(font5x7); //already set in init.font
    glcd_clear();
    lcd_putsf("Hello World"); //this is using built-in 8x16 font
    /* Display literal char string located in FLASH */
    glcd_outtextxyf(0, 20, "ST7920 font5x7\nHello World");
    while (1) {
    }
}

If I omit the glcd_clear() call things do not go well.

 

I suggest that you do everything with glcd_xxx() functions.   I am surprised that the compiler accepted the lcd_putsf() statement.

 

Note that there are lots of glcd_xxx() functions.   e.g. several ways to set write position,  draw text,  ...

I printed "glcd.h" file on paper.

 

It is always wise to start with the examples e.g. ST7920/Full_Demo

Then you can add / remove the bits that you want

 

David.

Last Edited: Tue. Jun 1, 2021 - 07:43 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi again!

I read St7920 datasheet and it says that we can use lcd_function(…). Because of that I used lcd_functions. Anyway, I use your code but I didn’t get correct result.

It shows me Chinese character (I know that this lcd support Chinese character but I don’t know why it shows me that).

I connect lcd pins like this

GND, BLK à GND

VCC, PSB, RST, BLAà 5(v)

VO, VOUT, NCà not connected

RS, R/W, E, DB4, DB5, DB6, DB7 àlike before  

Is it ok?

I convert all pins from AVR (12(v) to 5 (v)). I measure LCD pins by voltmeter, everything was ok except Enable pin. Enable pin from micro was 6.8 v and after converting it was 2.8 volt. I think because of this pin I can’t see correct character.

Do you have any idea about that?

I ran this module with Arduino and it worked but by atxmega it has problem. Also, I ran alphabet Lcd by atxmega and it worked so I know that both Lcd and micro are ok but I don’t know the way to connect them.

prsbsvrn.

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

Please post a schematic.

 

I measure LCD pins by voltmeter,

You really need an oscilloscope or logic analyser to see what's going on

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

prsbsvrn wrote:

I read St7920 datasheet and it says that we can use lcd_function(…). Because of that I used lcd_functions. Anyway, I use your code but I didn’t get correct result.

Yes,  the ST7920 can operate as a regular 16x4 Character LCD  and still do pixel addressable graphics.   But I advise you to just use glcd_xxx() functions.

 

What happened with my code ?   I presume that you had added your clocks_init(), ports_init(), ... stuff.

 

First off.   You should always build and run the Library examples e.g. ST7920/Full_Demo.   I suggest that you start with the Demo wiring.   Then edit the GUI to suit different wiring.  Build and run the example to verify that your new wiring is correct.

 

I run my code on a Uno for convenience.   I could dig out an 128A1 but I don't have an 128A1U.

The only difference is that I don't need the separate "ports_init.c" etc that you have with Xmega.

I still configure the pins with the GUI.

 

From memory,  PORTJ is just a regular port on the 128A1U.   If you have any external electronics on PORTJ,  I suggest that you choose a different PORT.

Of course my advice about the examples would have shown any problems with the wiring.

My Xplained board has EBI memory on PORTJ.   I can't access PORTJ from headers.

 

If necessary I could run on an Xmega but it would probably be 128A4U.

 

I strongly disagree with Andy.   A scope or Logic Analyser would only confuse.   The best strategy is to run the example(s).   Then report any problem(s).    I don't mind debugging a proven example.

 

David.

Last Edited: Tue. Jun 1, 2021 - 11:06 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:
A scope or Logic Analyser would only confuse.  

But a voltmeter is also likely to give misleading results on dynamic digital signals.

 

and there's mention of voltage translation - which might be messing-up signals even if the software is working perfectly.

 

There's been a few threads recently where people were fixating on the software, but the problem turned out to be hardware.

 

I suggest that you start with the Demo wiring.

Absolutely - start with known-good hardware.

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

But a voltmeter is also likely to give misleading results on dynamic digital signals.

Yes,  a voltmeter would confuse even more.

 

Start with Demo wiring scheme.

Simple continuity checks with a DMM will show broken wires.   Documenting wire colours for each signal helps check for correct route.

 

These examples bit-bang signals at relatively slow speed.    It is unlikely that there will be capacitance, inductance, ... problems.   It is generally a question of connecting the right coloured wire to the correct pins.

 

David.

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

Actually I used oscilloscope but I don’t understand a lot. Also, it shows GND when it touched Enable pin.

I didn't used proteus because it doesn't have atxmega.

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

Thanks David! Actually I have been trying to use demo code. I think problem are wiring Lcd pins. I have been trying to fix it. I'll tell you the result inn future.

prsbsvrn.

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

in #13, prsbsvrn wrote:
I measure LCD pins by voltmeter, everything was ok except Enable pin. Enable pin from micro was 6.8 v and after converting it was 2.8 volt.

in #19, prsbsvrn wrote:
I used oscilloscope ... it shows GND when it touched Enable pin.

Something definitely not right there, then!

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

prsbsvrn wrote:

Thanks David! Actually I have been trying to use demo code. I think problem are wiring Lcd pins. I have been trying to fix it. I'll tell you the result inn future.

prsbsvrn.

My apologies.   The Colour TFT, SSD1306, ... example demos tend to be for an 128A1 dev board.

However the ST7920 (and several other GLCD) are written for an ATmega328P e.g. Uno

 

So it sounds as if you require a ST7920/Full_Demo project specifically for your 128A1U

 

I took the regular ST7920/Full_Demo/main.c and configured the GUI for ATxmega128A4U, 2MHz,  ST7920 wiring:

And edited the Notes:

Default UNO connections in main.c comments but config in GUI
Config Project Properties: F_CPU=2MHz, ST7920 connections

The LCD module to ATxmega128A4U connections are:
 7 DB0  - not connected
 8 DB1  - not connected
 9 DB2  - not connected
10 DB3  - not connected
11 DB4  - PORTC bit 4 (Digital 4)
12 DB5  - PORTC bit 5 (Digital 5)
13 DB6  - PORTC bit 6 (Digital 6)
14 DB7  - PORTC bit 7 (Digital 7)

 6 E    - PORTB bit 4 (Analog 2)
 5 R/W  - PORTB bit 5 (Analog 1)
 4 RS   - PORTB bit 6 (Analog 0)
17 /RST - PORTE bit 1 (Analog 5)

15 PSB  - +5V

 1 VSS  - GND
 2 VDD  - +5V
 3 VO   - -------------| Contrast control voltage
                       |
                       V  10k
                 |-----------|
18 Vout - -------|           |--|GND
                 |-----------|

The original demo code worked straight out of the box.

My Ebay module does not need any contrast wires.  i.e. pin 3, 18 are n.c.

pin 15 can be 3V or 5V but pin 2 must be 5V to get a usable contrast.

 

Obviously you will edit the Configure Project GUI to suit your chip, wiring etc

 

It runs fairly slowly at 2MHz (default Xmega power-up speed)

But you can add a clocks_init() function to use PLL or 32MHz.

 

Please report back.

 

David.

Last Edited: Tue. Jun 1, 2021 - 02:06 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you.
Yes I saw that in cavr file example graphic lcd and I work with this demo. 
Unfortunately until next week(next Tuesday) I don’t have access to my modules but I’ll give you feedback as soon as possible.

prsbsvrn

Last Edited: Tue. Jun 1, 2021 - 02:10 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

Hi!

In these weeks I tried to fix problem with st720. I used st7920 datasheet and code vision graphic Lcd sample for st7920. (In datasheet it said that st7920 can work on Atmega and Atxmega).

This is my code. (I connected pins like this according to pins)

#include <io.h>
#include <delay.h>
#include <glcd.h>
#include <font5x7.h>
void system_clocks_init(void){….}
void event_system_init(void) {….}
void ports_init(void) {….}
void vports_init(void) {….}
void main(void)
{
// Declare your local variables here
unsigned char n;
// Variable used to store Graphic Display
// controller initialization data
GLCDINIT_t glcd_init_data;
// Interrupt system initialization
// Optimize for speed
#pragma optsize-
// Make sure the interrupts are disabled
#asm("cli")
// Low level interrupt: Off
// Round-robin scheduling for low level interrupt: Off
// Medium level interrupt: Off
// High level interrupt: Off
// The interrupt vectors will be placed at the start of the Application FLASH section
n=(PMIC.CTRL & (~(PMIC_RREN_bm | PMIC_IVSEL_bm | PMIC_HILVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_LOLVLEN_bm)));
CCP=CCP_IOREG_gc;
PMIC.CTRL=n;
// Set the default priority for round-robin scheduling
PMIC.INTPRI=0x00;
// Restore optimization for size if needed
#pragma optsize_default

// System clocks initialization
system_clocks_init();

// Event system initialization
event_system_init();

// Ports initialization
ports_init();

// Virtual Ports initialization
vports_init();

// Graphic Display Controller initialization
// The ST7920 connections are specified in the
// Project|Configure|C Compiler|Libraries|Graphic Display menu:
// E - PORTJ Pin 2
// R /W - PORTJ Pin 1
// RS - PORTJ Pin 0
// /RST - PORTJ Pin 3
// DB4 - PORTJ Pin 4
// DB5 - PORTJ Pin 5
// DB6 - PORTJ Pin 6
// DB7 - PORTJ Pin 7

// Specify the current font for displaying text
glcd_init_data.font=font5x7;
// No function is used for reading
// image data from external memory
glcd_init_data.readxmem=NULL;
// No function is used for writing
// image data to external memory
glcd_init_data.writexmem=NULL;

glcd_init(&glcd_init_data);
// glcd_display(0);delay_ms(2000);glcd_display(1);
while (1)
      {
      // Place your code here
      //glcd_clear();
      lcd_gotoxy(0,0);
      //lcd_putsf("Hello world");
      //delay_ms(100);
      lcd_putchar('0');
      lcd_putchar('1');
      lcd_putchar('2');
//      lcd_putchar('3');
//      lcd_putchar('4');
//      lcd_putchar('5');
//      lcd_putchar('6');
//      lcd_putchar('7');
//      lcd_putchar('8');
//      lcd_putchar('9');
     // lcd_putsf("0123456789");
      }
}

So I want to tell you the result:

First of all, it didn't show any character until I touch DB7 pin from micro!!!( I checked this pin, it isn't float!)

Then, instead of "Hello world", it showed (ll" 3oDld, llll" 3oDld, Hel" 3oDld, llo 3oDld) in different times.

It showed '0' correctly and when I added '1' and '2', it showed correctly again but when I added '3', it showed me wrong character again.(wrong character like before).

Actually I have 2 problems (touch DB7 to show and wrong character). I couldn't solve the problem that I should touch Lcd.

Do you have any suggestion?

 

Last Edited: Tue. Jun 15, 2021 - 10:26 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


 

I'm afraid the forum seems to have garbled your post:

 

 

frown

 

Perhaps post some photos of what you're seeing on the screen?

 

If touching contacts affects behaviour, that suggests bad wiring - so please also post your schematic, and a photo (or photos) of your setup.

 

ADDENDUM

 

Also some oscilloscope traces?

 

EDIT

 

It depends which browser I use; the "garbled" text, above was on Chrome; Edge shows this:

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Tue. Jun 15, 2021 - 11:27 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

First off.   Your photo in #24 does not have any soldered connections.   You need soldered wires or soldered header pins + crimped Dupont wires.

 

It would be useful to see the pcb view of your ST7920.   The front view looks like my ST7920 module (which has part number 12864ZW printed on the pcb).

Seriously.   I ran the demo on a 128A4U.

If you confirm that the screen on your desk has soldered connections,  I will run your code on my 128A1 Xplained board using PORTA or PORTD or PORTF but not with PORTJ.

 

David.

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

awneil wrote:
If touching contacts affects behaviour, that suggests bad wiring

hence:

david.prentice wrote:
You need soldered wires or soldered header pins

+1

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


That photo was from internet.

this is my st7920.

they are my output:

and this is my wiring(output of micro is 3.3 and in board by mc14504b it converts to 12 volt (I can't change it because it was soldered) . so I  converted it from 12 volt to 5 volt by breadboard and because of that my wiring is so complicated).

and it's pcb: (I only can use these ports for LCD)

and this photo is for setting codevision:

Actually I tried all ways like changing pins or changing rs and e and also now I'm trying to run 8 bit parallel but I don't know what the problem is and I believe that the problem is in front of my eyes. I will post my code in next comment.

Thank you.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
/*******************************************************
This program was created by the
CodeWizardAVR V3.12 Advanced
Automatic Program Generator
© Copyright 1998-2014 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

Project : 
Version : 
Date    : 6/15/2021
Author  : 
Company : 
Comments: 


Chip type               : ATxmega128A1U
Program type            : Application
AVR Core Clock frequency: 2.000000 MHz
Memory model            : Small
Data Stack size         : 2048
*******************************************************/

// I/O Registers definitions
#include <io.h>

// Graphic Display functions
#include <glcd.h>

// Font used for displaying text
// on the graphic display
#include <font5x7.h>

// Declare your global variables here

// System Clocks initialization
void system_clocks_init(void)
{
unsigned char n,s;

// Optimize for speed
#pragma optsize- 
// Save interrupts enabled/disabled state
s=SREG;
// Disable interrupts
#asm("cli")

// Internal 2 MHz RC oscillator initialization
// Enable the internal 2 MHz RC oscillator
OSC.CTRL|=OSC_RC2MEN_bm;

// System Clock prescaler A division factor: 1
// System Clock prescalers B & C division factors: B:1, C:1
// ClkPer4: 2000.000 kHz
// ClkPer2: 2000.000 kHz
// ClkPer:  2000.000 kHz
// ClkCPU:  2000.000 kHz
n=(CLK.PSCTRL & (~(CLK_PSADIV_gm | CLK_PSBCDIV1_bm | CLK_PSBCDIV0_bm))) |
	CLK_PSADIV_1_gc | CLK_PSBCDIV_1_1_gc;
CCP=CCP_IOREG_gc;
CLK.PSCTRL=n;

// Disable the auto-calibration of the internal 2 MHz RC oscillator
DFLLRC2M.CTRL&= ~DFLL_ENABLE_bm;

// Wait for the internal 2 MHz RC oscillator to stabilize
while ((OSC.STATUS & OSC_RC2MRDY_bm)==0);

// Select the system clock source: 2 MHz Internal RC Osc.
n=(CLK.CTRL & (~CLK_SCLKSEL_gm)) | CLK_SCLKSEL_RC2M_gc;
CCP=CCP_IOREG_gc;
CLK.CTRL=n;

// Disable the unused oscillators: 32 MHz, 32 kHz, external clock/crystal oscillator, PLL
OSC.CTRL&= ~(OSC_RC32MEN_bm | OSC_RC32KEN_bm | OSC_XOSCEN_bm | OSC_PLLEN_bm);

// ClkPer output disabled
PORTCFG.CLKEVOUT&= ~(PORTCFG_CLKOUTSEL_gm | PORTCFG_CLKOUT_gm);
// Restore interrupts enabled/disabled state
SREG=s;
// Restore optimization for size if needed
#pragma optsize_default
}

// Event System initialization
void event_system_init(void)
{
// Event System Channel 0 source: None
EVSYS.CH0MUX=EVSYS_CHMUX_OFF_gc;
// Event System Channel 1 source: None
EVSYS.CH1MUX=EVSYS_CHMUX_OFF_gc;
// Event System Channel 2 source: None
EVSYS.CH2MUX=EVSYS_CHMUX_OFF_gc;
// Event System Channel 3 source: None
EVSYS.CH3MUX=EVSYS_CHMUX_OFF_gc;
// Event System Channel 4 source: None
EVSYS.CH4MUX=EVSYS_CHMUX_OFF_gc;
// Event System Channel 5 source: None
EVSYS.CH5MUX=EVSYS_CHMUX_OFF_gc;
// Event System Channel 6 source: None
EVSYS.CH6MUX=EVSYS_CHMUX_OFF_gc;
// Event System Channel 7 source: None
EVSYS.CH7MUX=EVSYS_CHMUX_OFF_gc;

// Event System Channel 0 Digital Filter Coefficient: 1 Sample
// Quadrature Decoder: Off
EVSYS.CH0CTRL=(EVSYS.CH0CTRL & (~(EVSYS_QDIRM_gm | EVSYS_QDIEN_bm | EVSYS_QDEN_bm | EVSYS_DIGFILT_gm))) |
	EVSYS_DIGFILT_1SAMPLE_gc;
// Event System Channel 1 Digital Filter Coefficient: 1 Sample
EVSYS.CH1CTRL=EVSYS_DIGFILT_1SAMPLE_gc;
// Event System Channel 2 Digital Filter Coefficient: 1 Sample
// Quadrature Decoder: Off
EVSYS.CH2CTRL=(EVSYS.CH2CTRL & (~(EVSYS_QDIRM_gm | EVSYS_QDIEN_bm | EVSYS_QDEN_bm | EVSYS_DIGFILT_gm))) |
	EVSYS_DIGFILT_1SAMPLE_gc;
// Event System Channel 3 Digital Filter Coefficient: 1 Sample
EVSYS.CH3CTRL=EVSYS_DIGFILT_1SAMPLE_gc;
// Event System Channel 4 Digital Filter Coefficient: 1 Sample
// Quadrature Decoder: Off
EVSYS.CH4CTRL=(EVSYS.CH4CTRL & (~(EVSYS_QDIRM_gm | EVSYS_QDIEN_bm | EVSYS_QDEN_bm | EVSYS_DIGFILT_gm))) |
	EVSYS_DIGFILT_1SAMPLE_gc;
// Event System Channel 5 Digital Filter Coefficient: 1 Sample
EVSYS.CH5CTRL=EVSYS_DIGFILT_1SAMPLE_gc;
// Event System Channel 6 Digital Filter Coefficient: 1 Sample
EVSYS.CH6CTRL=EVSYS_DIGFILT_1SAMPLE_gc;
// Event System Channel 7 Digital Filter Coefficient: 1 Sample
EVSYS.CH7CTRL=EVSYS_DIGFILT_1SAMPLE_gc;

// Event System Channel output: Disabled
PORTCFG.CLKEVOUT&= ~PORTCFG_EVOUT_gm;
PORTCFG.EVOUTSEL&= ~PORTCFG_EVOUTSEL_gm;
}

// Ports initialization
void ports_init(void)
{
// PORTA initialization
// OUT register
PORTA.OUT=0x00;
// Pin0: Input
// Pin1: Input
// Pin2: Input
// Pin3: Input
// Pin4: Input
// Pin5: Input
// Pin6: Input
// Pin7: Input
PORTA.DIR=0x00;
// Pin0 Output/Pull configuration: Totempole/No
// Pin0 Input/Sense configuration: Sense both edges
// Pin0 Inverted: Off
// Pin0 Slew Rate Limitation: Off
PORTA.PIN0CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin1 Output/Pull configuration: Totempole/No
// Pin1 Input/Sense configuration: Sense both edges
// Pin1 Inverted: Off
// Pin1 Slew Rate Limitation: Off
PORTA.PIN1CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin2 Output/Pull configuration: Totempole/No
// Pin2 Input/Sense configuration: Sense both edges
// Pin2 Inverted: Off
// Pin2 Slew Rate Limitation: Off
PORTA.PIN2CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin3 Output/Pull configuration: Totempole/No
// Pin3 Input/Sense configuration: Sense both edges
// Pin3 Inverted: Off
// Pin3 Slew Rate Limitation: Off
PORTA.PIN3CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin4 Output/Pull configuration: Totempole/No
// Pin4 Input/Sense configuration: Sense both edges
// Pin4 Inverted: Off
// Pin4 Slew Rate Limitation: Off
PORTA.PIN4CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin5 Output/Pull configuration: Totempole/No
// Pin5 Input/Sense configuration: Sense both edges
// Pin5 Inverted: Off
// Pin5 Slew Rate Limitation: Off
PORTA.PIN5CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin6 Output/Pull configuration: Totempole/No
// Pin6 Input/Sense configuration: Sense both edges
// Pin6 Inverted: Off
// Pin6 Slew Rate Limitation: Off
PORTA.PIN6CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin7 Output/Pull configuration: Totempole/No
// Pin7 Input/Sense configuration: Sense both edges
// Pin7 Inverted: Off
// Pin7 Slew Rate Limitation: Off
PORTA.PIN7CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Interrupt 0 level: Disabled
// Interrupt 1 level: Disabled
PORTA.INTCTRL=(PORTA.INTCTRL & (~(PORT_INT1LVL_gm | PORT_INT0LVL_gm))) |
	PORT_INT1LVL_OFF_gc | PORT_INT0LVL_OFF_gc;
// Pin0 Pin Change interrupt 0: Off
// Pin1 Pin Change interrupt 0: Off
// Pin2 Pin Change interrupt 0: Off
// Pin3 Pin Change interrupt 0: Off
// Pin4 Pin Change interrupt 0: Off
// Pin5 Pin Change interrupt 0: Off
// Pin6 Pin Change interrupt 0: Off
// Pin7 Pin Change interrupt 0: Off
PORTA.INT0MASK=0x00;
// Pin0 Pin Change interrupt 1: Off
// Pin1 Pin Change interrupt 1: Off
// Pin2 Pin Change interrupt 1: Off
// Pin3 Pin Change interrupt 1: Off
// Pin4 Pin Change interrupt 1: Off
// Pin5 Pin Change interrupt 1: Off
// Pin6 Pin Change interrupt 1: Off
// Pin7 Pin Change interrupt 1: Off
PORTA.INT1MASK=0x00;

// PORTB initialization
// OUT register
PORTB.OUT=0x00;
// Pin0: Input
// Pin1: Input
// Pin2: Input
// Pin3: Input
// Pin4: Input
// Pin5: Input
// Pin6: Input
// Pin7: Input
PORTB.DIR=0x00;
// Pin0 Output/Pull configuration: Totempole/No
// Pin0 Input/Sense configuration: Sense both edges
// Pin0 Inverted: Off
// Pin0 Slew Rate Limitation: Off
PORTB.PIN0CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin1 Output/Pull configuration: Totempole/No
// Pin1 Input/Sense configuration: Sense both edges
// Pin1 Inverted: Off
// Pin1 Slew Rate Limitation: Off
PORTB.PIN1CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin2 Output/Pull configuration: Totempole/No
// Pin2 Input/Sense configuration: Sense both edges
// Pin2 Inverted: Off
// Pin2 Slew Rate Limitation: Off
PORTB.PIN2CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin3 Output/Pull configuration: Totempole/No
// Pin3 Input/Sense configuration: Sense both edges
// Pin3 Inverted: Off
// Pin3 Slew Rate Limitation: Off
PORTB.PIN3CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin4 Output/Pull configuration: Totempole/No
// Pin4 Input/Sense configuration: Sense both edges
// Pin4 Inverted: Off
// Pin4 Slew Rate Limitation: Off
PORTB.PIN4CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin5 Output/Pull configuration: Totempole/No
// Pin5 Input/Sense configuration: Sense both edges
// Pin5 Inverted: Off
// Pin5 Slew Rate Limitation: Off
PORTB.PIN5CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin6 Output/Pull configuration: Totempole/No
// Pin6 Input/Sense configuration: Sense both edges
// Pin6 Inverted: Off
// Pin6 Slew Rate Limitation: Off
PORTB.PIN6CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin7 Output/Pull configuration: Totempole/No
// Pin7 Input/Sense configuration: Sense both edges
// Pin7 Inverted: Off
// Pin7 Slew Rate Limitation: Off
PORTB.PIN7CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Interrupt 0 level: Disabled
// Interrupt 1 level: Disabled
PORTB.INTCTRL=(PORTB.INTCTRL & (~(PORT_INT1LVL_gm | PORT_INT0LVL_gm))) |
	PORT_INT1LVL_OFF_gc | PORT_INT0LVL_OFF_gc;
// Pin0 Pin Change interrupt 0: Off
// Pin1 Pin Change interrupt 0: Off
// Pin2 Pin Change interrupt 0: Off
// Pin3 Pin Change interrupt 0: Off
// Pin4 Pin Change interrupt 0: Off
// Pin5 Pin Change interrupt 0: Off
// Pin6 Pin Change interrupt 0: Off
// Pin7 Pin Change interrupt 0: Off
PORTB.INT0MASK=0x00;
// Pin0 Pin Change interrupt 1: Off
// Pin1 Pin Change interrupt 1: Off
// Pin2 Pin Change interrupt 1: Off
// Pin3 Pin Change interrupt 1: Off
// Pin4 Pin Change interrupt 1: Off
// Pin5 Pin Change interrupt 1: Off
// Pin6 Pin Change interrupt 1: Off
// Pin7 Pin Change interrupt 1: Off
PORTB.INT1MASK=0x00;

// PORTC initialization
// OUT register
PORTC.OUT=0x00;
// Pin0: Input
// Pin1: Input
// Pin2: Input
// Pin3: Input
// Pin4: Input
// Pin5: Input
// Pin6: Input
// Pin7: Input
PORTC.DIR=0x00;
// Pin0 Output/Pull configuration: Totempole/No
// Pin0 Input/Sense configuration: Sense both edges
// Pin0 Inverted: Off
// Pin0 Slew Rate Limitation: Off
PORTC.PIN0CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin1 Output/Pull configuration: Totempole/No
// Pin1 Input/Sense configuration: Sense both edges
// Pin1 Inverted: Off
// Pin1 Slew Rate Limitation: Off
PORTC.PIN1CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin2 Output/Pull configuration: Totempole/No
// Pin2 Input/Sense configuration: Sense both edges
// Pin2 Inverted: Off
// Pin2 Slew Rate Limitation: Off
PORTC.PIN2CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin3 Output/Pull configuration: Totempole/No
// Pin3 Input/Sense configuration: Sense both edges
// Pin3 Inverted: Off
// Pin3 Slew Rate Limitation: Off
PORTC.PIN3CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin4 Output/Pull configuration: Totempole/No
// Pin4 Input/Sense configuration: Sense both edges
// Pin4 Inverted: Off
// Pin4 Slew Rate Limitation: Off
PORTC.PIN4CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin5 Output/Pull configuration: Totempole/No
// Pin5 Input/Sense configuration: Sense both edges
// Pin5 Inverted: Off
// Pin5 Slew Rate Limitation: Off
PORTC.PIN5CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin6 Output/Pull configuration: Totempole/No
// Pin6 Input/Sense configuration: Sense both edges
// Pin6 Inverted: Off
// Pin6 Slew Rate Limitation: Off
PORTC.PIN6CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin7 Output/Pull configuration: Totempole/No
// Pin7 Input/Sense configuration: Sense both edges
// Pin7 Inverted: Off
// Pin7 Slew Rate Limitation: Off
PORTC.PIN7CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// PORTC Peripheral Output Remapping
// OC0A Output: Pin 0
// OC0B Output: Pin 1
// OC0C Output: Pin 2
// OC0D Output: Pin 3
// USART0 XCK: Pin 1
// USART0 RXD: Pin 2
// USART0 TXD: Pin 3
// SPI MOSI: Pin 5
// SPI SCK: Pin 7
PORTC.REMAP=(0<<PORT_SPI_bp) | (0<<PORT_USART0_bp) | (0<<PORT_TC0D_bp) | (0<<PORT_TC0C_bp) | (0<<PORT_TC0B_bp) | (0<<PORT_TC0A_bp);
// Interrupt 0 level: Disabled
// Interrupt 1 level: Disabled
PORTC.INTCTRL=(PORTC.INTCTRL & (~(PORT_INT1LVL_gm | PORT_INT0LVL_gm))) |
	PORT_INT1LVL_OFF_gc | PORT_INT0LVL_OFF_gc;
// Pin0 Pin Change interrupt 0: Off
// Pin1 Pin Change interrupt 0: Off
// Pin2 Pin Change interrupt 0: Off
// Pin3 Pin Change interrupt 0: Off
// Pin4 Pin Change interrupt 0: Off
// Pin5 Pin Change interrupt 0: Off
// Pin6 Pin Change interrupt 0: Off
// Pin7 Pin Change interrupt 0: Off
PORTC.INT0MASK=0x00;
// Pin0 Pin Change interrupt 1: Off
// Pin1 Pin Change interrupt 1: Off
// Pin2 Pin Change interrupt 1: Off
// Pin3 Pin Change interrupt 1: Off
// Pin4 Pin Change interrupt 1: Off
// Pin5 Pin Change interrupt 1: Off
// Pin6 Pin Change interrupt 1: Off
// Pin7 Pin Change interrupt 1: Off
PORTC.INT1MASK=0x00;

// PORTD initialization
// OUT register
PORTD.OUT=0x00;
// Pin0: Input
// Pin1: Input
// Pin2: Input
// Pin3: Input
// Pin4: Input
// Pin5: Input
// Pin6: Input
// Pin7: Input
PORTD.DIR=0x00;
// Pin0 Output/Pull configuration: Totempole/No
// Pin0 Input/Sense configuration: Sense both edges
// Pin0 Inverted: Off
// Pin0 Slew Rate Limitation: Off
PORTD.PIN0CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin1 Output/Pull configuration: Totempole/No
// Pin1 Input/Sense configuration: Sense both edges
// Pin1 Inverted: Off
// Pin1 Slew Rate Limitation: Off
PORTD.PIN1CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin2 Output/Pull configuration: Totempole/No
// Pin2 Input/Sense configuration: Sense both edges
// Pin2 Inverted: Off
// Pin2 Slew Rate Limitation: Off
PORTD.PIN2CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin3 Output/Pull configuration: Totempole/No
// Pin3 Input/Sense configuration: Sense both edges
// Pin3 Inverted: Off
// Pin3 Slew Rate Limitation: Off
PORTD.PIN3CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin4 Output/Pull configuration: Totempole/No
// Pin4 Input/Sense configuration: Sense both edges
// Pin4 Inverted: Off
// Pin4 Slew Rate Limitation: Off
PORTD.PIN4CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin5 Output/Pull configuration: Totempole/No
// Pin5 Input/Sense configuration: Sense both edges
// Pin5 Inverted: Off
// Pin5 Slew Rate Limitation: Off
PORTD.PIN5CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin6 Output/Pull configuration: Totempole/No
// Pin6 Input/Sense configuration: Sense both edges
// Pin6 Inverted: Off
// Pin6 Slew Rate Limitation: Off
PORTD.PIN6CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin7 Output/Pull configuration: Totempole/No
// Pin7 Input/Sense configuration: Sense both edges
// Pin7 Inverted: Off
// Pin7 Slew Rate Limitation: Off
PORTD.PIN7CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Interrupt 0 level: Disabled
// Interrupt 1 level: Disabled
PORTD.INTCTRL=(PORTD.INTCTRL & (~(PORT_INT1LVL_gm | PORT_INT0LVL_gm))) |
	PORT_INT1LVL_OFF_gc | PORT_INT0LVL_OFF_gc;
// Pin0 Pin Change interrupt 0: Off
// Pin1 Pin Change interrupt 0: Off
// Pin2 Pin Change interrupt 0: Off
// Pin3 Pin Change interrupt 0: Off
// Pin4 Pin Change interrupt 0: Off
// Pin5 Pin Change interrupt 0: Off
// Pin6 Pin Change interrupt 0: Off
// Pin7 Pin Change interrupt 0: Off
PORTD.INT0MASK=0x00;
// Pin0 Pin Change interrupt 1: Off
// Pin1 Pin Change interrupt 1: Off
// Pin2 Pin Change interrupt 1: Off
// Pin3 Pin Change interrupt 1: Off
// Pin4 Pin Change interrupt 1: Off
// Pin5 Pin Change interrupt 1: Off
// Pin6 Pin Change interrupt 1: Off
// Pin7 Pin Change interrupt 1: Off
PORTD.INT1MASK=0x00;

// PORTE initialization
// OUT register
PORTE.OUT=0x00;
// Pin0: Input
// Pin1: Input
// Pin2: Input
// Pin3: Input
// Pin4: Input
// Pin5: Input
// Pin6: Input
// Pin7: Input
PORTE.DIR=0x00;
// Pin0 Output/Pull configuration: Totempole/No
// Pin0 Input/Sense configuration: Sense both edges
// Pin0 Inverted: Off
// Pin0 Slew Rate Limitation: Off
PORTE.PIN0CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin1 Output/Pull configuration: Totempole/No
// Pin1 Input/Sense configuration: Sense both edges
// Pin1 Inverted: Off
// Pin1 Slew Rate Limitation: Off
PORTE.PIN1CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin2 Output/Pull configuration: Totempole/No
// Pin2 Input/Sense configuration: Sense both edges
// Pin2 Inverted: Off
// Pin2 Slew Rate Limitation: Off
PORTE.PIN2CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin3 Output/Pull configuration: Totempole/No
// Pin3 Input/Sense configuration: Sense both edges
// Pin3 Inverted: Off
// Pin3 Slew Rate Limitation: Off
PORTE.PIN3CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin4 Output/Pull configuration: Totempole/No
// Pin4 Input/Sense configuration: Sense both edges
// Pin4 Inverted: Off
// Pin4 Slew Rate Limitation: Off
PORTE.PIN4CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin5 Output/Pull configuration: Totempole/No
// Pin5 Input/Sense configuration: Sense both edges
// Pin5 Inverted: Off
// Pin5 Slew Rate Limitation: Off
PORTE.PIN5CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin6 Output/Pull configuration: Totempole/No
// Pin6 Input/Sense configuration: Sense both edges
// Pin6 Inverted: Off
// Pin6 Slew Rate Limitation: Off
PORTE.PIN6CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin7 Output/Pull configuration: Totempole/No
// Pin7 Input/Sense configuration: Sense both edges
// Pin7 Inverted: Off
// Pin7 Slew Rate Limitation: Off
PORTE.PIN7CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Interrupt 0 level: Disabled
// Interrupt 1 level: Disabled
PORTE.INTCTRL=(PORTE.INTCTRL & (~(PORT_INT1LVL_gm | PORT_INT0LVL_gm))) |
	PORT_INT1LVL_OFF_gc | PORT_INT0LVL_OFF_gc;
// Pin0 Pin Change interrupt 0: Off
// Pin1 Pin Change interrupt 0: Off
// Pin2 Pin Change interrupt 0: Off
// Pin3 Pin Change interrupt 0: Off
// Pin4 Pin Change interrupt 0: Off
// Pin5 Pin Change interrupt 0: Off
// Pin6 Pin Change interrupt 0: Off
// Pin7 Pin Change interrupt 0: Off
PORTE.INT0MASK=0x00;
// Pin0 Pin Change interrupt 1: Off
// Pin1 Pin Change interrupt 1: Off
// Pin2 Pin Change interrupt 1: Off
// Pin3 Pin Change interrupt 1: Off
// Pin4 Pin Change interrupt 1: Off
// Pin5 Pin Change interrupt 1: Off
// Pin6 Pin Change interrupt 1: Off
// Pin7 Pin Change interrupt 1: Off
PORTE.INT1MASK=0x00;

// PORTF initialization
// OUT register
PORTF.OUT=0x00;
// Pin0: Input
// Pin1: Input
// Pin2: Input
// Pin3: Input
// Pin4: Input
// Pin5: Input
// Pin6: Input
// Pin7: Input
PORTF.DIR=0x00;
// Pin0 Output/Pull configuration: Totempole/No
// Pin0 Input/Sense configuration: Sense both edges
// Pin0 Inverted: Off
// Pin0 Slew Rate Limitation: Off
PORTF.PIN0CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin1 Output/Pull configuration: Totempole/No
// Pin1 Input/Sense configuration: Sense both edges
// Pin1 Inverted: Off
// Pin1 Slew Rate Limitation: Off
PORTF.PIN1CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin2 Output/Pull configuration: Totempole/No
// Pin2 Input/Sense configuration: Sense both edges
// Pin2 Inverted: Off
// Pin2 Slew Rate Limitation: Off
PORTF.PIN2CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin3 Output/Pull configuration: Totempole/No
// Pin3 Input/Sense configuration: Sense both edges
// Pin3 Inverted: Off
// Pin3 Slew Rate Limitation: Off
PORTF.PIN3CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin4 Output/Pull configuration: Totempole/No
// Pin4 Input/Sense configuration: Sense both edges
// Pin4 Inverted: Off
// Pin4 Slew Rate Limitation: Off
PORTF.PIN4CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin5 Output/Pull configuration: Totempole/No
// Pin5 Input/Sense configuration: Sense both edges
// Pin5 Inverted: Off
// Pin5 Slew Rate Limitation: Off
PORTF.PIN5CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin6 Output/Pull configuration: Totempole/No
// Pin6 Input/Sense configuration: Sense both edges
// Pin6 Inverted: Off
// Pin6 Slew Rate Limitation: Off
PORTF.PIN6CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin7 Output/Pull configuration: Totempole/No
// Pin7 Input/Sense configuration: Sense both edges
// Pin7 Inverted: Off
// Pin7 Slew Rate Limitation: Off
PORTF.PIN7CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Interrupt 0 level: Disabled
// Interrupt 1 level: Disabled
PORTF.INTCTRL=(PORTF.INTCTRL & (~(PORT_INT1LVL_gm | PORT_INT0LVL_gm))) |
	PORT_INT1LVL_OFF_gc | PORT_INT0LVL_OFF_gc;
// Pin0 Pin Change interrupt 0: Off
// Pin1 Pin Change interrupt 0: Off
// Pin2 Pin Change interrupt 0: Off
// Pin3 Pin Change interrupt 0: Off
// Pin4 Pin Change interrupt 0: Off
// Pin5 Pin Change interrupt 0: Off
// Pin6 Pin Change interrupt 0: Off
// Pin7 Pin Change interrupt 0: Off
PORTF.INT0MASK=0x00;
// Pin0 Pin Change interrupt 1: Off
// Pin1 Pin Change interrupt 1: Off
// Pin2 Pin Change interrupt 1: Off
// Pin3 Pin Change interrupt 1: Off
// Pin4 Pin Change interrupt 1: Off
// Pin5 Pin Change interrupt 1: Off
// Pin6 Pin Change interrupt 1: Off
// Pin7 Pin Change interrupt 1: Off
PORTF.INT1MASK=0x00;

// PORTH initialization
// OUT register
PORTH.OUT=0x00;
// Pin0: Input
// Pin1: Input
// Pin2: Input
// Pin3: Input
// Pin4: Input
// Pin5: Input
// Pin6: Input
// Pin7: Input
PORTH.DIR=0x00;
// Pin0 Output/Pull configuration: Totempole/No
// Pin0 Input/Sense configuration: Sense both edges
// Pin0 Inverted: Off
// Pin0 Slew Rate Limitation: Off
PORTH.PIN0CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin1 Output/Pull configuration: Totempole/No
// Pin1 Input/Sense configuration: Sense both edges
// Pin1 Inverted: Off
// Pin1 Slew Rate Limitation: Off
PORTH.PIN1CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin2 Output/Pull configuration: Totempole/No
// Pin2 Input/Sense configuration: Sense both edges
// Pin2 Inverted: Off
// Pin2 Slew Rate Limitation: Off
PORTH.PIN2CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin3 Output/Pull configuration: Totempole/No
// Pin3 Input/Sense configuration: Sense both edges
// Pin3 Inverted: Off
// Pin3 Slew Rate Limitation: Off
PORTH.PIN3CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin4 Output/Pull configuration: Totempole/No
// Pin4 Input/Sense configuration: Sense both edges
// Pin4 Inverted: Off
// Pin4 Slew Rate Limitation: Off
PORTH.PIN4CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin5 Output/Pull configuration: Totempole/No
// Pin5 Input/Sense configuration: Sense both edges
// Pin5 Inverted: Off
// Pin5 Slew Rate Limitation: Off
PORTH.PIN5CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin6 Output/Pull configuration: Totempole/No
// Pin6 Input/Sense configuration: Sense both edges
// Pin6 Inverted: Off
// Pin6 Slew Rate Limitation: Off
PORTH.PIN6CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin7 Output/Pull configuration: Totempole/No
// Pin7 Input/Sense configuration: Sense both edges
// Pin7 Inverted: Off
// Pin7 Slew Rate Limitation: Off
PORTH.PIN7CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Interrupt 0 level: Disabled
// Interrupt 1 level: Disabled
PORTH.INTCTRL=(PORTH.INTCTRL & (~(PORT_INT1LVL_gm | PORT_INT0LVL_gm))) |
	PORT_INT1LVL_OFF_gc | PORT_INT0LVL_OFF_gc;
// Pin0 Pin Change interrupt 0: Off
// Pin1 Pin Change interrupt 0: Off
// Pin2 Pin Change interrupt 0: Off
// Pin3 Pin Change interrupt 0: Off
// Pin4 Pin Change interrupt 0: Off
// Pin5 Pin Change interrupt 0: Off
// Pin6 Pin Change interrupt 0: Off
// Pin7 Pin Change interrupt 0: Off
PORTH.INT0MASK=0x00;
// Pin0 Pin Change interrupt 1: Off
// Pin1 Pin Change interrupt 1: Off
// Pin2 Pin Change interrupt 1: Off
// Pin3 Pin Change interrupt 1: Off
// Pin4 Pin Change interrupt 1: Off
// Pin5 Pin Change interrupt 1: Off
// Pin6 Pin Change interrupt 1: Off
// Pin7 Pin Change interrupt 1: Off
PORTH.INT1MASK=0x00;

// PORTJ initialization
// OUT register
PORTJ.OUT=0x00;
// Pin0: Input
// Pin1: Input
// Pin2: Input
// Pin3: Input
// Pin4: Input
// Pin5: Input
// Pin6: Input
// Pin7: Input
PORTJ.DIR=0x00;
// Pin0 Output/Pull configuration: Totempole/No
// Pin0 Input/Sense configuration: Sense both edges
// Pin0 Inverted: Off
// Pin0 Slew Rate Limitation: Off
PORTJ.PIN0CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin1 Output/Pull configuration: Totempole/No
// Pin1 Input/Sense configuration: Sense both edges
// Pin1 Inverted: Off
// Pin1 Slew Rate Limitation: Off
PORTJ.PIN1CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin2 Output/Pull configuration: Totempole/No
// Pin2 Input/Sense configuration: Sense both edges
// Pin2 Inverted: Off
// Pin2 Slew Rate Limitation: Off
PORTJ.PIN2CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin3 Output/Pull configuration: Totempole/No
// Pin3 Input/Sense configuration: Sense both edges
// Pin3 Inverted: Off
// Pin3 Slew Rate Limitation: Off
PORTJ.PIN3CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin4 Output/Pull configuration: Totempole/No
// Pin4 Input/Sense configuration: Sense both edges
// Pin4 Inverted: Off
// Pin4 Slew Rate Limitation: Off
PORTJ.PIN4CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin5 Output/Pull configuration: Totempole/No
// Pin5 Input/Sense configuration: Sense both edges
// Pin5 Inverted: Off
// Pin5 Slew Rate Limitation: Off
PORTJ.PIN5CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin6 Output/Pull configuration: Totempole/No
// Pin6 Input/Sense configuration: Sense both edges
// Pin6 Inverted: Off
// Pin6 Slew Rate Limitation: Off
PORTJ.PIN6CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin7 Output/Pull configuration: Totempole/No
// Pin7 Input/Sense configuration: Sense both edges
// Pin7 Inverted: Off
// Pin7 Slew Rate Limitation: Off
PORTJ.PIN7CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Interrupt 0 level: Disabled
// Interrupt 1 level: Disabled
PORTJ.INTCTRL=(PORTJ.INTCTRL & (~(PORT_INT1LVL_gm | PORT_INT0LVL_gm))) |
	PORT_INT1LVL_OFF_gc | PORT_INT0LVL_OFF_gc;
// Pin0 Pin Change interrupt 0: Off
// Pin1 Pin Change interrupt 0: Off
// Pin2 Pin Change interrupt 0: Off
// Pin3 Pin Change interrupt 0: Off
// Pin4 Pin Change interrupt 0: Off
// Pin5 Pin Change interrupt 0: Off
// Pin6 Pin Change interrupt 0: Off
// Pin7 Pin Change interrupt 0: Off
PORTJ.INT0MASK=0x00;
// Pin0 Pin Change interrupt 1: Off
// Pin1 Pin Change interrupt 1: Off
// Pin2 Pin Change interrupt 1: Off
// Pin3 Pin Change interrupt 1: Off
// Pin4 Pin Change interrupt 1: Off
// Pin5 Pin Change interrupt 1: Off
// Pin6 Pin Change interrupt 1: Off
// Pin7 Pin Change interrupt 1: Off
PORTJ.INT1MASK=0x00;

// PORTK initialization
// OUT register
PORTK.OUT=0x00;
// Pin0: Input
// Pin1: Input
// Pin2: Input
// Pin3: Input
// Pin4: Input
// Pin5: Input
// Pin6: Input
// Pin7: Input
PORTK.DIR=0x00;
// Pin0 Output/Pull configuration: Totempole/No
// Pin0 Input/Sense configuration: Sense both edges
// Pin0 Inverted: Off
// Pin0 Slew Rate Limitation: Off
PORTK.PIN0CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin1 Output/Pull configuration: Totempole/No
// Pin1 Input/Sense configuration: Sense both edges
// Pin1 Inverted: Off
// Pin1 Slew Rate Limitation: Off
PORTK.PIN1CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin2 Output/Pull configuration: Totempole/No
// Pin2 Input/Sense configuration: Sense both edges
// Pin2 Inverted: Off
// Pin2 Slew Rate Limitation: Off
PORTK.PIN2CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin3 Output/Pull configuration: Totempole/No
// Pin3 Input/Sense configuration: Sense both edges
// Pin3 Inverted: Off
// Pin3 Slew Rate Limitation: Off
PORTK.PIN3CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin4 Output/Pull configuration: Totempole/No
// Pin4 Input/Sense configuration: Sense both edges
// Pin4 Inverted: Off
// Pin4 Slew Rate Limitation: Off
PORTK.PIN4CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin5 Output/Pull configuration: Totempole/No
// Pin5 Input/Sense configuration: Sense both edges
// Pin5 Inverted: Off
// Pin5 Slew Rate Limitation: Off
PORTK.PIN5CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin6 Output/Pull configuration: Totempole/No
// Pin6 Input/Sense configuration: Sense both edges
// Pin6 Inverted: Off
// Pin6 Slew Rate Limitation: Off
PORTK.PIN6CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin7 Output/Pull configuration: Totempole/No
// Pin7 Input/Sense configuration: Sense both edges
// Pin7 Inverted: Off
// Pin7 Slew Rate Limitation: Off
PORTK.PIN7CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Interrupt 0 level: Disabled
// Interrupt 1 level: Disabled
PORTK.INTCTRL=(PORTK.INTCTRL & (~(PORT_INT1LVL_gm | PORT_INT0LVL_gm))) |
	PORT_INT1LVL_OFF_gc | PORT_INT0LVL_OFF_gc;
// Pin0 Pin Change interrupt 0: Off
// Pin1 Pin Change interrupt 0: Off
// Pin2 Pin Change interrupt 0: Off
// Pin3 Pin Change interrupt 0: Off
// Pin4 Pin Change interrupt 0: Off
// Pin5 Pin Change interrupt 0: Off
// Pin6 Pin Change interrupt 0: Off
// Pin7 Pin Change interrupt 0: Off
PORTK.INT0MASK=0x00;
// Pin0 Pin Change interrupt 1: Off
// Pin1 Pin Change interrupt 1: Off
// Pin2 Pin Change interrupt 1: Off
// Pin3 Pin Change interrupt 1: Off
// Pin4 Pin Change interrupt 1: Off
// Pin5 Pin Change interrupt 1: Off
// Pin6 Pin Change interrupt 1: Off
// Pin7 Pin Change interrupt 1: Off
PORTK.INT1MASK=0x00;

// PORTQ initialization
// OUT register
PORTQ.OUT=0x00;
// Pin0: Input
// Pin1: Input
// Pin2: Input
// Pin3: Input
PORTQ.DIR=0x00;
// Pin0 Output/Pull configuration: Totempole/No
// Pin0 Input/Sense configuration: Sense both edges
// Pin0 Inverted: Off
// Pin0 Slew Rate Limitation: Off
PORTQ.PIN0CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin1 Output/Pull configuration: Totempole/No
// Pin1 Input/Sense configuration: Sense both edges
// Pin1 Inverted: Off
// Pin1 Slew Rate Limitation: Off
PORTQ.PIN1CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin2 Output/Pull configuration: Totempole/No
// Pin2 Input/Sense configuration: Sense both edges
// Pin2 Inverted: Off
// Pin2 Slew Rate Limitation: Off
PORTQ.PIN2CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin3 Output/Pull configuration: Totempole/No
// Pin3 Input/Sense configuration: Sense both edges
// Pin3 Inverted: Off
// Pin3 Slew Rate Limitation: Off
PORTQ.PIN3CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Interrupt 0 level: Disabled
// Interrupt 1 level: Disabled
PORTQ.INTCTRL=(PORTQ.INTCTRL & (~(PORT_INT1LVL_gm | PORT_INT0LVL_gm))) |
	PORT_INT1LVL_OFF_gc | PORT_INT0LVL_OFF_gc;
// Pin0 Pin Change interrupt 0: Off
// Pin1 Pin Change interrupt 0: Off
// Pin2 Pin Change interrupt 0: Off
// Pin3 Pin Change interrupt 0: Off
PORTQ.INT0MASK=0x00;
// Pin0 Pin Change interrupt 1: Off
// Pin1 Pin Change interrupt 1: Off
// Pin2 Pin Change interrupt 1: Off
// Pin3 Pin Change interrupt 1: Off
PORTQ.INT1MASK=0x00;

// PORTR initialization
// OUT register
PORTR.OUT=0x00;
// Pin0: Input
// Pin1: Input
PORTR.DIR=0x00;
// Pin0 Output/Pull configuration: Totempole/No
// Pin0 Input/Sense configuration: Sense both edges
// Pin0 Inverted: Off
// Pin0 Slew Rate Limitation: Off
PORTR.PIN0CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Pin1 Output/Pull configuration: Totempole/No
// Pin1 Input/Sense configuration: Sense both edges
// Pin1 Inverted: Off
// Pin1 Slew Rate Limitation: Off
PORTR.PIN1CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc;
// Interrupt 0 level: Disabled
// Interrupt 1 level: Disabled
PORTR.INTCTRL=(PORTR.INTCTRL & (~(PORT_INT1LVL_gm | PORT_INT0LVL_gm))) |
	PORT_INT1LVL_OFF_gc | PORT_INT0LVL_OFF_gc;
// Pin0 Pin Change interrupt 0: Off
// Pin1 Pin Change interrupt 0: Off
PORTR.INT0MASK=0x00;
// Pin0 Pin Change interrupt 1: Off
// Pin1 Pin Change interrupt 1: Off
PORTR.INT1MASK=0x00;
}

// Virtual Ports initialization
void vports_init(void)
{
// PORTA mapped to VPORT0
// PORTB mapped to VPORT1
PORTCFG.VPCTRLA=PORTCFG_VP13MAP_PORTB_gc | PORTCFG_VP02MAP_PORTA_gc;
// PORTC mapped to VPORT2
// PORTD mapped to VPORT3
PORTCFG.VPCTRLB=PORTCFG_VP13MAP_PORTD_gc | PORTCFG_VP02MAP_PORTC_gc;
}

void main(void)
{
// Declare your local variables here
unsigned char n;
// Variable used to store Graphic Display
// controller initialization data
GLCDINIT_t glcd_init_data;

// Interrupt system initialization
// Optimize for speed
#pragma optsize- 
// Make sure the interrupts are disabled
#asm("cli")
// Low level interrupt: Off
// Round-robin scheduling for low level interrupt: Off
// Medium level interrupt: Off
// High level interrupt: Off
// The interrupt vectors will be placed at the start of the Application FLASH section
n=(PMIC.CTRL & (~(PMIC_RREN_bm | PMIC_IVSEL_bm | PMIC_HILVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_LOLVLEN_bm)));
CCP=CCP_IOREG_gc;
PMIC.CTRL=n;
// Set the default priority for round-robin scheduling
PMIC.INTPRI=0x00;
// Restore optimization for size if needed
#pragma optsize_default

// System clocks initialization
system_clocks_init();

// Event system initialization
event_system_init();

// Ports initialization
ports_init();

// Virtual Ports initialization
vports_init();

// Graphic Display Controller initialization
// The ST7920 connections are specified in the
// Project|Configure|C Compiler|Libraries|Graphic Display menu:
// E - PORTJ Pin 5
// R /W - PORTJ Pin 7
// RS - PORTJ Pin 6
// /RST - PORTC Pin 3
// DB4 - PORTJ Pin 1
// DB5 - PORTJ Pin 2
// DB6 - PORTJ Pin 3
// DB7 - PORTJ Pin 4

// Specify the current font for displaying text
glcd_init_data.font=font5x7;
// No function is used for reading
// image data from external memory
glcd_init_data.readxmem=NULL;
// No function is used for writing
// image data to external memory
glcd_init_data.writexmem=NULL;

glcd_init(&glcd_init_data);

while (1)
      {
      // Place your code here
      //lcd_putchar('1'); 
      lcd_gotoxy(0,0); 
      lcd_putsf("Hello world"); 
      //glcd_circle(20,20,20);
      //glcd_fillcircle(30,30,10);
      //glcd_arc(160,60,0,270,50);
      }
}

 

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

prsbsvrn wrote:
and this is my wiring

not surprising that you get "strange things" with that!

 

surprise

 

again, have you used your oscilloscope to see what's going on ?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you for answering.

about wiring i try my best no to connect pins wrong but about noise I don't know too.

And about that text, I edited that. and also I send some photos.

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


unfortunately yes this wiring is so complicated:(( but it's necessary.

I used oscilloscope and nothing is strange(they were 12 or 0 volt). Just DB7, if I touch DB7 with prob, it has weird output but it is that pin that let LCD to show characters.

this is DB7 output:

Last Edited: Tue. Jun 15, 2021 - 12:12 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


I ran parallel 8 bit and I still have those problems.

part of my code(it looks like parallel 4 bit).

// DB0 - PORTH Pin 5
// DB1 - PORTH Pin 6
// DB2 - PORTH Pin 7
// DB3 - PORTJ Pin 0
// DB4 - PORTJ Pin 1
// DB5 - PORTJ Pin 2
// DB6 - PORTJ Pin 3
// DB7 - PORTJ Pin 4
// E - PORTJ Pin 5
// R /W - PORTJ Pin 7
// RS - PORTJ Pin 6
// /RST - PORTC Pin 3
........................
lcd_gotoxy(0,0);
lcd_putsf("Hello world");

these are my output:

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

First off.   What country are you in ?

 

I copy-pasted your code from #29.   And removed the PORTF - PORTQ initialisation (because my 128A4U does not have these pins)

 

Then ran it on my 128A4U board.   It displayed "Hello World" in the built-in LCD font.  i.e. nothing to do with Graphics or glcd library.

The letters are perfectly formed.   But obviously I do not have a rats-nest wiring scheme.

 

If you want to use the ST7920 as a 16x4 AlphaNumeric LCD it will behave much like a regular 16x2 or 20x4 LCD with "alcd.h".

 

Seriously.   If you want Graphics,   select the glcd library.   Use the glcd_xxx() functions as documented in the IDE Library Help and whose signatures are available in "glcd.h"

 

David.

Last Edited: Tue. Jun 15, 2021 - 12:17 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


Was there a very strong wind blowing from the East when your o'scope picture was taken?...

 

 

I'm kind of guessing the transitions were supposed to be vertical ??

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

            First off.   What country are you in ?

I'm from Iran.

            It displayed "Hello World" in the built-in LCD font ...

Thank you for your response. So now I believe that my wiring makes problem.

            If you want Graphics,   select the glcd library.   Use the glcd_xxx() functions as documented in the IDE Library Help and whose signatures are available in "glcd.h" .

Actually I had problem with this simple code with LCD so I tried to fix it and after that using graphic lcd options. But inn one of my code I draw a circle and the whole picture was circle but some lines were besides that.

 

Thank you for all your help.

prsbsvrn

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

I would expect everything to work fine in Iran.   But it is your responsibility to solder joints and to connect wires properly.

"glcd.h" library should work 100%

 

Incidentally "alcd.h" using ST7920 will print text but the gotoxy() and alignment behaves differently.

 

David.

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

ST7920 is in U8g2 though couldn't identify a 4-bit mode.

 

Home · olikraus/u8g2 Wiki · GitHub

 

"Dare to be naïve." - Buckminster Fuller

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

😂I said that this output is weird. Again I tell that it is DB7 that when I touch Lcd starts to show character and the output is weird. But I can’t see this pin before touching because when I touch it, it changes.

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

In documents of code vision in c driver, there is a part about St7920 and it says that this function can run in graphic lcd and lcd.

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


It's not surprising your having problems with your solderless breadboard, in general they suck! 

The number one rule if I can impress upon you is: neatness counts above all else!

Your board should look like this, take the time to do it right, or spend 10x hours troubleshooting.

good luck with your project!

Jim

 

 

FF = PI > S.E.T

 

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

The rats-nest wiring in #28 does not look reliable.

 

Please "improve" your wiring.   When you have done this I am sure that the Codevision library will work 100% on your Xmega.

 

I am sure that U8g2 will work on a regular AVR using avr-gcc C Compiler.

I suspect that there would be some work involved to port U8g2 to CodevisionAVR C.

 

It all depends on how important it is to use Codevision versus avr-gcc.

Personally,  I would use Codevision C libraries.  

Or build C++ project with avr-g++ ,  C project with avr-gcc.

 

David.

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

Next time I try to fix this. 
Thank you

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

Actually my xmega and some of wiring are fixed on board. I want to try to use another xmega that isn’t on board to avoid this complicated wiring.

 

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

You should not need that many wires...you lcd does take soldered connections---if you can solder a cable to it, then there are that many less loose connections to deal with.

 

A lot of the cheap breadboards can give bad connections, just to make life interesting.  They used to use very springy metal, now often crappy metal (tin/steel?) that just bends away.

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

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

"Dare to be naïve." - Buckminster Fuller

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

avrcandies wrote:
(tin/steel?)
conversely

How can I judge the quality of a breadboard? | BusBoard Prototype Systems

[mid-page]

... the correct metal composition (phosphor bronze with plated nickel finish) ...

"Dare to be naïve." - Buckminster Fuller

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

Hi!

I've connected wires in a right way but my problem still doesn't solved. I don't know what the problem is. I suspect to glcd library . Could you send me your glcd library? And another question, how can I open and read "glcd.lib" file?

Thanks.

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

Sit down with a nice cup of tea.

 

Choose which target you want to use e.g. ATmega128A1U

Choose the wiring that you want to use.

Choose whether you want to use Codevision or GCC.

 

We can probably help you with your project.

Your "configuration" images in #28 are excellent.

The rats-nest wiring in #28 is horrible.

 

You need to get the Codevision demo examples working 100% before you write any programs for yourself.

 

David.

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

prsbsvrn wrote:
how can I open and read "glcd.lib" file?

A ".lib" is likely a pre-compiled binary - so you can't really "open & read" it.

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

You can read the built in Codevision Help from the IDE.   Both CV IDE and the AS7.0 IDE.  

You can read the glcd.h header file in both IDEs.

 

No,  you can't read pre-compiled library files.

 

You can always ask questions about examples or sections of the Library Help.

You need to quote which example or which part of the Help.   e.g. Xmega library functions, AVR library functions, ...

 

It must be difficult for a non-English speaker to read English documentation.  And then ask questions in English too !

 

Mind you,   Pavel Haiduc is from Romania.   And he does excellent English.

 

David.

Pages