?? 320240minechumo.c
字號:
#include<aduc836.h>
#include<intrins.h>
#include<User.h>
sbit bWRZ=P3^4;
sbit bRDZ=P3^5;
sbit bCSZ=P3^7;
sbit RS=P1^0;
sbit RST=P1^1;
sbit DATA=P0;
void Dis_DDRAM1_Pic(void);
void Dis_DDRAM2_Pic(void);
void Dis_Data_x(uchar x);
void delay1ms(unsigned int z)
{
unsigned int x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
unsigned char Read_Status(void)
{
unsigned char temp=0;
RS=1;
bCSZ=0;
bWRZ=1;
bRDZ=0;
temp=P0;
bRDZ=1;
bCSZ=1;
P0=0xff;
RS=0;
return (temp);
}
void Wr_Data(unsigned char Addr,unsigned char Data)
{
RS=1;
bCSZ=0;
bWRZ=0;
bRDZ=1;
P0=Addr;
bWRZ=1;
bCSZ=1;
RS=0;
bCSZ=0;
bWRZ=0;
P0=Data;
bWRZ=1;
bCSZ=1;
RS=1;
P0=0xff;
}
void Wrr_Addr(unsigned char cmd)
{
_nop_();
bCSZ = 0;
RS = 1;
bWRZ = 0;
P0 = cmd;
bWRZ = 1;
bCSZ = 1;
P0 = 0xff;
RS = 0;
}
void Wrr_Data(unsigned char Data)
{
_nop_();
bCSZ = 0;
RS = 0;
bWRZ = 0;
P0 = Data;
bWRZ = 1;
bCSZ = 1;
P0 = 0xff;
RS = 1;
}
unsigned char Read_Data(void)
{
uchar temp;
bWRZ = 1;
bCSZ = 0;
RS = 0;
bRDZ = 0;
temp = P0;
bRDZ = 1;
bCSZ = 1;
RS = 1;
return(temp);
}
void Rst()
{
RST=0;
delay1ms(30);
RST=1;
delay1ms(20);
}
void Lcd_On(void)
{
uchar temp;
Wrr_Addr(WLCR);
temp = Read_Data();
temp |= cSetb2;
Wrr_Addr(WLCR);
Wrr_Data(temp);
}
void Lcd_Graphic(void)
{
unsigned char temp;
temp=0;
Wrr_Addr(0);
temp = Read_Data();
temp &= 0xf7;
Wrr_Addr(0);
Wrr_Data(temp);
}
void Access_2Pages(void)
{
unsigned char temp;
temp=0;
Wrr_Addr(0x12);
temp=Read_Data();
temp|=0x02;
temp|=0x01;
Wrr_Addr(0x12);
Wrr_Data(temp);
}
void Set_Fill_PNTR_to_DDRAM(void)
{
unsigned temp;
temp=0;
Wrr_Addr(0xf0);
temp=Read_Data();
temp|=0x08;
Wr_Data(0xf0,temp);
do{
_nop_();
_nop_();
}while(Read_Status()&0x80);
}
void Lcd_Clear(void)
{
Lcd_Graphic();
Access_2Pages();
Wr_Data(0xe0,0x00);
Set_Fill_PNTR_to_DDRAM();
}
void Access_Page1(void)
{
uchar temp;
Wrr_Addr(MAMR);
temp = Read_Data();
temp &= cClrb1;
temp |= cSetb0;
Wrr_Addr(MAMR);
Wrr_Data(temp);
}
void Access_Page2(void)
{
uchar temp;
Wrr_Addr(MAMR);
temp = Read_Data();
temp &= cClrb0;
temp |= cSetb1;
Wrr_Addr(MAMR);
Wrr_Data(temp);
}
void Only_Show_Page1(void)
{
uchar temp;
Wrr_Addr(MAMR);
temp = Read_Data();
temp &= cClrb6;
temp &= cClrb5;
temp |= cSetb4;
Wrr_Addr(MAMR);
Wrr_Data(temp);
}
void Only_Show_Page2(void)
{
uchar temp;
Wrr_Addr(MAMR);
temp = Read_Data();
temp &= cClrb6;
temp &= cClrb4;
temp |= cSetb5;
Wrr_Addr(MAMR);
Wrr_Data(temp);
}
void LCD_Text(void)
{
uchar temp;
Wrr_Addr(WLCR);
temp = Read_Data();
temp |= cSetb3;
Wrr_Addr(WLCR);
Wrr_Data(temp);
}
void LCD_GotoXY(uchar x, uchar y)
{
Wrr_Addr(CURX);
Wrr_Data(x);
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
Wrr_Addr(CURY);
Wrr_Data((y & B1111_1111));
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
}
void LCD_FontSize(uchar buf)//15為四倍字體,10為三倍字體,5為兩倍字體
{
uchar temp;
buf = buf << 4;
temp = (buf & 0xF0) | (0x0F);
Wrr_Addr(FVHT);
Wrr_Data(temp);
}
void LCD_Inv(void)//寫入數據取反顯示
{
uchar temp;
Wrr_Addr(WCCR);
temp = Read_Data();
temp |= cSetb5; //@@@@@@@@@@@@@@
Wrr_Addr(WCCR);
Wrr_Data(temp);
}
void LCD_NoInv(void)
{
uchar temp;
Wrr_Addr(WCCR);
temp = Read_Data();
temp &= cClrb5; //@@@@@@@@@@@@@@
Wrr_Addr(WCCR);
Wrr_Data(temp);
}
void LCD_Bold(void)//顯示粗體字
{
uchar temp;
Wrr_Addr(WCCR);
temp = Read_Data();
temp |= cSetb4;
Wrr_Addr(WCCR);
Wrr_Data(temp);
}
void LCD_NoBold(void)
{
uchar temp;
Wrr_Addr(WCCR);
temp = Read_Data();
temp &= cClrb4;
Wrr_Addr(WCCR);
Wrr_Data(temp);
}
void Gray_Mode(void)//灰度模式,不支持漢字
{
uchar temp;
Wrr_Addr(MAMR);
temp = Read_Data();
temp &= cClrb6;
temp &= cClrb5;
temp &= cClrb4;
Wrr_Addr(MAMR);
Wrr_Data(temp);
}
void COM_DIR_239_0(void)//掃描模式修改,從239行開始掃描
{
uchar temp;
Wrr_Addr(MISC);
temp = Read_Data();
temp |= cSetb0;
Wrr_Addr(MISC);
Wrr_Data(temp);
}
void LCD_Rotate90(void)//文字旋轉90度
{
uchar temp;
Wrr_Addr(WCCR);
temp = Read_Data();
temp |= cSetb3;
Wrr_Addr(WCCR);
Wrr_Data(temp);
}
void LCD_LineDist_Adjust(uchar dis)//文字之間的行間距0-16
{
uchar temp;
Wrr_Addr(CHWI); // Line Distance
temp = Read_Data();
temp &= 0xf0;
temp |= (dis & 0x0f);
Wrr_Addr(CHWI); // Line Distance
Wrr_Data(temp);
}
unsigned char ADC_X1_MSB(void)
{
uchar temp;
Wrr_Addr(TPXR);
temp = Read_Data();
delay1ms(10);
return temp;
}
unsigned char ADC_Y1_MSB(void)
{
uchar temp;
Wrr_Addr(TPYR);
temp = Read_Data();
delay1ms(10);
return temp;
}
unsigned char ADC_X1_LSB(void)
{
uchar temp;
Wrr_Addr(TPZR);
temp = Read_Data();
temp &= 0xa0;
delay1ms(10);
return temp;
}
unsigned char ADC_Y1_LSB(void)
{
uchar temp;
Wrr_Addr(TPZR);
temp = Read_Data();
temp &= 0x0a;
delay1ms(10);
return temp;
}
unsigned int ADC_X1(unsigned char MSB,unsigned char LSB )
{
unsigned int temp1,temp2;
temp1 = MSB;
temp1 = temp1<<2;
temp2 = LSB;
temp2 = temp2>>6;
temp1 |= temp2;
return temp1;
}
unsigned int ADC_Y1(unsigned char MSB,unsigned char LSB )
{
unsigned int temp1,temp2;
temp1 = MSB;
temp1 = temp1<<2;
temp2 = LSB;
temp2 = temp2>>2;
temp1 |= temp2;
return temp1;
}
uchar Print_Hex(uchar buf)
{
uchar temp1,temp2,tempM;
temp1=buf;
temp1 = (temp1 >>4) & 0x0F;
tempM = temp1;
if(temp1 < 0x0A)
{
temp1 |= 0x30;
}
else temp1 = temp1 + 0x37;
LCD_Text();
Access_Page1();
LCD_GotoXY(0x21,0x10);
Wrr_Addr(0xb0);
Wrr_Data(temp1);
delay1ms(1);
temp2=buf;
temp2 = temp2 & 0x0F;
if(temp2 < 0x0A)
{
temp2 |= 0x30;
}
else temp2 = temp2 + 0x37;
//Wrr_Addr(0xb0);
Wrr_Data(temp2);
delay1ms(1);
return (tempM);
}
void Dis_Touch()
{
uchar temp=0;
unsigned char X1,Y1,X2,Y2;
uchar YMSB;
//count = 0;
Wrr_Addr(0xc0);
Wrr_Data(0xc4);
while(1)
{
Wrr_Addr(0x0f);
Wrr_Data(0x00);
delay1ms(10);
Wrr_Addr(0x0f);
temp = Read_Data();
if((temp&0x01)==0x01)
{
X1 = ADC_X1_MSB();
Y1 = ADC_Y1_MSB();
delay1ms(2);
if((X1 > 0x18)&&(X1 < 0xF0)&&(Y1 > 0x1B)&&(Y1 < 0xEA))
{
//count++;
do
{
X2 = ADC_X1_MSB();
Y2 = ADC_Y1_MSB();
if((X2 == X1)&&(Y2 == Y1))
{
X1 = X2;
Y1 = Y2;
YMSB = Print_Hex(Y1);
while(YMSB < 0x03)
{
Only_Show_Page2();
}
delay1ms(5);
temp = 0;
}
Wrr_Addr(0x0f);
Wrr_Data(0);
delay1ms(10);
Wrr_Addr(0x0f);
temp = Read_Data();
}while(temp & 0x01);//松手監測
Wrr_Addr(0x0f);
Wrr_Data(0);
}
}
}
}
void Dis_Ratate_90(void)//文字縱向顯示
{
int i;
LCD_Text();
LCD_Rotate90();
//COM_DIR_239_0();
LCD_LineDist_Adjust(12);
LCD_GotoXY(0,48);
Wrr_Addr(0xb0);
for(i=0;i<29;i++)
{
Wrr_Data(sRAiO1[i]);
delay1ms(1);
}
}
void test(void)
{
int i;
Lcd_Graphic();
Gray_Mode();
LCD_GotoXY(0x00,0x0);
Wrr_Addr(0xb0);
/*Mode2();
Mode3();
Mode4();*/
for(i=0;i<4800;i++)
{
Wrr_Data(0);
}
for(i=0;i<4800;i++)
{
Wrr_Data(0x55);
}
for(i=0;i<4800;i++)
{
Wrr_Data(0xaa);
}
for(i=0;i<4800;i++)
{
Wrr_Data(0xff);
}
}
void Dis_Text()
{
uchar i;
Access_Page1();
Only_Show_Page1();
LCD_Text();
LCD_GotoXY(0x00,0x0);
Wrr_Addr(0xb0);
for(i=0;i<33;i++)
{
Wrr_Data(sRAiO1[i]);
delay1ms(5);
}
LCD_GotoXY(0,16);
Wrr_Addr(0xb0);
for(i=0;i<40;i++)
{
Wrr_Data(sRAiO2[i]);
delay1ms(1);
}
LCD_Inv();
Wrr_Addr(0xb0);
for(i=0;i<21;i++)
{
Wrr_Data(sRAiO3[i]);
delay1ms(1);
}
LCD_NoInv();
LCD_GotoXY(0,64);
Wrr_Addr(0xb0);
for(i=0;i<40;i++)
{
Wrr_Data(sRAiO2[i]);
delay1ms(1);
}
LCD_FontSize(15);
LCD_GotoXY(0,80);
Wrr_Addr(0xb0);
for(i=0;i<12;i++)
{
Wrr_Data(sRAiO5[i]);
delay1ms(5);
}
LCD_FontSize(0);
LCD_GotoXY(0,160);
Wrr_Addr(0xb0);
for(i=0;i<40;i++)
{
Wrr_Data(i);
delay1ms(1);
}
LCD_Bold();
Wrr_Addr(0xb0);
for(i=40;i<80;i++)
{
Wrr_Data(i);
delay1ms(1);
}
/*LCD_NoBold();
Wrr_Addr(0xb0);
for(i=40;i<120;i++)
{
Wrr_Data(i);
delay1ms(1);
}*/
}
void Dis_DDRAM1_Pic(void)
{
int i;
Access_Page1();
Only_Show_Page1();
Lcd_Graphic();
LCD_GotoXY(0,0);
Wrr_Addr(0xb0);
for(i=0;i<9600;i++)
Wrr_Data(gImage_pic1[i]);
do{
_nop_();
_nop_();
}while(Read_Status()&0x80);
}
void Dis_DDRAM2_Pic(void)
{
int i;
Access_Page2();
//Only_Show_Page2();
Lcd_Graphic();
LCD_GotoXY(0,0);
Wrr_Addr(0xb0);
for(i=0;i<9600;i++)
Wrr_Data(gImage_pic2[i]);
do{
_nop_();
_nop_();
}while(Read_Status()&0x80);
}
void Initiate(void)
{
Wr_Data(0,0);
_nop_();
Wr_Data(1,4);
_nop_();
Wr_Data(3,0);
_nop_();
Wr_Data(0x0f,0);
_nop_();
Wr_Data(0x10,0);
_nop_();
Wr_Data(0x11,0);
_nop_();
Wr_Data(0x12,0x11);
_nop_();
Wr_Data(0x20,0x27);
_nop_();
Wr_Data(0x21,0x27);
_nop_();
Wr_Data(0x30,0xef);
_nop_();
Wr_Data(0x31,0xef);
_nop_();
Wr_Data(0x40,0);
_nop_();
Wr_Data(0x50,0);
_nop_();
Wr_Data(0x60,0);
_nop_();
Wr_Data(0x61,0);
_nop_();
Wr_Data(0x62,0);
_nop_();
Wr_Data(0x70,0);
_nop_();
Wr_Data(0x71,0);
_nop_();
Wr_Data(0x72,0);
_nop_();
Wr_Data(0x80,0);
_nop_();
Wr_Data(0x90,0);
_nop_();
Wr_Data(0xa0,0);
_nop_();
Wr_Data(0xa1,0);
_nop_();
Wr_Data(0xa2,0);
_nop_();
Wr_Data(0xa3,0);
_nop_();
Wr_Data(0xa4,0);
_nop_();
Wr_Data(0xc0,0);
_nop_();
Wr_Data(0xc1,0);
_nop_();
Wr_Data(0xc2,0);
_nop_();
Wr_Data(0xc3,0);
_nop_();
Wr_Data(0xc4,0);
_nop_();
Wr_Data(0xd1,0);
_nop_();
Wr_Data(0xe0,0);
_nop_();
Wr_Data(0xf0,0);
_nop_();
Wr_Data(0xf1,0);
_nop_();
}
void main()
{
delay1ms(20);
Rst();
Initiate();
Wrr_Addr(BTMR); //光標閃爍時間
Wrr_Data(0x20);
//Wr_Data(ITCR,0xff);
Lcd_On();
Lcd_Clear();
Dis_DDRAM2_Pic();
//test();
Dis_Touch();
while(1);
//Display_Picture();
//LCD_CmdWrite(ITCR);
//LCD_DataWrite(0xff);
//LCD_LineDist_Adjust(0);
//Dis_Text();
//Dis_Ratate_90();
/*Dis_DDRAM1_Pic();
Dis_DDRAM2_Pic();
while(1)
{
Only_Show_Page2();
delay1ms(100);
Only_Show_Page1();
delay1ms(100);
}*/
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -