butterfly
Joined: 04 Jun 2006 Posts: 35
|
graphic lcd problem |
Posted: Mon Jun 26, 2006 2:41 am |
|
|
i 've worked to make my lcd work last 21 week. I use PIC16F877A and my lcd conroler is t6963c.. I check data sheets and application notes a lot but i can not find why it is not working..
my code
Code: |
#include <16F877A.h>
#use delay(clock=20000000)
#include <string.h>
#include <STDLIB.H>
const int16 GraphicsArea = 0x001E; // how many bytes before a new line
const int16 GraphicsHome = 0x0000;
const int8 GraphicsAreaset = 0x43; /////
const int8 GraphicsHomeset = 0x42; ///// 0x24
const int8 AddressPointerSet = 0x24;
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 QWE
{
BOOLEAN A0; //B0
BOOLEAN A1; // B1
BOOLEAN A2; // B2
BOOLEAN A3; // B3
BOOLEAN A4; // B4 Write bar active low
BOOLEAN A5; // B5 Read bar active low
BOOLEAN A6; // CB6 Command/Data BAR 1=command 0=data
BOOLEAN A7; // B7 Reset active low
};
struct QWE PORTA;
#byte PORTA = 0x05 // portB address on 16F877
struct lcd_pin_def
{
BOOLEAN unused1; //B0
BOOLEAN unused2; // B1
BOOLEAN unused3; // B2
BOOLEAN CE; // B3
BOOLEAN WR; // B4 Write bar active low
BOOLEAN RD; // B5 Read bar active low
BOOLEAN CD; // CB6 Command/Data BAR 1=command 0=data
BOOLEAN RST; // B7 Reset active low
};
struct lcd_pin_def LCD;
#byte LCD = 0x06 // portB address on 16F877
#byte PORTD = 0x08 // portd address on 16F877
void LCD_INITILAZE(void);
void wrdata(unsigned char data);
void wrcommand(unsigned char data);
void LCD_clear_graph(void);
void statuscheck(void);
void statuscheck1(void);
void wrdata1(unsigned char data);
void wrbyte(int1 cd, unsigned char data);
void main()
{
char i;
char k;
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_counters(RTCC_INTERNAL,RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
set_tris_a (0x00);
set_tris_b (0x00);
set_tris_d (0x00);
i=0;
k=0;
PORTD=0x07;
PORTD=0x00;
set_tris_d (0xff);
LCD_INITILAZE();
while (1)
{
PORTA=0xFF;
LCD_clear_graph();
}
}
LCD_INITILAZE(void)
{
LCD.CE=0; //SET ce
LCD.RD=1; //SET wr
LCD.WR=1; //SET wr
LCD.CD=1; // SET cd
LCD.RST=0;
DELAY_mS(10);
LCD.RST=1;
//set graphic home adress settings
wrbyte(0,GraphicsHome);
wrbyte(0,GraphicsHome>>8);
wrbyte(1,GraphicsHomeset);
//set graphic area
wrbyte(0,GraphicsArea);
wrbyte(0,GraphicsArea>>8);
wrbyte(1,GraphicsAreaset);
// SET THE ADREESS POINTER
wrbyte(0,GraphicsHome);
wrbyte(0,GraphicsHome>>8);
wrbyte(1,AddressPointerSet);
}
LCD_clear_graph(void)
{
int16 counter;
// Clear all RAM of LCD (8k)
wrbyte(1,AutoModeWrite);
for (counter = 0; counter < 0x0f00; counter++)
{
wrdata1(0xF0); // fill everything with zeros
}
wrbyte(1,AutoModeReset);
}
wrdata1(unsigned char data)
{
statuscheck1();
LCD.CD=0; //clear ce
output_d (data);
set_tris_d (0x00);
LCD.RD=1;//SET READ
LCD.CE=0; //clear ce
LCD.WR=0; //clear wr
delay_us(10);
LCD.CE=1; //SET ce
LCD.WR=1; //SET wr
LCD.CD; // SET cd*
set_tris_d (0xff);
}
statuscheck1(void) {
int status = 0, temp = 0;
set_tris_d (0xff);
LCD.wr = 1;
LCD.rd = 1;
LCD.cd = 1;
LCD.ce = 0;
while (status != 0x08) { // is LCD busy?
LCD.rd = 0;
temp = PORTD;
LCD.rd = 1;
status = temp & 0x08;
}
LCD.ce = 1;
}
wrbyte(int1 cd, unsigned char data)
{
statuscheck();
LCD.CD=cd;
output_d (data);
set_tris_d (0x00);
LCD.RD=1;//SET READ
LCD.CE=0; //clear ce
LCD.WR=0; //clear wr
delay_us(10);
LCD.CE=1; //SET ce
LCD.WR=1; //SET wr
set_tris_d (0xff);
}
statuscheck(void) {
int status = 0, temp = 0;
set_tris_d (0xff);
LCD.wr = 1;
LCD.rd = 1;
LCD.cd = 1;
LCD.ce = 0;
while (status != 0x03) { // is LCD busy?
LCD.rd = 0;
temp = PORTD;
LCD.rd = 1;
status = temp & 0x03;
}
LCD.ce = 1;
}
|
Any idea or advice you can give..
thanks for help... |
|