zhiling0229
Joined: 13 Sep 2006 Posts: 10
|
|
Posted: Sat Sep 23, 2006 12:02 am |
|
|
Sorry I didn't want to post the full code since it is very long. Here is the whole program code:
#include <16F877A.h>
#device *=16
#device adc=10
#use delay(clock=4000000)
#fuses XT, NOBROWNOUT, NOLVP, NOWDT
/////////////////////////////////////////////////////////////////////////
//// ////
//// 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)
//TRIS DataBus=x, note:control bus (PORTC) always outputs
const int16 TextHome = 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;
struct lcd_pin_def
{
BOOLEAN cd; // A0 Command/Data BAR 1=command 0=data
BOOLEAN r_bar; // A1 Read bar active low
BOOLEAN w_bar; // A2 Write bar active low
BOOLEAN reset_bar; // A3 Reset active low
BOOLEAN unused1; // A4
BOOLEAN unused2; // A5
BOOLEAN unused3; //
BOOLEAN unused4; //
int data : 8; // PortB=Data bus
};
struct lcd_pin_def LCD;
#byte LCD = 0x05 // portA address on 16F877A
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 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
// 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 < 0x20ff; 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 - 1) * line) + x - 1;
glcd_WriteCmd2(location, 0x24);
}
void glcd_logo (void)
{
int x, y;
int8 mask;
const unsigned int8 table[15][17] =
{
{0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0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x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xF,0xFF,0xFF,0xFF,0xFE,0x0,0x0},
{0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x7,0xFF,0xFF,0xFF,0xF8,0x0,0x0},
{0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1,0xFF,0xFF,0xFF,0xE0,0x0,0x0},
{0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xFF,0xFF,0xFF,0xC0,0x0,0x0},
{0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1F,0xFF,0xFE,0x0,0x0,0x0}
};
const unsigned int8 table4[5][17] =
{
{0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x3,0xFF,0xF0,0x0,0x0,0x0},
{0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
{0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
{0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
{0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
};
for(y=0; y<15; y++)
{
for(x=0; x<17; x++)
{
mask = table[y][x];
glcd_gotoxy(x+1+6,y+1,0);
glcd_WriteCmd1(mask,0xc0);
}
}
for(y=0; y<15; y++)
{
for(x=0; x<17; x++)
{
mask = table1[y][x];
glcd_gotoxy(x+1+6,y+16,0);
glcd_WriteCmd1(mask,0xc0);
}
}
for(y=0; y<15; y++)
{
for(x=0; x<17; x++)
{
mask = table2[y][x];
glcd_gotoxy(x+1+6,y+31,0);
glcd_WriteCmd1(mask,0xc0);
}
}
for(y=0; y<15; y++)
{
for(x=0; x<17; x++)
{
mask = table3[y][x];
glcd_gotoxy(x+1+6,y+46,0);
glcd_WriteCmd1(mask,0xc0);
}
}
for(y=0; y<5; y++)
{
for(x=0; x<17; x++)
{
mask = table4[y][x];
glcd_gotoxy(x+1+6,y+61,0);
glcd_WriteCmd1(mask,0xc0);
}
}
}
#use fast_io(D)
void main() {
setup_adc(ADC_OFF);
set_tris_a(0x00); // graphic lcd control lines all output
glcd_init();
glcd_WriteByte(1, (LCDModeSet|LCDMode_XOR));
glcd_WriteByte(1, (LCDDispMode|LCDDisp_TXT|LCDDisp_GRH));
glcd_logo();
}
Thanks |
|