CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

I need help with my graphic lcd based in T6963C

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
rafa



Joined: 28 Sep 2004
Posts: 0
Location: valencia

View user's profile Send private message AIM Address ICQ Number

I need help with my graphic lcd based in T6963C
PostPosted: Tue Sep 28, 2004 10:32 am     Reply with quote

I can't make my lcd function. I have found code for it but it isn't sufficient.
Please, someboby give me the code. I already have been 1 month workng and i don't find a solution.

Thanks, rafa
Oznog



Joined: 16 Oct 2004
Posts: 6

View user's profile Send private message

PostPosted: Sat Oct 16, 2004 1:59 am     Reply with quote

What is it doing?

Post your code, maybe we can fix it? I've done T6963C, graphics tasks, graphical fonts, it's all good.

And- the question that will make you find something breakable around you and smash it if this is it- did you give it the appropriate -Vee? Display won't show anything without it!
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Sat Oct 16, 2004 10:28 am     Reply with quote

Then post your question in the other forum. This one is for posting code to share with others and not for asking questions. Also do a search. That is the first thing you should do. I know I have seen routines posted for that controller. Heck, it is even in this forum!!!

http://www.ccsinfo.com/forum/viewtopic.php?t=19957&highlight=t6963c
rafa



Joined: 28 Sep 2004
Posts: 0
Location: valencia

View user's profile Send private message AIM Address ICQ Number

PostPosted: Mon Oct 18, 2004 5:02 am     Reply with quote

This is the code i'm using. Initially this war for a pic18f452. I have intented change it but i can't get function it for my pic16f877.

Thanks


/////////////////////////////////////////////////////////////////////////
//// EX_GLCD.C ////
//// ////
//// This example program demonstrates the use of a graphic LCD. ////
//// A reading is taken by the analog to digital converter and ////
//// displayed on the LCD. A bar shows the current reading relative ////
//// to the minimum and maximum values. If the reading is greater ////
//// than 4 volts, a warning message is displayed. A clock timer ////
//// demonstrates the use of the circle and line functions and shows ////
//// that the program is active. ////
//// ////
/////////////////////////////////////////////////////////////////////////
//// (C) Copyright 1996,2003 Custom Computer Services ////
//// This source code may only be used by licensed users of the CCS ////
//// C compiler. This source code may only be distributed to other ////
//// licensed users of the CCS C compiler. No other use, ////
//// reproduction or distribution is permitted without written ////
//// permission. Derivative programs created using this software ////
//// in object code form are not restricted in any way. ////
/////////////////////////////////////////////////////////////////////////

#if defined(__PCM__)
#include <16f877.h> //CAMBIO

#CASE
//#fuses HS,NOWDT,PROTECT,NOLVP,WRT,BROWNOUT,BORV45,NODEBUG,STVREN,PUT,NODEBUG
#fuses HS,NOWDT,NOPROTECT,NOLVP,PUT,BROWNOUT
//CAMBIO: he cambiado este fuses por el de arriba + put + brownout

//#fuses HS,NOWDT,PROTECT,NOLVP,WRT,BROWNOUT,BORV45,NODEBUG,STVREN,PUT,NODEBUG,WRT,WRTD,WRTB,WRTC,CPD,CPB
#use delay(clock=4000000) //CAMBIO: ulilizo una velocidad de 4000000
//CAMBIOS:¿hacen falta las 3 proximas lineas?
//#use rs232(baud=38400,xmit=PIN_C4,INVERT,stream=DEBUG) // STDERR(same as DEBUG)
//#use rs232(baud=38400,xmit=PIN_C4,INVERT,stream=STDERR) // STDERR(same as DEBUG)
//#use rs232(baud=19200,xmit=PIN_C6,rcv=PIN_C7,stream=RS485) // RS485 is the default
#zero_ram

#use fast_io(D) //CAMBIO



#include <stdlib.h>
//#include <stdlibm.h> //AQUI ESTA EL ERROR
#include <math.h>

int16 ERRORS;
#include "LCD_T6963C.h" //CAMBIO: incluyo esta libreria

void displayVoltage(int data) {
char voltValue[9]; // Stores the converted number
sprintf(voltValue, "%f", (float)data * .01960784);// Converts number to text
voltValue[4] = '\0'; // Limit shown digits to 3
glcd_rect(45, 18, 69, 25, YES, OFF); // Clear the old number
glcd_text57(45, 18, voltValue, 1, ON); // Write the new number
}

void main() {
int value1 = 0, value2 = 0, Warn = 0;
char voltText[] = "Volts", warning[] = "Warning";
float theta = 0;

//setup_adc_ports(RA0_ANALOG); // Set the ADC to read A0
//setup_adc(ADC_CLOCK_INTERNAL); // Set the ADC clock
//set_adc_channel(0); // Set ADC to use channel 0
glcd_init(ON);
glcd_WriteCmd0(LCDDispMode | LCDDisp_GRH); // Must initialize the LCD
//glcd_rect(1, 5, 126, 15, NO, ON); // Draw the rectangle around the bar
glcd_text57(70, 18, voltText, 1, ON); // Write "Volts" on the LCD
while(1);
glcd_circle(30, 47, 10, NO, ON); // Draw the clock circle

do{value1 = read_adc(); // Read a value from the ADC
displayVoltage(value1); // Display the reading
value1 = (value1 > 250) ? 250 : value1; // Keep the value under 251

if(value1 > 200 && !Warn) { // Check if reading is above 200
glcd_rect(45, 38, 124, 55, YES, ON); // Draw a filled black rectangle
glcd_text57(47, 40, warning, 2, OFF); // Write "Warning" on the LCD
Warn = 1; }
else if(value1 <=200){
glcd_rect(45, 37, 125, 55, YES, OFF); // Draw a filled white rectangle
Warn = 0; }

// The following 3 lines make the clock hand spin around
glcd_line(30, 47, 30+(int)(8*sin(theta)+.5), 47-(int)(8*cos(theta)+.5), OFF);
theta = (theta > 5.9) ? 0 : (theta += .3);
glcd_line(30, 47, 30+(int)(8*sin(theta)+.5), 47-(int)(8*cos(theta)+.5), ON);

glcd_rect(value1/2, 6, value2/2, 14, YES, OFF); // Clears the old bar
glcd_rect(1, 6, value1/2, 14, YES, ON); // Draws a new bar
value2 = value1; // Set old value to new
delay_ms(150); // Delay for a bit
} while (TRUE);
}









/////////////////////////////////////////////////////////////////////////
// Notice : Copyright (c) 2004 Sentinel Systems Corporation
// : All Rights Reserved
// Date : 01-05-2004
// Version: 1.0
/////////////////////////////////////////////////////////////////////////
//// LCD_T6963C.c
//// 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 ////
//// ////
//// glcd_init(mode) ////
//// glcd_pixel(x,y,color) ////
//// glcd_line(x1,y1,x2,y2,color) ////
//// glcd_rect(x1,y1,x2,y2,fill,color) ////
//// glcd_bar(x1,y1,x2,y2,width,color) ////
//// glcd_circle(x,y,radius,fill,color) ////
//// glcd_text57(x,y,textptr,size,color) ////
//// glcd_fillScreen(color) ////
/////////////////////////////////////////////////////////////////////////
//5/25/2004 9:26AM consolidating pins on port A & D
//5/25/2004 10:06AM consolidating pins on port C & D
//5/26/2004 7:48AM V1.2.4
//5/26/2004 7:48AM Fixing little graphics problems
//5/26/2004 10:22AM V1.2.5
//5/27/2004 8:31AM V1.2.6 Good LCD, RX/TX, now working on keypad
#ifndef GLCD_COL
#define GLCD_COL 240 // Used for text wrapping by glcd_text57 function and sanity check
#endif
#ifndef GLCD_ROW
#define GLCD_ROW 128 //CAMBIO: 64 en vez de 128
// Used for text wrapping by glcd_text57 function and sanity check
#endif
#define ON 1
#define OFF 0
#define YES 1
#define NO 0
#define set_tris_lcd(x) set_tris_c(0b00000000);set_tris_d(x) //CAMBIO: 0b00000000 por 0b10000000
#define set_lcd_defaults(x) set_tris_lcd(0xFF);LCD.w_bar=1;LCD.r_bar=1;LCD.cd=1;LCD.reset=1 //CAMBIO:RESET
#define glcd_WriteCmd0(x) glcd_WriteByte(1,x)
#define DispScn(x) glcd_WriteCmd2(TextHome+240*x,0x80) //CAMBIO: 0x80 por 0x40
#define LCDTxtAdr(s,x,y) 0x780+(240*s)+(AreaSet_T*y)+x
#define LCDSetPtr 0x24
/////////////////////////////////////////////////
//FS=0, 5x7 char in 8x8 field, 30char/line, 240 char total,graphic pics 8pixels/address, 0x780 grh addresses
//FS=1, 5x7 char in 6x8 field, 40char/line, 320 char total,graphic pics 6pixels/address, 0xA00 grh addresses
// - - - - 64K RAM - - - - 0 to 0xFFFF
// 0 grh home
// ...
// grh end (right before txt home)
// 0x780----(screen 0) or 0xA00 Txt home depends on FS
// 0x870----(screen 1) adding 240 for each screen
// 0x960----(screen 2)
// 0xA50----(screen 3)
//////////////////////////////////////////////
const int1 LCDFont = 0;//FS pin has internal pull-up. FS=1 unless grounded
const int8 LCDField = 8+(!LCDFont*2); //CAMBIO:8 POR 6 //FS=1 then field=6. FS=0 then field=8
const int8 LCDCharWidth = GLCD_COL /LCDField;
const int16 CharPerScn= LCDCharWidth*16; //CAMBIO: 16 por 8 //number of characters on a screen
const int16 GraphicsHome=0x0000; //RAM area where graphics is held
const int8 AreaSet_G= 30+(LCDFont*10); //how many bytes before a new line
const int16 TextHome = (GLCD_COL/LCDField)*128; //CAMBIO: 128 por 64//text comes right after graphics area
const int8 AreaSet_T= 30+(LCDFont*10); //how many bytes before a new line. 30 or 40
//////////////////////////////////////////////////////////////////

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 position
const int8 LCDSetCursorSize=0xA0; //Number of lines in the 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 LCDMaxBusyCount = 4;//will try count-1 times before giving up

//#include <stdlibm.h> //CAMBIO: lo puse yo

struct lcd_pin_def
{
BOOLEAN fs1; // C0
BOOLEAN md2; // C1
BOOLEAN reset; // C2
BOOLEAN ce; // C3
BOOLEAN w_bar; // C4 Write bar active low
BOOLEAN r_bar; // C5 Read bar active low
BOOLEAN cd; // C6 Command/Data BCR 1=command 0=data
BOOLEAN unusedC7; // C7
//BOOLEAN unusedC4; // C4
//BOOLEAN unusedC5; // C5
//BOOLEAN unusedC6; // C6
//BOOLEAN unusedC7; // C7
// int data : 8; // D=Data bus
};

struct lcd_pin_def LCD;


struct lcd_pin_def1
{
int data:8;
};

struct lcd_pin_def1 LCD1;


#byte LCD = 0x07 //CAMBIO //note: no semicolin 5=A0 on a 16F877A
//int data[8];
#byte LCD1 = 0x08

//#use fast_io(C)
//#use fast_io(D)

//#byte LCD = 0xF82 //note: no semicolin 5=A0 on a 16F877A
#bit LCDSTA0 = 0x8.0 //CAMBIO: he cambiado las proximas direcciones
#bit LCDSTA1 = 0x8.1
#bit LCDSTA2 = 0x8.2
#bit LCDSTA3 = 0x8.3

//---------------- Prototypes--------------------
//void glcd_FontSelect(int1 fs);
glcd_WriteByte(int1 cd, BYTE data);
glcd_WriteByteAuto(BYTE data);
BYTE glcd_ReadByte();
BYTE glcd_ReadByteAuto();
glcd_WriteCmd1(BYTE data, BYTE cmd);
glcd_WriteCmd2(int16 data, BYTE cmd);
glcd_pixel(int16 x,int16 y,int1 color);
glcd_clr(int16 location, int16 size);
void glcd_CpyScn(unsigned int16 ptr1,unsigned int16 ptr2);



//***************************************************//
// INICIALIZACION //
//***************************************************//
void glcd_init(int1 mode)
{

//fprintf(DEBUG,"LCD init\n\r");
set_lcd_defaults();
//reset
//LCD.w_bar=0; // preform a reset. When w_bar=0 & r_bar=0 then reset_bar=0
//LCD.r_bar=0; // preform a reset.

LCD.reset=0; //reset
delay_ms(1); // delay 1ms minimo,CAMBIO:yo pongo 2 por ejemplo
LCD.reset=1;

LCD.fs1=0;
LCD.md2=0;
LCD.ce=0;

//LCD.w_bar=1; // run
//LCD.r_bar=1; //
//Set up the graphics and text areas

glcd_WriteCmd2(TextHome,0x40); //set text home
glcd_WriteCmd2(AreaSet_T,0x41); //set text area
glcd_WriteCmd2(GraphicsHome,0x42);//set graphics home
glcd_WriteCmd2(AreaSet_G,0x43); //set graphics area
//cursor
glcd_WriteCmd0(LCDSetCursorSize | (0x01-1));//1 line cursor
glcd_WriteCmd2(0x0000,LCDSetCursorPtr);//0x yy xx , cursor position
//modes
glcd_WriteCmd0(LCDModeSet | LCDMode_XOR);
//glcd_WriteCmd0(LCDDispMode | LCDDisp_TXT |LCDDisp_BLK | LCDDisp_CUR);
glcd_WriteCmd0(LCDDispMode | LCDDisp_TXT);
//offset register
glcd_WriteCmd2(0x0002,0x22);//offset register=0x0002
//Clear all RAM of LCD
glcd_clr(0x0000,0xFFFF);//Clear all of RAM
//fprintf(DEBUG,"LCD init DONE.\n\r");
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
// Purpose: Copys a screen(CharPerScn bytes) from ptr2 to ptr1
// Inputs: ptr1 ptr2
// Ouputs:
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
void glcd_CpyScn(unsigned int16 ptr1,unsigned int16 ptr2)
{
int8 x;
int8 temp_array[128]; //CAMBIO
////fprintf(DEBUG,"ptr1=%lx ptr2=%lx\n\r",ptr1,ptr2);

//read data and put in array
glcd_WriteCmd2(ptr2,LCDSetPtr);
glcd_WriteCmd0(AutoModeRead);
for (x=0;x<CharPerScn;x++)
{
temp_array[x]=glcd_ReadByteAuto();
////fprintf(DEBUG,"0x%lx<-0x%x ",ptr2+x,temp_array[x]);

}
glcd_WriteCmd0(AutoModeReset);

//write data from array
glcd_WriteCmd2(ptr1,LCDSetPtr);
glcd_WriteCmd0(AutoModeWrite);
for (x=0;x<CharPerScn;x++)
{
glcd_WriteByteAuto(temp_array[x]);
////fprintf(DEBUG,"0x%x->0x%lx ",temp_array[x],ptr1+x);
}
glcd_WriteCmd0(AutoModeReset);


}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
// Purpose: Writes a byte of data from the current location
// Inputs: cd 1=command 0=data BYTE data
// Ouputs: Int1 1=success 0=failure
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
void glcd_WriteByte(int1 cd, BYTE data)
{
set_lcd_defaults();
LCD.r_bar=0; // Read
while(!LCDSTA0 && !LCDSTA1) //CAMBIO:&& por || //wait till both are one
;
////fprintf(DEBUG,".");
LCD.r_bar=1; // Release
// if(cd==0) {//fprintf(DEBUG,"D=%lx ",data);}
// if(cd==1) {//fprintf(DEBUG,"C=%lx ",data);}
set_tris_lcd(0x00); //All outputs
LCD.cd=cd; //Command/Data bar
LCD1.data=data;
LCD.w_bar=0; //write
set_lcd_defaults();
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
// Purpose: Writes continuous bytes of data from the current location
// Inputs: BYTE data
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
void glcd_WriteByteAuto(BYTE data)
{
set_lcd_defaults();
LCD.r_bar=0; // Read
while(!LCDSTA3) //wait till STA3 is one
;
////fprintf(DEBUG,".");
LCD.r_bar=1; // Release
set_tris_lcd(0x00); //All outputs
LCD.cd=0; //This is always data, cd=0
LCD1.data=data; //Put data on data bus
LCD.w_bar=0; //write
set_lcd_defaults();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
// Purpose: Reads continuous bytes of data from the current location, and inc
// Ouputs: Data byte read
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
BYTE glcd_ReadByteAuto(void)
{
int8 data;
set_lcd_defaults();
LCD.r_bar=0; // Read
while(!LCDSTA2) //wait till STA2 is one
;
////fprintf(DEBUG,".");
LCD.r_bar=1; // Release
set_tris_lcd(0xff); // All inputs
LCD.cd=0; // This is always data, cd=0
LCD.r_bar=0; // Read
data=LCD1.data; // Read data bus
LCD.r_bar=1; // Release
set_lcd_defaults();
return (data); //Return status
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
// Purpose: Writes a one byte of data and a command
// Inputs: BYTE data BYTE cmd
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
void glcd_WriteCmd1(BYTE data, BYTE cmd)
{
glcd_WriteByte(0,data);
glcd_WriteCmd0(cmd);
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
// Purpose: Writes a two data byte command
// Inputs: int16 data BYTE cmd
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
void glcd_WriteCmd2(int16 data, BYTE cmd)
{
int8 lcddata;
// glcd_WriteByte(0,data & 0xFF);
// glcd_WriteByte(0,data>>8);
// glcd_WriteCmd0(cmd);
// - - - - - - - - - - - - data - - - - - - - - -
set_lcd_defaults();
lcddata=data & 0xFF;
LCD.r_bar=0; // Read
while(!LCDSTA0 && !LCDSTA1) //CAMBIO:&& por || //wai t till both are one
;
LCD.r_bar=1; // Release
set_tris_lcd(0x00); //All outputs
LCD.cd=0; //Command/Data bar
LCD1.data=lcddata;
LCD.w_bar=0; //write
// - - - - - - - - - - - - data - - - - - - - - -
set_lcd_defaults();
lcddata=data>>8;
LCD.r_bar=0; // Read
while(!LCDSTA0 && !LCDSTA1) //CAMBIO:&& por || //wait till both are one
;
LCD.r_bar=1; // Release
set_tris_lcd(0x00); //All outputs
LCD.cd=0; //Command/Data bar
LCD1.data=lcddata;
LCD.w_bar=0; //write
// - - - - - - - - - - - - command- - - - - - - -
set_lcd_defaults();
LCD.r_bar=0; // Read
while(!LCDSTA0 && !LCDSTA1) //CAMBIO:&& por || //wait till both are one
;
LCD.r_bar=1; // Release
set_tris_lcd(0x00); //All outputs
LCD.cd=1; //Command/Data bar
LCD1.data=cmd;
LCD.w_bar=0; //write
set_lcd_defaults();
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
// Purpose: Clears LCD RAM
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
void glcd_clr(int16 location,int16 size)
{
////fprintf(DEBUG,"loc=%lu size=%lu\n\r",location,size);
glcd_WriteCmd2(location,LCDSetPtr);
glcd_WriteCmd0(AutoModeWrite);
for (;size;size--)
{
glcd_WriteByteAuto(0x00);//clear ram
}
glcd_WriteCmd0(AutoModeReset);
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
// Purpose: Reads a byte of data from the current location
// Ouputs: A byte of data read from the LCD
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
BYTE glcd_ReadByte()
{
int8 data=0;
//do a read and don't inc command
glcd_WriteCmd0(0xc5);
//- - - - - - - - - - -
set_lcd_defaults();
LCD.r_bar=0; // Read
while(!LCDSTA0 && !LCDSTA1) //CAMBIO:&& por || //wait till both are one
;
////fprintf(DEBUG,".");
LCD.r_bar=1; // Release
LCD.cd=0; // Command/Data bar
LCD.r_bar=0; // Read
data=LCD1.data; // Latch data
LCD.r_bar=1; // Release
set_lcd_defaults();
////fprintf(DEBUG,"-0x%x-",data);
return(data); //Return the read data
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
// Purpose: Sends data to LCD
// Ouputs: A byte of data read from the LCD
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
void glcd_putc( char c) {
////fprintf(DEBUG,"P=0x%x ",c);
switch (c) {
// case '\f' : lcd_send_byte(0,1);
// delay_ms(2);
// break;
// case '\n' : lcd_gotoxy(1,2); break;
// case '\b' : lcd_send_byte(0,0x10); break;
default : glcd_WriteCmd1(c-0x20,0xc0);break;//Write to LCD autoinc

}
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
// 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') //falta un = // 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;
// }
//}

////////////////////////////////JUNK YARD ////////////////////////////////////
////////////////////////////////JUNK YARD ////////////////////////////////////
////////////////////////////////JUNK YARD ////////////////////////////////////
////// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
////// Purpose: Reads status of LCD
////// Ouputs: Returns 1=busy 0=not busy
////// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
////int1 glcd_notbusy()
////{
//// BYTE data,count=0; // Stores the data read from the LCD
//// do
//// {
//// set_tris_lcd(0xFF) ; // Port D inputs
//// LCD.cd=1; //Instruction
//// LCD.r_bar=0; //Read
//// LCD.w_bar=1; //not write
//// data=LCD.data;
//// LCD.r_bar=1; //Release Read
//// set_tris_lcd(0xFF);//Port D tristate
//// ++count;
////// //fprintf(DEBUG,"count=%U\r",count);
//// if (count>3){return(0);}
//// }while (!bit_test(data,1) || !bit_test (data,0) );//til bit0 and bit1==1
//// return (1); //Return status
////}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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