[SOLVED]graphic lcd (GLCD) interfacing, can't move x address issue

Thread Starter

Kim-JiHoon

Joined May 3, 2020
133
Hello!

i want interfacing GLCD with Atmega328p(AVR series).

but my lcd dosen't look okay like this

IMG_2385.jpg

and this is my circuit (i)

ATmega_Interface_GLCD128x64.png

i think circuit is fine.

i have so many other open source codes, but every time i get same result. (like first picture).

what is my problem?

my code? or any other (ex, Crystal poor contact,..etc)

this is my code!



C:
#define F_CPU 16000000UL

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

#define GLCD_DATA_PORT PORTB
#define GLCD_CTRL_PORT PORTC
#define GLCD_DPORT_DIR DDRB
#define GLCD_CPORT_DIR DDRC

#define RS PORTC0
#define RW PORTC1
#define E PORTC2

#define CS1 PORTC3
#define CS2 PORTC4
#define RST PORTC5

void glcd_cmd(unsigned char cmd);
void glcd_data(unsigned char dta);
void glcd_PageSelect(char pge);
void glcd_writeChar(char *chr);
void glcd_SetCursor(uint8_t x,uint8_t y);
void glcd_writeStr(char *str);
void glcd_writeImg(char *pxl);
void glcd_int(void);

int main(void)
{
    char xharA[5] = {0x7E, 0x11, 0x11, 0x11, 0x7E}; //A
    glcd_int();
  
    while(1){
        glcd_writeChar(xharA);
        _delay_ms(100);
    }
}

void glcd_cmd(unsigned char cmd){
    GLCD_DATA_PORT = cmd;
    GLCD_CTRL_PORT &= ~(1<<RS);
    GLCD_CTRL_PORT &= ~(1<<RW);
    GLCD_CTRL_PORT |=  (1<<E);
    _delay_ms(1);
    GLCD_CTRL_PORT &= ~(1<<E);
}
void glcd_data(unsigned char dta){
    GLCD_DATA_PORT = dta;
    GLCD_CTRL_PORT &= ~(1<<RS);
    GLCD_CTRL_PORT &= ~(1<<RW);
    GLCD_CTRL_PORT |=  (1<<E);
    _delay_ms(1);
    GLCD_CTRL_PORT &= ~(1<<E);
}
void glcd_PageSelect(char pge){
    switch(pge){
        case 0:
            GLCD_CTRL_PORT |=  (1 << CS1);
            GLCD_CTRL_PORT &= ~(1 << CS2);
            break;
        case 1:
            GLCD_CTRL_PORT |=  (1 << CS2);
            GLCD_CTRL_PORT &= ~(1 << CS1);
            break;
        case 2:
            GLCD_CTRL_PORT |=  (1 << CS1);
            GLCD_CTRL_PORT |=  (1 << CS2);
            break;
        case 3:
            GLCD_CTRL_PORT &= ~(1 << CS1);
            GLCD_CTRL_PORT &= ~(1 << CS2);
            break;
        default:
            GLCD_CTRL_PORT |=  (1 << CS1);
            GLCD_CTRL_PORT &= ~(1 << CS2);
            break;
    }
}
void glcd_int(void){
    GLCD_DPORT_DIR = 0xFF;
    GLCD_CPORT_DIR = 0xFF;
    GLCD_CTRL_PORT &= ~(1<<RST);
    _delay_ms(10);
    GLCD_CTRL_PORT |= (1<<RST);
    _delay_ms(1);
  
    glcd_PageSelect(2);
    _delay_ms(1);
    glcd_cmd(0x3F); //display on
    glcd_cmd(0xC0); //set start line
    _delay_ms(1);
    glcd_PageSelect(3);
    _delay_ms(1);
}

void glcd_SetCursor(uint8_t x,uint8_t y){
    glcd_cmd(0xB8+x);
    glcd_cmd(0x40+y);
}

void glcd_writeChar(char *chr){
    uint8_t i;
    glcd_SetCursor(0,0);
    for(i=0; i<5; i++){
        glcd_data(*(chr+i));
    }
}
void glcd_writeStr(char *str){
  
}
void glcd_writeImg(char *pxl){
  
}
 

Attachments

Last edited:

KeithWalker

Joined Jul 10, 2017
3,090
What are you using as a power source and how is it wired to the MCU chip and display? In one of my applications I had to connect a 100uF capacitor directly across the display power input to get it to work reliably.
Are you using the internal clock on the MCU chip? What frequency are you running it at?
 

Thread Starter

Kim-JiHoon

Joined May 3, 2020
133
What are you using as a power source and how is it wired to the MCU chip and display? In one of my applications I had to connect a 100uF capacitor directly across the display power input to get it to work reliably.
Are you using the internal clock on the MCU chip? What frequency are you running it at?
1. my power source
i'm using one main source, USB power (ISP connect)
2. my power circuit
MCU ------ GLCD VCC (with no capacitor)
my circuit is perfectly same as that circuit picture
3. clock using
external clock 16Mhz

is this power problem??

but i tested, 5v power supply direct but result was same

But i saw many of cases that working well with USB power (ISP connect).

i don't know what the problem....
 

mckenney

Joined Nov 10, 2018
125
This code appears to set RS low for both command and data. I'm not quite sure how you're getting any display at all.

I suggest you set RS high in glcd_data().
 

Thread Starter

Kim-JiHoon

Joined May 3, 2020
133
[SOLVED]

thank you all!

i solved this problem with "re wiring"

the problem was in OVERLAP PORT (COMMAND PORT - ISP PORT)

and code was little twisted

this is my solution

1. don't overlap port(ISP or XTAL)

2. give enough time to read/write instruction (recommend datasheet)
(I used nop instead of _delay)
(coeVison -> #asm("NOP")
(Atmel Studio -> vo volatile_asm("NOP")

3. run GLCD with supply
(desktop or laptop can't fully on GLCD)

4. add capacitor to VCC, GND


thank you all!!
 
Top