Hello!
i want interfacing GLCD with Atmega328p(AVR series).
but my lcd dosen't look okay like this

and this is my circuit (i)

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!
i want interfacing GLCD with Atmega328p(AVR series).
but my lcd dosen't look okay like this

and this is my circuit (i)

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
-
590.1 KB Views: 5
Last edited: