|
|
View previous topic :: View next topic |
Author |
Message |
endSly
Joined: 27 Jun 2007 Posts: 6
|
Extended GLCD Driver (T6963C) |
Posted: Thu Jun 28, 2007 8:46 am |
|
|
I've been working in this GLCD driver:
http://www.ccsinfo.com/forum/viewtopic.php?t=19957
Original source code by treitmey
Changelog:
v0.1
* Works with all resolutions (240x128, 240x64, 128x128), use glcd_init(240,128);
* Suports Graphics Functions glcd_pixel, glcd_pixel8, glcd_line, glcd_square, glcd_box, glcd_image8.
* First pixel is 0,0
Code: |
/////////////////////////////////////////////////////////////////////////
//// T6963C.c - T6963C driver ////
//// Not for comercial Use ////
//// Driver by treitmey Graphic functions and Resolution Select ////
//// by endSly ([email protected]) ////
//// ////
//// This file contains drivers for using a Tosiba T6963C controller ////
//// in parallel/8080(intel) mode. The T6963C is 240 pixels across ////
//// and 64 pixels down. The driver treats the upper left pixel 0,0 ////
//// ////
//// Connections are as follows: ////
//// /WR - - C4 ////
//// /RD - - C5 ////
//// C//D- - C6 ////
//// /RST- - C7 ////
//// DATA0-7 PORTD0-7 ////
//// LCD's FS is tied low (FS = 0 is 8x8 font) ////
//// ////
/////////////////////////////////////////////////////////////////////////
// 240 x 64 in the 8x8 font mode means that 30 characters across by
// 8 rows of characters may be displayed
#define set_tris_lcd(x) set_tris_d(x)
#define LCDColorBlack 0b1
#define LCDColorWhite 0b0
//TRIS DataBus=x, note:control bus (PORTC) always outputs
unsigned int16 TextHome = 0x0F00;//0x0780;
const int8 TextArea = 0x001E; // how many bytes before a new line
const int16 GraphicsHome = 0x0000;
const int8 GraphicsArea = 0x001E; // 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;
const int8 LCDBitSet = 0xF8;
const int8 LCDBitReset = 0xF0;
const int8 LCDBit0 = 0b000;
const int8 LCDBit1 = 0b001;
const int8 LCDBit2 = 0b010;
const int8 LCDBit3 = 0b011;
const int8 LCDBit4 = 0b100;
const int8 LCDBit5 = 0b101;
const int8 LCDBit6 = 0b110;
const int8 LCDBit7 = 0b111;
const int8 LCDSetPtr = 0xE0;
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 = 0xf82 // portC address on 18F452
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);
#inline
void glcd_init(unsigned int16 res_x, unsigned int16 res_y) {
int16 counter;
TextHome = (res_x/8)*res_y; //0x0F00;//0x0780;
set_tris_c(0x00); // graphic lcd control lines all output
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
// Set up the graphics and text areas
glcd_WriteCmd2(TextHome, 0x40);
glcd_WriteCmd2(TextArea, 0x41);
glcd_WriteCmd2(GraphicsHome, 0x42);
glcd_WriteCmd2(GraphicsArea, 0x43);
// set address to 0
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
}
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 #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) * line) + x;
glcd_WriteCmd2(location, 0x24);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
// Purpose: Clears LCD RAM
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
void glcd_clr(int16 location,int16 size)
{
////fprintf(DEBUG,"loc=%lu size=%lu\n\r",location,size);
// look very simular to the init,... doesn't it. : )
glcd_WriteCmd2(location,LCDSetPtr);
glcd_WriteCmd1(1,AutoModeWrite);
for (;size;size--)
{
glcd_WriteByteAuto(0x00);//clear ram
}
glcd_WriteCmd1(1,AutoModeReset);
}
/////////////////////////////////////////
// Graphics Controller by endSly (c)2007
// [email protected]
// Not for comercial use
/////////////////////////////////////////
unsigned int8 i; //General Purpouse variable
// glcd_pixel(x,y,c) sets pixel x,y with c color
void glcd_pixel(unsigned int8 x, unsigned int8 y, int1 c){
unsigned int8 x_H;
unsigned int8 x_L=0;
x_H = (x / 8);
x_L = 7 - (x - 8*x_H);
glcd_gotoxy(x_H,y,0); //Bug fixed, thanks to etiedon
if(c){
glcd_WriteCmd1(1,(LCDBitSet|x_L));
} else {
glcd_WriteCmd1(1,(LCDBitReset|x_L));
}
}
// glcd_pixel8(x,y,px8) sets 8 pixels in line.
void glcd_pixel8(unsigned int8 x, unsigned int8 y, int8 pixel8){
unsigned int8 x_H;
x_H = (x / 8);
glcd_gotoxy(x_H+1,y,0);
glcd_WriteCmd1(pixel8,0xc0);
}
// glcd_line(x0,y0, x1,y1, c) puts line from (x0, y0) to (x1, y1) with c color
#separate
void glcd_line(signed int16 x0, signed int16 y0,
signed int16 x1, signed int16 y1 , int1 c){
int16 x;
int16 y;
unsigned int16 n;
int1 m_case;
x=abs(x1-x0);
y=abs(y1-y0);
if (y > x){
n=(y1-y0);
m_case=1;
} else {
n=(x1-x0);
m_case=0;
}
for(i=0 ; i<=n ; i++){
if (m_case){
y=i + y0;
x=(y*(x1-x0))/(y1-y0) + x0;
} else {
x=i + x0;
y=(x*(y1-y0))/(x1-x0) + y0;
}
glcd_pixel(x, y,c);
}
}
// glcd_square(x0,y0,x1,y1, c) sets square
void glcd_square( unsigned int8 x0, unsigned int8 y0,
unsigned int8 x1, unsigned int8 y1 , int1 c){
glcd_line(x0,y0, x1,y0, c);
glcd_line(x1,y0, x1,y1, c);
glcd_line(x0,y1, x1,y1, c);
glcd_line(x0,y0, x0,y1, c);
}
// glcd_box(x0,y0,x1,y1, c)
void glcd_box( unsigned int8 x0, unsigned int8 y0,
unsigned int8 x1, unsigned int8 y1 , int1 c){
unsigned int8 x;
unsigned int8 y;
for(y=y0; y<=y1;y++){
for(x=x0; x<=x1;x++){
if((!(x%8)) && ((x1-x)>8)){
glcd_pixel8(x,y,0xFF*c); //Same time to write 8 pixel
x +=7 ;
} else {
glcd_pixel(x,y,c);
}
}
}
}
//glcd_image8 (*Pic, x, y, size_x, size_y)
void glcd_image8(int8 *pic_px, unsigned int8 x, unsigned int8 y,
unsigned int8 size_x, unsigned int8 size_y){
unsigned int8 px_y;
unsigned int8 px_x;
unsigned int8 px=0;
for(px_y=y; px_y<(y+size_y); px_y++){
for(px_x=x; px_x<(x+size_x); px_x+=8){
glcd_pixel8(px_x, px_y, *(pic_px+px));
px+=1;
}
}
}
#use fast_io(D)
|
Example program:
Code: |
#include <18F452.h>
//#device *=16
//#device adc=10
#use delay(clock=4000000)//,RESTART_WDT)
#use rs232(baud=9600, xmit=PIN_A2,rcv=PIN_A3)
#fuses XT, BROWNOUT, BORV27, PUT, STVREN, NOLVP
#include <T6963C.c>
void main() {
int n;
int8 bt_logo[11] = { //8x11 picture
0b00010000, // XX
0b00011000, // XXXX
0b00010100, // XX XX
0b01010010, // XX XX XX
0b00110100, // XXXX XX
0b00011000, // XXXX
0b00110100, // XXXX XX
0b01010010, // XX XX XX
0b00010100, // XX XX
0b00011000, // XXXX
0b00010000 // XX
};
glcd_init(240,128);
glcd_WriteByte(1, (LCDModeSet|LCDMode_XOR));
glcd_WriteByte(1, (LCDDispMode|LCDDisp_TXT|LCDDisp_GRH));
glcd_gotoxy(3,0,1); // 1 = text area of memory; note that there are only
// 8 rows of text possible
glcd_putc("Hi there.");
glcd_line(30,6,200,50,1);
glcd_line(3,6,20,50,1);
glcd_line(100,40,210,20,1);
glcd_box(14,14,100,60,1);
glcd_box(60,30,100,60,0);
glcd_square(20,12,180,50,1);
glcd_image8(&bt_logo[0],212,40,8,11);
glcd_image8(&bt_logo[0],216,40,8,11);
glcd_line(30,6,200,100,1);
glcd_square(2,32,130,113,1);
glcd_image8(&bt_logo[0],26,110,8,11);
}
| [/code]
Last edited by endSly on Mon Jul 30, 2007 3:57 am; edited 1 time in total |
|
|
etiedon
Joined: 23 Jul 2007 Posts: 12
|
|
Posted: Mon Jul 30, 2007 2:38 am |
|
|
Hi,
I think there is a problem with glcd_pixel or glcd_gotoxy functions.
When you try to put a pixel to 0,0, it start after 7-8 pixels. And you cant put any pixel to 231,232,233,234,...,240. It starts from the 0,0.
Here is the code;
Code: | glcd_pixel(0,0,1); //puts a pixel to (8,0)
glcd_pixel(232,0,1); //puts a pixel to (0,0) |
If you solve that problem it will be very good. And i am working on it too, if i solve i will post it here.. |
|
|
endSly
Joined: 27 Jun 2007 Posts: 6
|
|
Posted: Mon Jul 30, 2007 3:55 am |
|
|
thanks, the problem was here:
void glcd_pixel(unsigned int8 x, unsigned int8 y, int1 c){
unsigned int8 x_H;
unsigned int8 x_L=0;
x_H = (x / 8);
x_L = 7 - (x - 8*x_H);
glcd_gotoxy(x_H+1,y,0);
if(c){
glcd_WriteCmd1(1,(LCDBitSet|x_L));
} else {
glcd_WriteCmd1(1,(LCDBitReset|x_L));
}
} |
|
|
etiedon
Joined: 23 Jul 2007 Posts: 12
|
|
Posted: Wed Aug 01, 2007 6:05 am |
|
|
Hi,
I want to write a function that reverses the pixels in a specific area.
I wrote a piece of code like that, but it doesnt works. It only clears the area. I guess glcd_readbyte function returns zero.
Code: |
void ters_cevir(int8 x1,int8 y1, int8 x2, int8 y2)
{
int8 i,j,data;
for(i=y1;i<=y2;i++)
for(j=x1;j<=x2;j++)
{
glcd_gotoxy(j,i,0);
data=glcd_ReadByte();
glcd_pixel8(j,i,data);
}
}
|
I think i cant use glcd_ReadByte() function properly.
Thanks for your help. |
|
|
endSly
Joined: 27 Jun 2007 Posts: 6
|
|
Posted: Thu Aug 02, 2007 5:42 am |
|
|
I don't know why, but glcd_ReadByte doesn't go. I'll try to solve this |
|
|
etiedon
Joined: 23 Jul 2007 Posts: 12
|
|
Posted: Sat Aug 04, 2007 6:12 am |
|
|
One more thing;
We have to change x_H+1 to x_H in pixel8 function too ;) |
|
|
etiedon
Joined: 23 Jul 2007 Posts: 12
|
|
Posted: Tue Aug 07, 2007 5:46 pm |
|
|
And one more thing..
How can we reverse the text ?
I am trying to use glcd_writecmd1(0x05,0xc0);
0x05 reverses the area i guess..But of course it doesnt works :D |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
|
etiedon
Joined: 23 Jul 2007 Posts: 12
|
|
Posted: Sat Sep 29, 2007 10:46 am |
|
|
Thanks, i did it.
endSly, any improvements with read function? I am working it too, but cant work it properly. I also try to use screen peek, application notes says screen peek command both put the 1 byte text and graph to the stack and then you can take it with read command. But i am not successful with that to.
I have to read the lcd, i am taking an extarnal interrupt and cleaning the screen and put a error icon, and when back from the interrupt routine i want to put the last screen again (I can't redraw it cause i can be anywhere in the software) So i have to read all of the lcd, write it somewhere then take it and write to lcd again... :|
Thanks for your help. I translated your code for an ARM7 processor(lpc21xx) and add a mmc function to take screens from mmc and put it on the screen. I can share some of the code if anyone need. |
|
|
VoltageJoe
Joined: 16 Oct 2007 Posts: 1
|
CE-Signal |
Posted: Tue Oct 16, 2007 3:33 pm |
|
|
For some days I've been working with the T6963 and I want to use a PIC 18F452 and the T6963.h!
I have a question concerning the pinning......
These connections are clear!
//// Connections are as follows: ////
//// /WR - - C4 ////
//// /RD - - C5 ////
//// C//D- - C6 ////
//// /RST- - C7 ////
//// DATA0-7 PORTD0-7 ////
//// LCD's FS is tied low (FS = 0 is 8x8 font) ////
but what are you doing with /CE????
Thanks for your help!! |
|
|
etiedon
Joined: 23 Jul 2007 Posts: 12
|
|
Posted: Wed Oct 17, 2007 6:17 am |
|
|
It is always enable. That driver don't use /CE pin. And it works ok. |
|
|
rolirw
Joined: 17 Dec 2007 Posts: 2
|
Extended GLCD Driver (T6963C) |
Posted: Mon Dec 17, 2007 1:27 am |
|
|
Hello
can someone tell me how to show an ADC result on the Display
thanks in advance |
|
|
etiedon
Joined: 23 Jul 2007 Posts: 12
|
|
Posted: Mon Dec 17, 2007 5:04 am |
|
|
Will you show it in numbers?
Just get the ADC results from the registers, than divide it to numbers (like if result is ->1234, divide it to 1 , 2 ,3 ,4) and then use glcd_gotoxy command to set where you want to show the result.
Then use the glcd_putc() function to put the numbers to the screen. (for example, glcd_putc(adc_result[0]+48) , 48 for the ascii and the adc_result[0] is your first number of the result.) |
|
|
etiedon
Joined: 23 Jul 2007 Posts: 12
|
|
Posted: Wed Dec 19, 2007 4:56 am |
|
|
fvgm wrote: | hi, please i want a function to reverse the pixel in determinated area.
Can you send to me?
Thanks.. |
The right way to reverse the pixels in a determined area is the read the area from lcd, then making '1' to '0' and vice versa. But this driver's read function doesn't work properly. So you can do things below to reverse an area;
1) If you want to make a text reverse, first put the text to lcd and then put a black box (with glcd_box function) on it. And text will be reversed, then you can reverse it again by putting a white box on it this time.
2) If you want to reverse a bitmap, then read the bitmap array and put the every pixel reverse itself. If you want to reverse it again, this time put the array as it is.
But if you want only one pixel to reversed, you have to know what is the color of the pixel. But as i said read function doesnt work (if you can make it work please share.) Or you can check the t6963c's datasheet there are some useful commands there, you can try them. |
|
|
fvgm
Joined: 18 Dec 2007 Posts: 1
|
|
Posted: Thu Dec 20, 2007 12:38 pm |
|
|
Ok, works!
I have add "~" operator in every byte of my sprite.
Thanks! |
|
|
|
|
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
|