液晶TC6393单片机子程序

主页
兴趣
相册
喜好站点
个人简历
个人小新闻
算法程序

/*液晶TC6393,LCD128646 */

/*CPU: AT89C52 */

/*晶振:11.0592MHz*/

#include <reg51.h>

typedef unsigned char byte;
typedef unsigned int word;

#define C8952
#define Definecly 10

#include "HLSHZK2.DAT"
#include "T6963C.h"
#include "TestDef.h"

#define LCD_cmd_Port (*(char xdata *)0x8100)
#define LCD_dat_Port (*(char xdata *)0x8000)

sbit ADSCLK = P1^6;
sbit ADSel = P1^5;
sbit ADDOUT = P3^3;

void main()
{
unsigned int data xx;
unsigned int data i,j;

TH0=0x4C;
TH0=0x00;
TH1=0xFD;//9600bps
TL1=0xFD;
TMOD=0x21;
IE=0x82;//9A;
TCON=0x50;
SCON=0x40;
SBUF=0x00;
TR1=1;

xx=0;
delay=0;
ADSCLK=0;
ADSel=0;
P1=0x00;
Dis_point=0;
Grap_point=0;
delay=40;
i=0;j=0;
while(1) { 
if(i >=9999) i=0;
i++;
xx=i;
Dis_Buffer[0] =(xx / 1000) | 0x80;
xx = xx % 1000;
Dis_Buffer[1] =(xx/100) | 0x80;
xx = xx % 100;
Dis_Buffer[2] =(xx/10) | 0x80;
xx = xx % 10;
Dis_Buffer[3] =xx | 0x80;
Dis_Buffer[4] = 0;
Display16(Dis_Buffer,0,2);

Dis_Buffer[0]=1;
Dis_Buffer[1]=2;
Dis_Buffer[2]=3;
Dis_Buffer[3]=4;
Dis_Buffer[4]=5;
Dis_Buffer[5]=6;
Dis_Buffer[6]=7;
Dis_Buffer[7]=8;
Dis_Buffer[8]=0;
Display16(Dis_Buffer,0,0);
Dis_Buffer[0]=9;
Dis_Buffer[1]=10;
Dis_Buffer[2]=0;
Display16(Dis_Buffer,0,1);

P1=0xFF;
delay=20;
while (delay > 0);
P1=0;
delay=20;
while (delay > 0); 
}
}

void Rd_Wr_Ready () small
{
auto byte data Statue;
do {
Statue=LCD_cmd_Port & 0x23;
}while (Statue != 0x23);
}

void Auto_Wr_Ready() small
{
auto byte data Statue;
do {
Statue=LCD_cmd_Port & 0x28;
}while (Statue!=0x28);
}

void Auto_Write() small
{
auto byte data Statue;
do {
Statue=LCD_cmd_Port & 0x21;
}while (Statue!=0x21);
LCD_cmd_Port=Auto_write;
}

void Two_para_cmd(byte D1,byte D2,byte Cmd) small
{
Rd_Wr_Ready();
LCD_dat_Port=D1;
Rd_Wr_Ready();
LCD_dat_Port=D2;
Rd_Wr_Ready();
LCD_cmd_Port=Cmd;
}

void Non_para_cmd(byte Cmd) small
{
Rd_Wr_Ready();
LCD_cmd_Port=Cmd;
}

void gotoxy(byte x,byte y) small
{
if (x > 15) x=x%16;
if (y > 63) y=0;
Dis_point=y*16+x+0x400; //(Dis_point & 0xfc00)+
Rd_Wr_Ready();
LCD_dat_Port= (Dis_point & 0x00ff);
Rd_Wr_Ready();
LCD_dat_Port= (Dis_point & 0xff00) >> 8;
Rd_Wr_Ready();
LCD_cmd_Port=Address_p;
}

void clrscr()
{
word data i;
Two_para_cmd(0,0,Address_p);
Auto_Write();
for (i=0;i<=0x1fff;i++) {//
Auto_Wr_Ready();
LCD_dat_Port=0x00;
}
Dis_point=0;
Grap_point=0;
Non_para_cmd(Write_over);
Two_para_cmd(0,PAGE0,TEXT_addr);
Two_para_cmd(0,PAGE3,GRAP_addr);
gotoxy(0,0);
ZiKu=0;
}

void Init_Display()
{
Two_para_cmd(0,0,CGRAM_offset);
Two_para_cmd(0,0,Address_p);
Two_para_cmd(0,0,TEXT_addr);
Two_para_cmd(16,0,TEXT_wide);
Two_para_cmd(0,PAGE3,GRAP_addr);
Two_para_cmd(16,0,GRAP_wide);

Non_para_cmd(Cursor_shape | 0x07);
Non_para_cmd(Disp_swit | TEXT_disp | GRAP_disp);
/*光标闪烁、文本、图形显示,文本特征方式*/
Non_para_cmd(Disp_swit | Cursor_fls | Cursor_disp | TEXT_disp | GRAP_disp);
Non_para_cmd(Disp_modeA);
Non_para_cmd(0x9C);
}

void Display16(byte *p_Dis,byte x,byte y)
{
byte data i,AddL,AddH;
byte *p;
EA=0;
AddL=x;
AddH=y;
if (x > 15) AddL = 0;
if (y >= 4) AddH = 0;
AddH=AddH*16;
y=AddH;
p=p_Dis;

while(*p) {
if(*p < 0x80){
for (i=0;i<=15;i++) {
gotoxy(AddL,AddH); 
Rd_Wr_Ready();
LCD_dat_Port=HZK1[(*p -1) * 32+i*2+288];
Rd_Wr_Ready();
LCD_cmd_Port=0xC0;
gotoxy(AddL+1,AddH); 
Rd_Wr_Ready();
LCD_dat_Port=HZK1[(*p -1) * 32+i*2+1+288];
Rd_Wr_Ready();
LCD_cmd_Port=0xC0;
AddH++;
}
AddL++;
}
else
for (i=0;i<=15;i++) {
gotoxy(AddL,AddH); 
Rd_Wr_Ready();
LCD_dat_Port=HZK1[(*p & 0x0f) * 16+i];
Rd_Wr_Ready();
LCD_cmd_Port=0xC0;
AddH++;
}
AddH=y;
AddL++;
p++;
}
EA=1;
}