Korzystam z gotowego kodu i efekt wygląda tak:
Jak widać na pierwszym obrazku po zmianie temperatury "2" została nadpisana "3". Dzieje się tak w każdym przypadku.
Kod z którego korzystam:
/*
S1D15705.c
-- definicja funkcji do obslugi wyswietlacza gragicznego EPSON S1D15705
*/
#ifndef F_CPU
#define F_CPU 1000000UL
#endif
#include <math.h>
#include <avr/io.h>
#include "S1D15705.h"
#include <util/delay.h>
#include <avr/pgmspace.h>
void delay(unsigned char t)
{
unsigned char i,j;
for (i=0; i<t; i++){
for (j=0; j<10; j++){
asm("nop");
}
}
}
void LCD_reset(void) //*
{
LCD_RD_SET();
LCD_WR_CLR();
LCD_DATA_SET(0xE2);
LCD_RS_CLR();
LCD_CS_CLR();
delay(5);
LCD_CS_SET();
LCD_RS_SET();
}
void lcdWait(void)
{
LCD_DATA_READ(); // ustawienie portu danych w tryb wejściowy
LCD_RS_CLR(); // niski stan na linii RS -> odczyt rejestru statusu
LCD_WR_SET(); // wysoki stan na linii RW -> odczyt z wyświetlacza
LCD_RD_CLR();
do { //pętla
// delay(); // opóźnienie
LCD_CS_CLR();
delay(2);
LCD_CS_SET();
} while((PD7==1)); // powtarzaj do
// wyzerowania flagi BUSY
LCD_DATA_WRITE(); // ustawienie portu danych w tryb wyjściowy
LCD_RS_SET();
LCD_WR_SET();
}
void command_write(unsigned char cmd)
{
LCD_RS_CLR();
LCD_RD_SET();
LCD_WR_CLR();
LCD_DATA_SET(cmd);
LCD_CS_CLR();
LCD_CS_SET();
LCD_WR_SET();
LCD_DATA_SET(0xFF);
}
void data_write(unsigned char dat)
{
lcdWait();
LCD_RS_SET();
LCD_RD_SET();
LCD_WR_CLR();
LCD_DATA_SET(dat);
LCD_CS_CLR();
LCD_CS_SET();
LCD_WR_SET();
LCD_DATA_SET(0xFF);
}
unsigned char data_read(void)
{
unsigned char dat;
LCD_RS_SET();
LCD_WR_SET();
LCD_CS_CLR();
LCD_CS_SET();
LCD_DATA_SET(0xAA);
LCD_DATA_READ();
LCD_RD_CLR();
LCD_CS_CLR();
LCD_CS_SET();
LCD_CS_CLR();
delay(1);
//lcdWait();
LCD_DATA_GET(dat);
LCD_CS_SET();
LCD_RD_SET();
//DDRD = 0xff;
// DATA=0xff;
LCD_DATA_WRITE();
return(dat);
}
void LCD_init(void)
{
unsigned char init[16]={0xe1, 0xab,0xa3,0xa0,0xc8,0x20,0x2b, 0x26, 0x81,0x13,0xaf, 0xa7 ,0x42,0xb0,0x10,0x03};
unsigned char i, j;
LCD_INIT_GPIO();
LCD_DATA_WRITE();
// RESET=0;
LCD_RST_CLR();
// RESET=1;
LCD_RST_SET();
for(i=0;i<16;i++) command_write(init[i]);
for(j=0xb0;j<0xb9;j++)
{
command_write(j);
command_write(0x10);
command_write(0x03);
for(i=0;i<162;i++)
//if(j!=0xb8)
//if(j%2==0) data_write(0x00);
// else
// data_write(0xff); //pozytyw
data_write(0x00); //negatyw
}
}
void LCD_pixel(unsigned char x,unsigned char y,unsigned char mode)
{
unsigned char x_h, x_l;
unsigned char tmp;
unsigned char page;
x+=3;
x_h=(x>>4); //wyzsze bity kolumny
x_l=x&0x0f; //nizsze bity kolumny
page=y/8; //wybor strony
tmp=y-page*8;
y=0x01<<tmp;
if(mode==0) y=~y;
command_write(0x40); //ustawienie linii poczatkowej
command_write(0xb0|page); //ustawienie numeru strony
command_write(x_h|0x10); //ustawienie kolumny
command_write(x_l);
tmp=data_read(); //wczytanie aktualnie wyswietlanych danych na stronie
if(mode==0) //nadpisanie danych
y&=tmp;
else
y|=tmp;
command_write(0xb0|page); //ustawienie numeru strony
command_write(x_h|0x10);
command_write(x_l);
data_write(y);
}
#define abs(x) ((x<0)?-x:x)
void LCD_line(unsigned char x0,unsigned char y0,unsigned char x1,unsigned char y1,unsigned char mode)
{
unsigned char x, y, dx, dy;
float x_0, y_0, x_1, y_1, x_, y_;
dx=abs(x0-x1);
dy=abs(y0-y1);
x_0=x0;
y_0=y0;
x_1=x1;
y_1=y1;
if(dx>=dy)
{
for(x=x0;x<=x1;x++)
{
x_=x;
y=((x_-x_0)/(x_1-x_0))*(y_1-y_0)+y_0;
LCD_pixel(x,y,mode);
}
}
else
{
for(y=y0;y<=y1;y++)
{
y_=y;
x=((y_-y_0)/(y_1-y_0))*(x_1-x_0)+x_0;
LCD_pixel(x,y,mode);
}
}
}
void LCD_rectangle(unsigned char x0,unsigned char y0,unsigned char x1,unsigned char y1,unsigned char mode,unsigned char fill)
{// (kolumna,
unsigned char i, j;
for(i=x0;i<=x1;i++)
{
LCD_pixel(i,y0,mode);
LCD_pixel(i,y1,mode);
if(fill!=0)
for(j=y1-1;j>y0;j--)
LCD_pixel(i,j,mode);
}
for(i=y0;i<=y1;i++)
{
LCD_pixel(x0,i,mode);
LCD_pixel(x1,i,mode);
}
}
void LCD_ellipse(unsigned char x0,unsigned char y0,unsigned char rx,unsigned char ry,unsigned char mode,unsigned char fill)
{
unsigned char x, y, j, xp, yp;
float a;
xp=0;
yp=0;
a=0.00;
do
{
x=rx*cos(a)+x0;
y=ry*sin(a)+y0;
if((x!=xp)||(y!=yp))
{
xp=x;
yp=y;
LCD_pixel(x,y,mode);
LCD_pixel(x,y0-y+y0,mode);
LCD_pixel(x0-x+x0,y,mode);
LCD_pixel(x0-x+x0,y0-y+y0,mode);
if(fill!=0)
{
for(j=y0-y+y0+1;j<y;j++)
{
LCD_pixel(x,j,mode);
LCD_pixel(x0-x+x0,j,mode);
}
}
}
a+=0.01;
}
while(a<1.58);
}
void LCD_frame(unsigned char x0,unsigned char y0,unsigned char x1,unsigned char y1,unsigned char size, unsigned char mode)
{
unsigned char i, j;
unsigned char x=mode;
for(i=x0;i<=x1;i++)
{
if(i%2==0){
x = mode;
for(j=0; j<size; j++){
LCD_pixel(i,y0+j,x);
LCD_pixel(i,y1+j,x);
x = ~x;
}
}else{
x = mode;
for(j=0; j<size; j++){
LCD_pixel(i,y0+j,~x);
LCD_pixel(i,y1+j,~x);
x = ~x;
}
}
}
for(i=y0;i<=y1+size-1;i++)
{
if(i%2==0){
x = mode;
for(j=0; j<size; j++){
LCD_pixel(x0+j,i,x);
LCD_pixel(x1+j,i,x);
x = ~x;
}
}else{
x = mode;
for(j=0; j<size; j++){
LCD_pixel(x0+j,i,~x);
LCD_pixel(x1+j,i,~x);
x = ~x;
}
}
}
}
void LCD_char(unsigned char c,unsigned char x,unsigned char y,unsigned char type,unsigned char mode)
{
unsigned int pos, b;
unsigned char i, p, j, bl, bh, sx, sy;
sx=(((unsigned char)type>>4)&0x0f)+1;
sy=((unsigned char)type&0x0f)+1;
if(sy>8)
sx<<=1;
pos=(c-32)*sx;
i=p=0;
bl=0;
bh=0;
while(i<sx)
{
//bl=chars5x8[pos+i];
bl = pgm_read_byte(&chars5x8[pos+i]);
b=(bh<<8)|bl;
for(j=0;j<sy;j++)
{
if((b&0x0001)!=0)
LCD_pixel(x+p,y+j,mode);
b>>=1;
}
i++;
p++;
}
}
void LCD_string(unsigned char *s,unsigned char x,unsigned char y,unsigned char type,unsigned char mode)
{
unsigned char cx, sx;
cx=x;
sx=(((unsigned char)type>>4)&0x0f)+1;
while(*s)
{
LCD_char(*s,cx,y,type,mode);
cx+=sx+1;
s++;
}
}
#ifndef F_CPU
#define F_CPU 1000000UL
#endif
#include <math.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#define LCD_DATA_SET(x) PORTA = x
#define LCD_DATA_GET(x) x = PINA
#define LCD_DATA_READ() DDRA = 0x00
#define LCD_DATA_WRITE() DDRA = 0xFF
#define LCD_DATA_PIN PINA
#define DISPLAY_STATUS_BUSY 0x80
#define LCD_RS_SET() PORTD |= (1<<PD3) //a0
#define LCD_RS_CLR() PORTD &= ~(1<<PD3)
#define LCD_RD_SET() PORTD |= (1<<PD1)
#define LCD_RD_CLR() PORTD &= ~(1<<PD1)
#define LCD_WR_SET() PORTD |= (1<<PD2)
#define LCD_WR_CLR() PORTD &= ~(1<<PD2)
#define LCD_CS_SET() PORTD |= (1<<PD6)
#define LCD_CS_CLR() PORTD &= ~(1<<PD6)
#define LCD_RST_SET() PORTD |= (1<<PD0)
#define LCD_RST_CLR() PORTD &= ~(1<<PD0)
#define LCD_INIT_GPIO() DDRD |= 0x4F; PORTD |=0x4F
#define OFF 0x00
#define ON 0x01
#define F3x6 0x25
#define F5x8 0x47
#define F4x12 0x3b
#define F6x12 0x5b
#define F7x12 0x6b
#define F8x16 0x7f
#define F10x16 0x9f
static const prog_uchar chars5x8[95*5]= {0x00,0x00,0x00,0x00,0x00, //spacja
0x00,0x06,0x5F,0x06,0x00, //!
0x07,0x03,0x00,0x07,0x03, //"
0x24,0x7E,0x24,0x7E,0x24, //#
0x24,0x2B,0x6A,0x12,0x00, //$
0x63,0x13,0x08,0x64,0x63, //%
0x36,0x49,0x56,0x20,0x50, //&
0x00,0x07,0x03,0x00,0x00, //'
0x00,0x3E,0x41,0x00,0x00, //(
0x00,0x41,0x3E,0x00,0x00, //)
0x08,0x3E,0x1C,0x3E,0x08, //*
0x08,0x08,0x3E,0x08,0x08, //+
0x00,0xE0,0x60,0x00,0x00, //
0x08,0x08,0x08,0x08,0x08, //-
0x00,0x60,0x60,0x00,0x00, //.
0x20,0x10,0x08,0x04,0x02, ///
0x3E,0x51,0x49,0x45,0x3E, //0
0x00,0x42,0x7F,0x40,0x00, //1
0x62,0x51,0x49,0x49,0x46, //2
0x22,0x49,0x49,0x49,0x36, //3
0x18,0x14,0x12,0x7F,0x10, //4
0x2F,0x49,0x49,0x49,0x31, //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,0x6C,0x6C,0x00,0x00, //:
0x00,0xEC,0x6C,0x00,0x00, //;
0x08,0x14,0x22,0x41,0x00, //<
0x24,0x24,0x24,0x24,0x24, //=
0x00,0x41,0x22,0x14,0x08, //>
0x02,0x01,0x59,0x09,0x06, //?
0x3E,0x41,0x5D,0x55,0x1E, //@
0x7E,0x11,0x11,0x11,0x7E, //A
0x7F,0x49,0x49,0x49,0x36, //B
0x3E,0x41,0x41,0x41,0x22, //C
0x7F,0x41,0x41,0x41,0x3E, //D
0x7F,0x49,0x49,0x49,0x41, //E
0x7F,0x09,0x09,0x09,0x01, //F
0x3E,0x41,0x49,0x49,0x7A, //G
0x7F,0x08,0x08,0x08,0x7F, //H
0x00,0x41,0x7F,0x41,0x00, //I
0x30,0x40,0x40,0x40,0x3F, //J
0x7F,0x08,0x14,0x22,0x41, //K
0x7F,0x40,0x40,0x40,0x40, //L
0x7F,0x02,0x04,0x02,0x7F, //M
0x7F,0x02,0x04,0x08,0x7F, //N
0x3E,0x41,0x41,0x41,0x3E, //O
0x7F,0x09,0x09,0x09,0x06, //P
0x3E,0x41,0x51,0x21,0x5E, //Q
0x7F,0x09,0x09,0x19,0x66, //R
0x26,0x49,0x49,0x49,0x32, //S
0x01,0x01,0x7F,0x01,0x01, //T
0x3F,0x40,0x40,0x40,0x3F, //U
0x1F,0x20,0x40,0x20,0x1F, //V
0x3F,0x40,0x3C,0x40,0x3F, //W
0x63,0x14,0x08,0x14,0x63, //X
0x07,0x08,0x70,0x08,0x07, //Y
0x61,0x51,0x49,0x45,0x43, //Z
0x00,0x7F,0x41,0x41,0x00, //[
0x02,0x04,0x08,0x10,0x20, //backslash
0x00,0x41,0x41,0x7F,0x00, //]
0x04,0x02,0x01,0x02,0x04, //^
0x80,0x80,0x80,0x80,0x80, //_
0x00,0x03,0x07,0x00,0x00, //`
0x20,0x54,0x54,0x54,0x78, //a
0x7F,0x44,0x44,0x44,0x38, //b
0x38,0x44,0x44,0x44,0x28, //c
0x38,0x44,0x44,0x44,0x7F, //d
0x38,0x54,0x54,0x54,0x08, //e
0x08,0x7E,0x09,0x09,0x00, //f
0x18,0xA4,0xA4,0xA4,0x7C, //g
0x7F,0x04,0x04,0x78,0x00, //h
0x00,0x00,0x7D,0x40,0x00, //i
0x40,0x80,0x84,0x7D,0x00, //j
0x7F,0x10,0x28,0x44,0x00, //k
0x00,0x00,0x7F,0x40,0x00, //l
0x7C,0x04,0x18,0x04,0x78, //m
0x7C,0x04,0x04,0x78,0x00, //n
0x38,0x44,0x44,0x44,0x38, //o
0xFC,0x44,0x44,0x44,0x38, //p
0x38,0x44,0x44,0x44,0xFC, //q
0x44,0x78,0x44,0x04,0x08, //r
0x08,0x54,0x54,0x54,0x20, //s
0x04,0x3E,0x44,0x24,0x00, //t
0x3C,0x40,0x20,0x7C,0x00, //u
0x1C,0x20,0x40,0x20,0x1C, //v
0x3C,0x60,0x30,0x60,0x3C, //w
0x6C,0x10,0x10,0x6C,0x00, //x
0x9C,0xA0,0x60,0x3C,0x00, //y
0x64,0x54,0x54,0x4C,0x00, //z
0x08,0x3E,0x41,0x41,0x00, //{
0x00,0x00,0x77,0x00,0x00, //|
0x00,0x41,0x41,0x3E,0x08, //}
0x02,0x01,0x02,0x01,0x00}; //~
void delay(unsigned char t);
void LCD_reset(void); //*
void lcdWait(void);
void command_write(unsigned char cmd);
void data_write(unsigned char dat);
unsigned char data_read(void);
void LCD_init(void);
void LCD_pixel(unsigned char x,unsigned char y,unsigned char mode);
//#define abs(x) ((x<0)?-x:x)
void LCD_line(unsigned char x0,unsigned char y0,unsigned char x1,unsigned char y1,unsigned char mode);
void LCD_rectangle(unsigned char x0,unsigned char y0,unsigned char x1,unsigned char y1,unsigned char mode,unsigned char fill);
void LCD_ellipse(unsigned char x0,unsigned char y0,unsigned char rx,unsigned char ry,unsigned char mode,unsigned char fill);
void LCD_frame(unsigned char x0,unsigned char y0,unsigned char x1,unsigned char y1,unsigned char size, unsigned char mode);
void LCD_char(unsigned char c,unsigned char x,unsigned char y,unsigned char type,unsigned char mode);
void LCD_string(unsigned char *s,unsigned char x,unsigned char y,unsigned char type,unsigned char mode);
Napisy wyświetlam tak:
LCD_string((unsigned char*) dzgodz, 10, 50, F5x8, 1);
LCD_string((unsigned char*) godz, 20, 50, F5x8, 1);
LCD_string((unsigned char*) ":", 30, 50, F5x8, 1);
LCD_string((unsigned char*) dzmin, 40, 50, F5x8, 1);
LCD_string((unsigned char*) min, 50, 50, F5x8, 1);
Wydaje mi się że w mojej sytuacji błąd może być w miejscu zastępowania wartości inną tylko co dokładnie może być źle ? Bardzo prosze o pomoc.