|
|
View previous topic :: View next topic |
Author |
Message |
malte Guest
|
T6963C problems |
Posted: Thu Aug 11, 2005 10:01 am |
|
|
Hello,
since a few days I�m trying to write a libary for my T6963C 128x128 Display. Could someone please take a look at my Code. The complete display is filled with chars. I tried to compare my code with code in this form. But I found no solution.
Another problem is my LCDText function. MPLAb says :"Bad expression syntax
". What�s wrong with it
Thanks
Malte
T6963C.h: Code: |
//*********************************************************
//T6963C.h
//
//CCS Compiler
//*********************************************************
#include <18F452.h>
#use delay(clock=20000000)
#fuses NOWDT,HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
//Werte f�r 18F452
#byte PORTD = 0xF83
#byte PORTC = 0xF82
#bit WR = PORTC.4
#bit RD = PORTC.5
#bit CD = PORTC.6
//diese Werte entsprechend �ndern
#define LCD_WIDTH 128
#define LCD_HEIGHT 128
//gew�nschter Wert auskommentieren
#define PIXPERBYTE 6
//#define PIXPERBYTE 8
//wieviele Bytes pro Zeile
#define BYTES_PER_ROW LCD_WIDTH/PIXPERBYTE
#define DISPLAYBYTES (unsigned int)(BYTES_PER_ROW * LCD_HEIGHT)
//Def. LCD Display Screen 0
#define T_BASE 0x0000//begin of textarea
#define T_END (unsigned int)(BYTES_PER_ROW * LCD_HEIGHT/8))//end of textarea
#define G_BASE (unsigned int)0x0000//base address of first screen
#define G_END G_BASE+DISPLAYBYTES-1
//Def. Screen 1
#define G_BASE1 G_BASE+DISPLAYBYTES
#define G_END1 G_BASE+DISPLAYBYTES-1
#define DATA_DIR_IN() set_tris_d(0xFF)
#define DATA_DIR_OUT() set_tris_d(0x00)
#define READ_DATA PORTD
#define WRITE_DATA PORTD
//8F=100011111
#define INIT_CONTROL_PINS() {set_tris_c(0x8F); set_tris_d(0xFF);}
#define WR_ON() {WR=1; delay_ms(1);}
#define WR_OFF() {WR=0; delay_ms(1);}
#define RD_ON() {RD=1; delay_ms(1);}
#define RD_OFF() {RD=0; delay_ms(1);}
#define CTRL() {CD=1; delay_ms(1);}
#define DATA() {CD=0; delay_ms(1);}
|
|
|
|
Guest
|
|
Posted: Thu Aug 11, 2005 10:02 am |
|
|
and
T6963C.c Code: | #include <T6963C.h>
void CheckBusy(void);
void WriteCTRL(unsigned char dat);
void WriteData1(unsigned char dat, unsigned char command);
void WriteData2(unsigned int dat, unsigned char command);
void WriteData(unsigned char dat);
void WriteCommand(unsigned char command);
void SetPixel(unsigned char xpos, unsigned char ypos, unsigned char mode);
void DisplayOn(void);
unsigned char ConvertText(unsigned char ch);
void LCDText(char *txt, unsigned char xpos, unsigned char ypos);
void ClearTextScreen(void);
void ClearGScreen(unsigned int begin, unsigned int end);
void ClearScreen();
//void SetGBaseLine(unsigned char line);
//void ShowHex(unsigned char dat);
//*********************************************************
void CheckBusy(void)
{
unsigned char by;
DATA_DIR_IN();
CTRL();
do
{
RD_OFF();
by=READ_DATA;
RD_ON();
}while((by&3) != 3);
DATA();
}
//*********************************************************
void WriteCTRL(unsigned char dat)
{
DATA_DIR_OUT();
CTRL();
WRITE_DATA=dat;
WR_OFF();
WR_ON();
DATA();
}
//*********************************************************
void WriteData1(unsigned char dat, unsigned char command)
{
WriteData(dat);
WriteCommand(command);
}
//*********************************************************
void WriteData2(unsigned int dat, unsigned char command)
{
WriteData((unsigned char)(dat&0xFF));
WriteData((unsigned char)(dat>>8));
WriteCommand(command);
}
//*********************************************************
void WriteData(unsigned char dat)
{
CheckBusy();
DATA_DIR_OUT();
DATA();
WRITE_DATA=dat;
WR_OFF();
WR_ON();
}
//*********************************************************
void WriteCommand(unsigned char command)
{
CheckBusy();
WriteCTRL(command);
}
//*********************************************************
void SetPixel(unsigned char xpos, unsigned char ypos, unsigned char mode)
{
unsigned int adress;
unsigned char tmp, pixel;
if(xpos>=LCD_WIDTH) return;
if(ypos>=LCD_HEIGHT) return;
adress=(unsigned int)G_BASE;
adress+=(unsigned int)BYTES_PER_ROW * (unsigned int)ypos;
adress+=(unsigned int)xpos/(unsigned int)PIXPERBYTE;
WriteData((unsigned char)(adress&0xFF));
WriteData((unsigned char)(adress>>8));
if(mode==0) pixel = 0xF0;
else pixel = 0xF8;
tmp=(PIXPERBYTE-1)-(xpos%PIXPERBYTE);
pixel|=tmp;
WriteCommand(pixel);
}
//*********************************************************
void DisplayOn(void)
{
INIT_CONTROL_PINS();//set WR,CE,RD,C/D to outputs
WR_ON();
RD_ON();
DATA();
DATA_DIR_OUT();
WriteData2(T_BASE, 0x40);
WriteData2(BYTES_PER_ROW, 0x41);
WriteData2(G_Base, 0x42);
WriteData2(BYTES_PER_ROW, 0x43);
WriteCommand(0x80);
WriteCommand(0x9C);
//WriteData2(0x0000, 0x24);
//WriteData2(0x0000, 0x24);
ClearScreen();
}
//*********************************************************
unsigned char ConvertText(unsigned char ch)
{
unsigned char tmp;
tmp=ch;
switch(ch)
{
case 196: tmp=0x6E; break; // �
case 228: tmp=0x64; break; // �
case 214: tmp=0x79; break; // �
case 246: tmp=0x74; break; // �
case 220: tmp=0x7A; break; // �
case 252: tmp=0x61; break; // �
case 223: tmp=223; break; // �
default: tmp-=0x20; break;
}
return tmp;
}
//*********************************************************
void LCDText( char *txt, unsigned char xpos, unsigned char ypos)
{
char ps;
WriteData2(xpos+(BYTES_PER_ROW)*ypos,0x24);
while(ps = txt) //Solange Zeichen gr��er 0x00
{
txt++;
if (ps== 0) break;
ps=ConvertText(ps); //�bersetzungstabelle aufrufen
WriteData1(ps,0xC0); //Write ps, Auto Inkrement
}
}
//*********************************************************
void ClearTextScreen(void)
{
int i;
WriteData2(T_BASE, 0x24);
for(i=0; i<(BYTES_PER_ROW * LCD_HEIGHT/8); i++)
{
WriteData1(0x00, 0xC0);
}
}
//*********************************************************
void ClearGScreen(unsigned int begin, unsigned int end)
{
unsigned int i;
WriteData2(begin,0x24); //Setze Startadresse des zu l�schenden Bereiches
for(i=begin; i<=end; i++) WriteData1(0x00,0xC0);
}
//*********************************************************
void ClearScreen()
{
ClearGScreen(G_BASE,G_END1);
ClearTextScreen();
//SetGCursor(0,0);
}
//*********************************************************
void SetGBaseLine(unsigned char line)
{
unsigned int adr;
adr=G_BASE;
adr+=BYTES_PER_ROW * line;
WriteData2(adr,0x42);
}
//*********************************************************
void ShowHex(unsigned char dat)
{
unsigned char tmp;
tmp=dat>>4;
if(tmp<0x0A) WriteData1(tmp+'0'-0x20,0xC0); //Write ps, Auto Inkrement
else WriteData1(tmp+0x37-0x20,0xC0);
tmp=dat&0x0F;
if(tmp<0x0A) WriteData1(tmp+'0'-0x20,0xC0); //Write ps, Auto Inkrement
else WriteData1(tmp+0x37-0x20,0xC0);
}
//Hauptprogramm
//*********************************************************
void main()
{
set_tris_b(0);
DisplayOn();
ClearScreen();
output_high(PIN_B7);
SetPixel(10,10,1);
//LCDText("Hello World",10,10);
}
|
|
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Thu Aug 11, 2005 10:53 am |
|
|
You should perhaps start with the driver from the code library.240x64
That we know works.
Once you can get SOMETHING to the display.(read and write bytes) Then the rest is just changing settings/parameters to get it to do 128x128.
http://www.ccsinfo.com/forum/viewtopic.php?t=19957
Also, Do you have a link to the spec. This would help us understand the requirements. |
|
|
maltejahn
Joined: 03 Aug 2005 Posts: 0
|
|
Posted: Thu Aug 11, 2005 12:44 pm |
|
|
Hi,
thanks for you reply. I tried the code. And it works.
Code: | const int16 TextHome = 0x0780;
const int8 TextArea = 0x001E; //
const int16 GraphicsHome = 0x0000;
const int8 GraphicsArea = 0x001E; // ne
|
I changed 0x01E to 0x0010. But near the last line I see a few dots.
My Display is a Toshiba TLX 1391(http://www.pollin.de/service/LCD/120241.zip)
I changed this im my Code:
Code: |
#byte PORTD = 0xF83
#byte PORTC = 0xF82
#bit WR = PORTC.4
#bit RD = PORTC.5
#bit CD = PORTC.6
#define T_BASE 0x0780
#define T_END 0x0010
#define G_BASE 0x0000
#define G_END 0x0010 |
Code: |
void DisplayOn(void)
{
INIT_CONTROL_PINS();//set WR,CE,RD,C/D to outputs
WR_ON();
RD_ON();
DATA();
DATA_DIR_OUT();
WriteData2(T_BASE, 0x40);
WriteData2(G_Base, 0x42);
WriteData2(BYTES_PER_ROW, 0x41);
WriteData2(BYTES_PER_ROW, 0x43);
WriteCommand(0x80);
WriteCommand(0x9C);
//WriteData2(0x0000, 0x24);
//WriteData2(0x0000, 0x24);
ClearScreen();
}
//*********************************************************
void CheckBusy(void)
{
unsigned char by;
DATA_DIR_IN();
CTRL();
do
{
RD_OFF();
by=READ_DATA;
RD_ON();
}while((by&3) != 3);
DATA();
}
//*********************************************************
void WriteCTRL(int dat)
{
DATA_DIR_OUT();
CTRL();
WRITE_DATA=dat;
WR_OFF();
WR_ON();
DATA();
}
//*********************************************************
void WriteData1(int16 dat, int command)
{
WriteData(dat);
WriteCommand(command);
}
//*********************************************************
void WriteData2(int16 dat, int command)
{
WriteData(dat&0xFF);
WriteData(dat>>8);
WriteCommand(command);
}
//*********************************************************
void WriteData(int dat)
{
CheckBusy();
DATA_DIR_OUT();
DATA();
WRITE_DATA=dat;
WR_OFF();
WR_ON();
}
//*********************************************************
void WriteCommand(unsigned char command)
{
CheckBusy();
WriteCTRL(command);
} |
and a little main()
Code: | void main()
{
set_tris_b(0);
DisplayOn();
ClearScreen();
output_high(PIN_B7);
SetPixel(10,10,1);
//LCDText("Hello World",10,10);
} |
It seems to me like my pic hangs somewhere(no output_high...) |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Thu Aug 11, 2005 1:23 pm |
|
|
maltejahn wrote: | I tried the code. And it works. |
Then you mention that the code hangs. No output_high.
So are you saying that library code works, but yours doesn't? Yours hangs? |
|
|
maltejahn
Joined: 03 Aug 2005 Posts: 0
|
|
Posted: Thu Aug 11, 2005 2:39 pm |
|
|
Hi,
sorry . The code from the Libary works( just a few problems. There are some dots where no dots should be).
My own code hangs.
This line didn�t work
->output_high(PIN_B7);
I try to find out whats wrong with my code
Malte |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Thu Aug 11, 2005 2:48 pm |
|
|
The pdf says the max address is 0x1FFF. Is that what is being cleared?
If it is all getting cleared. and you still see dots, try increasing the number.
Also note, in your code((((IN ALL CODE)))) you should have at infinite loop at the end. So the code doesn't fall off into no-man-land.
This is a good habit to get into.
while(1);
OR
while (TRUE){
}
OR
loop:
goto loop; |
|
|
maltejahn
Joined: 03 Aug 2005 Posts: 0
|
|
Posted: Sat Aug 13, 2005 2:37 pm |
|
|
Hi,
I still have some problems with my T6963C. I didnt understand exactly what you mean with:
Quote: | The pdf says the max address is 0x1FFF. Is that what is being cleared?
If it is all getting cleared. and you still see dots, try increasing the number. |
Do you mean this:
Code: | for (counter = 0; counter < 0x1fff; counter++)
{
glcd_WriteByteAuto(0); // fill everything with zeros
delay_us(10);
}
glcd_WriteByte(1, AutoModeReset);
} |
I tried to change this value. Nothing happend.
FS is 8x8(PIN low)
-I changed TextHome from 0x0780 to 0x0000.
- The glcd_pixel function didnt work. The position of the pixel is maybe 15,100. Not 50,50
Here are some pictures of my current screen:
http://home.arcor.de/maltejahn/LCD/DSCF0197.JPG
http://home.arcor.de/maltejahn/LCD/DSCF0198.JPG
http://home.arcor.de/maltejahn/LCD/DSCF0199.JPG
Thanks
Malte
Code: | #include <16F877a.h>
#include <math.h>
//#device *=16
//#device adc=10
#use delay(clock=4 000 000)
#fuses NOWDT,HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT
//#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#define set_tris_lcd(x) set_tris_d(x)
const int16 TextHome = 0x0000;
const int8 TextArea = 0x0010; // how many bytes before a new line
const int16 GraphicsHome = 0x0000;
const int8 GraphicsArea = 0x0010; // how many bytes before a new line
const int8 AutoModeWrite = 0xB0;
const int8 AutoModeRead = 0xB1;
const int8 AutoModeReset = 0xB2;
const int8 LCDModeSet = 0x80; // send this OR'd with the following
const int8 LCDMode_OR = 0b0000;
const int8 LCDMode_XOR = 0b0001;
const int8 LCDMode_AND = 0b0010;
const int8 LCDMode_TA = 0b0100; // TEXT ATTRIBUTE mode.
const int8 LCDMode_RAM = 0b1000; // 1=CG RAM, 0=internal CG ROM
const int8 LCDSetCursorPtr = 0x21; // cursor address
const int8 LCDSetCursorSize = 0xA0; // 1 line cursor
const int8 LCDDispMode = 0x90; // send this OR'd with the following
const int8 LCDDisp_BLK = 0b0001;
const int8 LCDDisp_CUR = 0b0010;
const int8 LCDDisp_TXT = 0b0100;
const int8 LCDDisp_GRH = 0b1000;
struct lcd_pin_def
{
BOOLEAN unused1; // C0
BOOLEAN unused2; // C1
BOOLEAN unused3; // C2
BOOLEAN unused4; // C3
BOOLEAN w_bar; // C4 Write bar active low
BOOLEAN r_bar; // C5 Read bar active low
BOOLEAN cd; // C6 Command/Data BAR 1=command 0=data
BOOLEAN reset_bar; // C7 Reset active low
int data : 8; // PortD=Data bus
};
struct lcd_pin_def LCD;
#byte LCD = 7
int glcd_ReadByte(void);
void glcd_WriteByte(int1 cd, int data);
void glcd_WriteByteAuto(int data);
void glcd_WriteCmd2(int16 data, int cmd);
void glcd_WriteCmd1(int data, int cmd);
void glcd_gotoxy(int x, int y, int1 text);
void SetPixel(int xpos, int ypos, char mode);
glcd_pixel(int16 x,int16 y, int1 color);
unsigned char ConvertText(int ch);
//*********************************************************
void glcd_init(void) {
int16 counter;
set_tris_lcd(0xff); //TRIS DATA bus,note:control bus always outputs
LCD.w_bar = 1; // INITIAL STATES OF CONTROL PINS
LCD.r_bar = 1; //
LCD.cd = 1; // command
LCD.reset_bar = 0; // perform a reset
delay_us(10); // delay for a reset
LCD.reset_bar = 1; // run
glcd_WriteCmd2(TextHome, 0x40);
glcd_WriteCmd2(TextArea, 0x41);
glcd_WriteCmd2(GraphicsHome, 0x42);
glcd_WriteCmd2(GraphicsArea, 0x43);
glcd_WriteCmd2(0x0000, 0x24);
glcd_WriteCmd2(0x0000, 0x24);
// Clear all RAM of LCD (8k)
glcd_WriteByte(1, AutoModeWrite);
for (counter = 0; counter < 0x1fff; counter++)
{
glcd_WriteByteAuto(0); // fill everything with zeros
delay_us(10);
}
glcd_WriteByte(1, AutoModeReset);
}
//*********************************************************
void glcd_WriteByte(int1 cd, int data)
{
int status = 0, temp = 0;
set_tris_lcd(0xff);
LCD.w_bar = 1;
LCD.r_bar= 1;
LCD.cd = 1;//defaults
while (status != 0x03) { // is LCD busy?
LCD.r_bar= 0;
temp = LCD.data;
LCD.r_bar = 1;
status = temp & 0x03;
}
set_tris_lcd(0x00); // All outputs
LCD.cd = cd; // Command/Data bar
LCD.data = data;
LCD.r_bar = 1; // not read
LCD.w_bar = 0; // write
LCD.w_bar = 1; // release
}
//*********************************************************
void glcd_WriteByteAuto(int data)
{
int status = 0, temp = 0; // status bits ARE DIFFERENT BITS THAN NORMAL
set_tris_lcd(0xff);
LCD.w_bar = 1;
LCD.r_bar = 1;
LCD.cd = 1; // defaults
while (status != 0x08) { // is LCD busy?
LCD.r_bar = 0;
temp = LCD.data;
LCD.r_bar = 1;
status = temp & 0x08;
}
set_tris_lcd(0x00); // All outputs
LCD.cd = 0; // This is always data, cd=0
LCD.data = data; // Put data on data bus
LCD.w_bar = 0; // write
LCD.w_bar = 1; // release
}
//*********************************************************
void glcd_WriteCmd1(int data, int cmd)
{
glcd_WriteByte(0, data);
glcd_WriteByte(1, cmd);
}
//*********************************************************
void glcd_WriteCmd2(int16 data, int cmd)
{
glcd_WriteByte(0, data & 0xff);
glcd_WriteByte(0, data>>8);
glcd_WriteByte(1, cmd);
}
//*********************************************************
int glcd_ReadByte(void)
{
int data = 0, status = 0, temp = 0;
set_tris_lcd(0xff);
LCD.w_bar = 1;
LCD.r_bar = 1;
LCD.cd = 1; // defaults
#asm nop nop #endasm
while (status != 0x03) { // is LCD busy?
LCD.r_bar = 0;
temp = LCD.data;
LCD.r_bar = 1;
status = temp & 0x03;
}
LCD.cd = 0; // Command/Data bar
LCD.r_bar = 0; // read
/////////////////////////////////////////////////////////
#asm nop #endasm // THIS PAUSE IS VERY NESSESARY !!!//
/////////////////////////////////////////////////////////
data = LCD.data;
LCD.r_bar = 1;
LCD.cd = 1;
return data; // Return the read data
}
//*********************************************************
void glcd_putc(char c) {
glcd_WriteCmd1(c - 0x20, 0xc0);
}
//*********************************************************
void glcd_gotoxy(int x, int y, int1 text) { // sets memory location to screen location x, y
// location 1,1 is upper left corner; text = 1 (text area), text = 0 (graphics area)
int16 location, home;
int line;
if (!text) {
home = GraphicsHome;
line = GraphicsArea;
}
else {
home = TextHome;
line = TextArea;
}
location = home + (((int16)y - 1) * line) + x - 1;
glcd_WriteCmd2(location, 0x24);
}
//*********************************************************
//Holger Klabundes Code
void SetPixel(int xpos, int ypos, char mode)
{
int adress;
char tmp, pixel;
if(xpos>=128) return;
if(ypos>=128) return;
adress=GraphicsHome;
adress+=16 * ypos;
adress+=xpos/8;
glcd_WriteByte(0,adress&0xFF);
glcd_WriteByte(0,adress>>8);
if(mode==0) pixel = 0xF0;
else pixel = 0xF8;
tmp=(8-1)-(xpos%8);
pixel|=tmp;
glcd_WriteByte(1,pixel);
}
//*********************************************************
//Code aus dem CCS Forum
glcd_pixel(int16 x,int16 y, int1 color)
{
int8 r=0,c=0;
c=color;
r=fmod(x,8);
glcd_WriteCmd2(GraphicsHome+(y*30+(x/8)),0x24);
glcd_WriteByte(1,0xf0|(c<<3) |(7-r));
}
//*********************************************************
void LCDText( char *txt, int xpos, int ypos)
{
char ps;
glcd_WriteCMD2(xpos+(8)*ypos,0x24);
while(ps = txt) //Solange Zeichen gr��er 0x00
{
txt++;
if (ps== 0) break;
ps=ConvertText(ps); //�bersetzungstabelle aufrufen
glcd_WriteCMD1(ps,0xC0); //Write ps, Auto Inkrement
}
}
//*********************************************************
unsigned char ConvertText(unsigned char ch)
{
unsigned char tmp;
tmp=ch;
switch(ch)
{
case 196: tmp=0x6E; break; // �
case 228: tmp=0x64; break; // �
case 214: tmp=0x79; break; // �
case 246: tmp=0x74; break; // �
case 220: tmp=0x7A; break; // �
case 252: tmp=0x61; break; // �
case 223: tmp=223; break; // �
default: tmp-=0x20; break;
}
return tmp;
}
//*********************************************************
#use fast_io(D)
void main() {
int n;
set_tris_a(0);set_tris_b(0);set_tris_c(0);
set_tris_d(0);set_tris_e(0);
set_tris_c(0x00); // graphic lcd control lines all output
glcd_init();
glcd_WriteByte(1, (LCDModeSet|LCDMode_XOR));
glcd_WriteByte(1, (LCDDispMode|LCDDisp_TXT|LCDDisp_GRH));
while(1)
{
for (n = 0; n< 8; n++) {
glcd_gotoxy(2,43+n,0); // 0 = graphics memory area; note that there
// are still 30 columns (30 x 8 pixels = 240), but now there are now 64
// rows so pixel location 9,43 translates into column 2, row 43. A little
// confusing, I know, but that's the way it works.
glcd_WriteCmd1(0xFF,0xc0);
}
delay_ms(1000);
glcd_pixel(50,50,1);
delay_ms(1000);
glcd_gotoxy(1,1,1); // 1 = text area of memory; note that there are only
// 8 rows of text possible
glcd_putc("Hi there");
}
} |
|
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Sat Aug 13, 2005 3:25 pm |
|
|
In respose to the first part. You are correct. I wanted to check that all memory 0x1FFF was being cleared.
so...
If you do nothing but clear the display. Do you still see the dots? |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Sat Aug 13, 2005 3:32 pm |
|
|
compair this set pixel with the code you wrote.
I think I tested most of this.
Code: |
///////////////////////////////////////////////////////////////////////
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
// Purpose: Turn a pixel on a graphic LCD on or off
// Inputs: x - the x coordinate of the pixel
// y - the y coordinate of the pixel
// color - ON or OFF
// Output: 1 if coordinate out of range, 0 if in range
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
glcd_pixel(int16 x,int16 y, int1 color)
{
int8 r=0,c=0;
c=color;//converting booean to an int8
if (x>=GLCD_COL)
{
bit_set(ERRORS,5);//ERRORS=bit 5. LCD x range exceeded
return (FALSE);
}
if (y>=GLCD_ROW)
{
bit_set(ERRORS,6);//ERRORS=bit 6. LCD y range exceeded
return (FALSE);
}
r=fmod(x,8);
glcd_WriteCmd2(GraphicsHome+(y*30+(x/8)),LCDSetPtr);
glcd_WriteCmd0(0xf0|(c<<3) |(7-r));
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
// Purpose: Draw a line on a graphic LCD using Bresenham's
// line drawing algorithm
// Inputs: (x1, y1) - the start coordinate
// (x2, y2) - the end coordinate
// color - ON or OFF
// Dependencies: glcd_pixel()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
void glcd_line(int x1, int y1, int x2, int y2, int1 color)
{
signed int x, y, addx, addy, dx, dy;
signed long P;
int i;
dx = abs((signed int)(x2 - x1));
dy = abs((signed int)(y2 - y1));
x = x1;
y = y1;
if(x1 > x2)
addx = -1;
else
addx = 1;
if(y1 > y2)
addy = -1;
else
addy = 1;
if(dx >= dy)
{
P = 2*dy - dx;
for(i=0; i<=dx; ++i)
{
glcd_pixel(x, y, color);
if(P < 0)
{
P += 2*dy;
x += addx;
}
else
{
P += 2*dy - 2*dx;
x += addx;
y += addy;
}
}
}
else
{
P = 2*dx - dy;
for(i=0; i<=dy; ++i)
{
glcd_pixel(x, y, color);
if(P < 0)
{
P += 2*dx;
y += addy;
}
else
{
P += 2*dx - 2*dy;
x += addx;
y += addy;
}
}
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
// Purpose: Draw a rectangle on a graphic LCD
// Inputs: (x1, y1) - the start coordinate
// (x2, y2) - the end coordinate
// fill - YES or NO
// color - ON or OFF
// Dependencies: glcd_pixel(), glcd_line()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
void glcd_rect(int x1, int y1, int x2, int y2, int fill, int1 color)
{
if(fill)
{
int y, ymax; // Find the y min and max
if(y1 < y2)
{
y = y1;
ymax = y2;
}
else
{
y = y2;
ymax = y1;
}
for(; y<=ymax; ++y) // Draw lines to fill the rectangle
glcd_line(x1, y, x2, y, color);
}
else
{
glcd_line(x1, y1, x2, y1, color); // Draw the 4 sides
glcd_line(x1, y2, x2, y2, color);
glcd_line(x1, y1, x1, y2, color);
glcd_line(x2, y1, x2, y2, color);
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
// Purpose: Draw a bar (wide line) on a graphic LCD
// Inputs: (x1, y1) - the start coordinate
// (x2, y2) - the end coordinate
// width - The number of pixels wide
// color - ON or OFF
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
void glcd_bar(int x1, int y1, int x2, int y2, int width, int1 color)
{
signed int x, y, addx, addy, j;
signed long P, dx, dy, c1, c2;
int i;
dx = abs((signed int)(x2 - x1));
dy = abs((signed int)(y2 - y1));
x = x1;
y = y1;
c1 = -dx*x1 - dy*y1;
c2 = -dx*x2 - dy*y2;
if(x1 > x2)
{
addx = -1;
c1 = -dx*x2 - dy*y2;
c2 = -dx*x1 - dy*y1;
}
else
addx = 1;
if(y1 > y2)
{
addy = -1;
c1 = -dx*x2 - dy*y2;
c2 = -dx*x1 - dy*y1;
}
else
addy = 1;
if(dx >= dy)
{
P = 2*dy - dx;
for(i=0; i<=dx; ++i)
{
for(j=-(width/2); j<width/2+width%2; ++j)
{
if(dx*x+dy*(y+j)+c1 >= 0 && dx*x+dy*(y+j)+c2 <=0)
glcd_pixel(x, y+j, color);
}
if(P < 0)
{
P += 2*dy;
x += addx;
}
else
{
P += 2*dy - 2*dx;
x += addx;
y += addy;
}
}
}
else
{
P = 2*dx - dy;
for(i=0; i<=dy; ++i)
{
if(P < 0)
{
P += 2*dx;
y += addy;
}
else
{
P += 2*dx - 2*dy;
x += addx;
y += addy;
}
for(j=-(width/2); j<width/2+width%2; ++j)
{
if(dx*x+dy*(y+j)+c1 >= 0 && dx*x+dy*(y+j)+c2 <=0)
glcd_pixel(x+j, y, color);
}
}
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
// Purpose: Draw a circle on a graphic LCD
// Inputs: (x,y) - the center of the circle
// radius - the radius of the circle
// fill - YES or NO
// color - ON or OFF
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
void glcd_circle(int x, int y, int radius, int1 fill, int1 color)
{
signed int a, b, P;
a = 0;
b = radius;
P = 1 - radius;
do
{
if(fill)
{
glcd_line(x-a, y+b, x+a, y+b, color);
glcd_line(x-a, y-b, x+a, y-b, color);
glcd_line(x-b, y+a, x+b, y+a, color);
glcd_line(x-b, y-a, x+b, y-a, color);
}
else
{
glcd_pixel(a+x, b+y, color);
glcd_pixel(b+x, a+y, color);
glcd_pixel(x-a, b+y, color);
glcd_pixel(x-b, a+y, color);
glcd_pixel(b+x, y-a, color);
glcd_pixel(a+x, y-b, color);
glcd_pixel(x-a, y-b, color);
glcd_pixel(x-b, y-a, color);
}
if(P < 0)
P+= 3 + 2*a++;
else
P+= 5 + 2*(a++ - b--);
} while(a <= b);
}
//////////////////////////////////////////////////////////////////
const BYTE TEXT[51][5] ={ 0x00, 0x00, 0x00, 0x00, 0x00, // SPACE
0x00, 0x00, 0x5F, 0x00, 0x00, // !
0x00, 0x03, 0x00, 0x03, 0x00, // "
0x14, 0x3E, 0x14, 0x3E, 0x14, // #
0x24, 0x2A, 0x7F, 0x2A, 0x12, // $
0x43, 0x33, 0x08, 0x66, 0x61, // %
0x36, 0x49, 0x55, 0x22, 0x50, // &
0x00, 0x05, 0x03, 0x00, 0x00, // '
0x00, 0x1C, 0x22, 0x41, 0x00, // (
0x00, 0x41, 0x22, 0x1C, 0x00, // )
0x14, 0x08, 0x3E, 0x08, 0x14, // *
0x08, 0x08, 0x3E, 0x08, 0x08, // +
0x00, 0x50, 0x30, 0x00, 0x00, // ,
0x08, 0x08, 0x08, 0x08, 0x08, // -
0x00, 0x60, 0x60, 0x00, 0x00, // .
0x20, 0x10, 0x08, 0x04, 0x02, // /
0x3E, 0x51, 0x49, 0x45, 0x3E, // 0
0x04, 0x02, 0x7F, 0x00, 0x00, // 1
0x42, 0x61, 0x51, 0x49, 0x46, // 2
0x22, 0x41, 0x49, 0x49, 0x36, // 3
0x18, 0x14, 0x12, 0x7F, 0x10, // 4
0x27, 0x45, 0x45, 0x45, 0x39, // 5
0x3E, 0x49, 0x49, 0x49, 0x32, // 6
0x01, 0x01, 0x71, 0x09, 0x07, // 7
0x36, 0x49, 0x49, 0x49, 0x36, // 8
0x26, 0x49, 0x49, 0x49, 0x3E, // 9
0x00, 0x36, 0x36, 0x00, 0x00, // :
0x00, 0x56, 0x36, 0x00, 0x00, // ;
0x08, 0x14, 0x22, 0x41, 0x00, // <
0x14, 0x14, 0x14, 0x14, 0x14, // =
0x00, 0x41, 0x22, 0x14, 0x08, // >
0x02, 0x01, 0x51, 0x09, 0x06, // ?
0x3E, 0x41, 0x59, 0x55, 0x5E, // @
0x7E, 0x09, 0x09, 0x09, 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, 0x41, 0x49, 0x3A, // 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, 0x0C, 0x02, 0x7F, // M
0x7F, 0x02, 0x04, 0x08, 0x7F, // N
0x3E, 0x41, 0x41, 0x41, 0x3E, // O
0x7F, 0x09, 0x09, 0x09, 0x06, // P
0x1E, 0x21, 0x21, 0x21, 0x5E, // Q
0x7F, 0x09, 0x09, 0x09, 0x76};// R
const BYTE TEXT2[44][5]={ 0x26, 0x49, 0x49, 0x49, 0x32, // S
0x01, 0x01, 0x7F, 0x01, 0x01, // T
0x3F, 0x40, 0x40, 0x40, 0x3F, // U
0x1F, 0x20, 0x40, 0x20, 0x1F, // V
0x7F, 0x20, 0x10, 0x20, 0x7F, // W
0x41, 0x22, 0x1C, 0x22, 0x41, // X
0x07, 0x08, 0x70, 0x08, 0x07, // Y
0x61, 0x51, 0x49, 0x45, 0x43, // Z
0x00, 0x7F, 0x41, 0x00, 0x00, // [
0x02, 0x04, 0x08, 0x10, 0x20, // \
0x00, 0x00, 0x41, 0x7F, 0x00, // ]
0x04, 0x02, 0x01, 0x02, 0x04, // ^
0x40, 0x40, 0x40, 0x40, 0x40, // _
0x00, 0x01, 0x02, 0x04, 0x00, // `
0x20, 0x54, 0x54, 0x54, 0x78, // a
0x7F, 0x44, 0x44, 0x44, 0x38, // b
0x38, 0x44, 0x44, 0x44, 0x44, // c
0x38, 0x44, 0x44, 0x44, 0x7F, // d
0x38, 0x54, 0x54, 0x54, 0x18, // e
0x04, 0x04, 0x7E, 0x05, 0x05, // f
0x08, 0x54, 0x54, 0x54, 0x3C, // g
0x7F, 0x08, 0x04, 0x04, 0x78, // h
0x00, 0x44, 0x7D, 0x40, 0x00, // i
0x20, 0x40, 0x44, 0x3D, 0x00, // j
0x7F, 0x10, 0x28, 0x44, 0x00, // k
0x00, 0x41, 0x7F, 0x40, 0x00, // l
0x7C, 0x04, 0x78, 0x04, 0x78, // m
0x7C, 0x08, 0x04, 0x04, 0x78, // n
0x38, 0x44, 0x44, 0x44, 0x38, // o
0x7C, 0x14, 0x14, 0x14, 0x08, // p
0x08, 0x14, 0x14, 0x14, 0x7C, // q
0x00, 0x7C, 0x08, 0x04, 0x04, // r
0x48, 0x54, 0x54, 0x54, 0x20, // s
0x04, 0x04, 0x3F, 0x44, 0x44, // t
0x3C, 0x40, 0x40, 0x20, 0x7C, // u
0x1C, 0x20, 0x40, 0x20, 0x1C, // v
0x3C, 0x40, 0x30, 0x40, 0x3C, // w
0x44, 0x28, 0x10, 0x28, 0x44, // x
0x0C, 0x50, 0x50, 0x50, 0x3C, // y
0x44, 0x64, 0x54, 0x4C, 0x44, // z
0x00, 0x08, 0x36, 0x41, 0x41, // {
0x00, 0x00, 0x7F, 0x00, 0x00, // |
0x41, 0x41, 0x36, 0x08, 0x00, // }
0x02, 0x01, 0x02, 0x04, 0x02};// ~
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
// Purpose: Write text on a graphic LCD
// Inputs: (x,y) - The upper left coordinate of the first letter
// textptr - A pointer to an array of text to display
// size - The size of the text: 1 = 5x7, 2 = 10x14, ...
// color - ON or OFF
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
void glcd_text57(int x, int y, char* textptr, int size, int1 color)
{
const BYTE bytes_per_char=5;
int i, j, k, l, m; // Loop counters
BYTE pixelData[bytes_per_char]; // Stores character data
for(i=0; textptr[i] != '\0'; ++i, ++x) // Loop through the passed string
{
if(textptr[i] < 'S') // Checks if the letter is in the first or second array
memcpy(pixelData, TEXT[textptr[i]-' '], bytes_per_char);
else if(textptr[i] <= '~') // Check if the letter is in the second array
memcpy(pixelData, TEXT2[textptr[i]-'S'], bytes_per_char);
else
memcpy(pixelData, TEXT[0], bytes_per_char); // Default to space
if(x+5*size >= GLCD_COL) // Performs character wrapping
{
x = 0; // Set x at far left position
y += 7*size + 1; // Set y at next position down
}
for(j=0; j<bytes_per_char; ++j, x+=size) // 5 bytes per character
{
for(k=0; k<7*size; ++k) // Loop through the vertical pixels
{
if(bit_test(pixelData[j], k)) // Check if the pixel should be set
{
for(l=0; l<size; ++l) // The next two loops change the
{ // character's size
for(m=0; m<size; ++m)
{
glcd_pixel(x+m, y+k*size+l, color); // Draws the pixel
}
}
}
}
}
}
}
//// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
//// Purpose: Fill the LCD screen with the passed in color.
//// Works much faster than drawing a rectangle to fill the screen
//// Inputs: ON - turn all the pixels on
//// OFF - turn all the pixels off
//// Dependencies: glcd_WriteByte()
//// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
//void glcd_fillScreen(int1 color)
//{
// int line_num, column;
// // Loop through the lines
// //fprintf(DEBUG,"Fill screen with %d\n\r",color);
// for(line_num = 0; line_num < 8; ++line_num)
// {
// glcd_WriteByte(0, 0xB0+line_num);
// glcd_WriteByte(0, 0x10);
// glcd_WriteByte(0, 0x00);
// // Loop through the horline_numzontal sectline_numons
// for(column = 0; column < 128; ++column)
// {
// glcd_WriteByte(1, 0xFF*color); // Turn all pixels on or off
// }
// }
//
//}
//// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
//// Purpose: Selects a font and sets up areas
//// Ouputs: A bit that is applied to the FS(font select) pin
//// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
//void glcd_FontSelect(int1 fs) {
// LCD.fs=fs;
// switch (fs)
// {
// case 1:
// glcd_WriteCmd2(TextHome,0x40);
// glcd_WriteCmd2(AreaSet_T,0x41);
// glcd_WriteCmd2(GraphicsHome,0x42);
// glcd_WriteCmd2(AreaSet_G,0x43);
// break;
// default:
// glcd_WriteCmd1(c-0x20,0xc0);
// break;
// }
//}
|
|
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Sat Aug 13, 2005 3:48 pm |
|
|
One other thing. The numbers don't seem right. Graphics is ON TOP OF the text area. Think of it as a linear address space.
Text space uses (16x16=256) from 0 to 256.
Then the next byte is graphics space.
graphics size is 128x128=16384 big
So graphics space is from 257 to 16641
OK? |
|
|
maltejahn
Joined: 03 Aug 2005 Posts: 0
|
|
Posted: Sun Aug 14, 2005 3:16 am |
|
|
Hi,
now it works -many thanks.
I have changed this:
-GraphicsHome from 0x0000 to 0x0101;
- at your glcd_pixel function
glcd_WriteCmd2(GraphicsHome+(y*16+(x/8)),0x24);
now i can put a pixel from 0,0 to 127,127
Malte |
|
|
LTS
Joined: 08 Dec 2005 Posts: 8
|
T6963 problem here... |
Posted: Fri Dec 16, 2005 8:46 pm |
|
|
Im trying to get my T6963 (128x64 pixels) to work with a PIC16F877A
I've tried the code here, but i doesn't work. I think my pic hangs somewhere.
Maybe you could post your code that works matlejahn?
Thanks in advance
LT |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Mon Dec 19, 2005 12:55 pm |
|
|
LT.
That too little to go on.
Start a NEW post. Don't tack onto this old one.
And post more info about what it is and isn't doing.
Did you change the #byte so the lcd pin def in correct for the 16F877A |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|